From 3768ef89b98f89de00550b6f3f97edea5571471f Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 10 Feb 2023 07:12:25 +0100 Subject: [PATCH] mxf: simplify essence track matching By directly providing a valid descriptor to match against Part-of: --- .../gst-plugins-bad/gst/mxf/mxfaes-bwf.c | 42 +++++-------------- subprojects/gst-plugins-bad/gst/mxf/mxfalaw.c | 30 +++---------- .../gst-plugins-bad/gst/mxf/mxfcustom.c | 23 +--------- subprojects/gst-plugins-bad/gst/mxf/mxfd10.c | 32 ++++---------- .../gst-plugins-bad/gst/mxf/mxfdv-dif.c | 42 +++++++------------ .../gst-plugins-bad/gst/mxf/mxfessence.c | 23 +++++++--- .../gst-plugins-bad/gst/mxf/mxfessence.h | 2 +- .../gst-plugins-bad/gst/mxf/mxfjpeg2000.c | 30 +++---------- subprojects/gst-plugins-bad/gst/mxf/mxfmpeg.c | 36 ++++------------ .../gst-plugins-bad/gst/mxf/mxfprores.c | 26 ++---------- subprojects/gst-plugins-bad/gst/mxf/mxfup.c | 27 +++--------- subprojects/gst-plugins-bad/gst/mxf/mxfvanc.c | 29 +++---------- subprojects/gst-plugins-bad/gst/mxf/mxfvc3.c | 42 +++++++------------ 13 files changed, 103 insertions(+), 281 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfaes-bwf.c b/subprojects/gst-plugins-bad/gst/mxf/mxfaes-bwf.c index 93d433bf0c..bf22b0b74d 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfaes-bwf.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfaes-bwf.c @@ -1077,39 +1077,19 @@ static void } static gboolean -mxf_is_aes_bwf_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_aes_bwf_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; + const MXFUL *key = &d->essence_container; - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) { - GST_ERROR ("No descriptor for this track"); - return FALSE; - } - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 382M 9 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && - key->u[13] == 0x06 && - (key->u[14] == 0x01 || - key->u[14] == 0x02 || - key->u[14] == 0x03 || - key->u[14] == 0x04 || key->u[14] == 0x08 || key->u[14] == 0x09 || - key->u[14] == 0x0a || key->u[14] == 0x0b)) - return TRUE; - } - - - return FALSE; + /* SMPTE 382M 9 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && + key->u[13] == 0x06 && + (key->u[14] == 0x01 || + key->u[14] == 0x02 || + key->u[14] == 0x03 || + key->u[14] == 0x04 || key->u[14] == 0x08 || key->u[14] == 0x09 || + key->u[14] == 0x0a || key->u[14] == 0x0b)); } static MXFEssenceWrapping diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfalaw.c b/subprojects/gst-plugins-bad/gst/mxf/mxfalaw.c index d490033e90..b102bad6c6 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfalaw.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfalaw.c @@ -35,31 +35,13 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug); #define GST_CAT_DEFAULT mxf_debug static gboolean -mxf_is_alaw_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_alaw_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; - - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 388M 6.1 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x0a && - (key->u[14] == 0x01 || key->u[14] == 0x02 || key->u[14] == 0x03)) - return TRUE; - } - - return FALSE; + const MXFUL *key = &d->essence_container; + /* SMPTE 388M 6.1 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x0a && + (key->u[14] == 0x01 || key->u[14] == 0x02 || key->u[14] == 0x03)); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c b/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c index d266045785..2c31a9c69a 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c @@ -43,28 +43,9 @@ static const MXFUL mxf_canon_xf_hevc = { {0x06, 0x0E, 0x2B, 0x34, }; static gboolean -mxf_is_canon_xfhevc_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_canon_xfhevc_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; - - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - if (mxf_ul_is_equal (key, &mxf_canon_xf_hevc)) - return TRUE; - } - - return FALSE; + return mxf_ul_is_equal (&d->essence_container, &mxf_canon_xf_hevc); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfd10.c b/subprojects/gst-plugins-bad/gst/mxf/mxfd10.c index 66c071372a..03854d9303 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfd10.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfd10.c @@ -43,32 +43,14 @@ typedef struct } MXFD10AudioMappingData; static gboolean -mxf_is_d10_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_d10_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; - - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 386M 5.1 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x01 && - (key->u[14] >= 0x01 && key->u[14] <= 0x06) && - (key->u[15] == 0x01 || key->u[15] == 0x02 || key->u[15] == 0x7f)) - return TRUE; - } - - return FALSE; + const MXFUL *key = &d->essence_container; + /* SMPTE 386M 5.1 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x01 && + (key->u[14] >= 0x01 && key->u[14] <= 0x06) && + (key->u[15] == 0x01 || key->u[15] == 0x02 || key->u[15] == 0x7f)); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfdv-dif.c b/subprojects/gst-plugins-bad/gst/mxf/mxfdv-dif.c index dbfe3490a3..72da93fc84 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfdv-dif.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfdv-dif.c @@ -48,38 +48,24 @@ static const MXFUL picture_essence_coding_dv = { { }; static gboolean -mxf_is_dv_dif_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_dv_dif_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; + const MXFUL *key = &d->essence_container; + /* SMPTE 383M 8 */ + if (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x02) { + return TRUE; + } + if (mxf_is_avid_essence_container_label (key)) { + MXFMetadataGenericPictureEssenceDescriptor *p; - g_return_val_if_fail (track != NULL, FALSE); + if (!MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d)) + return FALSE; + p = MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d); - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 383M 8 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x02) { + key = &p->picture_essence_coding; + if (mxf_ul_is_subclass (&picture_essence_coding_dv, key)) return TRUE; - } else if (mxf_is_avid_essence_container_label (key)) { - MXFMetadataGenericPictureEssenceDescriptor *p; - - if (!MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d)) - return FALSE; - p = MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d); - - key = &p->picture_essence_coding; - if (mxf_ul_is_subclass (&picture_essence_coding_dv, key)) - return TRUE; - } } return FALSE; diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfessence.c b/subprojects/gst-plugins-bad/gst/mxf/mxfessence.c index 35c3c7172d..4597327eb3 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfessence.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfessence.c @@ -43,17 +43,28 @@ const MXFEssenceElementHandler * mxf_essence_element_handler_find (const MXFMetadataTimelineTrack * track) { GSList *l; - const MXFEssenceElementHandler *ret = NULL; + guint i; + MXFMetadataTrack *parent = (MXFMetadataTrack *) track; - for (l = _mxf_essence_element_handler_registry; l; l = l->next) { - MXFEssenceElementHandler *current = l->data; + g_return_val_if_fail (track != NULL, NULL); - if (current->handles_track (track)) { - ret = current; + if (parent->descriptor == NULL) + return NULL; + + for (i = 0; i < parent->n_descriptor; i++) { + MXFMetadataFileDescriptor *d = parent->descriptor[i]; + + if (d) { + for (l = _mxf_essence_element_handler_registry; l; l = l->next) { + MXFEssenceElementHandler *current = l->data; + + if (current->handles_descriptor (d)) + return current; + } } } - return ret; + return NULL; } static GList *_essence_element_writer_registry = NULL; diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfessence.h b/subprojects/gst-plugins-bad/gst/mxf/mxfessence.h index e32515165e..963638b7ac 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfessence.h +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfessence.h @@ -36,7 +36,7 @@ typedef enum { typedef GstFlowReturn (*MXFEssenceElementHandleFunc) (const MXFUL *key, GstBuffer *buffer, GstCaps *caps, MXFMetadataTimelineTrack *track, gpointer mapping_data, GstBuffer **outbuf); typedef struct { - gboolean (*handles_track) (const MXFMetadataTimelineTrack *track); + gboolean (*handles_descriptor) (const MXFMetadataFileDescriptor *d); MXFEssenceWrapping (*get_track_wrapping) (const MXFMetadataTimelineTrack *track); GstCaps * (*create_caps) (MXFMetadataTimelineTrack *track, GstTagList **tags, gboolean * intra_only, MXFEssenceElementHandleFunc *handler, gpointer *mapping_data); } MXFEssenceElementHandler; diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfjpeg2000.c b/subprojects/gst-plugins-bad/gst/mxf/mxfjpeg2000.c index 5d084f24f8..3637ddcb77 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfjpeg2000.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfjpeg2000.c @@ -41,31 +41,13 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug); #define GST_CAT_DEFAULT mxf_debug static gboolean -mxf_is_jpeg2000_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_jpeg2000_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; - - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 422M 5.4 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x0c && - (key->u[14] == 0x01 || key->u[14] == 0x02)) - return TRUE; - } - - return FALSE; + const MXFUL *key = &d->essence_container; + /* SMPTE 422M 5.4 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x0c && + (key->u[14] == 0x01 || key->u[14] == 0x02)); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfmpeg.c b/subprojects/gst-plugins-bad/gst/mxf/mxfmpeg.c index f6f632854e..2be0976e74 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfmpeg.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfmpeg.c @@ -392,34 +392,16 @@ typedef enum } MXFMPEGEssenceType; static gboolean -mxf_is_mpeg_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_mpeg_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; - - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 381M 7 */ - /* SMPTE RP2008 8.1 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && - (key->u[13] == 0x04 || - key->u[13] == 0x07 || key->u[13] == 0x08 || key->u[13] == 0x09 || - key->u[13] == 0x0f || key->u[13] == 0x10)) - return TRUE; - } - - return FALSE; + const MXFUL *key = &d->essence_container; + /* SMPTE 381M 7 */ + /* SMPTE RP2008 8.1 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && + (key->u[13] == 0x04 || + key->u[13] == 0x07 || key->u[13] == 0x08 || key->u[13] == 0x09 || + key->u[13] == 0x0f || key->u[13] == 0x10)); } /* See ISO/IEC 13818-2 for MPEG ES format */ diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfprores.c b/subprojects/gst-plugins-bad/gst/mxf/mxfprores.c index 543b48554b..4feb8b4242 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfprores.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfprores.c @@ -34,30 +34,12 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug); * and Application of Apple ProRes" */ static gboolean -mxf_is_prores_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_prores_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; + const MXFUL *key = &d->essence_container; - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x1C) { - return TRUE; - } - } - - return FALSE; + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x1C); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfup.c b/subprojects/gst-plugins-bad/gst/mxf/mxfup.c index d8b6664dab..5812a6b6d6 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfup.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfup.c @@ -101,30 +101,13 @@ typedef struct } MXFUPMappingData; static gboolean -mxf_is_up_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_up_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; + const MXFUL *key = &d->essence_container; - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 384M 8 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x05 && key->u[15] <= 0x03) - return TRUE; - } - - return FALSE; + /* SMPTE 384M 8 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x05 && key->u[15] <= 0x03); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfvanc.c b/subprojects/gst-plugins-bad/gst/mxf/mxfvanc.c index 69279c30a6..3fa97afd4e 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfvanc.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfvanc.c @@ -71,31 +71,14 @@ static void } static gboolean -mxf_is_vanc_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_vanc_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; + const MXFUL *key = &d->essence_container; - g_return_val_if_fail (track != NULL, FALSE); - - if (track->parent.descriptor == NULL) - return FALSE; - - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; - - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE 436M 4.3 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x0e && - key->u[14] == 0x00 && key->u[15] == 0x00) - return TRUE; - } - - return FALSE; + /* SMPTE 436M 4.3 */ + return (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x0e && + key->u[14] == 0x00 && key->u[15] == 0x00); } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfvc3.c b/subprojects/gst-plugins-bad/gst/mxf/mxfvc3.c index 76188a5a2b..4018b6d0ea 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfvc3.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfvc3.c @@ -42,39 +42,27 @@ static const MXFUL picture_essence_coding_vc3_avid = { { }; static gboolean -mxf_is_vc3_essence_track (const MXFMetadataTimelineTrack * track) +mxf_is_vc3_essence_track (const MXFMetadataFileDescriptor * d) { - guint i; + const MXFUL *key = &d->essence_container; - g_return_val_if_fail (track != NULL, FALSE); + /* SMPTE S2019-4 7 */ + if (mxf_is_generic_container_essence_container_label (key) && + key->u[12] == 0x02 && key->u[13] == 0x11 && + (key->u[14] == 0x01 || key->u[14] == 0x02)) { + return TRUE; + } - if (track->parent.descriptor == NULL) - return FALSE; + if (mxf_is_avid_essence_container_label (key)) { + MXFMetadataGenericPictureEssenceDescriptor *p; - for (i = 0; i < track->parent.n_descriptor; i++) { - MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; - MXFUL *key; + if (!MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d)) + return FALSE; + p = MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d); - if (!d) - continue; - - key = &d->essence_container; - /* SMPTE S2019-4 7 */ - if (mxf_is_generic_container_essence_container_label (key) && - key->u[12] == 0x02 && key->u[13] == 0x11 && - (key->u[14] == 0x01 || key->u[14] == 0x02)) { + key = &p->picture_essence_coding; + if (mxf_ul_is_subclass (&picture_essence_coding_vc3_avid, key)) return TRUE; - } else if (mxf_is_avid_essence_container_label (key)) { - MXFMetadataGenericPictureEssenceDescriptor *p; - - if (!MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d)) - return FALSE; - p = MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d); - - key = &p->picture_essence_coding; - if (mxf_ul_is_subclass (&picture_essence_coding_vc3_avid, key)) - return TRUE; - } } return FALSE;