[FFmpeg-devel] [PATCH] get rid of mpeg_mc_decode_init

Reimar Döffinger Reimar.Doeffinger
Sun Mar 1 10:51:05 CET 2009


Hello,
if this conflicts with the hwaccel patches it is probably not such a
good idea, but this patch moves the extra code from mpeg_mc_decode_init
into mpeg_decode_init and mpeg_get_pixelformat.
The "normal" MPEG-1/2 decoder is then already usable to decode to XvMC
if the right PIX_FMTs are added to ff_hwaccel_pixfmt_list_420 (e.g. for
MPlayer only avctx->get_format must be always set and the function fixed
to work with non-accelerated formats instead of returning PIX_FMT_NONE).
It will make the builds compiled without XvMC support a few bytes
larger though...
-------------- next part --------------
Index: libavcodec/mpeg12.c
===================================================================
--- libavcodec/mpeg12.c	(revision 17676)
+++ libavcodec/mpeg12.c	(working copy)
@@ -1188,6 +1188,8 @@
     s->mpeg_enc_ctx.picture_number = 0;
     s->repeat_field = 0;
     s->mpeg_enc_ctx.codec_id= avctx->codec->id;
+    if (avctx->codec->capabilities & CODEC_CAP_HWACCEL)
+        avctx->xvmc_acceleration = 2;//2 - the blocks are packed!
     return 0;
 }
 
@@ -1206,9 +1208,10 @@
 static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){
     Mpeg1Context *s1 = avctx->priv_data;
     MpegEncContext *s = &s1->mpeg_enc_ctx;
+    enum PixelFormat fmt;
 
     if(avctx->xvmc_acceleration)
-        return avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
+        fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
     else if(avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
         if(avctx->codec_id == CODEC_ID_MPEG1VIDEO)
             return PIX_FMT_VDPAU_MPEG1;
@@ -1216,12 +1219,23 @@
             return PIX_FMT_VDPAU_MPEG2;
     }else{
         if(s->chroma_format <  2)
-            return avctx->get_format(avctx,ff_hwaccel_pixfmt_list_420);
+            fmt = avctx->get_format(avctx,ff_hwaccel_pixfmt_list_420);
         else if(s->chroma_format == 2)
             return PIX_FMT_YUV422P;
         else
             return PIX_FMT_YUV444P;
     }
+    if (fmt == PIX_FMT_XVMC_MPEG2_IDCT || fmt == PIX_FMT_XVMC_MPEG2_MC) {
+        avctx->xvmc_acceleration = 2;
+        if( avctx->thread_count > 1)
+            return PIX_FMT_NONE;
+        if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
+            return PIX_FMT_NONE;
+        if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
+            dprintf(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
+        }
+    }
+    return fmt;
 }
 
 /* Call this function when we know all parameters.
@@ -2507,28 +2521,12 @@
 };
 
 #if CONFIG_MPEG_XVMC_DECODER
-static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){
-    if( avctx->thread_count > 1)
-        return -1;
-    if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
-        return -1;
-    if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
-        dprintf(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
-    }
-    mpeg_decode_init(avctx);
-
-    avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
-    avctx->xvmc_acceleration = 2;//2 - the blocks are packed!
-
-    return 0;
-}
-
 AVCodec mpeg_xvmc_decoder = {
     "mpegvideo_xvmc",
     CODEC_TYPE_VIDEO,
     CODEC_ID_MPEG2VIDEO_XVMC,
     sizeof(Mpeg1Context),
-    mpeg_mc_decode_init,
+    mpeg_decode_init,
     NULL,
     mpeg_decode_end,
     mpeg_decode_frame,



More information about the ffmpeg-devel mailing list