Message ID | 20191219050907.15041-3-lance.lmwang@gmail.com |
---|---|
State | Superseded |
Headers | show |
On 12/19/2019 2:09 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 | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c > index 31f6b32aa4..bb3b37e0c5 100644 > --- a/libavfilter/vf_showinfo.c > +++ b/libavfilter/vf_showinfo.c > @@ -169,6 +169,36 @@ static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *s > metadata->MaxCLL, metadata->MaxFALL); > } > > +static int string_is_ascii(const uint8_t *str) > +{ > + while (*str && *str < 128) str++; I don't think the buffer is guaranteed to end with \0. You have sd->size, so you should probably use that, while also ensuring it ends with a \0 so the av_log below using %s works as intended. Also < 128 includes DEL. And you're not checking for >= 32. > + return !*str; > +} > + > +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"); > + > + user_data += uuid_size; > + /* Only print the user data details if it's string */ > + if (string_is_ascii(user_data)) { > + av_log(ctx, AV_LOG_INFO, "User Data="); > + av_log(ctx, AV_LOG_INFO, "%s", user_data); > + } > +} > + > static void dump_color_property(AVFilterContext *ctx, AVFrame *frame) > { > const char *color_range_str = av_color_range_name(frame->color_range); > @@ -319,6 +349,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); >
On Fri, Dec 20, 2019 at 02:30:23PM -0300, James Almer wrote: > On 12/19/2019 2:09 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 | 33 +++++++++++++++++++++++++++++++++ > > 1 file changed, 33 insertions(+) > > > > diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c > > index 31f6b32aa4..bb3b37e0c5 100644 > > --- a/libavfilter/vf_showinfo.c > > +++ b/libavfilter/vf_showinfo.c > > @@ -169,6 +169,36 @@ static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *s > > metadata->MaxCLL, metadata->MaxFALL); > > } > > > > +static int string_is_ascii(const uint8_t *str) > > +{ > > + while (*str && *str < 128) str++; > > I don't think the buffer is guaranteed to end with \0. You have > sd->size, so you should probably use that, while also ensuring it ends > with a \0 so the av_log below using %s works as intended. If the str has any '\0', it'll end immediately, even < sd->size still, for the print %s will work like that. In case it's end without '\0', we don't consider it's string, so it'll not print out like binary code. Below is the example: 'hello\0' will print hello 'hello\0tty' will print hello 'hello' don't print > > Also < 128 includes DEL. And you're not checking for >= 32. I consider LF(\r), CR(\n) should be expected ascii, for example the string may be json format, so I change to include all valid ascii including the control character(0-31 and 121). For example 'hello\ncc' will print hello cc > > > + return !*str; > > +} > > + > > +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"); > > + > > + user_data += uuid_size; > > + /* Only print the user data details if it's string */ > > + if (string_is_ascii(user_data)) { > > + av_log(ctx, AV_LOG_INFO, "User Data="); > > + av_log(ctx, AV_LOG_INFO, "%s", user_data); > > + } > > +} > > + > > static void dump_color_property(AVFilterContext *ctx, AVFrame *frame) > > { > > const char *color_range_str = av_color_range_name(frame->color_range); > > @@ -319,6 +349,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 --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 31f6b32aa4..bb3b37e0c5 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -169,6 +169,36 @@ static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *s metadata->MaxCLL, metadata->MaxFALL); } +static int string_is_ascii(const uint8_t *str) +{ + while (*str && *str < 128) str++; + return !*str; +} + +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"); + + user_data += uuid_size; + /* Only print the user data details if it's string */ + if (string_is_ascii(user_data)) { + av_log(ctx, AV_LOG_INFO, "User Data="); + av_log(ctx, AV_LOG_INFO, "%s", user_data); + } +} + static void dump_color_property(AVFilterContext *ctx, AVFrame *frame) { const char *color_range_str = av_color_range_name(frame->color_range); @@ -319,6 +349,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);