locked
How to use evr custom presenter in side MF RRS feed

  • Question

  • I am new to media foundation. I need to render a video onto a directx surface. So I need to use EVR custom presenter, but I dont find any exmaple to use it inside media foundation. There is one from a old example "MFPlayer" from windows SDK, but it does not exist any more in current windows SDK, I dont know if I should still use it and when I ran it, it has runtime error. There is a new MFPlayer example, but the document said IMFPMediaPlayer wont be valid in the future version of windows, and people should use MediaSession. But I dont find any exmaple to show me how to use it. Can any one give me some hint to the right direction. Thank you very much.
    color your life
    Thursday, February 17, 2011 12:26 PM

Answers

  • Hi, I worked a little more on it.

     

    1. I am using media session example code from 

    http://msdn.microsoft.com/en-us/library/ff728866(v=vs.85).aspx

    2. And put EVRCustomPresenter inside the same project, and add IMFActivate interface to EVRCustomPresenter and imeplement it. There are a lots of functions from IMFAttribute. anyway.

     

    Then

     

    3. I add my custom presenter into EVR by following code into function CreateMediaSinkActivate(). 

     

    		hr = MFCreateVideoRendererActivate(hVideoWindow, &pActivate);
    		IMFVideoPresenter* presenter;
    		EVRCustomPresenter::CreateInstance(NULL, __uuidof(IMFVideoPresenter), (void**)&presenter);
    		CComPtr<IUnknown> unk(presenter);
    		hr = pActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE, unk);
    

     

    When I run the program, there is no runtime error or anyother returned error code. But custom presenter is still not used, it still use its own default presenter. 

    Is there any possible reason? Thank you,

     

    There was a runtime error from EVRCustomPresenter::CreateOptimalVideoType() I fixed it by

     

    HRESULT EVRCustomPresenter::CreateOptimalVideoType(IMFMediaType* pProposedType, IMFMediaType **ppOptimalType)
    {
     HRESULT hr
    = S_OK;

     RECT rcOutput
    ;
     
    ZeroMemory(&rcOutput, sizeof(rcOutput));

     
    MFVideoArea displayArea;
     
    ZeroMemory(&displayArea, sizeof(displayArea));

     
    // Helper object to manipulate the optimal type.
     
    VideoType mtOptimal;
     mtOptimal
    .CreateEmptyType(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     
    // Clone the proposed type.
     CHECK_HR(hr = mtOptimal.CopyFrom(pProposedType));

    ..........

    • Marked as answer by chiwa737 Monday, February 21, 2011 2:33 PM
    Friday, February 18, 2011 4:13 PM
  • I have made it work by using the following code. Before calling the following code, I have make EVRCustomPresenter inherit from CComObjectRoot instead of BaseObject.

     

    CComObject<EVRCustomPresenter> *my_activate_obj;

    CComObject<EVRCustomPresenter>::CreateInstance(&my_activate_obj);

    CComPtr<IUnknown> unk;

    my_activate_obj->QueryInterface(&unk);

    hr = pActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE, unk);

     

     


    color your life
    • Marked as answer by chiwa737 Monday, February 21, 2011 2:33 PM
    Monday, February 21, 2011 2:32 PM

All replies

  • Hey,

    check the links I posted here: http://social.msdn.microsoft.com/Forums/en-US/mediafoundationdevelopment/thread/a59fb399-3478-41b1-80fa-4baffdbabe7b

    There is one version of the MFPlayer sample and EVRCustomPresenter stuff that works in combination IF you remember to read the readme and manually register the presenter DLL ... I'm working on something similar to what you are up to, haven't found any source code or samples either. I'm still struggling to get the textures over from the present engine to my 3D rendering part. Somehow I have the feeling MF isn't too keen on sharing its samples with another part of the program that does 3D rendering with the same surface...

    Good luck... : )

    Alex

    • Proposed as answer by ak_ventuz Thursday, February 17, 2011 4:05 PM
    Thursday, February 17, 2011 12:37 PM
  • Thank you so much. That is what I need, it explains some of my confusions.
    color your life
    Thursday, February 17, 2011 2:23 PM
  • I sooooo know what you mean... :)

    Alex

    Thursday, February 17, 2011 4:04 PM
  • Hi, I worked a little more on it.

     

    1. I am using media session example code from 

    http://msdn.microsoft.com/en-us/library/ff728866(v=vs.85).aspx

    2. And put EVRCustomPresenter inside the same project, and add IMFActivate interface to EVRCustomPresenter and imeplement it. There are a lots of functions from IMFAttribute. anyway.

     

    Then

     

    3. I add my custom presenter into EVR by following code into function CreateMediaSinkActivate(). 

     

    		hr = MFCreateVideoRendererActivate(hVideoWindow, &pActivate);
    		IMFVideoPresenter* presenter;
    		EVRCustomPresenter::CreateInstance(NULL, __uuidof(IMFVideoPresenter), (void**)&presenter);
    		CComPtr<IUnknown> unk(presenter);
    		hr = pActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE, unk);
    

     

    When I run the program, there is no runtime error or anyother returned error code. But custom presenter is still not used, it still use its own default presenter. 

    Is there any possible reason? Thank you,

     

    There was a runtime error from EVRCustomPresenter::CreateOptimalVideoType() I fixed it by

     

    HRESULT EVRCustomPresenter::CreateOptimalVideoType(IMFMediaType* pProposedType, IMFMediaType **ppOptimalType)
    {
     HRESULT hr
    = S_OK;

     RECT rcOutput
    ;
     
    ZeroMemory(&rcOutput, sizeof(rcOutput));

     
    MFVideoArea displayArea;
     
    ZeroMemory(&displayArea, sizeof(displayArea));

     
    // Helper object to manipulate the optimal type.
     
    VideoType mtOptimal;
     mtOptimal
    .CreateEmptyType(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     
    // Clone the proposed type.
     CHECK_HR(hr = mtOptimal.CopyFrom(pProposedType));

    ..........

    • Marked as answer by chiwa737 Monday, February 21, 2011 2:33 PM
    Friday, February 18, 2011 4:13 PM
  • This approach works for me in un protected media path, but it dose not work in PMP, I haven't know why it not work.

    Set MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE as step 3 and implement the IMFActivate::ActivateObject() as below, custom presenter will be used.

    HRESULT  EVRCustomPresenter::ActivateObject(REFIID riid, void **ppv)
    {
     if (!ppv)
     {
      return E_POINTER;
     }

     if(riid == IID_IMFVideoPresenter)
     {
      *ppv = static_cast<IMFVideoPresenter*>(this);
      AddRef();
     }

     return S_OK;
    }


     

    Monday, February 21, 2011 8:32 AM
  • I have made it work by using the following code. Before calling the following code, I have make EVRCustomPresenter inherit from CComObjectRoot instead of BaseObject.

     

    CComObject<EVRCustomPresenter> *my_activate_obj;

    CComObject<EVRCustomPresenter>::CreateInstance(&my_activate_obj);

    CComPtr<IUnknown> unk;

    my_activate_obj->QueryInterface(&unk);

    hr = pActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE, unk);

     

     


    color your life
    • Marked as answer by chiwa737 Monday, February 21, 2011 2:33 PM
    Monday, February 21, 2011 2:32 PM