[FFmpeg-devel] [PATCH 7/9] avcodec/h264: add decode_params callback to AVHWAccel

Aman Gupta ffmpeg at tmm1.net
Tue Sep 26 03:36:29 EEST 2017


From: Aman Gupta <aman at tmm1.net>

This callback will be used by the VideoToolbox H264 hwaccel so that it
can receive SPS and PPS NALUs. VideoToolbox requires PPS changes to be
fed into the decoder session, and for the session to be recreated when
the SPS changes.
---
 libavcodec/avcodec.h | 12 ++++++++++++
 libavcodec/h264dec.c | 14 ++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 5c84974e03..14bb509f66 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3921,6 +3921,18 @@ typedef struct AVHWAccel {
     int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
 
     /**
+     * Callback for parameter data.
+     *
+     * Used for SPS/PPS in H264 streams.
+     *
+     * @param avctx the codec context
+     * @param buf the slice data buffer base
+     * @param buf_size the size of the slice in bytes
+     * @return zero if successful, a negative value otherwise
+     */
+    int (*decode_params)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
+
+    /**
      * Callback for each slice.
      *
      * Meaningful slice information (codec specific) is guaranteed to
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index a8263f2e19..ab95beb020 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -738,6 +738,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
             break;
         case H264_NAL_SPS: {
             GetBitContext tmp_gb = nal->gb;
+            if (avctx->hwaccel && avctx->hwaccel->decode_params) {
+                ret = avctx->hwaccel->decode_params(avctx,
+                                                    nal->data,
+                                                    nal->size);
+                if (ret < 0)
+                    goto end;
+            }
             if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0)
                 break;
             av_log(h->avctx, AV_LOG_DEBUG,
@@ -749,6 +756,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
             break;
         }
         case H264_NAL_PPS:
+            if (avctx->hwaccel && avctx->hwaccel->decode_params) {
+                ret = avctx->hwaccel->decode_params(avctx,
+                                                    nal->data,
+                                                    nal->size);
+                if (ret < 0)
+                    goto end;
+            }
             ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,
                                                        nal->size_bits);
             if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
-- 
2.13.5 (Apple Git-94)



More information about the ffmpeg-devel mailing list