Revision 8d1a5af7

View differences:

libavformat/mxfenc.c
1089 1089
    put_byte(pb, mxf->slice_count);
1090 1090

  
1091 1091
    if (!mxf->edit_unit_byte_count) {
1092
    // delta entry array
1093
    mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09);
1094
    put_be32(pb, s->nb_streams+1); // num of entries
1095
    put_be32(pb, 6);             // size of one entry
1096
    // write system item delta entry
1097
    put_byte(pb, 0);
1098
    put_byte(pb, 0); // slice entry
1099
    put_be32(pb, 0); // element delta
1100
    for (i = 0; i < s->nb_streams; i++) {
1101
        AVStream *st = s->streams[i];
1102
        MXFStreamContext *sc = st->priv_data;
1103
        put_byte(pb, sc->temporal_reordering);
1104
        if (sc->temporal_reordering)
1105
            temporal_reordering = 1;
1106
        // slice number
1107
        if (i == 0) { // video track
1108
            put_byte(pb, 0); // slice number
1109
            put_be32(pb, KAG_SIZE); // system item size including klv fill
1110
        } else { // audio track
1111
            unsigned audio_frame_size = sc->aic.samples[0]*sc->aic.sample_size;
1112
            audio_frame_size += klv_fill_size(audio_frame_size);
1113
            put_byte(pb, 1);
1114
            put_be32(pb, (i-1)*audio_frame_size); // element delta
1092
        // delta entry array
1093
        mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09);
1094
        put_be32(pb, s->nb_streams+1); // num of entries
1095
        put_be32(pb, 6);               // size of one entry
1096
        // write system item delta entry
1097
        put_byte(pb, 0);
1098
        put_byte(pb, 0); // slice entry
1099
        put_be32(pb, 0); // element delta
1100
        for (i = 0; i < s->nb_streams; i++) {
1101
            AVStream *st = s->streams[i];
1102
            MXFStreamContext *sc = st->priv_data;
1103
            put_byte(pb, sc->temporal_reordering);
1104
            if (sc->temporal_reordering)
1105
                temporal_reordering = 1;
1106
            if (i == 0) { // video track
1107
                put_byte(pb, 0); // slice number
1108
                put_be32(pb, KAG_SIZE); // system item size including klv fill
1109
            } else { // audio track
1110
                unsigned audio_frame_size = sc->aic.samples[0]*sc->aic.sample_size;
1111
                audio_frame_size += klv_fill_size(audio_frame_size);
1112
                put_byte(pb, 1);
1113
                put_be32(pb, (i-1)*audio_frame_size); // element delta
1114
            }
1115 1115
        }
1116
    }
1117 1116

  
1118
    mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A);
1119
    put_be32(pb, mxf->edit_units_count);  // num of entries
1120
    put_be32(pb, 11+mxf->slice_count*4);  // size of one entry
1121
    for (i = 0; i < mxf->edit_units_count; i++) {
1122
        if (temporal_reordering) {
1123
            int temporal_offset = 0;
1124
            for (j = i+1; j < mxf->edit_units_count; j++) {
1125
                temporal_offset++;
1126
                if (mxf->index_entries[j].flags & 0x10) { // backward prediction
1127
                    // next is not b, so is reordered
1128
                    if (!(mxf->index_entries[i+1].flags & 0x10)) {
1129
                        if ((mxf->index_entries[i].flags & 0x11) == 0) // i frame
1130
                            temporal_offset = 0;
1131
                        else
1132
                            temporal_offset = -temporal_offset;
1117
        mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A);
1118
        put_be32(pb, mxf->edit_units_count);  // num of entries
1119
        put_be32(pb, 11+mxf->slice_count*4);  // size of one entry
1120
        for (i = 0; i < mxf->edit_units_count; i++) {
1121
            if (temporal_reordering) {
1122
                int temporal_offset = 0;
1123
                for (j = i+1; j < mxf->edit_units_count; j++) {
1124
                    temporal_offset++;
1125
                    if (mxf->index_entries[j].flags & 0x10) { // backward prediction
1126
                        // next is not b, so is reordered
1127
                        if (!(mxf->index_entries[i+1].flags & 0x10)) {
1128
                            if ((mxf->index_entries[i].flags & 0x11) == 0) // i frame
1129
                                temporal_offset = 0;
1130
                            else
1131
                                temporal_offset = -temporal_offset;
1132
                        }
1133
                        break;
1133 1134
                    }
1134
                    break;
1135 1135
                }
1136
            }
1137
            put_byte(pb, temporal_offset);
1138
        } else
1139
            put_byte(pb, 0);
1140
        if (!(mxf->index_entries[i].flags & 0x33)) { // I frame
1141
            mxf->last_key_index = key_index;
1142
            key_index = i;
1143
        }
1144
        if (mxf->index_entries[i].flags & 0x10 && // backward prediction
1145
            !(mxf->index_entries[key_index].flags & 0x80)) { // open gop
1146
            put_byte(pb, mxf->last_key_index - i);
1147
        } else {
1148
            put_byte(pb, key_index - i); // key frame offset
1149
            if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
1136
                put_byte(pb, temporal_offset);
1137
            } else
1138
                put_byte(pb, 0);
1139
            if (!(mxf->index_entries[i].flags & 0x33)) { // I frame
1150 1140
                mxf->last_key_index = key_index;
1141
                key_index = i;
1142
            }
1143
            if (mxf->index_entries[i].flags & 0x10 && // backward prediction
1144
                !(mxf->index_entries[key_index].flags & 0x80)) { // open gop
1145
                put_byte(pb, mxf->last_key_index - i);
1146
            } else {
1147
                put_byte(pb, key_index - i); // key frame offset
1148
                if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
1149
                    mxf->last_key_index = key_index;
1150
            }
1151
            put_byte(pb, mxf->index_entries[i].flags);
1152
            // stream offset
1153
            put_be64(pb, mxf->index_entries[i].offset - mxf->first_edit_unit_offset);
1154
            if (s->nb_streams > 1)
1155
                put_be32(pb, mxf->index_entries[i].slice_offset);
1151 1156
        }
1152
        put_byte(pb, mxf->index_entries[i].flags);
1153
        // stream offset
1154
        put_be64(pb, mxf->index_entries[i].offset - mxf->first_edit_unit_offset);
1155
        if (s->nb_streams > 1)
1156
            put_be32(pb, mxf->index_entries[i].slice_offset);
1157
    }
1158 1157

  
1159
    mxf->last_key_index = key_index - mxf->edit_units_count;
1160
    mxf->last_indexed_edit_unit += mxf->edit_units_count;
1161
    mxf->edit_units_count = 0;
1158
        mxf->last_key_index = key_index - mxf->edit_units_count;
1159
        mxf->last_indexed_edit_unit += mxf->edit_units_count;
1160
        mxf->edit_units_count = 0;
1162 1161
    }
1163 1162
}
1164 1163

  
......
1207 1206

  
1208 1207
    // write klv
1209 1208
    put_buffer(pb, key, 16);
1210

  
1211 1209
    klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);
1212 1210

  
1213 1211
    // write partition value
......
1458 1456
        }
1459 1457

  
1460 1458
        if (!sc->index) {
1461
        sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
1462
        if (sc->index == -1) {
1463
            av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
1464
                   "codec not currently supported in container\n", i);
1465
            return -1;
1466
        }
1459
            sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
1460
            if (sc->index == -1) {
1461
                av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
1462
                       "codec not currently supported in container\n", i);
1463
                return -1;
1464
            }
1467 1465
        }
1468 1466

  
1469 1467
        sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
......
1473 1471
            present[sc->index] = 1;
1474 1472
        } else
1475 1473
            present[sc->index]++;
1474

  
1476 1475
        memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
1477 1476
        sc->track_essence_element_key[15] = present[sc->index];
1478 1477
        PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
......
1770 1769
    if (mxf->edit_unit_byte_count) { // no need to repeat index
1771 1770
        mxf_write_partition(s, 0, 0, footer_partition_key, 0);
1772 1771
    } else {
1773
    mxf_write_partition(s, 0, 2, footer_partition_key, 0);
1772
        mxf_write_partition(s, 0, 2, footer_partition_key, 0);
1774 1773

  
1775
    mxf_write_klv_fill(s);
1776
    mxf_write_index_table_segment(s);
1774
        mxf_write_klv_fill(s);
1775
        mxf_write_index_table_segment(s);
1777 1776
    }
1778 1777

  
1779 1778
    mxf_write_klv_fill(s);
......
1806 1805
    av_freep(&mxf->timecode_track);
1807 1806

  
1808 1807
    mxf_free(s);
1808

  
1809 1809
    return 0;
1810 1810
}
1811 1811

  

Also available in: Unified diff