~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavformat/avidec.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
    int remaining;
40
40
    int packet_size;
41
41
 
42
 
    int scale;
43
 
    int rate;
 
42
    uint32_t scale;
 
43
    uint32_t rate;
44
44
    int sample_size; /* size of one sample (or packet) (in the rate/scale sense) in bytes */
45
45
 
46
46
    int64_t cum_len; /* temporary storage (used during seek) */
325
325
    }
326
326
}
327
327
 
328
 
static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
 
328
static int avi_read_header(AVFormatContext *s)
329
329
{
330
330
    AVIContext *avi = s->priv_data;
331
331
    AVIOContext *pb = s->pb;
513
513
            avio_rl32(pb); /* quality */
514
514
            ast->sample_size = avio_rl32(pb); /* sample ssize */
515
515
            ast->cum_len *= FFMAX(1, ast->sample_size);
516
 
//            av_log(s, AV_LOG_DEBUG, "%d %d %d %d\n", ast->rate, ast->scale, ast->start, ast->sample_size);
 
516
            av_dlog(s, "%"PRIu32" %"PRIu32" %d\n",
 
517
                    ast->rate, ast->scale, ast->sample_size);
517
518
 
518
519
            switch(tag1) {
519
520
            case MKTAG('v', 'i', 'd', 's'):
554
555
                        st->codec->width=avih_width;
555
556
                        st->codec->height=avih_height;
556
557
                        st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
557
 
                        st->codec->codec_id = CODEC_ID_AMV;
 
558
                        st->codec->codec_id = AV_CODEC_ID_AMV;
558
559
                        avio_skip(pb, size);
559
560
                        break;
560
561
                    }
563
564
                    if (tag1 == MKTAG('D', 'X', 'S', 'B') || tag1 == MKTAG('D','X','S','A')) {
564
565
                        st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
565
566
                        st->codec->codec_tag = tag1;
566
 
                        st->codec->codec_id = CODEC_ID_XSUB;
 
567
                        st->codec->codec_id = AV_CODEC_ID_XSUB;
567
568
                        break;
568
569
                    }
569
570
 
608
609
                    if(tag1 == MKTAG('A', 'V', 'R', 'n') &&
609
610
                       st->codec->extradata_size >= 31 &&
610
611
                       !memcmp(&st->codec->extradata[28], "1:1", 3))
611
 
                        st->codec->codec_id = CODEC_ID_RAWVIDEO;
 
612
                        st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
612
613
 
613
614
                    if(st->codec->codec_tag==0 && st->codec->height > 0 && st->codec->extradata_size < 1U<<30){
614
615
                        st->codec->extradata_size+= 9;
637
638
                    /* ADTS header is in extradata, AAC without header must be
638
639
                     * stored as exact frames. Parser not needed and it will
639
640
                     * fail. */
640
 
                    if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size)
 
641
                    if (st->codec->codec_id == AV_CODEC_ID_AAC && st->codec->extradata_size)
641
642
                        st->need_parsing = AVSTREAM_PARSE_NONE;
642
643
                    /* AVI files with Xan DPCM audio (wrongly) declare PCM
643
644
                     * audio in the header but have Axan as stream_code_tag. */
644
645
                    if (st->codec->stream_codec_tag == AV_RL32("Axan")){
645
 
                        st->codec->codec_id  = CODEC_ID_XAN_DPCM;
 
646
                        st->codec->codec_id  = AV_CODEC_ID_XAN_DPCM;
646
647
                        st->codec->codec_tag = 0;
647
648
                    }
648
649
                    if (amv_file_format){
649
 
                        st->codec->codec_id  = CODEC_ID_ADPCM_IMA_AMV;
 
650
                        st->codec->codec_id  = AV_CODEC_ID_ADPCM_IMA_AMV;
650
651
                        ast->dshow_block_align = 0;
651
652
                    }
652
653
                    break;
653
654
                case AVMEDIA_TYPE_SUBTITLE:
654
655
                    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
655
 
                    st->codec->codec_id   = CODEC_ID_PROBE;
 
656
                    st->codec->codec_id   = AV_CODEC_ID_PROBE;
656
657
                    break;
657
658
                default:
658
659
                    st->codec->codec_type = AVMEDIA_TYPE_DATA;
659
 
                    st->codec->codec_id= CODEC_ID_NONE;
 
660
                    st->codec->codec_id= AV_CODEC_ID_NONE;
660
661
                    st->codec->codec_tag= 0;
661
662
                    avio_skip(pb, size);
662
663
                    break;
690
691
 
691
692
                if(active_aspect.num && active_aspect.den && active.num && active.den){
692
693
                    st->sample_aspect_ratio= av_div_q(active_aspect, active);
693
 
//av_log(s, AV_LOG_ERROR, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect.den, active.num, active.den);
 
694
                    av_dlog(s, "vprp %d/%d %d/%d\n",
 
695
                            active_aspect.num, active_aspect.den,
 
696
                            active.num, active.den);
694
697
                }
695
698
                size -= 9*4;
696
699
            }
782
785
 
783
786
        ast->sub_ctx->pb      = pb;
784
787
        if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
785
 
            av_read_packet(ast->sub_ctx, &ast->sub_pkt);
 
788
            ff_read_packet(ast->sub_ctx, &ast->sub_pkt);
786
789
            *st->codec = *ast->sub_ctx->streams[0]->codec;
787
790
            ast->sub_ctx->streams[0]->codec->extradata = NULL;
788
791
            time_base = ast->sub_ctx->streams[0]->time_base;
824
827
        ast = sub_st->priv_data;
825
828
        *pkt = ast->sub_pkt;
826
829
        pkt->stream_index = sub_st->index;
827
 
        if (av_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0)
 
830
        if (ff_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0)
828
831
            ast->sub_pkt.data = NULL;
829
832
    }
830
833
    return sub_st;
860
863
        size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
861
864
 
862
865
        n= get_stream_idx(d+2);
863
 
//av_log(s, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
 
866
        av_dlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n",
 
867
                d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
864
868
        if(i + (uint64_t)size > avi->fsize || d[0] > 127)
865
869
            continue;
866
870
 
870
874
           ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')
871
875
           ||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){
872
876
            avio_skip(pb, size);
873
 
//av_log(s, AV_LOG_DEBUG, "SKIP\n");
874
877
            goto start_sync;
875
878
        }
876
879
 
944
947
 
945
948
                if (exit_early)
946
949
                    return 0;
947
 
//av_log(s, AV_LOG_DEBUG, "OK\n");
948
950
                if(d[2]*256+d[3] == ast->prefix)
949
951
                    ast->prefix_count++;
950
952
                else{
1005
1007
 
1006
1008
            ts = av_rescale_q(ts, st->time_base, (AVRational){FFMAX(1, ast->sample_size), AV_TIME_BASE});
1007
1009
 
1008
 
//            av_log(s, AV_LOG_DEBUG, "%"PRId64" %d/%d %"PRId64"\n", ts, st->time_base.num, st->time_base.den, ast->frame_offset);
 
1010
            av_dlog(s, "%"PRId64" %d/%d %"PRId64"\n", ts,
 
1011
                    st->time_base.num, st->time_base.den, ast->frame_offset);
1009
1012
            if(ts < best_ts){
1010
1013
                best_ts= ts;
1011
1014
                best_st= st;
1025
1028
                best_ast->frame_offset= best_st->index_entries[i].timestamp;
1026
1029
        }
1027
1030
 
1028
 
//        av_log(s, AV_LOG_DEBUG, "%d\n", i);
1029
1031
        if(i>=0){
1030
1032
            int64_t pos= best_st->index_entries[i].pos;
1031
1033
            pos += best_ast->packet_size - best_ast->remaining;
1032
1034
            avio_seek(s->pb, pos + 8, SEEK_SET);
1033
 
//        av_log(s, AV_LOG_DEBUG, "pos=%"PRId64"\n", pos);
1034
1035
 
1035
1036
            assert(best_ast->remaining <= best_ast->packet_size);
1036
1037
 
1096
1097
//                pkt->dts += ast->start;
1097
1098
            if(ast->sample_size)
1098
1099
                pkt->dts /= ast->sample_size;
1099
 
//av_log(s, AV_LOG_DEBUG, "dts:%"PRId64" offset:%"PRId64" %d/%d smpl_siz:%d base:%d st:%d size:%d\n", pkt->dts, ast->frame_offset, ast->scale, ast->rate, ast->sample_size, AV_TIME_BASE, avi->stream_index, size);
 
1100
            av_dlog(s, "dts:%"PRId64" offset:%"PRId64" %d/%d smpl_siz:%d base:%d st:%d size:%d\n",
 
1101
                    pkt->dts, ast->frame_offset, ast->scale, ast->rate,
 
1102
                    ast->sample_size, AV_TIME_BASE, avi->stream_index, size);
1100
1103
            pkt->stream_index = avi->stream_index;
1101
1104
 
1102
1105
            if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
1268
1271
    av_free_packet(&ast2->sub_pkt);
1269
1272
    if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
1270
1273
        avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
1271
 
        av_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
 
1274
        ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
1272
1275
}
1273
1276
 
1274
1277
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
1296
1299
    pos = st->index_entries[index].pos;
1297
1300
    timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
1298
1301
 
1299
 
//    av_log(s, AV_LOG_DEBUG, "XX %"PRId64" %d %"PRId64"\n", timestamp, index, st->index_entries[index].timestamp);
 
1302
    av_dlog(s, "XX %"PRId64" %d %"PRId64"\n",
 
1303
            timestamp, index, st->index_entries[index].timestamp);
1300
1304
 
1301
1305
    if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1302
1306
        /* One and only one real stream for DV in AVI, and it has video  */
1306
1310
 
1307
1311
        /* Feed the DV video stream version of the timestamp to the */
1308
1312
        /* DV demux so it can synthesize correct timestamps.        */
1309
 
        dv_offset_reset(avi->dv_demux, timestamp);
 
1313
        ff_dv_offset_reset(avi->dv_demux, timestamp);
1310
1314
 
1311
1315
        avio_seek(s->pb, pos, SEEK_SET);
1312
1316
        avi->stream_index= -1;
1344
1348
                index++;
1345
1349
        }
1346
1350
 
1347
 
//        av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %"PRId64"\n", timestamp, index, st2->index_entries[index].timestamp);
 
1351
        av_dlog(s, "%"PRId64" %d %"PRId64"\n",
 
1352
                timestamp, index, st2->index_entries[index].timestamp);
1348
1353
        /* extract the current frame number */
1349
1354
        ast2->frame_offset = st2->index_entries[index].timestamp;
1350
1355
    }
1393
1398
 
1394
1399
AVInputFormat ff_avi_demuxer = {
1395
1400
    .name           = "avi",
1396
 
    .long_name      = NULL_IF_CONFIG_SMALL("AVI format"),
 
1401
    .long_name      = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1397
1402
    .priv_data_size = sizeof(AVIContext),
1398
1403
    .read_probe     = avi_probe,
1399
1404
    .read_header    = avi_read_header,