diff mbox

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

Message ID 20170926003631.55571-7-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Karmani Sept. 26, 2017, 12:36 a.m. UTC
From: Aman Gupta <aman@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(+)

Comments

Hendrik Leppkes Sept. 26, 2017, 8:16 a.m. UTC | #1
On Tue, Sep 26, 2017 at 2:36 AM, Aman Gupta <ffmpeg@tmm1.net> wrote:
> From: Aman Gupta <aman@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);

You probably want nal->raw_data and raw_size here (and below),
hardware typically works on raw (escaped) data.
diff mbox

Patch

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))