locked
How to enable DXVA for media foundation's source reader?

    Question

  • Hi,

    I met a problem when I try to enable DXVA of the source reader.

    I need a IDirect3DDeviceManager9 interface to enable DXVA, but seems I can't found a way to create it.

    Does anybody know how to get the D3D device manage for metro app?

    Thank you~~

    Eric

    Thursday, November 10, 2011 6:34 AM

Answers

  • Hi Peng,

    I guess to set DXVA capabilities over the SourceReader, you need to set the following attributes

        CHECK_HR( hr = pAttributes->SetUnknown(MF_SOURCE_READER_D3D_MANAGER, m_pD3DManager) );
        CHECK_HR( hr = pAttributes->SetUINT32(MF_SOURCE_READER_DISABLE_DXVA, FALSE) );

    To create a D3DDeviceManager you could do the following:

    1) Create a D3D9 device first

        D3DPRESENT_PARAMETERS d3dpp;        
        ZeroMemory(&d3dpp,sizeof(d3dpp));   
        d3dpp.Windowed = true;
        d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
        d3dpp.hDeviceWindow = g_hwndVideo;   //give the window handle of the window we created above
        d3dpp.BackBufferCount = 1;          
        if(Mode == "fullscreen")
        {
            d3dpp.BackBufferWidth = x;       //set the buffer to our window width
            d3dpp.BackBufferHeight = y;      //set the buffer to out window height
        }
        else if(Mode == "winmode")
        {
            d3dpp.BackBufferWidth = width;     //set the buffer to our window width
            d3dpp.BackBufferHeight = height; //set the buffer to out window height         
        }
    
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; //the backbuffer format
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //SwapEffect   
        Direct3DCreate9Ex(D3D_SDK_VERSION, &pD3D); //Create the presentation parameters
     
        // Create the D3d9 device ...
    
        if(FAILED(pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,g_hwndVideo,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, NULL, &pDevice))) //create the device and check if it failed
        {       
            return 1; //exit the program return 1 error
        }



    2) Then create the D3DDeviceManager:
        UINT resetToken = 0;
        IDirect3DDeviceManager9 *pD3DManager = NULL;
        HRESULT hr = DXVA2CreateDirect3DDeviceManager9(&resetToken, &pD3DManager);
        hr = pD3DManager->ResetDevice(pDevice, resetToken);
        


        

    Additionally, there is one more attribute we could specify on the SourceReader to enable HardwareMFT. But on my machine I've seen it makes not difference.
        CHECK_HR( hr = pAttributes->SetUINT32( MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS,    TRUE) );

    Hope this works for you.    
    Mots

    • Marked as answer by Peng Huan Hung Tuesday, November 29, 2011 12:54 PM
    Tuesday, November 29, 2011 11:19 AM

All replies

  • Eric,

    Thanks for your interest in using DXVA technologies in Metro style applications. You should not need explicit control over the DXVA subsystem to play video content in a Metro style application. The rich compositor and the upstream video codec should handle any video acceleration for you automatically. Is there some specific reason why you are trying to access the DXVA subsystem directly?

    I honestly can’t think of any reason why you would need to do this in the Metro environment. Can you give us more information about what you are trying to accomplish? Typically we would recommend that you use the Media Element or the Video tag to play media content in the Metro environment.

    I hope this helps,

    James


    Global Technical Escalations Lead
    Windows Media SDK Technologies
    Microsoft Developer Services
    http://blogs.msdn.com/mediasdkstuff/

    Friday, November 11, 2011 11:09 PM
    Moderator
  • Hi James,

    We are creating a video player and video editor application.

    Our applications need to support non-native video format, so we have our own ByteStreamHandler and video/audio decoder. Dues to performance will be one of the critical issue of our application. In the document:http://msdn.microsoft.com/en-us/library/windows/desktop/dd389281(v=VS.85).aspx Hardware Acceleration section said I need D3D device manager to enable DXVA for source reader. So I want to make sure the video decoding will get the full hardware acceleration benefit.

    Currently I have two jobs to do:

    1. Create a snapshot/all frames of non-native supported video format. (This already done, but I am not verify the performance issue yet.)

    2. Get hardware media sample(or texture) that can be used by D3D directly. We will use D3D to do some video composition work then export to screen(source will be from multiple videos/images.).

    If the DXVA is default enable on the metro system, could you tell me how can I make sure I am using hardware acceleration or CPU power the decode the media file?  Thank you~~~   Eric


    Sunday, November 13, 2011 7:41 PM
  • I also met performance issue on native format. (MP4, H264)

    When I decode a 480*320 video, the frame rate( using ReadSample with in a while loop.) is about 150 fps in developer machine.

    But when I decode 1920*1080 video, the frame down to 8 fps. This result is far slower than the playback rate. 

    This result seems DXVA doesn't enable for video decoding.

    I also met a strange issue. I try to set output format to YV12, all checking said it set YV12 successfully. But the final result I dump from media sample is still RGB32. Did I miss something?

    Thank you~~ 

    Eric

    Tuesday, November 15, 2011 4:24 PM
  • Eric,

    I apologize but I am still confused about your reply. You will not be able to use DXVA for non-native video formats. Most Video hardware only supports a handful of codecs that can be accelerated (although with some programmable GPUs it might be possible to create your own HW decoding algorithm but this is way beyond the scope of a forum question). Because of this you are going to have a big challenge ahead of you if you expect to enable DXVA decoding using video formats that are not supported natively by the video hardware. That said the Metro rich compositor should use D3D to facilitate any resize or rotation operations to give you much better performance than doing the transformations yourself.

    If you are looking to get a handle to the D3D surface before we hand it to the Metro rich compositor this is a totally different question.

    Is this helpful at all? Maybe I'm still not fully understanding what it is that you are trying to do.


    -James
    Wednesday, November 16, 2011 10:42 PM
    Moderator
  • Hi, James,

    I have two tasks to work with source reader.

    1. Get a thumbnail from some .mkv, .mpg, ... etc.

        For this case, we create our mpeg2/ac3/dts decoder, mkv spliter, and some other related bytestream reader & video/audio decoder.

        - For this case, I failed to load these media foundation component from my winrt component, I register my component from app create by javascript and play file successfully.  But failed to load by source reader in winrt component. This seems anther issue. I appreciate if you can give me some advice also. 

    2. Get media sample from source reader from video file's including the format mention about as soon as possible. Because I need to create a video editing metro app. (like iMovie.)

       - Dues to I failed loading some component, I try to decode mp4, the native support format first(mp4, h264). But I got very bad performance, this is why I wonder DXVA doesn't enable on decoding the frame and try to enable it, this is what I ask on this thread. I set the output format to RGB32 on the source reader . The performance result of decoding 1080p is far slower than playing.

    ps: RGB32 just a test case, because these is the format I try successfully. I also try other output format(YV12), but get strange result. I guess my problem is I don't know what a real output format I can set of the source reader, because I enumerate the native format of source, the return format is H264 only.

      - Because I failed to using source reader to achieve my task. I am trying to use media engine instead of source reader now. But I still looks for source reader solution for my task, dues to source reader & sink writer look like a good candidate for the video editing app.

    Thanks for all your reply~~ I really appreciate it. 

    Eric

     



    Thursday, November 17, 2011 1:50 AM
  • Hi Peng,

    I guess to set DXVA capabilities over the SourceReader, you need to set the following attributes

        CHECK_HR( hr = pAttributes->SetUnknown(MF_SOURCE_READER_D3D_MANAGER, m_pD3DManager) );
        CHECK_HR( hr = pAttributes->SetUINT32(MF_SOURCE_READER_DISABLE_DXVA, FALSE) );

    To create a D3DDeviceManager you could do the following:

    1) Create a D3D9 device first

        D3DPRESENT_PARAMETERS d3dpp;        
        ZeroMemory(&d3dpp,sizeof(d3dpp));   
        d3dpp.Windowed = true;
        d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
        d3dpp.hDeviceWindow = g_hwndVideo;   //give the window handle of the window we created above
        d3dpp.BackBufferCount = 1;          
        if(Mode == "fullscreen")
        {
            d3dpp.BackBufferWidth = x;       //set the buffer to our window width
            d3dpp.BackBufferHeight = y;      //set the buffer to out window height
        }
        else if(Mode == "winmode")
        {
            d3dpp.BackBufferWidth = width;     //set the buffer to our window width
            d3dpp.BackBufferHeight = height; //set the buffer to out window height         
        }
    
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; //the backbuffer format
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //SwapEffect   
        Direct3DCreate9Ex(D3D_SDK_VERSION, &pD3D); //Create the presentation parameters
     
        // Create the D3d9 device ...
    
        if(FAILED(pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,g_hwndVideo,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, NULL, &pDevice))) //create the device and check if it failed
        {       
            return 1; //exit the program return 1 error
        }



    2) Then create the D3DDeviceManager:
        UINT resetToken = 0;
        IDirect3DDeviceManager9 *pD3DManager = NULL;
        HRESULT hr = DXVA2CreateDirect3DDeviceManager9(&resetToken, &pD3DManager);
        hr = pD3DManager->ResetDevice(pDevice, resetToken);
        


        

    Additionally, there is one more attribute we could specify on the SourceReader to enable HardwareMFT. But on my machine I've seen it makes not difference.
        CHECK_HR( hr = pAttributes->SetUINT32( MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS,    TRUE) );

    Hope this works for you.    
    Mots

    • Marked as answer by Peng Huan Hung Tuesday, November 29, 2011 12:54 PM
    Tuesday, November 29, 2011 11:19 AM
  • Thanks~~That really help~

    I using similar solution MFCreateDXGIDeviceManager

    to create the device manager on metro system.

    Tuesday, November 29, 2011 12:55 PM
  • Supporting Direct3D 11 Video Decoding in Media Foundation(D3D11)
    http://msdn.microsoft.com/en-us/library/windows/desktop/hh162912(v=VS.85).aspx

    Supporting DXVA 2.0 in Media Foundation(D3D9)
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa965266(v=vs.85).aspx

    Thursday, December 08, 2011 3:41 AM
  • mark
    Thursday, August 07, 2014 6:35 AM