diff mbox

[FFmpeg-devel,v1,5/5] avcodec/h264: create user data unregistered side data for H.264

Message ID 20191217102217.4811-5-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>

Below is the sample message for -vf showinfo(need to apply the patchset):
[Parsed_showinfo_0 @ 0x7fac7b702080]   side data - User data unregistered:
[Parsed_showinfo_0 @ 0x7fac7b702080] UUID=186f369370304f2c603021492feee5b8
[Parsed_showinfo_0 @ 0x7fac7b702080] User Data=hello

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/h264_sei.c   |  5 ++++-
 libavcodec/h264_sei.h   |  3 +++
 libavcodec/h264_slice.c | 11 +++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Dec. 17, 2019, 8:49 p.m. UTC | #1
On Tue, Dec 17, 2019 at 06:22:17PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Below is the sample message for -vf showinfo(need to apply the patchset):
> [Parsed_showinfo_0 @ 0x7fac7b702080]   side data - User data unregistered:
> [Parsed_showinfo_0 @ 0x7fac7b702080] UUID=186f369370304f2c603021492feee5b8
> [Parsed_showinfo_0 @ 0x7fac7b702080] User Data=hello
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/h264_sei.c   |  5 ++++-
>  libavcodec/h264_sei.h   |  3 +++
>  libavcodec/h264_slice.c | 11 +++++++++++
>  3 files changed, 18 insertions(+), 1 deletion(-)

seems to break 
make: *** [fate-mov-zombie] Error 1

[...]
James Almer Dec. 17, 2019, 9:11 p.m. UTC | #2
On 12/17/2019 7:22 AM, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Below is the sample message for -vf showinfo(need to apply the patchset):
> [Parsed_showinfo_0 @ 0x7fac7b702080]   side data - User data unregistered:
> [Parsed_showinfo_0 @ 0x7fac7b702080] UUID=186f369370304f2c603021492feee5b8
> [Parsed_showinfo_0 @ 0x7fac7b702080] User Data=hello
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/h264_sei.c   |  5 ++++-
>  libavcodec/h264_sei.h   |  3 +++
>  libavcodec/h264_slice.c | 11 +++++++++++
>  3 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
> index 46fe8692dd..c70a5122ec 100644
> --- a/libavcodec/h264_sei.c
> +++ b/libavcodec/h264_sei.c
> @@ -50,6 +50,7 @@ void ff_h264_sei_uninit(H264SEIContext *h)
>      h->frame_packing.present       = 0;
>      h->display_orientation.present = 0;
>      h->afd.present                 =  0;
> +    h->unregistered.present        = 0;
>  
>      av_buffer_unref(&h->a53_caption.buf_ref);
>  }
> @@ -258,6 +259,8 @@ static int decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
>          user_data[i] = get_bits(gb, 8);
>  
>      memset(user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> +    h->user_data = user_data;
> +    h->user_data_size = size;

Use AVBufferRef if you're going to export it, please.

>  
>      e = sscanf(user_data + 16, "x264 - core %d", &build);
>      if (e == 1 && build > 0)
> @@ -265,7 +268,7 @@ static int decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
>      if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16))
>          h->x264_build = 67;
>  
> -    av_free(user_data);
> +    h->present = 1;
>      return 0;
>  }
>  
> diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h
> index a75c3aa175..4bded8e579 100644
> --- a/libavcodec/h264_sei.h
> +++ b/libavcodec/h264_sei.h
> @@ -121,6 +121,9 @@ typedef struct H264SEIA53Caption {
>  
>  typedef struct H264SEIUnregistered {
>      int x264_build;
> +    int present;
> +    int user_data_size;
> +    uint8_t *user_data;
>  } H264SEIUnregistered;
>  
>  typedef struct H264SEIRecoveryPoint {
> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
> index e24d41ca50..4fb99c9263 100644
> --- a/libavcodec/h264_slice.c
> +++ b/libavcodec/h264_slice.c
> @@ -1285,6 +1285,17 @@ static int h264_export_frame_props(H264Context *h)
>          h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
>      }
>  
> +    if (h->sei.unregistered.present) {
> +        AVFrameSideData *sd = av_frame_new_side_data(cur->f, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
> +                                                     h->sei.unregistered.user_data_size);
> +        if (sd)
> +            memcpy(sd->data, h->sei.unregistered.user_data,
> +                h->sei.unregistered.user_data_size);
> +        av_freep(&h->sei.unregistered.user_data);

Look at how H264SEIA53Caption is handled above using
av_frame_new_side_data_from_buf() from the AVBufferRef allocated in
h264_sei.c

> +        h->sei.unregistered.user_data_size = 0;
> +        h->sei.unregistered.present = 0;
> +    }
> +
>      if (h->sei.picture_timing.timecode_cnt > 0) {
>          uint32_t tc = 0;
>          uint32_t *tc_sd;
>
Limin Wang Dec. 18, 2019, 11:12 a.m. UTC | #3
On Tue, Dec 17, 2019 at 09:49:28PM +0100, Michael Niedermayer wrote:
> On Tue, Dec 17, 2019 at 06:22:17PM +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Below is the sample message for -vf showinfo(need to apply the patchset):
> > [Parsed_showinfo_0 @ 0x7fac7b702080]   side data - User data unregistered:
> > [Parsed_showinfo_0 @ 0x7fac7b702080] UUID=186f369370304f2c603021492feee5b8
> > [Parsed_showinfo_0 @ 0x7fac7b702080] User Data=hello
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavcodec/h264_sei.c   |  5 ++++-
> >  libavcodec/h264_sei.h   |  3 +++
> >  libavcodec/h264_slice.c | 11 +++++++++++
> >  3 files changed, 18 insertions(+), 1 deletion(-)
> 
> seems to break 
> make: *** [fate-mov-zombie] Error 1

Fixed and update the patch.

> 
> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Concerning the gods, I have no means of knowing whether they exist or not
> or of what sort they may be, because of the obscurity of the subject, and
> the brevity of human life -- Protagoras



> _______________________________________________
> 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/h264_sei.c b/libavcodec/h264_sei.c
index 46fe8692dd..c70a5122ec 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -50,6 +50,7 @@  void ff_h264_sei_uninit(H264SEIContext *h)
     h->frame_packing.present       = 0;
     h->display_orientation.present = 0;
     h->afd.present                 =  0;
+    h->unregistered.present        = 0;
 
     av_buffer_unref(&h->a53_caption.buf_ref);
 }
@@ -258,6 +259,8 @@  static int decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
         user_data[i] = get_bits(gb, 8);
 
     memset(user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+    h->user_data = user_data;
+    h->user_data_size = size;
 
     e = sscanf(user_data + 16, "x264 - core %d", &build);
     if (e == 1 && build > 0)
@@ -265,7 +268,7 @@  static int decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
     if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16))
         h->x264_build = 67;
 
-    av_free(user_data);
+    h->present = 1;
     return 0;
 }
 
diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h
index a75c3aa175..4bded8e579 100644
--- a/libavcodec/h264_sei.h
+++ b/libavcodec/h264_sei.h
@@ -121,6 +121,9 @@  typedef struct H264SEIA53Caption {
 
 typedef struct H264SEIUnregistered {
     int x264_build;
+    int present;
+    int user_data_size;
+    uint8_t *user_data;
 } H264SEIUnregistered;
 
 typedef struct H264SEIRecoveryPoint {
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index e24d41ca50..4fb99c9263 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1285,6 +1285,17 @@  static int h264_export_frame_props(H264Context *h)
         h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
     }
 
+    if (h->sei.unregistered.present) {
+        AVFrameSideData *sd = av_frame_new_side_data(cur->f, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
+                                                     h->sei.unregistered.user_data_size);
+        if (sd)
+            memcpy(sd->data, h->sei.unregistered.user_data,
+                h->sei.unregistered.user_data_size);
+        av_freep(&h->sei.unregistered.user_data);
+        h->sei.unregistered.user_data_size = 0;
+        h->sei.unregistered.present = 0;
+    }
+
     if (h->sei.picture_timing.timecode_cnt > 0) {
         uint32_t tc = 0;
         uint32_t *tc_sd;