~ubuntu-branches/debian/experimental/libav/experimental

« back to all changes in this revision

Viewing changes to libavformat/mxfdec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-01-18 15:46:55 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20140118154655-iz6u00yevkat1jqi
Tags: 6:10~alpha2-1
New Upstream release 10_alpha2. This upstream git snapshot has too many
changes to list here, cf. to the upstream Changelog:
http://git.libav.org/?p=libav.git;a=blob;f=Changelog;hb=refs/tags/v10_alpha2

Show diffs side-by-side

added added

removed removed

Lines of Context:
312
312
    data_ptr = pkt->data;
313
313
    end_ptr = pkt->data + length;
314
314
    buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */
315
 
    for (; buf_ptr + st->codec->channels*4 < end_ptr; ) {
 
315
    for (; end_ptr - buf_ptr >= st->codec->channels * 4; ) {
316
316
        for (i = 0; i < st->codec->channels; i++) {
317
317
            uint32_t sample = bytestream_get_le32(&buf_ptr);
318
318
            if (st->codec->bits_per_coded_sample == 24)
418
418
    uint32_t nb_essence_containers;
419
419
    int err;
420
420
 
421
 
    if (mxf->partitions_count+1 >= UINT_MAX / sizeof(*mxf->partitions))
422
 
        return AVERROR(ENOMEM);
423
 
 
424
421
    if ((err = av_reallocp_array(&mxf->partitions, mxf->partitions_count + 1,
425
422
                                 sizeof(*mxf->partitions))) < 0) {
426
423
        mxf->partitions_count = 0;
552
549
{
553
550
    int err;
554
551
 
555
 
    if (mxf->metadata_sets_count+1 >= UINT_MAX / sizeof(*mxf->metadata_sets))
556
 
        return AVERROR(ENOMEM);
557
552
    if ((err = av_reallocp_array(&mxf->metadata_sets, mxf->metadata_sets_count + 1,
558
553
                                 sizeof(*mxf->metadata_sets))) < 0) {
559
554
        mxf->metadata_sets_count = 0;
863
858
    default:
864
859
        /* Private uid used by SONY C0023S01.mxf */
865
860
        if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) {
 
861
            av_free(descriptor->extradata);
 
862
            descriptor->extradata_size = 0;
866
863
            descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
867
864
            if (!descriptor->extradata)
868
865
                return AVERROR(ENOMEM);
974
971
    /* sort segments by {BodySID, IndexSID, IndexStartPosition}, remove duplicates while we're at it */
975
972
    for (i = 0; i < nb_segments; i++) {
976
973
        int best = -1, best_body_sid = -1, best_index_sid = -1, best_index_start = -1;
 
974
        uint64_t best_index_duration = 0;
977
975
 
978
976
        for (j = 0; j < nb_segments; j++) {
979
977
            MXFIndexTableSegment *s = unsorted_segments[j];
980
978
 
981
979
            /* Require larger BosySID, IndexSID or IndexStartPosition then the previous entry. This removes duplicates.
982
980
             * We want the smallest values for the keys than what we currently have, unless this is the first such entry this time around.
 
981
             * If we come across an entry with the same IndexStartPosition but larger IndexDuration, then we'll prefer it over the one we currently have.
983
982
             */
984
983
            if ((i == 0     || s->body_sid > last_body_sid || s->index_sid > last_index_sid || s->index_start_position > last_index_start) &&
985
 
                (best == -1 || s->body_sid < best_body_sid || s->index_sid < best_index_sid || s->index_start_position < best_index_start)) {
 
984
                (best == -1 || s->body_sid < best_body_sid || s->index_sid < best_index_sid || s->index_start_position < best_index_start ||
 
985
                (s->index_start_position == best_index_start && s->index_duration > best_index_duration))) {
986
986
                best             = j;
987
987
                best_body_sid    = s->body_sid;
988
988
                best_index_sid   = s->index_sid;
989
989
                best_index_start = s->index_start_position;
 
990
                best_index_duration = s->index_duration;
990
991
            }
991
992
        }
992
993
 
1239
1240
        }
1240
1241
    }
1241
1242
 
1242
 
    if (mxf->nb_index_tables > INT_MAX / sizeof(MXFIndexTable) ||
1243
 
        !(mxf->index_tables = av_mallocz(mxf->nb_index_tables *
1244
 
                                         sizeof(MXFIndexTable)))) {
 
1243
    mxf->index_tables = av_mallocz_array(mxf->nb_index_tables,
 
1244
                                         sizeof(*mxf->index_tables));
 
1245
    if (!mxf->index_tables) {
1245
1246
        av_log(mxf->fc, AV_LOG_ERROR, "failed to allocate index tables\n");
1246
1247
        ret = AVERROR(ENOMEM);
1247
1248
        goto finish_decoding_index;
1260
1261
    for (i = j = 0; j < mxf->nb_index_tables; i += mxf->index_tables[j++].nb_segments) {
1261
1262
        MXFIndexTable *t = &mxf->index_tables[j];
1262
1263
 
1263
 
        if (t->nb_segments >
1264
 
            (INT_MAX / sizeof(MXFIndexTableSegment *)) ||
1265
 
            !(t->segments = av_mallocz(t->nb_segments *
1266
 
                                       sizeof(MXFIndexTableSegment*)))) {
 
1264
        t->segments = av_mallocz_array(t->nb_segments,
 
1265
                                       sizeof(*t->segments));
 
1266
 
 
1267
        if (!t->segments) {
1267
1268
            av_log(mxf->fc, AV_LOG_ERROR, "failed to allocate IndexTableSegment"
1268
1269
                   " pointer array\n");
1269
1270
            ret = AVERROR(ENOMEM);
1484
1485
                           "SegmentedFrame layout isn't currently supported\n");
1485
1486
                    break;
1486
1487
                case FullFrame:
 
1488
                    st->codec->field_order = AV_FIELD_PROGRESSIVE;
1487
1489
                    break;
1488
1490
                case OneField:
1489
1491
                    /* Every other line is stored and needs to be duplicated. */
1646
1648
        /* Accept the 64k local set limit being exceeded (Avid). Don't accept
1647
1649
         * it extending past the end of the KLV though (zzuf5.mxf). */
1648
1650
        if (avio_tell(pb) > klv_end) {
 
1651
            if (ctx_size)
 
1652
                av_free(ctx);
 
1653
 
1649
1654
            av_log(mxf->fc, AV_LOG_ERROR,
1650
1655
                   "local tag %#04x extends past end of local set @ %#"PRIx64"\n",
1651
1656
                   tag, klv->offset);
2237
2242
        sample_time = 0;
2238
2243
    seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);
2239
2244
 
2240
 
    if ((ret = avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET)) < 0)
2241
 
        return ret;
 
2245
    seekpos = avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET);
 
2246
    if (seekpos < 0)
 
2247
        return seekpos;
 
2248
 
2242
2249
    ff_update_cur_dts(s, st, sample_time);
2243
2250
    mxf->current_edit_unit = sample_time;
2244
2251
    } else {