~ubuntu-branches/ubuntu/precise/libav/precise-updates

« back to all changes in this revision

Viewing changes to libavformat/mxfdec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:30:00 UTC
  • mfrom: (1.2.8) (1.1.13 experimental)
  • Revision ID: package-import@ubuntu.com-20120112223000-cmfo7w78q13i2fd9
Tags: 4:0.8~beta2-1ubuntu1
* Merge from debian, remaining changes:
  - don't build against libdirac, lame, libopenjpeg, librtmp, 
    x264, and xvid  (all in universe)

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
//#define DEBUG
47
47
 
48
48
#include "libavutil/aes.h"
 
49
#include "libavutil/mathematics.h"
49
50
#include "libavcodec/bytestream.h"
50
51
#include "avformat.h"
 
52
#include "internal.h"
51
53
#include "mxf.h"
52
54
 
53
55
typedef struct {
223
225
 
224
226
    if (length > 61444) /* worst case PAL 1920 samples 8 channels */
225
227
        return -1;
226
 
    av_new_packet(pkt, length);
227
 
    avio_read(pb, pkt->data, length);
 
228
    length = av_get_packet(pb, pkt, length);
 
229
    if (length < 0)
 
230
        return length;
228
231
    data_ptr = pkt->data;
229
232
    end_ptr = pkt->data + length;
230
233
    buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */
231
 
    for (; buf_ptr < end_ptr; ) {
 
234
    for (; buf_ptr + st->codec->channels*4 < end_ptr; ) {
232
235
        for (i = 0; i < st->codec->channels; i++) {
233
236
            uint32_t sample = bytestream_get_le32(&buf_ptr);
234
237
            if (st->codec->bits_per_coded_sample == 24)
238
241
        }
239
242
        buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M
240
243
    }
241
 
    pkt->size = data_ptr - pkt->data;
 
244
    av_shrink_packet(pkt, data_ptr - pkt->data);
242
245
    return 0;
243
246
}
244
247
 
248
251
    MXFContext *mxf = s->priv_data;
249
252
    AVIOContext *pb = s->pb;
250
253
    int64_t end = avio_tell(pb) + klv->length;
251
 
    uint64_t size;
 
254
    int64_t size;
252
255
    uint64_t orig_size;
253
256
    uint64_t plaintext_size;
254
257
    uint8_t ivec[16];
290
293
    if (memcmp(tmpbuf, checkv, 16))
291
294
        av_log(s, AV_LOG_ERROR, "probably incorrect decryption key\n");
292
295
    size -= 32;
293
 
    av_get_packet(pb, pkt, size);
 
296
    size = av_get_packet(pb, pkt, size);
 
297
    if (size < 0)
 
298
        return size;
 
299
    else if (size < plaintext_size)
 
300
        return AVERROR_INVALIDDATA;
294
301
    size -= plaintext_size;
295
302
    if (mxf->aesc)
296
303
        av_aes_crypt(mxf->aesc, &pkt->data[plaintext_size],
297
304
                     &pkt->data[plaintext_size], size >> 4, ivec, 1);
298
 
    pkt->size = orig_size;
 
305
    av_shrink_packet(pkt, orig_size);
299
306
    pkt->stream_index = index;
300
307
    avio_skip(pb, end - avio_tell(pb));
301
308
    return 0;
332
339
                    av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");
333
340
                    return -1;
334
341
                }
335
 
            } else
336
 
                av_get_packet(s->pb, pkt, klv.length);
 
342
            } else {
 
343
                int ret = av_get_packet(s->pb, pkt, klv.length);
 
344
                if (ret < 0)
 
345
                    return ret;
 
346
            }
337
347
            pkt->stream_index = index;
338
348
            pkt->pos = klv.offset;
339
349
            return 0;
737
747
        if (!source_track)
738
748
            continue;
739
749
 
740
 
        st = av_new_stream(mxf->fc, source_track->track_id);
 
750
        st = avformat_new_stream(mxf->fc, NULL);
741
751
        if (!st) {
742
752
            av_log(mxf->fc, AV_LOG_ERROR, "could not allocate stream\n");
743
753
            return -1;
744
754
        }
 
755
        st->id = source_track->track_id;
745
756
        st->priv_data = source_track;
746
757
        st->duration = component->duration;
747
758
        if (st->duration == -1)
748
759
            st->duration = AV_NOPTS_VALUE;
749
760
        st->start_time = component->start_position;
750
 
        av_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den);
 
761
        avpriv_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den);
751
762
 
752
763
        if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) {
753
764
            av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n");
820
831
            st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
821
832
            /* TODO: implement CODEC_ID_RAWAUDIO */
822
833
            if (st->codec->codec_id == CODEC_ID_PCM_S16LE) {
823
 
                if (descriptor->bits_per_sample == 24)
 
834
                if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)
824
835
                    st->codec->codec_id = CODEC_ID_PCM_S24LE;
825
836
                else if (descriptor->bits_per_sample == 32)
826
837
                    st->codec->codec_id = CODEC_ID_PCM_S32LE;
827
838
            } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
828
 
                if (descriptor->bits_per_sample == 24)
 
839
                if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)
829
840
                    st->codec->codec_id = CODEC_ID_PCM_S24BE;
830
841
                else if (descriptor->bits_per_sample == 32)
831
842
                    st->codec->codec_id = CODEC_ID_PCM_S32BE;
1010
1021
        sample_time = 0;
1011
1022
    seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);
1012
1023
    avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET);
1013
 
    av_update_cur_dts(s, st, sample_time);
 
1024
    ff_update_cur_dts(s, st, sample_time);
1014
1025
    return 0;
1015
1026
}
1016
1027
 
1017
1028
AVInputFormat ff_mxf_demuxer = {
1018
 
    "mxf",
1019
 
    NULL_IF_CONFIG_SMALL("Material eXchange Format"),
1020
 
    sizeof(MXFContext),
1021
 
    mxf_probe,
1022
 
    mxf_read_header,
1023
 
    mxf_read_packet,
1024
 
    mxf_read_close,
1025
 
    mxf_read_seek,
 
1029
    .name           = "mxf",
 
1030
    .long_name      = NULL_IF_CONFIG_SMALL("Material eXchange Format"),
 
1031
    .priv_data_size = sizeof(MXFContext),
 
1032
    .read_probe     = mxf_probe,
 
1033
    .read_header    = mxf_read_header,
 
1034
    .read_packet    = mxf_read_packet,
 
1035
    .read_close     = mxf_read_close,
 
1036
    .read_seek      = mxf_read_seek,
1026
1037
};