diff mbox

[FFmpeg-devel,v2,3/5] avfilter/vf_showinfo: display user data unregistered message

Message ID 20191218110617.13295-3-lance.lmwang@gmail.com
State Superseded
Headers show

Commit Message

Limin Wang Dec. 18, 2019, 11:06 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/vf_showinfo.c | 40 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

Comments

James Almer Dec. 18, 2019, 3:47 p.m. UTC | #1
On 12/18/2019 8:06 AM, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/vf_showinfo.c | 40 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
> index 31f6b32aa4..77ee7f312c 100644
> --- a/libavfilter/vf_showinfo.c
> +++ b/libavfilter/vf_showinfo.c
> @@ -169,6 +169,43 @@ static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *s
>             metadata->MaxCLL, metadata->MaxFALL);
>  }
>  
> +static int is_ascii(uint8_t ch)
> +{
> +    if (ch >= 32 && ch <= 127)

Should be < 127, i think.

> +        return 1;
> +    else
> +        return 0;
> +}
> +
> +static void dump_user_data_unregistered_metadata(AVFilterContext *ctx, AVFrameSideData *sd)
> +{
> +    const int uuid_size = 16;
> +    uint8_t *user_data = sd->data;
> +
> +    if (sd->size < uuid_size) {
> +        av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))", sd->size, uuid_size);
> +        return;
> +    }
> +
> +    av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n");
> +    av_log(ctx, AV_LOG_INFO, "UUID=");
> +    for (int i = 0; i < uuid_size; i++)
> +        av_log(ctx, AV_LOG_INFO, "%x", user_data[i]);
> +    av_log(ctx, AV_LOG_INFO, "\n");
> +    av_log(ctx, AV_LOG_INFO, "User Data=");
> +    for (int i = uuid_size; i < sd->size; i++) {
> +        /* printable ascii */
> +        if (is_ascii(*(user_data + i))) {

user_data[i]
> +            av_log(ctx, AV_LOG_INFO, "%c", *(user_data + i));

Ditto.

> +        } else {
> +            /* don't print the last byte `\0` character for ascii */
> +            if ((i == sd->size - 1) && *(user_data + i) == 0)

Ditto.

> +                continue;
> +            av_log(ctx, AV_LOG_INFO, "%x", *(user_data + i));

Ditto.

Also, maybe print 0x%02x instead.

> +        }
> +    }

What if it's binary data where a few of the bytes are in the printable
range? It might be worth checking if the entire buffer is printable and
then choosing between using %s or %x for the whole thing.

Or maybe just not print anything at all. We're not doing it for closed
captions frame side data after all.

> +}
> +
>  static void dump_color_property(AVFilterContext *ctx, AVFrame *frame)
>  {
>      const char *color_range_str     = av_color_range_name(frame->color_range);
> @@ -319,6 +356,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>              av_log(ctx, AV_LOG_INFO, "GOP timecode - %s", tcbuf);
>              break;
>          }
> +        case AV_FRAME_DATA_USER_DATA_UNREGISTERED:
> +            dump_user_data_unregistered_metadata(ctx, sd);
> +            break;
>          default:
>              av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
>                     sd->type, sd->size);
>
Limin Wang Dec. 19, 2019, 1:18 a.m. UTC | #2
On Wed, Dec 18, 2019 at 12:47:49PM -0300, James Almer wrote:
> On 12/18/2019 8:06 AM, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavfilter/vf_showinfo.c | 40 +++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 40 insertions(+)
> > 
> > diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
> > index 31f6b32aa4..77ee7f312c 100644
> > --- a/libavfilter/vf_showinfo.c
> > +++ b/libavfilter/vf_showinfo.c
> > @@ -169,6 +169,43 @@ static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *s
> >             metadata->MaxCLL, metadata->MaxFALL);
> >  }
> >  
> > +static int is_ascii(uint8_t ch)
> > +{
> > +    if (ch >= 32 && ch <= 127)
> 
> Should be < 127, i think.
> 

yes, 127 is DEL control character

> > +        return 1;
> > +    else
> > +        return 0;
> > +}
> > +
> > +static void dump_user_data_unregistered_metadata(AVFilterContext *ctx, AVFrameSideData *sd)
> > +{
> > +    const int uuid_size = 16;
> > +    uint8_t *user_data = sd->data;
> > +
> > +    if (sd->size < uuid_size) {
> > +        av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))", sd->size, uuid_size);
> > +        return;
> > +    }
> > +
> > +    av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n");
> > +    av_log(ctx, AV_LOG_INFO, "UUID=");
> > +    for (int i = 0; i < uuid_size; i++)
> > +        av_log(ctx, AV_LOG_INFO, "%x", user_data[i]);
> > +    av_log(ctx, AV_LOG_INFO, "\n");
> > +    av_log(ctx, AV_LOG_INFO, "User Data=");
> > +    for (int i = uuid_size; i < sd->size; i++) {
> > +        /* printable ascii */
> > +        if (is_ascii(*(user_data + i))) {
> 
> user_data[i]

yes, it's more simple

> > +            av_log(ctx, AV_LOG_INFO, "%c", *(user_data + i));
> 
> Ditto.
> 
> > +        } else {
> > +            /* don't print the last byte `\0` character for ascii */
> > +            if ((i == sd->size - 1) && *(user_data + i) == 0)
> 
> Ditto.
> 
> > +                continue;
> > +            av_log(ctx, AV_LOG_INFO, "%x", *(user_data + i));
> 
> Ditto.
> 
> Also, maybe print 0x%02x instead.

sure.

> 
> > +        }
> > +    }
> 
> What if it's binary data where a few of the bytes are in the printable
> range? It might be worth checking if the entire buffer is printable and
> then choosing between using %s or %x for the whole thing.

I prefer to print the data, for most of user data is string, so it'll
helpful for user to dump the info. I'll add a function a check the entire buffer
first like below function:

 static int string_is_ascii(const uint8_t *str)
 {
     while (*str && *str < 128) str++;
     return !*str;
 }


> 
> Or maybe just not print anything at all. We're not doing it for closed
> captions frame side data after all.
> 
> > +}
> > +
> >  static void dump_color_property(AVFilterContext *ctx, AVFrame *frame)
> >  {
> >      const char *color_range_str     = av_color_range_name(frame->color_range);
> > @@ -319,6 +356,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> >              av_log(ctx, AV_LOG_INFO, "GOP timecode - %s", tcbuf);
> >              break;
> >          }
> > +        case AV_FRAME_DATA_USER_DATA_UNREGISTERED:
> > +            dump_user_data_unregistered_metadata(ctx, sd);
> > +            break;
> >          default:
> >              av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
> >                     sd->type, sd->size);
> > 
> 
> _______________________________________________
> 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/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 31f6b32aa4..77ee7f312c 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -169,6 +169,43 @@  static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *s
            metadata->MaxCLL, metadata->MaxFALL);
 }
 
+static int is_ascii(uint8_t ch)
+{
+    if (ch >= 32 && ch <= 127)
+        return 1;
+    else
+        return 0;
+}
+
+static void dump_user_data_unregistered_metadata(AVFilterContext *ctx, AVFrameSideData *sd)
+{
+    const int uuid_size = 16;
+    uint8_t *user_data = sd->data;
+
+    if (sd->size < uuid_size) {
+        av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))", sd->size, uuid_size);
+        return;
+    }
+
+    av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n");
+    av_log(ctx, AV_LOG_INFO, "UUID=");
+    for (int i = 0; i < uuid_size; i++)
+        av_log(ctx, AV_LOG_INFO, "%x", user_data[i]);
+    av_log(ctx, AV_LOG_INFO, "\n");
+    av_log(ctx, AV_LOG_INFO, "User Data=");
+    for (int i = uuid_size; i < sd->size; i++) {
+        /* printable ascii */
+        if (is_ascii(*(user_data + i))) {
+            av_log(ctx, AV_LOG_INFO, "%c", *(user_data + i));
+        } else {
+            /* don't print the last byte `\0` character for ascii */
+            if ((i == sd->size - 1) && *(user_data + i) == 0)
+                continue;
+            av_log(ctx, AV_LOG_INFO, "%x", *(user_data + i));
+        }
+    }
+}
+
 static void dump_color_property(AVFilterContext *ctx, AVFrame *frame)
 {
     const char *color_range_str     = av_color_range_name(frame->color_range);
@@ -319,6 +356,9 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             av_log(ctx, AV_LOG_INFO, "GOP timecode - %s", tcbuf);
             break;
         }
+        case AV_FRAME_DATA_USER_DATA_UNREGISTERED:
+            dump_user_data_unregistered_metadata(ctx, sd);
+            break;
         default:
             av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
                    sd->type, sd->size);