0

下面是从我的解码器转换过滤器中提取的代码,该过滤器从我的源过滤器中获取数据,该源过滤器从 IP 摄像机获取 RTP 网络数据。源过滤器,解码过滤器可以动态响应相机图像尺寸的变化,因为我需要处理解码库中的分辨率变化。

我使用了 DirectShow 帮助中描述的“ReceiveConnection”方法,在下一个示例中传递了新的 MediaType 数据。但是,即使在图形停止并重新启动时渲染器将呈现不同的分辨率,我也无法让视频混合渲染器动态接受分辨率变化。

谁能指出我需要做什么才能让渲染器处理动态分辨率变化?

HRESULT CDecoder::Receive(IMediaSample* pIn)
{
   //Input data does not necessarily correspond one-to-one
   //with output frames, so we must override Receive instead
   //of Transform.
   HRESULT hr = S_OK;

   //Deliver input to library
   long cBytes = pIn->GetActualDataLength();
   BYTE* pSrc;
   pIn->GetPointer(&pSrc);

   try
   {
      hr = m_codec.Decode(pSrc, cBytes, (hr == S_OK)?&tStart : NULL);
   } 
   catch (...)
   {
      hr = E_UNEXPECTED;
   }
   if (FAILED(hr))
   {
      if (theLog.enabled()){theLog.strm() << "Decoder Error " << hex << hr << dec << "     - resetting input"; theLog.write();}
      //Force reset of decoder
      m_bReset = true;
      m_codec.ResetInput();

      //We have handled the error -- don't pass upstream or the source may stop.
      return S_OK;
   }

   //Extract and deliver any decoded frames
   hr = DeliverDecodedFrames();

   return hr;
}

HRESULT CDecoder::DeliverDecodedFrames()
{
   HRESULT hr = S_OK;  

   for (;;)
   {
      DecodedFrame frame;
      bool bFrame = m_codec.GetDecodedFrame(frame);
      if (!bFrame)
      {
         break;
      }

      CMediaType mtIn;
      CMediaType mtOut;
      GetMediaType( PINDIR_INPUT, &mtIn);
      GetMediaType( PINDIR_OUTPUT, &mtOut);

      //Get the output pin's current image resolution
      VIDEOINFOHEADER* pvi = (VIDEOINFOHEADER*)mtOut.Format();

      if( pvi->bmiHeader.biWidth != m_cxInput || 
          pvi->bmiHeader.biHeight != m_cyInput)
      {
         HRESULT hr = GetPin(PINDIR_OUTPUT)->GetConnected()->ReceiveConnection(GetPin(PINDIR_OUTPUT), &mtIn);

         if(SUCCEEDED(hr))
         {
            SetMediaType(PINDIR_OUTPUT, &mtIn);
         }
      } 

      IMediaSamplePtr pOut;
      hr = m_pOutput->GetDeliveryBuffer(&pOut, 0, 0, NULL);

      if (FAILED(hr))
      {
         break;
      }

      AM_MEDIA_TYPE* pmt;
      if (pOut->GetMediaType(&pmt) == S_OK)
      {
         CMediaType mt(*pmt);
         DeleteMediaType(pmt);
         SetMediaType(PINDIR_OUTPUT, &mt);

         pOut->SetMediaType(&mt);
      }

      // crop, tramslate and deliver
     BYTE* pDest;
     pOut->GetPointer(&pDest);
     m_pConverter->Convert(frame.Width(), frame.Height(), frame.GetY(), frame.GetU(),  frame.GetV(), pDest);
     pOut->SetActualDataLength(m_pOutput->CurrentMediaType().GetSampleSize());
     pOut->SetSyncPoint(true);

     if (frame.HasTimestamp())
     {
        REFERENCE_TIME tStart = frame.Timestamp();
        REFERENCE_TIME tStop = tStart+1;
        pOut->SetTime(&tStart, &tStop);
     }

     m_pOutput->Deliver(pOut);
  }
  return hr;
}
4

1 回答 1

0

失败时会出现什么错误?可能您需要确保没有未完成的缓冲区——所有样本都需要在成功之前返回到分配器。您是否将您的代码与 www.gdcl.co.uk/gmfbridge 中的版本进行了比较?

于 2010-03-17T12:30:30.023 回答