[FFmpeg-soc] [Patch]MXF muxer version 0.0.3

zhentan feng spyfeng at gmail.com
Tue Aug 19 14:45:54 CEST 2008


Hi

2008/8/19 Michael Niedermayer <michaelni at gmx.at>

> On Tue, Aug 19, 2008 at 09:57:23AM +0800, zhentan feng wrote:
> > Hi
> >
> > 2008/8/19 Michael Niedermayer <michaelni at gmx.at>
> >
> > > On Tue, Aug 19, 2008 at 12:31:09AM +0800, zhentan feng wrote:
> > > > Hi,
> > > >
> > > > I have fixed bugs and improved the code into new version patch
> accordingt
> > > to
> > > > MXF muxer version 0.0.2 reviews from Michael.
> > > > However, it seems that the ok'ed parts are not commited into FFmpeg
> repo
> > > in
> > > > MXF muxer version 0.0.2 patch.
> > >
> > > Ive just commited them, please resubmit what is left.
> > >
> >
> > thanks.
> > here is the patch.
> >
> > --
> > Best wishes~
>
> > Index: mxfenc.c
> > ===================================================================
> > --- mxfenc.c  (revision 14829)
> > +++ mxfenc.c  (working copy)
> > @@ -38,6 +38,23 @@
> >      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;
>
> ok
>
>
> [...]
>
> > @@ -56,6 +148,18 @@
> >      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);
> > +}
>
> ok
>
>
> [...]
> > @@ -114,9 +218,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 +233,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)
>
> ok
>
>
> > @@ -138,6 +246,630 @@
> >      return uls;
> >  }
> >
>
> > +static int mxf_write_essence_container_refs(AVFormatContext *s)
>
> 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 = NULL;
>
> useless initialization
>
>
> > +
> > +    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;
>
> if(write)
>    put_buffer()
>
>
> > +                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;
> > +    }
> > +    // set the count of essence container for caculating the size of the
> references in other metadata sets
>
> > +    if (!mxf->essence_container_count)
> > +        mxf->essence_container_count = count;
> > +    else {
> > +        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);
> > +        }
> > +#ifdef DEBUG
> > +        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);
> > +#endif
> > +    }
> > +
> > +    return 0;
>
> return mxf->essence_container_count
>
>
>
>
> > +}
> > +
> > +static int mxf_write_preface(AVFormatContext *s)
> > +{
> > +    MXFContext *mxf = s->priv_data;
> > +    ByteIOContext *pb = s->pb;
> > +
> > +    mxf_write_metadata_key(pb, 0x012f00);
>
> > +#ifdef DEBUG
> > +    PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
> > +#endif
>
> PRINT_KEY can be #defined to nothing when DEBUG is not, this would avoid
> the #ifdef lines all over the code
>
>
> [...]
> > +static int 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);
> > +#ifdef DEBUG
> > +    PRINT_KEY(s, "track key", pb->buf_ptr - 16);
> > +#endif
> > +    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, Track * type, stream_index);
> > +#ifdef DEBUG
> > +    PRINT_KEY(s, "track uid", pb->buf_ptr - 16);
> > +#endif
> > +    // 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) {
> > +                // write track number
> > +                put_buffer(pb, element->uid + 12, 3);
> > +                put_byte(pb, element->uid[15] + track_number_sign[i]);
> > +                track_number_sign[i] ++;
> > +
> > +                // set essence_element key
>
> > +                memcpy(sc->track_essence_element_key, element->uid, 16);
>
> shouldnt [15] of track_essence_element_key be set to track_number_sign[i]
> as
> well?
>
I am not clear about your suggestion, could you please explain more?
thanks.

and I explain my intention here:
last 4 bytes of essence element key is the track number.
the last byte ,ie byte 16, is the index of different essence element to
distinguish different track has the same element key.

track_number_sign[i] record the  times of  the "i"th element key, when meet
the same element key , track_number_sign[i]++ , and be added on
track_essence_element[15], so the whole 16 bytes are used as element key.


> > +                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, Sequence * Track * type, stream_index);
>
> Is it intended to multiply the values of 2 enums with the type ?
>
yes. we choose the value of the enum represent the type of the metadata set.
it will generate a type to represent Sequence set, because the enum value of
Sequence is not big enough, it may confilict with other metadata set.


other reviews are defaulted as understand and will modify it soon.
thanks.
-- 
Best wishes~



More information about the FFmpeg-soc mailing list