C++ 呼叫IMemAllocator->;第二次调用时获取缓冲区块
在我的自定义输出引脚中,我调用IMemAllocator->GetBuffer以获取新样本并将数据复制到其中:C++ 呼叫IMemAllocator->;第二次调用时获取缓冲区块,c++,directshow,C++,Directshow,在我的自定义输出引脚中,我调用IMemAllocator->GetBuffer以获取新样本并将数据复制到其中: HRESULT MCMyOutputPin::Deliver(IMediaSample* sample) { HRESULT hr = NO_ERROR; myLogger->LogDebug("In Outputpin Deliver", L"D:\\TEMP\\yc.log"); if (sample->GetActualDataLength()
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);
BYTE* sampleBuffer = NULL;
BYTE* newBuffer = NULL;
sample->GetPointer(&sampleBuffer);
UINT32 ulDataLen = sample->GetSize();
outsample->GetPointer(&newBuffer);
ZeroMemory(newBuffer, ulDataLen);
CopyMemory(newBuffer, sampleBuffer, ulDataLen);
outsample->SetActualDataLength(ulDataLen);
m_pInputPin->Receive(outsample);
}
return hr;
}
问题是对GetBuffer的调用在第二次调用时会阻塞。
根据一些研究,如果缓冲区的大小太小,我就不会这样做。所以我试着加倍
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 = 1;
long buffersize = this->CurrentMediaType().lSampleSize;
pProps->cbBuffer = buffersize * 2;
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;
}
那没用。我可能只是忘了什么。由于这是第二次调用,我可能应该在调用GetBuffer后清理一些东西,但我不知道是什么。内存分配器管理固定数量的媒体样本。当所有媒体样本都被送出时,
GetBuffer
会阻塞,直到一些媒体样本恢复可用
在您的特定情况下,分配器中有一个媒体样本,并且您没有正确地释放COM接口,因此它永远不会恢复可用,并且您会得到无限锁定
m_pInputPin->Receive(outsample);
outsample->Release(); // <<--- Here is the missing thing
m_pInputPin->Receive(样本外);
外采样->释放()//