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
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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

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 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;

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;