diff mbox

[FFmpeg-devel,v1,2/5] avcodec/hevc_sei: add support for user data unregistered SEI message

Message ID 20191217102217.4811-2-lance.lmwang@gmail.com
State Superseded
Headers show

Commit Message

Limin Wang Dec. 17, 2019, 10:22 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/hevc_sei.c | 28 ++++++++++++++++++++++++++++
 libavcodec/hevc_sei.h |  7 +++++++
 libavcodec/hevcdec.c  | 10 ++++++++++
 3 files changed, 45 insertions(+)

Comments

James Almer Dec. 17, 2019, 9:15 p.m. UTC | #1
On 12/17/2019 7:22 AM, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/hevc_sei.c | 28 ++++++++++++++++++++++++++++
>  libavcodec/hevc_sei.h |  7 +++++++
>  libavcodec/hevcdec.c  | 10 ++++++++++
>  3 files changed, 45 insertions(+)
> 
> diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> index c59bd4321e..1af9594607 100644
> --- a/libavcodec/hevc_sei.c
> +++ b/libavcodec/hevc_sei.c
> @@ -206,6 +206,28 @@ 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)
> +{
> +    const int uuid_size = 16;
> +    int i;
> +
> +    if (size < uuid_size || size > INT_MAX - uuid_size)
> +       return AVERROR(EINVAL);
> +
> +    s->user_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
> +    if (!s->user_data)
> +        return AVERROR(ENOMEM);
> +    s->user_data_size = size;
> +
> +    for (i = 0; i < size; i++)
> +        s->user_data[i] = get_bits(gb, 8);
> +    memset(s->user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> +
> +    s->present = 1;
> +    return 0;
> +}
> +
>  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb,
>                                                           int size)
>  {
> @@ -293,6 +315,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 +389,8 @@ void ff_hevc_reset_sei(HEVCSEI *s)
>  {
>      s->a53_caption.a53_caption_size = 0;
>      av_freep(&s->a53_caption.a53_caption);
> +
> +    s->unregistered.user_data_size = 0;
> +    s->unregistered.present = 0;
> +    av_freep(&s->unregistered.user_data);
>  }
> diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
> index f6516ae982..1d312392e9 100644
> --- a/libavcodec/hevc_sei.h
> +++ b/libavcodec/hevc_sei.h
> @@ -87,6 +87,12 @@ typedef struct HEVCSEIA53Caption {
>      uint8_t *a53_caption;
>  } HEVCSEIA53Caption;
>  
> +typedef struct HEVCSEIUnregistered {
> +    int present;
> +    int user_data_size;
> +    uint8_t *user_data;

Same here as with h264, use AVBufferRef.

> +} HEVCSEIUnregistered;
> +
>  typedef struct HEVCSEIMasteringDisplay {
>      int present;
>      uint16_t display_primaries[3][2];
> @@ -112,6 +118,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..bc9ab7ceb7 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.present) {
> +        AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
> +                    s->sei.unregistered.user_data_size);
> +        if (sd)
> +            memcpy(sd->data, s->sei.unregistered.user_data, s->sei.unregistered.user_data_size);
> +        av_freep(&s->sei.unregistered.user_data);
> +        s->sei.unregistered.user_data_size = 0;
> +        s->sei.unregistered.present = 0;
> +    }
> +
>      return 0;
>  }
>  
>
Limin Wang Dec. 18, 2019, 12:42 a.m. UTC | #2
On Tue, Dec 17, 2019 at 06:15:42PM -0300, James Almer wrote:
> On 12/17/2019 7:22 AM, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavcodec/hevc_sei.c | 28 ++++++++++++++++++++++++++++
> >  libavcodec/hevc_sei.h |  7 +++++++
> >  libavcodec/hevcdec.c  | 10 ++++++++++
> >  3 files changed, 45 insertions(+)
> > 
> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > index c59bd4321e..1af9594607 100644
> > --- a/libavcodec/hevc_sei.c
> > +++ b/libavcodec/hevc_sei.c
> > @@ -206,6 +206,28 @@ 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)
> > +{
> > +    const int uuid_size = 16;
> > +    int i;
> > +
> > +    if (size < uuid_size || size > INT_MAX - uuid_size)
> > +       return AVERROR(EINVAL);
> > +
> > +    s->user_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
> > +    if (!s->user_data)
> > +        return AVERROR(ENOMEM);
> > +    s->user_data_size = size;
> > +
> > +    for (i = 0; i < size; i++)
> > +        s->user_data[i] = get_bits(gb, 8);
> > +    memset(s->user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> > +
> > +    s->present = 1;
> > +    return 0;
> > +}
> > +
> >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb,
> >                                                           int size)
> >  {
> > @@ -293,6 +315,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 +389,8 @@ void ff_hevc_reset_sei(HEVCSEI *s)
> >  {
> >      s->a53_caption.a53_caption_size = 0;
> >      av_freep(&s->a53_caption.a53_caption);
> > +
> > +    s->unregistered.user_data_size = 0;
> > +    s->unregistered.present = 0;
> > +    av_freep(&s->unregistered.user_data);
> >  }
> > diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
> > index f6516ae982..1d312392e9 100644
> > --- a/libavcodec/hevc_sei.h
> > +++ b/libavcodec/hevc_sei.h
> > @@ -87,6 +87,12 @@ typedef struct HEVCSEIA53Caption {
> >      uint8_t *a53_caption;
> >  } HEVCSEIA53Caption;
> >  
> > +typedef struct HEVCSEIUnregistered {
> > +    int present;
> > +    int user_data_size;
> > +    uint8_t *user_data;
> 
> Same here as with h264, use AVBufferRef.

OK, I'll update the patch to AVBufferRef.


> 
> > +} HEVCSEIUnregistered;
> > +
> >  typedef struct HEVCSEIMasteringDisplay {
> >      int present;
> >      uint16_t display_primaries[3][2];
> > @@ -112,6 +118,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..bc9ab7ceb7 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.present) {
> > +        AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
> > +                    s->sei.unregistered.user_data_size);
> > +        if (sd)
> > +            memcpy(sd->data, s->sei.unregistered.user_data, s->sei.unregistered.user_data_size);
> > +        av_freep(&s->sei.unregistered.user_data);
> > +        s->sei.unregistered.user_data_size = 0;
> > +        s->sei.unregistered.present = 0;
> > +    }
> > +
> >      return 0;
> >  }
> >  
> > 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..1af9594607 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -206,6 +206,28 @@  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)
+{
+    const int uuid_size = 16;
+    int i;
+
+    if (size < uuid_size || size > INT_MAX - uuid_size)
+       return AVERROR(EINVAL);
+
+    s->user_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
+    if (!s->user_data)
+        return AVERROR(ENOMEM);
+    s->user_data_size = size;
+
+    for (i = 0; i < size; i++)
+        s->user_data[i] = get_bits(gb, 8);
+    memset(s->user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+    s->present = 1;
+    return 0;
+}
+
 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb,
                                                          int size)
 {
@@ -293,6 +315,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 +389,8 @@  void ff_hevc_reset_sei(HEVCSEI *s)
 {
     s->a53_caption.a53_caption_size = 0;
     av_freep(&s->a53_caption.a53_caption);
+
+    s->unregistered.user_data_size = 0;
+    s->unregistered.present = 0;
+    av_freep(&s->unregistered.user_data);
 }
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index f6516ae982..1d312392e9 100644
--- a/libavcodec/hevc_sei.h
+++ b/libavcodec/hevc_sei.h
@@ -87,6 +87,12 @@  typedef struct HEVCSEIA53Caption {
     uint8_t *a53_caption;
 } HEVCSEIA53Caption;
 
+typedef struct HEVCSEIUnregistered {
+    int present;
+    int user_data_size;
+    uint8_t *user_data;
+} HEVCSEIUnregistered;
+
 typedef struct HEVCSEIMasteringDisplay {
     int present;
     uint16_t display_primaries[3][2];
@@ -112,6 +118,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..bc9ab7ceb7 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.present) {
+        AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
+                    s->sei.unregistered.user_data_size);
+        if (sd)
+            memcpy(sd->data, s->sei.unregistered.user_data, s->sei.unregistered.user_data_size);
+        av_freep(&s->sei.unregistered.user_data);
+        s->sei.unregistered.user_data_size = 0;
+        s->sei.unregistered.present = 0;
+    }
+
     return 0;
 }