typedef struct {
UID track_essence_element_key;
- const UID *essence_container_ul;
+ int index; //<<< index in mxf_essence_container_uls table
const UID *codec_ul;
int64_t duration;
- void (*write_desc)();
} MXFStreamContext;
typedef struct {
UID codec_ul;
enum CodecID id;
void (*write_desc)();
-} MXFContainerEssencePair;
+} MXFContainerEssenceEntry;
static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st);
static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st);
-static const MXFContainerEssencePair mxf_essence_container_uls[] = {
+static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 },
{ 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
}
/*
- * Get essence container ul and return its index position
+ * Get essence container ul index
*/
-static const UID *mxf_get_essence_container_ul(enum CodecID type, int *index)
+static int mxf_get_essence_container_ul_index(enum CodecID id)
{
- for (*index = 0; *index < sizeof(mxf_essence_container_uls)/
- sizeof(*mxf_essence_container_uls); (*index)++)
- if (mxf_essence_container_uls[*index].id == type)
- return &mxf_essence_container_uls[*index].container_ul;
- *index = -1;
- return NULL;
+ int i;
+ for (i = 0; i < sizeof(mxf_essence_container_uls)/
+ sizeof(*mxf_essence_container_uls); i++)
+ if (mxf_essence_container_uls[i].id == id)
+ return i;
+ return -1;
}
static void mxf_write_primer_pack(AVFormatContext *s)
mxf_write_uuid(pb, SourcePackage, 0);
}
-static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type)
-{
- ByteIOContext *pb = s->pb;
- int i;
-
- if (type == MaterialPackage) {
- mxf_write_metadata_key(pb, 0x013600);
- PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
- klv_encode_ber_length(pb, 92 + 16 * s->nb_streams);
- } else {
- mxf_write_metadata_key(pb, 0x013700);
- PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
- klv_encode_ber_length(pb, 112 + 16 * s->nb_streams); // 20 bytes length for descriptor reference
- }
-
- // write uid
- mxf_write_local_tag(pb, 16, 0x3C0A);
- mxf_write_uuid(pb, type, 0);
- av_log(s,AV_LOG_DEBUG, "package type:%d\n", type);
- PRINT_KEY(s, "package uid", pb->buf_ptr - 16);
-
- // write package umid
- mxf_write_local_tag(pb, 32, 0x4401);
- mxf_write_umid(pb, type, 0);
- PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
-
- // write create date
- mxf_write_local_tag(pb, 8, 0x4405);
- put_be64(pb, 0);
-
- // write modified date
- mxf_write_local_tag(pb, 8, 0x4404);
- put_be64(pb, 0);
-
- // write track refs
- mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x4403);
- mxf_write_refs_count(pb, s->nb_streams);
- for (i = 0; i < s->nb_streams; i++)
- mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, i);
-
- // write multiple descriptor reference
- if (type == SourcePackage) {
- mxf_write_local_tag(pb, 16, 0x4701);
- mxf_write_uuid(pb, MultipleDescriptor, 0);
- }
-}
-
static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
{
ByteIOContext *pb = s->pb;
put_be32(pb, st->time_base.num);
mxf_write_local_tag(pb, 16, 0x3004);
- put_buffer(pb, *sc->essence_container_ul, 16);
+ put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
mxf_write_local_tag(pb, 16, 0x3201);
put_buffer(pb, *sc->codec_ul, 16);
put_be32(pb, st->codec->channels);
mxf_write_local_tag(pb, 4, 0x3D01);
- put_be32(pb, st->codec->bits_per_sample);
+ put_be32(pb, st->codec->bits_per_coded_sample);
}
-static void mxf_build_structural_metadata(AVFormatContext *s, enum MXFMetadataSetType type)
+static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type)
{
+ ByteIOContext *pb = s->pb;
int i;
- mxf_write_package(s, type);
- if (type == SourcePackage)
- mxf_write_multi_descriptor(s);
+ if (type == MaterialPackage) {
+ mxf_write_metadata_key(pb, 0x013600);
+ PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
+ klv_encode_ber_length(pb, 92 + 16 * s->nb_streams);
+ } else {
+ mxf_write_metadata_key(pb, 0x013700);
+ PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
+ klv_encode_ber_length(pb, 112 + 16 * s->nb_streams); // 20 bytes length for descriptor reference
+ }
+
+ // write uid
+ mxf_write_local_tag(pb, 16, 0x3C0A);
+ mxf_write_uuid(pb, type, 0);
+ av_log(s,AV_LOG_DEBUG, "package type:%d\n", type);
+ PRINT_KEY(s, "package uid", pb->buf_ptr - 16);
+
+ // write package umid
+ mxf_write_local_tag(pb, 32, 0x4401);
+ mxf_write_umid(pb, type, 0);
+ PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
+
+ // write create date
+ mxf_write_local_tag(pb, 8, 0x4405);
+ put_be64(pb, 0);
+
+ // write modified date
+ mxf_write_local_tag(pb, 8, 0x4404);
+ put_be64(pb, 0);
+
+ // write track refs
+ mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x4403);
+ mxf_write_refs_count(pb, s->nb_streams);
+ for (i = 0; i < s->nb_streams; i++)
+ mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, i);
+
+ // write multiple descriptor reference
+ if (type == SourcePackage) {
+ mxf_write_local_tag(pb, 16, 0x4701);
+ if (s->nb_streams > 1) {
+ mxf_write_uuid(pb, MultipleDescriptor, 0);
+ mxf_write_multi_descriptor(s);
+ } else
+ mxf_write_uuid(pb, SubDescriptor, 0);
+ }
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
if (type == SourcePackage) {
MXFStreamContext *sc = st->priv_data;
- sc->write_desc(s, st);
+ mxf_essence_container_uls[sc->index].write_desc(s, st);
}
}
}
mxf_write_preface(s);
mxf_write_identification(s);
mxf_write_content_storage(s);
- mxf_build_structural_metadata(s, MaterialPackage);
- mxf_build_structural_metadata(s, SourcePackage);
+ mxf_write_package(s, MaterialPackage);
+ mxf_write_package(s, SourcePackage);
return 0;
}
static int mxf_write_header(AVFormatContext *s)
{
MXFContext *mxf = s->priv_data;
- int i, index;
+ int i;
uint8_t present[sizeof(mxf_essence_container_uls)/
sizeof(*mxf_essence_container_uls)] = {0};
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
sc->duration = -1;
- sc->essence_container_ul = mxf_get_essence_container_ul(st->codec->codec_id, &index);
- if (!sc->essence_container_ul) {
+ sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
+ if (sc->index == -1) {
av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
"codec not currently supported in container\n", i);
return -1;
return -1;
}
} else
- sc->codec_ul = &mxf_essence_container_uls[index].codec_ul;
+ sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
- if (!present[index]) {
- mxf->essence_containers_indices[mxf->essence_container_count++] = index;
- present[index] = 1;
+ if (!present[sc->index]) {
+ mxf->essence_containers_indices[mxf->essence_container_count++] = sc->index;
+ present[sc->index] = 1;
} else
- present[index]++;
- memcpy(sc->track_essence_element_key, mxf_essence_container_uls[index].element_ul, 15);
- sc->track_essence_element_key[15] = present[index];
+ present[sc->index]++;
+ memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
+ sc->track_essence_element_key[15] = present[sc->index];
PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
- sc->write_desc = mxf_essence_container_uls[index].write_desc;
}
mxf_write_partition(s, 1, header_open_partition_key, 1);