[MPlayer-dev-eng] DxVA in MPlayer

Laurent Aimar fenrir at elivagar.org
Fri Nov 19 22:53:21 CET 2010


Hi,

On Fri, Nov 19, 2010 at 11:20:41PM +0200, Georgi Petrov wrote:
> I saw the code today and I didn't suppose that FFmpeg guys have done
> so much work. This is just great! DxVA 2 accelerated codecs (as I call
> them) for H.264, VC-1 and MPEG-2 are already written!!! They don't
> really decode anything, but "prepare" the bitstream from the file into
> a suitable way for the DxVA VO. Is this right?
 It does a bit more than that, it lets DXVA2 decode it directly into a
direct3d surface.
 Basically, what you need to do to use the FFmpeg code is to
 - Initialize AVCodecContext::hwaccel_context. You have to provide 
 a IDirectXVideoDecoder, the DXVA2 configuration to use
 (DXVA2_ConfigPictureDecode), and an array of Direct3DSurface.
 - Override AVCodecContext::get_buffer/reget_buffer/release_buffer. They
 will allow to provide the Direct3DSurface to use for decoding each frame.

 Then FFmpeg will directly decode in the Direct3DSurface provided by
the AVCodecContext::get_buffer(). What to do with it is up to you, ie
you can read back from it as it is done in VLC, or give it to a 
DXVA2 renderer (maybe the Direct3DSurface can directly be used by a
direct3d renderer, I haven't tried that).

> As I understand it, I will have to implement only the VO (in a libvo
> library). Please, correct me in this one - I won't have to write any
> codec specific code (in libavcodec library). Is this right? My
> observations say so.
 You won't have to touch the libavcodec library but you will need to
modify the code in mplayer that calls FFmpeg.

 You can look at the VLC code (GPL) that setups and use FFmpeg in that
fashion (vlc.git/modules/codec/avcodec/dxva2.c and video.c).
 I would think that doing the read back first might be easier as you
would modify less mplayer code (ie the code you need to write would only
touch vd_ffmpeg.c). And then when switching to a dedicated renderer, I think
that the only code that you would have to throw away is the readback code
(~30 LOC if you don't write an optimized SSE2/SSE4.1 copy).
 
> H.264 / VC-1 are my primary target, but not the only one. Currently
> FFmpeg doesn't seem to support DxVA decoding for MPEG-4 ASP
> (DivX/XviD). I suppose it will be too hard for me to add it? It is one
> of the last requirements, but I suppose I should ask the FFmpeg
> developers about this one?
 When implementing the DXVA2 code in FFmpeg, I didn't find enough
documentation about doing MPEG-4, nor a GPU that supported it. But
I haven't really tried (HD is usually MPEG-2 or H264)

> One more - DxVA 1 H.264 support (for Windows XP) is also required.
> Using the hardware overlay (vo_directx). In case you don't know - DxVA
> 1 doesn't require EVR renderer and can be used with both overlay and
> the Direct 3D renderers. Are there any complications expected about
> this one? I suppose I will have to make a slight changes to these
> renderers? The problem is that FFmpeg doesn't seem to support DxVA 1
> at all, so I suppose that this question is better suited to their
> developers, right?
 I think (but not tested) that you can easily add support for DXVA1 for the
FFmpeg code without even modifying it. You simply have to write a dummy
IDirectXVideoDecoder that rewrites the calls toward DXVA1 code (the API is
really similar) and to store surface indexes(integer) inside Direct3DSurface*
(hackish). But read back won't work for DXVA1, and you need a different
renderer than the one for DXVA2.

Regards,

-- 
fenrir



More information about the MPlayer-dev-eng mailing list