From 3577fdec517e3e26a469452d20e7047d0c82fd62 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Tue, 10 Oct 2023 08:34:29 +0200 Subject: [PATCH] videoparsers: Clear user data explicitly in _reset_frame This fits better with the model used by the parser elements. It also properly resets the data when the parser is reset. Part-of: --- .../gst/videoparsers/gsth264parse.c | 1 + .../gst/videoparsers/gsth265parse.c | 1 + .../gst/videoparsers/gstmpegvideoparse.c | 1 + .../gst/videoparsers/gstvideoparseutils.c | 37 ++++++++----------- .../gst/videoparsers/gstvideoparseutils.h | 25 +++++-------- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c b/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c index ccddd963aa..1ea0d80d5d 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c @@ -262,6 +262,7 @@ gst_h264_parse_reset_frame (GstH264Parse * h264parse) h264parse->have_pps_in_frame = FALSE; h264parse->have_aud_in_frame = FALSE; gst_adapter_clear (h264parse->frame_out); + gst_video_clear_user_data (&h264parse->user_data); } static void diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c b/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c index 46440c28b8..6b215c2511 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c @@ -207,6 +207,7 @@ gst_h265_parse_reset_frame (GstH265Parse * h265parse) h265parse->have_sps_in_frame = FALSE; h265parse->have_pps_in_frame = FALSE; gst_adapter_clear (h265parse->frame_out); + gst_video_clear_user_data (&h265parse->user_data); } static void diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gstmpegvideoparse.c b/subprojects/gst-plugins-bad/gst/videoparsers/gstmpegvideoparse.c index 6fe694cecc..5132bf7569 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gstmpegvideoparse.c +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gstmpegvideoparse.c @@ -196,6 +196,7 @@ gst_mpegv_parse_reset_frame (GstMpegvParse * mpvparse) mpvparse->ext_count = 0; mpvparse->slice_count = 0; mpvparse->slice_offset = 0; + gst_video_clear_user_data (&mpvparse->user_data); } static void diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.c b/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.c index 42d3d09032..518af9e0c9 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.c +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.c @@ -123,10 +123,7 @@ gst_video_parse_user_data (GstElement * elt, GstVideoParseUserData * user_data, user_data->afd_spec = GST_VIDEO_AFD_SPEC_ATSC_A53; user_data->afd = temp; user_data->active_format_flag = TRUE; - } else { - user_data->active_format_flag = FALSE; } - user_data->has_afd = TRUE; user_data->field = field; break; case USER_DATA_ID_DIRECTV_CC: @@ -223,7 +220,6 @@ gst_video_parse_user_data (GstElement * elt, GstVideoParseUserData * user_data, break; memcpy (user_data->bar_data, data, bar_size); user_data->bar_data_size = bar_size; - user_data->has_bar_data = TRUE; user_data->field = field; GST_DEBUG_OBJECT (elt, "Bar data, %u bytes", bar_size); break; @@ -265,13 +261,10 @@ gst_video_push_user_data (GstElement * elt, GstVideoParseUserData * user_data, GST_DEBUG_OBJECT (elt, "Closed caption data already found on buffer, " "discarding to avoid duplication"); } - - user_data->closedcaptions_type = GST_VIDEO_CAPTION_TYPE_UNKNOWN; - user_data->closedcaptions_size = 0; } /* 2. handle AFD */ - if (user_data->has_afd) { + if (user_data->active_format_flag) { GstVideoAFD afd; if (gst_video_parse_utils_parse_afd (user_data->afd, user_data->afd_spec, user_data->field, &afd)) { @@ -279,16 +272,10 @@ gst_video_push_user_data (GstElement * elt, GstVideoParseUserData * user_data, } else { GST_WARNING_OBJECT (elt, "Invalid AFD value %d", user_data->afd); } - } else if (user_data->active_format_flag) { - /* AFD was present, but now it is no longer present */ - GST_DEBUG_OBJECT (elt, - "AFD was present in previous frame, now no longer present"); - user_data->active_format_flag = 0; } - user_data->has_afd = FALSE; /* 3. handle Bar data */ - if (user_data->has_bar_data) { + if (user_data->bar_data_size) { GstVideoBarData data; if (gst_video_parse_utils_parse_bar (user_data->bar_data, user_data->bar_data_size, user_data->field, &data)) { @@ -297,13 +284,7 @@ gst_video_push_user_data (GstElement * elt, GstVideoParseUserData * user_data, } else { GST_WARNING_OBJECT (elt, "Invalid Bar data"); } - } else if (user_data->bar_data_size) { - /* bar data was present, but now it is no longer present */ - GST_DEBUG_OBJECT (elt, - "Bar data was present in previous frame, now no longer present"); - user_data->bar_data_size = 0; } - user_data->has_bar_data = FALSE; } /* @@ -456,6 +437,20 @@ gst_video_parse_utils_parse_afd (const guint8 data, GstVideoAFDSpec spec, return TRUE; } +/* + * gst_video_clear_user_data: + * @user_data: #GstVideoParseUserData struct to hold parsed closed caption, bar and AFD data + * + * Clears the user data, resetting it for the next frame + */ +void +gst_video_clear_user_data (GstVideoParseUserData * user_data) +{ + user_data->closedcaptions_size = 0; + user_data->bar_data_size = 0; + user_data->active_format_flag = 0; +} + /* * gst_video_parse_user_data_unregistered: * @elt: #GstElement that is parsing user data diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.h b/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.h index c2d14dc578..3cc0f5ea23 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.h +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gstvideoparseutils.h @@ -158,19 +158,11 @@ typedef struct /* pending bar data */ guint8 bar_data[GST_VIDEO_BAR_MAX_BYTES]; guint bar_data_size; - gboolean has_bar_data; - - /* parsed bar data */ - GstVideoBarData bar_parsed; /* pending AFD data */ guint8 afd; gboolean active_format_flag; GstVideoAFDSpec afd_spec; - gboolean has_afd; - - /* parsed afd data */ - GstVideoAFD afd_parsed; } GstVideoParseUserData; @@ -188,17 +180,20 @@ typedef struct G_BEGIN_DECLS -void gst_video_parse_user_data(GstElement * elt, GstVideoParseUserData * user_data, - GstByteReader * br, guint8 field, guint16 provider_code); +void gst_video_parse_user_data (GstElement * elt, + GstVideoParseUserData * user_data, + GstByteReader * br, + guint8 field, + guint16 provider_code); -void gst_video_parse_user_data_unregistered(GstElement * elt, GstVideoParseUserDataUnregistered * user_data, - GstByteReader * br, guint8 uuid[16]); +void gst_video_push_user_data (GstElement * elt, + GstVideoParseUserData * user_data, + GstBuffer * buf); + +void gst_video_clear_user_data (GstVideoParseUserData * user_data); void gst_video_user_data_unregistered_clear(GstVideoParseUserDataUnregistered * user_data); -void gst_video_push_user_data(GstElement * elt, GstVideoParseUserData * user_data, - GstBuffer * buf); - void gst_video_push_user_data_unregistered(GstElement * elt, GstVideoParseUserDataUnregistered * user_data, GstBuffer * buf);