mxf: simplify essence track matching

By directly providing a valid descriptor to match against

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3899>
This commit is contained in:
Edward Hervey 2023-02-10 07:12:25 +01:00 committed by Edward Hervey
parent 2d5b71d6e3
commit 3768ef89b9
13 changed files with 103 additions and 281 deletions

View file

@ -1077,39 +1077,19 @@ static void
} }
static gboolean 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); /* SMPTE 382M 9 */
return (mxf_is_generic_container_essence_container_label (key) &&
if (track->parent.descriptor == NULL) { key->u[12] == 0x02 &&
GST_ERROR ("No descriptor for this track"); key->u[13] == 0x06 &&
return FALSE; (key->u[14] == 0x01 ||
} key->u[14] == 0x02 ||
key->u[14] == 0x03 ||
for (i = 0; i < track->parent.n_descriptor; i++) { key->u[14] == 0x04 || key->u[14] == 0x08 || key->u[14] == 0x09 ||
MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; key->u[14] == 0x0a || key->u[14] == 0x0b));
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;
} }
static MXFEssenceWrapping static MXFEssenceWrapping

View file

@ -35,31 +35,13 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
#define GST_CAT_DEFAULT mxf_debug #define GST_CAT_DEFAULT mxf_debug
static gboolean static gboolean
mxf_is_alaw_essence_track (const MXFMetadataTimelineTrack * track) mxf_is_alaw_essence_track (const MXFMetadataFileDescriptor * d)
{ {
guint i; const MXFUL *key = &d->essence_container;
/* SMPTE 388M 6.1 */
g_return_val_if_fail (track != NULL, FALSE); return (mxf_is_generic_container_essence_container_label (key) &&
key->u[12] == 0x02 && key->u[13] == 0x0a &&
if (track->parent.descriptor == NULL) (key->u[14] == 0x01 || key->u[14] == 0x02 || key->u[14] == 0x03));
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -43,28 +43,9 @@ static const MXFUL mxf_canon_xf_hevc = { {0x06, 0x0E, 0x2B, 0x34,
}; };
static gboolean static gboolean
mxf_is_canon_xfhevc_essence_track (const MXFMetadataTimelineTrack * track) mxf_is_canon_xfhevc_essence_track (const MXFMetadataFileDescriptor * d)
{ {
guint i; return mxf_ul_is_equal (&d->essence_container, &mxf_canon_xf_hevc);
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -43,32 +43,14 @@ typedef struct
} MXFD10AudioMappingData; } MXFD10AudioMappingData;
static gboolean static gboolean
mxf_is_d10_essence_track (const MXFMetadataTimelineTrack * track) mxf_is_d10_essence_track (const MXFMetadataFileDescriptor * d)
{ {
guint i; const MXFUL *key = &d->essence_container;
/* SMPTE 386M 5.1 */
g_return_val_if_fail (track != NULL, FALSE); return (mxf_is_generic_container_essence_container_label (key) &&
key->u[12] == 0x02 && key->u[13] == 0x01 &&
if (track->parent.descriptor == NULL) (key->u[14] >= 0x01 && key->u[14] <= 0x06) &&
return FALSE; (key->u[15] == 0x01 || key->u[15] == 0x02 || key->u[15] == 0x7f));
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -48,38 +48,24 @@ static const MXFUL picture_essence_coding_dv = { {
}; };
static gboolean 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) key = &p->picture_essence_coding;
return FALSE; if (mxf_ul_is_subclass (&picture_essence_coding_dv, key))
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) {
return TRUE; 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; return FALSE;

View file

@ -43,17 +43,28 @@ const MXFEssenceElementHandler *
mxf_essence_element_handler_find (const MXFMetadataTimelineTrack * track) mxf_essence_element_handler_find (const MXFMetadataTimelineTrack * track)
{ {
GSList *l; GSList *l;
const MXFEssenceElementHandler *ret = NULL; guint i;
MXFMetadataTrack *parent = (MXFMetadataTrack *) track;
for (l = _mxf_essence_element_handler_registry; l; l = l->next) { g_return_val_if_fail (track != NULL, NULL);
MXFEssenceElementHandler *current = l->data;
if (current->handles_track (track)) { if (parent->descriptor == NULL)
ret = current; 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; static GList *_essence_element_writer_registry = NULL;

View file

@ -36,7 +36,7 @@ typedef enum {
typedef GstFlowReturn (*MXFEssenceElementHandleFunc) (const MXFUL *key, GstBuffer *buffer, GstCaps *caps, MXFMetadataTimelineTrack *track, gpointer mapping_data, GstBuffer **outbuf); typedef GstFlowReturn (*MXFEssenceElementHandleFunc) (const MXFUL *key, GstBuffer *buffer, GstCaps *caps, MXFMetadataTimelineTrack *track, gpointer mapping_data, GstBuffer **outbuf);
typedef struct { typedef struct {
gboolean (*handles_track) (const MXFMetadataTimelineTrack *track); gboolean (*handles_descriptor) (const MXFMetadataFileDescriptor *d);
MXFEssenceWrapping (*get_track_wrapping) (const MXFMetadataTimelineTrack *track); MXFEssenceWrapping (*get_track_wrapping) (const MXFMetadataTimelineTrack *track);
GstCaps * (*create_caps) (MXFMetadataTimelineTrack *track, GstTagList **tags, gboolean * intra_only, MXFEssenceElementHandleFunc *handler, gpointer *mapping_data); GstCaps * (*create_caps) (MXFMetadataTimelineTrack *track, GstTagList **tags, gboolean * intra_only, MXFEssenceElementHandleFunc *handler, gpointer *mapping_data);
} MXFEssenceElementHandler; } MXFEssenceElementHandler;

View file

@ -41,31 +41,13 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
#define GST_CAT_DEFAULT mxf_debug #define GST_CAT_DEFAULT mxf_debug
static gboolean static gboolean
mxf_is_jpeg2000_essence_track (const MXFMetadataTimelineTrack * track) mxf_is_jpeg2000_essence_track (const MXFMetadataFileDescriptor * d)
{ {
guint i; const MXFUL *key = &d->essence_container;
/* SMPTE 422M 5.4 */
g_return_val_if_fail (track != NULL, FALSE); return (mxf_is_generic_container_essence_container_label (key) &&
key->u[12] == 0x02 && key->u[13] == 0x0c &&
if (track->parent.descriptor == NULL) (key->u[14] == 0x01 || key->u[14] == 0x02));
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -392,34 +392,16 @@ typedef enum
} MXFMPEGEssenceType; } MXFMPEGEssenceType;
static gboolean static gboolean
mxf_is_mpeg_essence_track (const MXFMetadataTimelineTrack * track) mxf_is_mpeg_essence_track (const MXFMetadataFileDescriptor * d)
{ {
guint i; const MXFUL *key = &d->essence_container;
/* SMPTE 381M 7 */
g_return_val_if_fail (track != NULL, FALSE); /* SMPTE RP2008 8.1 */
return (mxf_is_generic_container_essence_container_label (key) &&
if (track->parent.descriptor == NULL) key->u[12] == 0x02 &&
return FALSE; (key->u[13] == 0x04 ||
key->u[13] == 0x07 || key->u[13] == 0x08 || key->u[13] == 0x09 ||
for (i = 0; i < track->parent.n_descriptor; i++) { key->u[13] == 0x0f || key->u[13] == 0x10));
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;
} }
/* See ISO/IEC 13818-2 for MPEG ES format */ /* See ISO/IEC 13818-2 for MPEG ES format */

View file

@ -34,30 +34,12 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
* and Application of Apple ProRes" * and Application of Apple ProRes"
*/ */
static gboolean 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); return (mxf_is_generic_container_essence_container_label (key) &&
key->u[12] == 0x02 && key->u[13] == 0x1C);
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -101,30 +101,13 @@ typedef struct
} MXFUPMappingData; } MXFUPMappingData;
static gboolean 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); /* SMPTE 384M 8 */
return (mxf_is_generic_container_essence_container_label (key) &&
if (track->parent.descriptor == NULL) key->u[12] == 0x02 && key->u[13] == 0x05 && key->u[15] <= 0x03);
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -71,31 +71,14 @@ static void
} }
static gboolean 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); /* SMPTE 436M 4.3 */
return (mxf_is_generic_container_essence_container_label (key) &&
if (track->parent.descriptor == NULL) key->u[12] == 0x02 && key->u[13] == 0x0e &&
return FALSE; key->u[14] == 0x00 && key->u[15] == 0x00);
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;
} }
static GstFlowReturn static GstFlowReturn

View file

@ -42,39 +42,27 @@ static const MXFUL picture_essence_coding_vc3_avid = { {
}; };
static gboolean 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) if (mxf_is_avid_essence_container_label (key)) {
return FALSE; MXFMetadataGenericPictureEssenceDescriptor *p;
for (i = 0; i < track->parent.n_descriptor; i++) { if (!MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d))
MXFMetadataFileDescriptor *d = track->parent.descriptor[i]; return FALSE;
MXFUL *key; p = MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (d);
if (!d) key = &p->picture_essence_coding;
continue; if (mxf_ul_is_subclass (&picture_essence_coding_vc3_avid, key))
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)) {
return TRUE; 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; return FALSE;