在第二次调用时调用IMemAllocator-> GetBuffer块

时间:2014-03-14 10:50:08

标签: 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() > 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之后清理一些东西,但我不知道是什么。

1 个答案:

答案 0 :(得分:2)

内存分配器管理固定数量的媒体样本。赠送所有媒体样本后,GetBuffer将阻止,直到某些媒体样本恢复可用为止。

在您的特定情况下,您在分配器中有一个媒体示例,并且您没有正确释放COM接口,因此它永远不会恢复可用,并且您获得无限锁定。

   m_pInputPin->Receive(outsample);
   outsample->Release(); // <<--- Here is the missing thing