[FFmpeg-cvslog] lavc: set AVCodecContext.hwaccel in ff_get_format()

Anton Khirnov git at videolan.org
Sun May 11 23:39:31 CEST 2014


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Mar  6 18:01:05 2014 +0100| [5c1d7246cd65dc4db1b6dc36e29ce39fc1068f3f] | committer: Luca Barbato

lavc: set AVCodecContext.hwaccel in ff_get_format()

This way each decoder does not have to do the same thing manually.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5c1d7246cd65dc4db1b6dc36e29ce39fc1068f3f
---

 libavcodec/h263dec.c    |    1 -
 libavcodec/h264_slice.c |    2 --
 libavcodec/internal.h   |    9 ---------
 libavcodec/mpeg12dec.c  |    2 --
 libavcodec/utils.c      |   48 ++++++++++++++++++++++++++++++++---------------
 libavcodec/vc1dec.c     |    1 -
 6 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index c430cf9..c380983 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -108,7 +108,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOSYS);
     }
     s->codec_id    = avctx->codec->id;
-    avctx->hwaccel = ff_find_hwaccel(avctx);
 
     /* for h263, we allocate the images after having read the header */
     if (avctx->codec->id != AV_CODEC_ID_H263 &&
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 5db8ef9..133b588 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1078,8 +1078,6 @@ static int h264_slice_header_init(H264Context *h, int reinit)
                   h->sps.num_units_in_tick, den, 1 << 30);
     }
 
-    h->avctx->hwaccel = ff_find_hwaccel(h->avctx);
-
     if (reinit)
         ff_h264_free_tables(h, 0);
     h->first_field           = 0;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 678d6f1..78af94e 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -103,15 +103,6 @@ struct AVCodecDefault {
 };
 
 /**
- * Return the hardware accelerated codec for codec codec_id and
- * pixel format pix_fmt.
- *
- * @param avctx The codec context containing the codec_id and pixel format.
- * @return the hardware accelerated codec, or NULL if none was found.
- */
-AVHWAccel *ff_find_hwaccel(AVCodecContext *avctx);
-
-/**
  * Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
  * If there is no such matching pair then size is returned.
  */
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index c2cafe5..1cd37fa 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1295,7 +1295,6 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
         } // MPEG-2
 
         avctx->pix_fmt = mpeg_get_pixelformat(avctx);
-        avctx->hwaccel = ff_find_hwaccel(avctx);
         // until then pix_fmt may be changed right after codec init
 #if FF_API_XVMC
         if ((avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT ||
@@ -2126,7 +2125,6 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
     s->low_delay        = 1;
 
     avctx->pix_fmt = mpeg_get_pixelformat(avctx);
-    avctx->hwaccel = ff_find_hwaccel(avctx);
 
 #if FF_API_XVMC
     if ((avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel) &&
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c6d793b..95aaa6e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -864,9 +864,41 @@ enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const en
     return fmt[0];
 }
 
+static AVHWAccel *find_hwaccel(enum AVCodecID codec_id,
+                               enum AVPixelFormat pix_fmt)
+{
+    AVHWAccel *hwaccel = NULL;
+
+    while ((hwaccel = av_hwaccel_next(hwaccel)))
+        if (hwaccel->id == codec_id
+            && hwaccel->pix_fmt == pix_fmt)
+            return hwaccel;
+    return NULL;
+}
+
+
 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
 {
-    return avctx->get_format(avctx, fmt);
+    const AVPixFmtDescriptor *desc;
+    enum AVPixelFormat ret = avctx->get_format(avctx, fmt);
+
+    desc = av_pix_fmt_desc_get(ret);
+    if (!desc)
+        return AV_PIX_FMT_NONE;
+
+    if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
+        avctx->hwaccel = find_hwaccel(avctx->codec_id, ret);
+        if (!avctx->hwaccel) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Could not find an AVHWAccel for the pixel format: %s",
+                   desc->name);
+            return AV_PIX_FMT_NONE;
+        }
+    } else {
+        avctx->hwaccel = NULL;
+    }
+
+    return ret;
 }
 
 #if FF_API_AVFRAME_LAVC
@@ -2207,20 +2239,6 @@ AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
     return hwaccel ? hwaccel->next : first_hwaccel;
 }
 
-AVHWAccel *ff_find_hwaccel(AVCodecContext *avctx)
-{
-    enum AVCodecID codec_id = avctx->codec->id;
-    enum AVPixelFormat pix_fmt = avctx->pix_fmt;
-
-    AVHWAccel *hwaccel = NULL;
-
-    while ((hwaccel = av_hwaccel_next(hwaccel)))
-        if (hwaccel->id == codec_id
-            && hwaccel->pix_fmt == pix_fmt)
-            return hwaccel;
-    return NULL;
-}
-
 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
 {
     if (lockmgr_cb) {
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 6590e8b..1b01d7e 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -5598,7 +5598,6 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
         avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
     else
         avctx->pix_fmt = AV_PIX_FMT_GRAY8;
-    avctx->hwaccel = ff_find_hwaccel(avctx);
     v->s.avctx = avctx;
 
     if (ff_vc1_init_common(v) < 0)



More information about the ffmpeg-cvslog mailing list