我有一个问题,当使用网络摄像头作为源时,输入示例大于分配器提供的缓冲区大小,如您在此代码的ASSERT语句中所见。
HRESULT MCMyOutputPin::Deliver(IMediaSample* sample)
{
HRESULT hr = NO_ERROR;
myLogger->LogDebug("In Outputpin Deliver", L"D:\\TEMP\\yc.log");
if (sample->GetActualDataLength() > 0)
{
IMediaSample *outsample;
hr = m_pAllocator->GetBuffer(&outsample, NULL, NULL, NULL);
if (FAILED(hr))
{
return hr;
}
BYTE* sampleBuffer = NULL;
BYTE* newBuffer = NULL;
long ulDataLen = sample->GetSize();
long datalenout = outsample->GetSize(); //this is always 92160
outsample->GetPointer(&newBuffer);
ASSERT(datalenout >= ulDataLen); //This fails
memcpy((void *)newBuffer, (void *)sampleBuffer, ulDataLen);
m_pInputPin->Receive(outsample);
outsample->Release();
sample->Release();
}
return hr;
//Forward to filter
}
因此memcpy肯定会失败,因为您无法将某些内容复制到小于数据的缓冲区中。
所以我尝试在
DecideBufferSize
中调整buffersize:HRESULT MCMyOutputPin::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProps)
{
myLogger->LogDebug("On DecideBufferSIze", L"D:\\TEMP\\yc.log");
ALLOCATOR_PROPERTIES act;
HRESULT hr;
// by default we do something like this...
pProps->cbAlign = 1;
pProps->cBuffers = 30;
long buffersize = this->CurrentMediaType().lSampleSize * 3;
pProps->cbBuffer = 10 * 10 * 1000;
pProps->cbPrefix = 0;
hr = pAlloc->SetProperties(pProps, &act);
if (FAILED(hr)) return hr;
// make sure the allocator is OK with it.
if ((pProps->cBuffers > act.cBuffers) ||
(pProps->cbBuffer > act.cbBuffer) ||
(pProps->cbAlign > act.cbAlign))
return E_FAIL;
return NOERROR;
}
被忽略。定位器返回的样本大小始终为92160。
我还确保实际调用DecideBufferSize方法。
如何设置Allocator-> GetBuffer()返回的Buffer的大小?
最佳答案
MSDN states it相当准确:
缓冲区大小的决定是协商的问题。您的设置要求并不意味着将被接受。
92160到底有什么问题,是什么让您认为它无效?您正在寻找错误问题的答案。如果您拥有分配器,则可以设置其缓冲区大小。如果您不拥有和管理它,那么您必须以已经拥有的规模生活。
我给了您MSDN链接a few question ago,它解释了为什么增大大小的缓冲区有时有效,甚至更有效-它们是不可避免的。