On 12/18/2019 8:06 AM, lance.lmw...@gmail.com wrote:
> From: Limin Wang <lance.lmw...@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmw...@gmail.com>
> ---
>  libavcodec/hevc_sei.c               | 22 ++++++++++++++++++++++
>  libavcodec/hevc_sei.h               |  5 +++++
>  libavcodec/hevcdec.c                | 10 ++++++++++
>  tests/ref/fate/hevc-monochrome-crop |  3 +++
>  4 files changed, 40 insertions(+)
> 
> diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> index c59bd4321e..55d67c8e15 100644
> --- a/libavcodec/hevc_sei.c
> +++ b/libavcodec/hevc_sei.c
> @@ -206,6 +206,24 @@ static int 
> decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
>      return 0;
>  }
>  
> +static int decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, 
> GetBitContext *gb,
> +                                                      int size)
> +{
> +    int i;
> +
> +    if (size < 16)
> +       return AVERROR(EINVAL);
> +
> +    s->buf_ref = av_buffer_alloc(size);

Can there be more than one of these SEI messages per frame? I think we
can export more than one frame side data of the same type, so this code
should consider that scenario.

> +    if (!s->buf_ref)
> +        return AVERROR(ENOMEM);
> +
> +    for (i = 0; i < size; i++)
> +        s->buf_ref->data[i] = get_bits(gb, 8);
> +
> +    return 0;
> +}
> +
>  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
> GetBitContext *gb,
>                                                           int size)
>  {
> @@ -293,6 +311,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, void 
> *logctx, HEVCSEI *s,
>          return decode_nal_sei_active_parameter_sets(s, gb, logctx);
>      case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
>          return decode_nal_sei_user_data_registered_itu_t_t35(s, gb, size);
> +    case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
> +        return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, 
> size);
>      case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
>          return decode_nal_sei_alternative_transfer(&s->alternative_transfer, 
> gb);
>      default:
> @@ -365,4 +385,6 @@ void ff_hevc_reset_sei(HEVCSEI *s)
>  {
>      s->a53_caption.a53_caption_size = 0;
>      av_freep(&s->a53_caption.a53_caption);
> +
> +    av_buffer_unref(&s->unregistered.buf_ref);
>  }
> diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
> index f6516ae982..a557ee7ab7 100644
> --- a/libavcodec/hevc_sei.h
> +++ b/libavcodec/hevc_sei.h
> @@ -87,6 +87,10 @@ typedef struct HEVCSEIA53Caption {
>      uint8_t *a53_caption;
>  } HEVCSEIA53Caption;
>  
> +typedef struct HEVCSEIUnregistered {
> +    AVBufferRef *buf_ref;
> +} HEVCSEIUnregistered;
> +
>  typedef struct HEVCSEIMasteringDisplay {
>      int present;
>      uint16_t display_primaries[3][2];
> @@ -112,6 +116,7 @@ typedef struct HEVCSEI {
>      HEVCSEIDisplayOrientation display_orientation;
>      HEVCSEIPictureTiming picture_timing;
>      HEVCSEIA53Caption a53_caption;
> +    HEVCSEIUnregistered unregistered;
>      HEVCSEIMasteringDisplay mastering_display;
>      HEVCSEIContentLight content_light;
>      int active_seq_parameter_set_id;
> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> index 8f1c162ace..b1c7af090e 100644
> --- a/libavcodec/hevcdec.c
> +++ b/libavcodec/hevcdec.c
> @@ -2789,6 +2789,16 @@ static int set_side_data(HEVCContext *s)
>          s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
>      }
>  
> +    if (s->sei.unregistered.buf_ref) {
> +        HEVCSEIUnregistered *unreg = &s->sei.unregistered;
> +
> +        AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, 
> AV_FRAME_DATA_USER_DATA_UNREGISTERED,
> +                    unreg->buf_ref);
> +        if (!sd)
> +            av_buffer_unref(&unreg->buf_ref);
> +        unreg->buf_ref = NULL;
> +    }
> +
>      return 0;
>  }
>  
> diff --git a/tests/ref/fate/hevc-monochrome-crop 
> b/tests/ref/fate/hevc-monochrome-crop
> index 4e45412acf..43f0abbcfa 100644
> --- a/tests/ref/fate/hevc-monochrome-crop
> +++ b/tests/ref/fate/hevc-monochrome-crop
> @@ -1,6 +1,9 @@
>  [FRAME]
>  width=384
>  height=240
> +[SIDE_DATA]
> +side_data_type=User Data Unregistered
> +[/SIDE_DATA]
>  [/FRAME]
>  [STREAM]
>  width=384
> 

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to