Hi

2008/8/22 Michael Niedermayer <[EMAIL PROTECTED]>
[...]

> [...]
> > > > +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 +
> > > 0xf0, i);
> > >
> > > a Track2 or any other name would be cleaner than Track + 0xf0
> > >
> >
> > do you mean add a new enum type for the other track?
> > if there many tracks, it will add Track2, Track3...
> >
> > so,
> > mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + 0xf0 + i,
> i);
> > is this ok?
>
> no
>
>
> > 0xf0 just like a offset.
>
> 0xf0 is the problem
> It should be an enum like
>
> mxf_write_uuid(pb, type == MaterialPackage ? Track : SomethingElse, i);
>
> Track + 0xf0 can be equal to another enum, its not likely but its just not
> correct to add random integers to an enum to create a new one.
>

here is the new patch of version 0.0.6.
I add a TypeBottom value at the end of MXFMetadataType, so when add new
type, TypeBottom is always at the bottom acting as a bottom line, so it
would be not conflict.

see attached patch.
thanks

-- 
Best wishes~
Index: mxfenc.c
===================================================================
--- mxfenc.c	(revision 14903)
+++ mxfenc.c	(working copy)
@@ -245,6 +245,43 @@
     return uls;
 }
 
+static int mxf_write_essence_container_refs(AVFormatContext *s, int write)
+{
+    MXFContext *mxf = s->priv_data;
+    ByteIOContext *pb = s->pb;
+    AVStream *st;
+    int i, count = 0, j = 0;
+    int essence_container_ul_sign[32] = { 0 };
+    const MXFCodecUL *codec_ul;
+
+    for (codec_ul = ff_mxf_essence_container_uls; codec_ul->id; codec_ul++) {
+        for (i = 0; i < s->nb_streams; i++) {
+            st = s->streams[i];
+            if (st->codec->codec_id == codec_ul->id) {
+                essence_container_ul_sign[count] = j;
+                count++;
+                break;
+            }
+        }
+        j++;
+        // considering WAV/AES3 frame wrapped, when get the first CODEC_ID_PCM_S16LE, break;
+        // this is a temporary method, when we can get  more information, modofy this.
+        if (codec_ul->id == CODEC_ID_PCM_S16LE)
+            break;
+    }
+
+    if (write) {
+        mxf_write_refs_count(pb, count);
+        for (i = 0; i < count; i++) {
+            put_buffer(pb, ff_mxf_essence_container_uls[essence_container_ul_sign[i]].uid, 16);
+        }
+        av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", count);
+        for (i = 0; i < count; i++)
+            PRINT_KEY(s, "essence container ul:\n", ff_mxf_essence_container_uls[essence_container_ul_sign[i]].uid);
+    }
+    return count;
+}
+
 static void mxf_write_preface(AVFormatContext *s)
 {
     MXFContext *mxf = s->priv_data;
@@ -352,6 +389,108 @@
     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);
+
+    if (type == SourcePackage) {
+        // write multiple descriptor reference
+        mxf_write_local_tag(pb, 16, 0x4701);
+        mxf_write_uuid(pb, MultipleDescriptor, 0);
+    }
+}
+
+static void mxf_write_track(AVFormatContext *s, int stream_index, enum MXFMetadataSetType type, int *track_number_sign)
+{
+    ByteIOContext *pb = s->pb;
+    AVStream *st;
+    MXFStreamContext *sc;
+    const MXFCodecUL *element;
+    int i = 0;
+
+    mxf_write_metadata_key(pb, 0x013b00);
+    PRINT_KEY(s, "track key", pb->buf_ptr - 16);
+    klv_encode_ber_length(pb, 80);
+
+    st = s->streams[stream_index];
+    sc = st->priv_data;
+
+    // write track uid
+    mxf_write_local_tag(pb, 16, 0x3C0A);
+    mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, stream_index);
+    PRINT_KEY(s, "track uid", pb->buf_ptr - 16);
+    // write track id
+    mxf_write_local_tag(pb, 4, 0x4801);
+    put_be32(pb, stream_index);
+
+    mxf_write_local_tag(pb, 4, 0x4804);
+    if (type != MaterialPackage) {
+        for (element = mxf_essence_element_key; element->id != CODEC_ID_NONE; element++) {
+            if (st->codec->codec_id== element->id) {
+                // set essence_element key
+                memcpy(sc->track_essence_element_key, element->uid, 16);
+                sc->track_essence_element_key[15] += track_number_sign[i];
+                // write track number
+                put_buffer(pb, sc->track_essence_element_key + 12, 4);
+
+                track_number_sign[i] ++;
+                break;
+            }
+            i++;
+        }
+    } else {
+        put_be32(pb, 0); // track number of material package is 0
+    }
+
+    mxf_write_local_tag(pb, 8, 0x4B01);
+    put_be32(pb, st->time_base.den);
+    put_be32(pb, st->time_base.num);
+
+    // write origin
+    mxf_write_local_tag(pb, 8, 0x4B02);
+    put_be64(pb, 0);
+
+    // write sequence refs
+    mxf_write_local_tag(pb, 16, 0x4803);
+    mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, stream_index);
+}
+
 static void mxf_write_common_fields(    ByteIOContext *pb, AVStream *st)
 {
     const MXFDataDefinitionUL * data_def_ul;
@@ -366,20 +505,69 @@
     put_be64(pb, st->duration);
 }
 
-static int mux_write_packet(AVFormatContext *s, AVPacket *pkt)
+static void mxf_write_sequence(AVFormatContext *s, int stream_index, enum MXFMetadataSetType type)
 {
     ByteIOContext *pb = s->pb;
-    AVStream *st = s->streams[pkt->stream_index];
-    MXFStreamContext *sc = st->priv_data;
+    AVStream *st;
 
-    put_buffer(pb, sc->track_essence_element_key, 16); // write key
-    klv_encode_ber_length(pb, pkt->size); // write length
-    put_buffer(pb, pkt->data, pkt->size); // write value
+    mxf_write_metadata_key(pb, 0x010f00);
+    PRINT_KEY(s, "sequence key", pb->buf_ptr - 16);
+    klv_encode_ber_length(pb, 80);
 
-    put_flush_packet(pb);
-    return 0;
+    st = s->streams[stream_index];
+
+    mxf_write_local_tag(pb, 16, 0x3C0A);
+    mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, stream_index);
+
+    PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16);
+    mxf_write_common_fields(pb, st);
+
+    // write structural component
+    mxf_write_local_tag(pb, 16 + 8, 0x1001);
+    mxf_write_refs_count(pb, 1);
+    mxf_write_uuid(pb, type == MaterialPackage ? SourceClip: SourceClip + TypeBottom, stream_index);
 }
 
+static void mxf_write_structural_component(AVFormatContext *s, int stream_index, enum MXFMetadataSetType type)
+{
+    ByteIOContext *pb = s->pb;
+    AVStream *st;
+    int i;
+
+    mxf_write_metadata_key(pb, 0x011100);
+    PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16);
+    klv_encode_ber_length(pb, 108);
+
+    st = s->streams[stream_index];
+
+    // write uid
+    mxf_write_local_tag(pb, 16, 0x3C0A);
+    mxf_write_uuid(pb, type == MaterialPackage ? SourceClip: SourceClip + TypeBottom, stream_index);
+
+    PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16);
+    mxf_write_common_fields(pb, st);
+
+    // write start_position
+    mxf_write_local_tag(pb, 8, 0x1201);
+    put_be64(pb, 0);
+
+    mxf_write_local_tag(pb, 32, 0x1101);
+    if (type == SourcePackage) {
+        // write source package uid, end of the reference
+        for (i = 0; i < 4; i++) {
+            put_be64(pb, 0);
+        }
+    } else
+        mxf_write_umid(pb, SourcePackage, 0);
+
+    mxf_write_local_tag(pb, 4, 0x1102);
+    if (type == SourcePackage)
+        // write source track id
+        put_be32(pb, 0);
+    else
+        put_be32(pb, stream_index);
+}
+
 static void mxf_write_multi_descriptor(AVFormatContext *s)
 {
     ByteIOContext *pb = s->pb;
@@ -541,6 +729,46 @@
     return 0;
 }
 
+static void mxf_write_partition(AVFormatContext *s, int64_t byte_position, int bodysid, const uint8_t *key)
+{
+    MXFContext *mxf = s->priv_data;
+    ByteIOContext *pb = s->pb;
+    // write klv
+    put_buffer(pb, key, 16);
+    if (!mxf->essence_container_count)
+        mxf->essence_container_count = mxf_write_essence_container_refs(s, 0);
+    klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);
+
+    // write partition value
+    put_be16(pb, 1); // majorVersion
+    put_be16(pb, 2); // minorVersion
+    put_be32(pb, 1); // kagSize
+
+    put_be64(pb, byte_position); // thisPartition
+    put_be64(pb, 0); // previousPartition
+
+    // set offset
+    if (!byte_position)
+        mxf->header_footer_partition_offset = url_ftell(pb);
+    put_be64(pb, byte_position); // footerPartition,update later
+
+    // set offset
+    if (!byte_position)
+        mxf->header_byte_count_offset = url_ftell(pb);
+    put_be64(pb, 0); // headerByteCount, update later
+
+    // no indexTable
+    put_be64(pb, 0); // indexByteCount
+    put_be32(pb, 0); // indexSID
+    put_be64(pb, 0); // bodyOffset
+
+    put_be32(pb, bodysid); // bodySID
+    put_buffer(pb, op1a_ul, 16); // operational pattern
+
+    // essence container
+    mxf_write_essence_container_refs(s, 1);
+}
+
 static int mux_write_header(AVFormatContext *s)
 {
     MXFContext *mxf = s->priv_data;
@@ -568,6 +796,20 @@
     return -1;
 }
 
+static int mux_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    ByteIOContext *pb = s->pb;
+    AVStream *st = s->streams[pkt->stream_index];
+    MXFStreamContext *sc = st->priv_data;
+
+    put_buffer(pb, sc->track_essence_element_key, 16); // write key
+    klv_encode_ber_length(pb, pkt->size); // write length
+    put_buffer(pb, pkt->data, pkt->size); // write value
+
+    put_flush_packet(pb);
+    return 0;
+}
+
 static void mxf_update_header_partition(AVFormatContext *s, int64_t footer_partition_offset)
 {
     MXFContext *mxf = s->priv_data;
Index: mxf.h
===================================================================
--- mxf.h	(revision 14903)
+++ mxf.h	(working copy)
@@ -41,6 +41,7 @@
     Identification,
     ContentStorage,
     SubDescriptor,
+    TypeBottom,// add metadata type before this
 };
 
 typedef struct {
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to