From 08d81d0a01e484dca3de0a269d042f151b8aeacd Mon Sep 17 00:00:00 2001 From: Mark Reid Date: Fri, 21 Nov 2014 17:43:09 -0800 Subject: [PATCH] libavformat/mxfdec.c: export source package uids and names as metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes since v1: * renamed mxf_read_source_package -> mxf_read_package v1 reviewed-by: Tomas Härdin Signed-off-by: Michael Niedermayer --- libavformat/mxfdec.c | 78 +++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index fa0a2f4b62..cc740b5a81 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -668,22 +668,6 @@ static int mxf_read_source_clip(void *arg, AVIOContext *pb, int tag, int size, U return 0; } -static int mxf_read_material_package(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) -{ - MXFPackage *package = arg; - switch(tag) { - case 0x4403: - package->tracks_count = avio_rb32(pb); - package->tracks_refs = av_calloc(package->tracks_count, sizeof(UID)); - if (!package->tracks_refs) - return AVERROR(ENOMEM); - avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ - avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); - break; - } - return 0; -} - static int mxf_read_timecode_component(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) { MXFTimecodeComponent *mxf_timecode = arg; @@ -779,7 +763,7 @@ static int mxf_read_utf16_string(AVIOContext *pb, int size, char** str) return ret; } -static int mxf_read_source_package(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) +static int mxf_read_package(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) { MXFPackage *package = arg; switch(tag) { @@ -1416,6 +1400,34 @@ static int mxf_is_intra_only(MXFDescriptor *descriptor) &descriptor->essence_codec_ul)->id != AV_CODEC_ID_NONE; } +static int mxf_uid_to_str(UID uid, char **str) +{ + int i; + char *p; + p = *str = av_mallocz(sizeof(UID) * 2 + 4 + 1); + if (!p) + return AVERROR(ENOMEM); + for (i = 0; i < sizeof(UID); i++) { + snprintf(p, 2 + 1, "%.2x", uid[i]); + p += 2; + if (i == 3 || i == 5 || i == 7 || i == 9) { + snprintf(p, 1 + 1, "-"); + p++; + } + } + return 0; +} + +static int mxf_add_uid_metadata(AVDictionary **pm, const char *key, UID uid) +{ + char *str; + int ret; + if ((ret = mxf_uid_to_str(uid, &str)) < 0) + return ret; + av_dict_set(pm, key, str, AV_DICT_DONT_STRDUP_VAL); + return 0; +} + static int mxf_add_timecode_metadata(AVDictionary **pm, const char *key, AVTimecode *tc) { char buf[AV_TIMECODE_STR_SIZE]; @@ -1476,6 +1488,8 @@ static int mxf_parse_physical_source_package(MXFContext *mxf, MXFTrack *source_t if (!physical_package) break; + mxf_add_uid_metadata(&st->metadata, "reel_uid", physical_package->package_uid); + /* the name of physical source package is name of the reel or tape */ if (physical_package->name && physical_package->name[0]) av_dict_set(&st->metadata, "reel_name", physical_package->name, 0); @@ -1532,6 +1546,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) return AVERROR_INVALIDDATA; } + mxf_add_uid_metadata(&mxf->fc->metadata, "material_package_uid", material_package->package_uid); + if (material_package->name && material_package->name[0]) + av_dict_set(&mxf->fc->metadata, "material_package_name", material_package->name, 0); + for (i = 0; i < material_package->tracks_count; i++) { MXFPackage *source_package = NULL; MXFTrack *material_track = NULL; @@ -1712,6 +1730,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } av_log(mxf->fc, AV_LOG_VERBOSE, "\n"); + mxf_add_uid_metadata(&st->metadata, "file_package_uid", source_package->package_uid); + if (source_package->name && source_package->name[0]) + av_dict_set(&st->metadata, "file_package_name", source_package->name, 0); + mxf_parse_physical_source_package(mxf, source_track, st); if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -1851,24 +1873,6 @@ fail_and_free: return ret; } -static int mxf_uid_to_str(UID uid, char **str) -{ - int i; - char *p; - p = *str = av_mallocz(sizeof(UID) * 2 + 4 + 1); - if (!p) - return AVERROR(ENOMEM); - for (i = 0; i < sizeof(UID); i++) { - snprintf(p, 2 + 1, "%.2x", uid[i]); - p += 2; - if (i == 3 || i == 5 || i == 7 || i == 9) { - snprintf(p, 1 + 1, "-"); - p++; - } - } - return 0; -} - static int mxf_timestamp_to_str(uint64_t timestamp, char **str) { struct tm time = { 0 }; @@ -1968,8 +1972,8 @@ static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = { { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }, mxf_read_partition_pack }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x30,0x00 }, mxf_read_identification_metadata }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_content_storage, 0, AnyType }, - { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_source_package, sizeof(MXFPackage), SourcePackage }, - { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_material_package, sizeof(MXFPackage), MaterialPackage }, + { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_package, sizeof(MXFPackage), SourcePackage }, + { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_package, sizeof(MXFPackage), MaterialPackage }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0f,0x00 }, mxf_read_sequence, sizeof(MXFSequence), Sequence }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_source_clip, sizeof(MXFStructuralComponent), SourceClip }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), MultipleDescriptor },