From 5269777a9743beb1e63d02b1ee008ac1518c0f6f Mon Sep 17 00:00:00 2001 From: yychao Date: Fri, 4 Sep 2020 23:28:58 +0800 Subject: [PATCH] tsdemux: Add new API for fetching extended descriptors Part-of: --- gst-libs/gst/mpegts/gstmpegtsdescriptor.c | 32 +++++++++++++++++++++++ gst-libs/gst/mpegts/gstmpegtsdescriptor.h | 10 +++++++ gst/mpegtsdemux/mpegtsbase.c | 14 ++++++++++ gst/mpegtsdemux/mpegtsbase.h | 2 ++ gst/mpegtsdemux/tsdemux.c | 7 +++-- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index 34bee79197..c5b758ae4f 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -988,6 +988,38 @@ gst_mpegts_find_descriptor (GPtrArray * descriptors, guint8 tag) return NULL; } +/** + * gst_mpegts_find_descriptor_with_extension: + * @descriptors: (element-type GstMpegtsDescriptor) (transfer none): an array + * of #GstMpegtsDescriptor + * @tag: the tag to look for + * + * Finds the first descriptor of type @tag with @tag_extension in the array. + * + * Note: To look for descriptors that can be present more than once in an + * array of descriptors, iterate the #GArray manually. + * + * Returns: (transfer none): the first descriptor matchin @tag with @tag_extension, else %NULL. + * + * Since: 1.20 + */ +const GstMpegtsDescriptor * +gst_mpegts_find_descriptor_with_extension (GPtrArray * descriptors, guint8 tag, + guint8 tag_extension) +{ + guint i, nb_desc; + + g_return_val_if_fail (descriptors != NULL, NULL); + + nb_desc = descriptors->len; + for (i = 0; i < nb_desc; i++) { + GstMpegtsDescriptor *desc = g_ptr_array_index (descriptors, i); + if ((desc->tag == tag) && (desc->tag_extension == tag_extension)) + return (const GstMpegtsDescriptor *) desc; + } + return NULL; +} + /* GST_MTS_DESC_REGISTRATION (0x05) */ /** * gst_mpegts_descriptor_from_registration: diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h index 73f6c748dc..70c1be7a7a 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h @@ -274,6 +274,10 @@ GST_MPEGTS_API const GstMpegtsDescriptor * gst_mpegts_find_descriptor (GPtrArray *descriptors, guint8 tag); +GST_MPEGTS_API +const GstMpegtsDescriptor * gst_mpegts_find_descriptor_with_extension (GPtrArray *descriptors, + guint8 tag, guint8 tag_extension); + /* GST_MTS_DESC_REGISTRATION (0x05) */ GST_MPEGTS_API @@ -375,6 +379,12 @@ GST_MPEGTS_API GstMpegtsDescriptor * gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 *data, gsize length); + +/** + * gst_mpegts_descriptor_from_custom_with_extension: + * + * Since: 1.20 + */ GST_MPEGTS_API GstMpegtsDescriptor * gst_mpegts_descriptor_from_custom_with_extension (guint8 tag, guint8 tag_extension, const guint8 *data, gsize length); diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index bfe084c0e9..cf440203ef 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -325,6 +325,20 @@ mpegts_get_descriptor_from_stream (MpegTSBaseStream * stream, guint8 tag) return gst_mpegts_find_descriptor (pmt->descriptors, tag); } +const GstMpegtsDescriptor * +mpegts_get_descriptor_from_stream_with_extension (MpegTSBaseStream * stream, + guint8 tag, guint8 tag_extension) +{ + GstMpegtsPMTStream *pmt = stream->stream; + + GST_DEBUG ("Searching for tag 0x%02x tag_extension 0x%02x " + "in stream 0x%04x (stream_type 0x%02x)", + tag, tag_extension, stream->pid, stream->stream_type); + + return gst_mpegts_find_descriptor_with_extension (pmt->descriptors, tag, + tag_extension); +} + typedef struct { gboolean res; diff --git a/gst/mpegtsdemux/mpegtsbase.h b/gst/mpegtsdemux/mpegtsbase.h index 896eb1dbd5..fe92a8a744 100644 --- a/gst/mpegtsdemux/mpegtsbase.h +++ b/gst/mpegtsdemux/mpegtsbase.h @@ -234,6 +234,8 @@ G_GNUC_INTERNAL MpegTSBaseProgram *mpegts_base_get_program (MpegTSBase * base, g G_GNUC_INTERNAL MpegTSBaseProgram *mpegts_base_add_program (MpegTSBase * base, gint program_number, guint16 pmt_pid); G_GNUC_INTERNAL const GstMpegtsDescriptor *mpegts_get_descriptor_from_stream (MpegTSBaseStream * stream, guint8 tag); +G_GNUC_INTERNAL const GstMpegtsDescriptor *mpegts_get_descriptor_from_stream_with_extension (MpegTSBaseStream * stream, + guint8 tag, guint8 tag_extension); G_GNUC_INTERNAL const GstMpegtsDescriptor *mpegts_get_descriptor_from_program (MpegTSBaseProgram * program, guint8 tag); G_GNUC_INTERNAL gboolean diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index 74846d962d..44f964a168 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -1266,10 +1266,9 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream, * types also, depending on registratino descriptors also */ - desc = - mpegts_get_descriptor_from_stream (bstream, - GST_MTS_DESC_DVB_EXTENSION); - if (desc != NULL && desc->tag_extension == GST_MTS_DESC_EXT_DVB_AC4) { + desc = mpegts_get_descriptor_from_stream_with_extension (bstream, + GST_MTS_DESC_DVB_EXTENSION, GST_MTS_DESC_EXT_DVB_AC4); + if (desc) { GST_LOG ("ac4 audio"); is_audio = TRUE; caps = gst_caps_new_empty_simple ("audio/x-ac4");