changeset 3740:b31821aa2235 libavformat

Ok-ed parts from patch by zhentan feng.
author cehoyos
date Tue, 19 Aug 2008 12:36:17 +0000
parents d7fa8d9effe5
children 1a05ff4c7d93
files mxfenc.c
diffstat 1 files changed, 71 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mxfenc.c	Tue Aug 19 11:05:29 2008 +0000
+++ b/mxfenc.c	Tue Aug 19 12:36:17 2008 +0000
@@ -38,6 +38,16 @@
     UID uid;
 } MXFLocalTagPair;
 
+typedef struct {
+    UID track_essence_element_key;
+} MXFStreamContext;
+
+typedef struct MXFContext {
+    int64_t header_byte_count;
+    int64_t header_byte_count_offset;
+    int64_t header_footer_partition_offset;
+    int essence_container_count;
+} MXFContext;
 static const uint8_t uuid_base[]            = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
 static const uint8_t umid_base[]            = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 };
 
@@ -56,6 +66,11 @@
     put_be16(pb, value);
 }
 
+static void mxf_write_umid(ByteIOContext *pb, enum CodecID type, int value)
+{
+    put_buffer(pb, umid_base, 16);
+    mxf_write_uuid(pb, type, value);
+}
 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len)
 {
     // Determine the best BER size
@@ -114,9 +129,14 @@
     put_be16(pb, value_size);
 }
 
+static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value)
+{
+    put_buffer(pb, header_metadata_key, 13);
+    put_be24(pb, value);
+}
+
 static void mxf_free(AVFormatContext *s)
 {
-    MXFContext *mxf = s->priv_data;
     AVStream *st;
     int i;
 
@@ -124,7 +144,6 @@
         st = s->streams[i];
         av_freep(&st->priv_data);
     }
-    av_freep(&mxf->essence_container_uls);
 }
 
 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type)
@@ -152,6 +171,56 @@
     return 0;
 }
 
+static int mxf_write_header_metadata_sets(AVFormatContext *s)
+{
+    AVStream *st;
+    MXFStreamContext *sc = NULL;
+    int i;
+    if (mxf_write_preface(s) < 0)
+        return -1;
+
+    if (mxf_write_identification(s) < 0)
+        return -1;
+
+    if (mxf_write_content_storage(s) < 0)
+        return -1;
+
+    for (i = 0; i < s->nb_streams; i++) {
+        st = s->streams[i];
+        sc = av_mallocz(sizeof(MXFStreamContext));
+        if (!sc)
+            return AVERROR(ENOMEM);
+        st->priv_data = sc;
+        // set pts information
+        if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+            av_set_pts_info(st, 64, 1, st->codec->time_base.den);
+        } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
+            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+        }
+    }
+
+    if (mxf_build_structural_metadata(s, MaterialPackage) < 0)
+        return -1;
+
+    if (mxf_build_structural_metadata(s, SourcePackage) < 0)
+        return -1;
+    return 0;
+}
+
+static int mxf_update_header_partition(AVFormatContext *s, int64_t footer_partition_offset)
+{
+    MXFContext *mxf = s->priv_data;
+    ByteIOContext *pb = s->pb;
+
+    url_fseek(pb, mxf->header_byte_count_offset, SEEK_SET);
+    put_be64(pb, mxf->header_byte_count);
+    put_flush_packet(pb);
+
+    url_fseek(pb, mxf->header_footer_partition_offset, SEEK_SET);
+    put_be64(pb, footer_partition_offset);
+    put_flush_packet(pb);
+    return 0;
+}
 AVOutputFormat mxf_muxer = {
     "mxf",
     NULL_IF_CONFIG_SMALL("Material eXchange Format"),