【问题标题】:Call to IMemAllocator->GetBuffer blocks at second call在第二次调用时调用 IMemAllocator->GetBuffer 块
【发布时间】:2014-03-14 10:50:08
【问题描述】:

在我的自定义输出引脚中,我调用 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 后清理一些东西,但我不知道是什么。

【问题讨论】:

    标签: c++ directshow


    【解决方案1】:

    内存分配器管理固定数量的媒体样本。当所有媒体样本都被分发出去时,GetBuffer 会阻塞,直到一些媒体样本恢复可用。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 2013-09-11
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 2010-12-21
      • 1970-01-01
      相关资源
      最近更新 更多