Ticket #6759: 0001-Sony-XDCAM-Fix.patch

File 0001-Sony-XDCAM-Fix.patch, 22.3 KB (added by AxelTechnology, 9 years ago)
  • libavformat/mxfenc.c

    From 5df395dc89727211600660d2cfe4c21f2989886e Mon Sep 17 00:00:00 2001
    From: "Axel Technology" <development@axeltechnology.com>
    Date: Fri, 20 Oct 2017 12:27:05 +0200
    Subject: [PATCH] Sony XDCAM Fix
    
    ---
     libavformat/mxfenc.c | 167 +++++++++++++++++++++++++++++++++++++++++----------
     1 file changed, 136 insertions(+), 31 deletions(-)
    
    diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
    index 7733ef8..91d617b 100644
    a b typedef struct MXFStreamContext {  
    8989    int h_chroma_sub_sample;
    9090    int temporal_reordering;
    9191    AVRational aspect_ratio; ///< display aspect ratio
    92     int closed_gop;          ///< gop is closed, used in mpeg-2 frame parsing
     92        // XDCAM remarked
     93    //int closed_gop;          ///< gop is closed, used in mpeg-2 frame parsing
    9394    int video_bit_rate;
    94 } MXFStreamContext;
     95        // XDCAM start added
     96    int seq_closed_gop;      ///< all gops in sequence are closed, used in mpeg-2 descriptor
     97    int closed_gop;          ///< previous gop was closed, used in mpeg-2 frame parsing
     98    int max_gop;             ///< maximum gop size, used by mpeg-2 descriptor
     99    int b_picture_count;     ///< maximum number of consecutive b pictures, used in mpeg-2 descriptor
     100    int low_delay;           ///< low delay, used in mpeg-2 descriptor
     101        // XDCAM end added
     102        } MXFStreamContext;
    95103
    96104typedef struct MXFContainerEssenceEntry {
    97105    UID container_ul;
    static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,  
    341349static const uint8_t random_index_pack_key[]       = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x11,0x01,0x00 };
    342350static const uint8_t header_open_partition_key[]   = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }; // OpenIncomplete
    343351static const uint8_t header_closed_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete
    344 static const uint8_t klv_fill_key[]                = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };
     352// XDCAM Changed line
     353//static const uint8_t klv_fill_key[]                = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };
     354static const uint8_t klv_fill_key[]                = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };// XDCAM
    345355static const uint8_t body_partition_key[]          = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete
    346356
    347357/**
    static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x  
    352362
    353363/**
    354364 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html
    355  *             https://smpte-ra.org/sites/default/files/Labels.xml
    356365 */
    357366static const MXFLocalTagPair mxf_local_tag_batch[] = {
    358367    // preface set
    static const MXFLocalTagPair mxf_local_tag_batch[] = {  
    409418    { 0x3002, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00}}, /* ContainerDuration */
    410419    { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */
    411420    // Generic Picture Essence Descriptor
     421        // XDCAM ADDED
     422        { 0x320A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0D,0x00,0x00,0x00}}, /* DisplayXOffset  XDCAM*/
     423    { 0x320B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0E,0x00,0x00,0x00}}, /* DisplayYOffset XDCAM */
     424        // XDCAM end added
    412425    { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */
    413     { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */
    414     { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */
     426        // XDCAM changed
     427    //{ 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */
     428        { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map XDCAM */
     429        // XDCAM ADDED
     430        { 0x3205, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x08,0x00,0x00,0x00}}, /* Sampled Width XDCAM*/
     431    { 0x3204, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x07,0x00,0x00,0x00}}, /* Sampled Height XDCAM*/
     432    // XDCAM end added
     433        { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */
    415434    { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */
    416435    { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */
    417436    { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */
    static const MXFLocalTagPair mxf_local_tag_batch[] = {  
    419438    { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */
    420439    { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */
    421440    { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */
    422     { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */
     441        // XDCAM changed
     442    { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard XDCAM*/
    423443    // CDCI Picture Essence Descriptor
    424444    { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */
    425445    { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */
    426     { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */
     446        // XDCAM added
     447        { 0x3308, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x01,0x10,0x00,0x00,0x00}}, /* Vertical Subsampling XDCAM */
     448    // XDCAM end added
     449        { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */
    427450    // Generic Sound Essence Descriptor
    428451    { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */
    429452    { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */
    static const MXFLocalTagPair mxf_local_tag_batch[] = {  
    439462    { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */
    440463    { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */
    441464    { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
    442     // MPEG video Descriptor
    443     { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
    444     { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
     465    // XDCAM REMMED MPEG video Descriptor
     466    //{ 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
     467    //{ 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
     468// XDCAM new MPEG video Descriptor section
     469    { 0x8003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}}, /* LowDelay */
     470    { 0x8004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}}, /* ClosedGOP */
     471    { 0x8006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}}, /* MaxGOP */
     472    { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}}, /* BPictureCount */
     473    { 0x8008, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel*/
     474    { 0x8009, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */   
    445475    // Wave Audio Essence Descriptor
    446476    { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
    447477    { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
    static int klv_ber_length(uint64_t len)  
    483513        return (av_log2(len) >> 3) + 2;
    484514}
    485515
     516// XDCAM remmed function
     517#if 0
    486518static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)
    487519{
    488520    // Determine the best BER size
    static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)  
    503535    }
    504536    return 0;
    505537}
     538#endif
    506539
    507540static void klv_encode_ber4_length(AVIOContext *pb, int len)
    508541{
    static void mxf_write_primer_pack(AVFormatContext *s)  
    538571    local_tag_number += mxf->store_user_comments * FF_ARRAY_ELEMS(mxf_user_comments_local_tag);
    539572
    540573    avio_write(pb, primer_pack_key, 16);
    541     klv_encode_ber_length(pb, local_tag_number * 18 + 8);
     574        // XDCAM ber4
     575    klv_encode_ber4_length(pb, local_tag_number * 18 + 8);
    542576
    543577    avio_wb32(pb, local_tag_number); // local_tag num
    544578    avio_wb32(pb, 18); // item size, always 18 according to the specs
    static void mxf_write_preface(AVFormatContext *s)  
    615649
    616650    mxf_write_metadata_key(pb, 0x012f00);
    617651    PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
    618     klv_encode_ber_length(pb, 130 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count));
     652        // XDCAM ber4
     653    klv_encode_ber4_length(pb, 130 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count));
    619654
    620655    // write preface set uid
    621656    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_identification(AVFormatContext *s)  
    730765    length = 72 + mxf_utf16_local_tag_length(company) +
    731766                  mxf_utf16_local_tag_length(product) +
    732767                  mxf_utf16_local_tag_length(version);
    733     klv_encode_ber_length(pb, length);
     768// XDCAM ber4
     769                                  klv_encode_ber4_length(pb, length);
    734770
    735771    // write uid
    736772    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_content_storage(AVFormatContext *s)  
    759795
    760796    mxf_write_metadata_key(pb, 0x011800);
    761797    PRINT_KEY(s, "content storage key", pb->buf_ptr - 16);
    762     klv_encode_ber_length(pb, 92);
     798    // XDCAM ber4
     799        klv_encode_ber4_length(pb, 92);
    763800
    764801    // write uid
    765802    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSe  
    786823
    787824    mxf_write_metadata_key(pb, 0x013b00);
    788825    PRINT_KEY(s, "track key", pb->buf_ptr - 16);
    789     klv_encode_ber_length(pb, 80);
     826    // XDCAM ber4
     827        klv_encode_ber4_length(pb, 80);
    790828
    791829    // write track uid
    792830    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_sequence(AVFormatContext *s, AVStream *st, enum MXFMetadat  
    857895
    858896    mxf_write_metadata_key(pb, 0x010f00);
    859897    PRINT_KEY(s, "sequence key", pb->buf_ptr - 16);
    860     klv_encode_ber_length(pb, 80);
     898    // XDCAM ber4
     899        klv_encode_ber4_length(pb, 80);
    861900
    862901    mxf_write_local_tag(pb, 16, 0x3C0A);
    863902    mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, st->index);
    static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum  
    883922    AVIOContext *pb = s->pb;
    884923
    885924    mxf_write_metadata_key(pb, 0x011400);
    886     klv_encode_ber_length(pb, 75);
     925    // XDCAM ber4
     926        klv_encode_ber4_length(pb, 75);
    887927
    888928    // UID
    889929    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enu  
    912952
    913953    mxf_write_metadata_key(pb, 0x011100);
    914954    PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16);
    915     klv_encode_ber_length(pb, 108);
     955    // XDCAM ber4
     956        klv_encode_ber4_length(pb, 108);
    916957
    917958    // write uid
    918959    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_multi_descriptor(AVFormatContext *s)  
    950991
    951992    mxf_write_metadata_key(pb, 0x014400);
    952993    PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16);
    953     klv_encode_ber_length(pb, 64 + 16LL * s->nb_streams);
     994    // XDCAM ber4
     995        klv_encode_ber4_length(pb, 64 + 16LL * s->nb_streams);
    954996
    955997    mxf_write_local_tag(pb, 16, 0x3C0A);
    956998    mxf_write_uuid(pb, MultipleDescriptor, 0);
    static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke  
    10141056    int stored_height = (st->codecpar->height+15)/16*16;
    10151057    int display_height;
    10161058    int f1, f2;
    1017     unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5;
     1059    // XDCAM added sc-.interlaced
     1060        unsigned desc_size = size+8+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20+5; // XDCAM
    10181061    if (sc->interlaced && sc->field_dominance)
    10191062        desc_size += 5;
    10201063    if (sc->signal_standard)
    static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke  
    10411084    mxf_write_local_tag(pb, 4, 0x3208);
    10421085    avio_wb32(pb, display_height>>sc->interlaced);
    10431086
     1087        // XDCAM added
     1088        // signal standard +5 XDCAM
     1089    mxf_write_local_tag(pb, 1, 0x3215);
     1090    if (display_height == 1080)
     1091        avio_w8(pb, 4); // SMPTE 274M
     1092    else if (display_height == 720)
     1093        avio_w8(pb, 5); // SMPTE 296M
     1094    else if (st->codec->width == 720) {
     1095        if (sc->interlaced)
     1096            avio_w8(pb, 1); // SMPTE 125M ITU-R BT.601
     1097        else
     1098            avio_w8(pb, 2); // SMPTE 293M ITU-R BT.1358
     1099    } else
     1100        avio_w8(pb, 0); // unknown
     1101        // XDCAM end added
    10441102    // presentation Y offset
    10451103    mxf_write_local_tag(pb, 4, 0x320B);
    10461104    avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced);
    static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke  
    10491107    mxf_write_local_tag(pb, 4, 0x3301);
    10501108    avio_wb32(pb, sc->component_depth);
    10511109
     1110// XDCAM added vertical subsampling
     1111    mxf_write_local_tag(pb, 4, 0x3308);
     1112    if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P)
     1113        avio_wb32(pb, 2);
     1114    else
     1115        avio_wb32(pb, 1);
     1116// XDCAM end added
    10521117    // horizontal subsampling
    10531118    mxf_write_local_tag(pb, 4, 0x3302);
    10541119    avio_wb32(pb, sc->h_chroma_sub_sample);
    static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)  
    11161181
    11171182    if (st->codecpar->codec_id != AV_CODEC_ID_H264) {
    11181183        mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
    1119 
     1184               
    11201185        // bit rate
    11211186        mxf_write_local_tag(pb, 4, 0x8000);
    11221187        avio_wb32(pb, sc->video_bit_rate);
    static int mxf_write_tagged_value(AVFormatContext *s, const char* name, const ch  
    12201285        return 1;
    12211286
    12221287    mxf_write_metadata_key(pb, 0x013f00);
    1223     klv_encode_ber_length(pb, 24 + name_size + indirect_value_size);
     1288    // XDCAM ber4
     1289        klv_encode_ber4_length(pb, 24 + name_size + indirect_value_size);
    12241290
    12251291    // write instance UID
    12261292    mxf_write_local_tag(pb, 16, 0x3C0A);
    static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type,  
    12691335            user_comment_count = mxf_write_user_comments(s, s->metadata);
    12701336        mxf_write_metadata_key(pb, 0x013600);
    12711337        PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
    1272         klv_encode_ber_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments);
     1338        // XDCAM ber4
     1339                klv_encode_ber4_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments);
    12731340    } else {
    12741341        mxf_write_metadata_key(pb, 0x013700);
    12751342        PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
    1276         klv_encode_ber_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference
     1343        // XDCAM ber4
     1344                klv_encode_ber4_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference
    12771345    }
    12781346
    12791347    // write uid
    static int mxf_write_essence_container_data(AVFormatContext *s)  
    13481416    AVIOContext *pb = s->pb;
    13491417
    13501418    mxf_write_metadata_key(pb, 0x012300);
    1351     klv_encode_ber_length(pb, 72);
     1419    // XDCAM ber4
     1420        klv_encode_ber4_length(pb, 72);
    13521421
    13531422    mxf_write_local_tag(pb, 16, 0x3C0A); // Instance UID
    13541423    mxf_write_uuid(pb, EssenceContainerData, 0);
    static void mxf_write_index_table_segment(AVFormatContext *s)  
    14131482    AVIOContext *pb = s->pb;
    14141483    int i, j, temporal_reordering = 0;
    14151484    int key_index = mxf->last_key_index;
     1485        // XDCAM added line
     1486        int prev_non_b_picture = 0;  // XDCAM
    14161487
    14171488    av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
    14181489
    static void mxf_write_index_table_segment(AVFormatContext *s)  
    14221493    avio_write(pb, index_table_segment_key, 16);
    14231494
    14241495    if (mxf->edit_unit_byte_count) {
    1425         klv_encode_ber_length(pb, 80);
     1496        // XDCAM ber4
     1497                klv_encode_ber4_length(pb, 80);
    14261498    } else {
    1427         klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1LL)*6 +
     1499        // XDCAM ber4
     1500                klv_encode_ber4_length(pb, 85 + 12+(s->nb_streams+1LL)*6 +
    14281501                              12+mxf->edit_units_count*(11+mxf->slice_count*4LL));
    14291502    }
    14301503
    static void mxf_write_index_table_segment(AVFormatContext *s)  
    14901563            }
    14911564        }
    14921565
     1566                // XDCAM added line
     1567                MXFStreamContext *sc = s->streams[0]->priv_data; // XDCAM
    14931568        mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A);
    14941569        avio_wb32(pb, mxf->edit_units_count);  // num of entries
    14951570        avio_wb32(pb, 11+mxf->slice_count*4);  // size of one entry
    static void mxf_write_index_table_segment(AVFormatContext *s)  
    14981573            int temporal_offset = 0;
    14991574
    15001575            if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame
     1576                                // XDCAM added line
     1577                                sc->max_gop = FFMAX(sc->max_gop, i - mxf->last_key_index); // XDCAM
    15011578                mxf->last_key_index = key_index;
    15021579                key_index = i;
    15031580            }
    static void mxf_write_index_table_segment(AVFormatContext *s)  
    15171594            avio_w8(pb, temporal_offset);
    15181595
    15191596            if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction
     1597                                // XDCAM added line
     1598                                sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture); // XDCAM
    15201599                avio_w8(pb, mxf->last_key_index - i);
    15211600            } else {
    15221601                avio_w8(pb, key_index - i); // key frame offset
    15231602                if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
    15241603                    mxf->last_key_index = key_index;
     1604                                // XDCAM added line
     1605                                prev_non_b_picture = i; // XDCAM
    15251606            }
    15261607
    15271608            if (!(mxf->index_entries[i].flags & 0x33) && // I-frame
    static int mxf_write_partition(AVFormatContext *s, int bodysid,  
    15901671    else
    15911672        avio_write(pb, body_partition_key, 16);
    15921673
    1593     klv_encode_ber_length(pb, 88 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count));
     1674    // XDCAM ber4
     1675        klv_encode_ber4_length(pb, 88 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count));
    15941676
    15951677    // write partition value
    15961678    avio_wb16(pb, 1); // majorVersion
    static const struct {  
    18231905    int profile;
    18241906    uint8_t interlaced;
    18251907} mxf_h264_codec_uls[] = {
    1826     {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 },      0,  66, 0 }, // AVC Baseline, Unconstrained Coding
    18271908    {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x20,0x01 },      0, 110, 0 }, // AVC High 10 Intra
    18281909    {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 232960,   0, 1 }, // AVC Intra 50 1080i60
    18291910    {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 281088,   0, 1 }, // AVC Intra 50 1080i50
    static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st,  
    19532034            if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
    19542035                st->codecpar->profile = pkt->data[i+1] & 0x07;
    19552036                st->codecpar->level   = pkt->data[i+2] >> 4;
     2037                                // XDCAM added line
     2038                                sc->low_delay = pkt->data[i+6] >> 7; // XDCAM
    19562039            } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
    19572040                sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
    19582041                if (sc->interlaced)
    static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational rate)  
    20392122
    20402123static int mxf_write_header(AVFormatContext *s)
    20412124{
     2125        local_log("Writing MXF header");
     2126       
    20422127    MXFContext *mxf = s->priv_data;
    20432128    int i, ret;
    20442129    uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
    static int mxf_write_header(AVFormatContext *s)  
    21452230                    av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
    21462231                }
    21472232                sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1;
     2233
    21482234            } else if (s->oformat == &ff_mxf_opatom_muxer) {
    21492235                AVRational tbc = av_inv_q(mxf->audio_edit_rate);
    21502236
    static void mxf_write_system_item(AVFormatContext *s)  
    22542340    avio_w8(pb, 0x00); // content package type
    22552341    avio_wb16(pb, 0x00); // channel handle
    22562342    avio_wb16(pb, (mxf->tc.start + frame) & 0xFFFF); // continuity count, supposed to overflow
     2343        // XDCAM added line
     2344    avio_wb16(pb, mxf->last_indexed_edit_unit + mxf->edit_units_count); // continuity count
    22572345    if (mxf->essence_container_count > 1)
    22582346        avio_write(pb, multiple_desc_ul, 16);
    22592347    else {
    static void mxf_write_random_index_pack(AVFormatContext *s)  
    25022590    int i;
    25032591
    25042592    avio_write(pb, random_index_pack_key, 16);
    2505     klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count);
     2593    // XDCAM ber4
     2594        klv_encode_ber4_length(pb, 28 + 12LL*mxf->body_partitions_count);
    25062595
    25072596    if (mxf->edit_unit_byte_count && s->oformat != &ff_mxf_opatom_muxer)
    25082597        avio_wb32(pb, 1); // BodySID of header partition
    AVOutputFormat ff_mxf_opatom_muxer = {  
    27642853    .interleave_packet = mxf_interleave,
    27652854    .priv_class        = &mxf_opatom_muxer_class,
    27662855};
     2856
     2857static void local_log(char * line)
     2858{
     2859    FILE *f = fopen("c:\\ffmpeg_log.txt", "w");
     2860        if (f == NULL)
     2861        {
     2862                printf("Error opening file!\n");
     2863                exit(1);
     2864        }
     2865       
     2866        /* print some text */
     2867        const char *text = "Write this to the file";
     2868        fprintf(f, "", line);
     2869       
     2870        fclose(f);
     2871}