locked
How to set media format in IMFMediaSource RRS feed

  • Question

  • I'm, trying to implement a grabber using IMFMediaSource, IMFMediaSession and IMFTopology. I built a topology including the IMFMediaSource and an IMFSampleGrabberSinkCallback. My problem is how to set the current media format. I found a function in msdn:

    HRESULT cMFDevice::setDeviceFormat(IMFMediaType *i_type)
    {
      IMFPresentationDescriptor *presentationDescriptor = nullptr;
      HRESULT hr = m_mediaSource->CreatePresentationDescriptor(&presentationDescriptor);
    
      if (SUCCEEDED(hr))
      {
        BOOL selected = FALSE;
        IMFStreamDescriptor *streamDescriptor = nullptr;
        hr = presentationDescriptor->GetStreamDescriptorByIndex(0, &selected, &streamDescriptor);
    
        if (SUCCEEDED(hr))
        {
          IMFMediaTypeHandler *handler = nullptr;
          hr = streamDescriptor->GetMediaTypeHandler(&handler);
    
          if (SUCCEEDED(hr))
          {
            hr = handler->SetCurrentMediaType(i_type);
            SafeRelease(&handler);
          }
    
          SafeRelease(&streamDescriptor);
        }
      }
    
      SafeRelease(&presentationDescriptor);
      return hr;
    }


    That function works. But only once. If I start the session and stopped it, the current format does change. All return values are fine, but format does not changes in OnProcessSample callback. Any ideas? Do I have to rebuilt complete topology? Must I stop the session?


    Wednesday, March 11, 2015 11:20 AM