Ticket #3000: ticket_3000.diff

File ticket_3000.diff, 7.0 KB (added by skamithi, 19 years ago)

danielk found out that actually the root cause is the url_fseek call that was added in ffmpeg changeset 7560. preventing avf_seek from been called for a dvd resolves the issue as well. So far haven't seen any harm in leaving it this way. Also fixed some compiling warnings in avformatdecoder.cpp

  • libs/libavformat/mpeg.c

     
    14401440{
    14411441    MpegDemuxContext *m = s->priv_data;
    14421442    int len, size, startcode, c, flags, header_len;
    1443     int64_t pts, dts, last_pos;
     1443    int64_t pts, dts;
     1444    int64_t last_sync= url_ftell(&s->pb);
    14441445
    1445     last_pos = -1;
     1446 error_redo:
     1447        url_fseek(&s->pb, last_sync, SEEK_SET);
    14461448 redo:
    14471449        /* next start code (should be immediately after) */
    14481450        m->header_state = 0xff;
    14491451        size = MAX_SYNC_SIZE;
    14501452        startcode = find_next_start_code(&s->pb, &size, &m->header_state);
    1451     //printf("startcode=%x pos=0x%Lx\n", startcode, url_ftell(&s->pb));
     1453        last_sync = url_ftell(&s->pb);
     1454    //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, url_ftell(&s->pb));
    14521455    if (startcode < 0)
    14531456        return AVERROR_IO;
    14541457    if (startcode == PACK_START_CODE)
     
    14811484    /* stuffing */
    14821485    for(;;) {
    14831486        if (len < 1)
    1484             goto redo;
     1487            goto error_redo;
    14851488        c = get_byte(&s->pb);
    14861489        len--;
    14871490        /* XXX: for mpeg1, should test only bit 7 */
     
    14901493    }
    14911494    if ((c & 0xc0) == 0x40) {
    14921495        /* buffer scale & size */
    1493         if (len < 2)
    1494             goto redo;
    14951496        get_byte(&s->pb);
    14961497        c = get_byte(&s->pb);
    14971498        len -= 2;
    14981499    }
    1499     if ((c & 0xf0) == 0x20) {
    1500         if (len < 4)
    1501             goto redo;
     1500    if ((c & 0xe0) == 0x20) {
    15021501        dts = pts = get_pts(&s->pb, c);
    15031502        len -= 4;
    1504     } else if ((c & 0xf0) == 0x30) {
    1505         if (len < 9)
    1506             goto redo;
    1507         pts = get_pts(&s->pb, c);
    1508         dts = get_pts(&s->pb, -1);
    1509         len -= 9;
     1503        if (c & 0x10){
     1504            dts = get_pts(&s->pb, -1);
     1505            len -= 5;
     1506        }
    15101507    } else if ((c & 0xc0) == 0x80) {
    15111508        /* mpeg 2 PES */
    15121509#if 0 /* some streams have this field set for no apparent reason */
     
    15191516        header_len = get_byte(&s->pb);
    15201517        len -= 2;
    15211518        if (header_len > len)
    1522             goto redo;
    1523         if ((flags & 0xc0) == 0x80) {
     1519            goto error_redo;
     1520        len -= header_len;
     1521        if (flags & 0x80) {
    15241522            dts = pts = get_pts(&s->pb, -1);
    1525             if (header_len < 5)
    1526                 goto redo;
    15271523            header_len -= 5;
    1528             len -= 5;
    1529         } if ((flags & 0xc0) == 0xc0) {
    1530             pts = get_pts(&s->pb, -1);
    1531             dts = get_pts(&s->pb, -1);
    1532             if (header_len < 10)
    1533                 goto redo;
    1534             header_len -= 10;
    1535             len -= 10;
     1524            if (flags & 0x40) {
     1525                dts = get_pts(&s->pb, -1);
     1526                header_len -= 5;
     1527            }
    15361528        }
    1537         len -= header_len;
    1538         while (header_len > 0) {
    1539             get_byte(&s->pb);
    1540             header_len--;
    1541         }
     1529        if(header_len < 0)
     1530            goto error_redo;
     1531        url_fskip(&s->pb, header_len);
    15421532    }
    15431533    else if( c!= 0xf )
    15441534        goto redo;
    15451535
    15461536    if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) {
    1547         if (len < 1)
    1548             goto redo;
    15491537        startcode = get_byte(&s->pb);
    15501538        len--;
    15511539        if (startcode >= 0x80 && startcode <= 0xbf) {
    15521540            /* audio: skip header */
    1553             if (len < 3)
    1554                 goto redo;
    15551541            get_byte(&s->pb);
    15561542            get_byte(&s->pb);
    15571543            get_byte(&s->pb);
    15581544            len -= 3;
    15591545        }
    15601546    }
     1547    if(len<0)
     1548        goto error_redo;
    15611549    if(dts != AV_NOPTS_VALUE && ppos && s->build_index){
    15621550        int i;
    15631551        for(i=0; i<s->nb_streams; i++){
  • libs/libmythtv/avformatdecoder.cpp

     
    341341{
    342342    if (ic)
    343343    {
    344         for (int i = 0; i < ic->nb_streams; i++)
     344        for (unsigned int i = 0; i < ic->nb_streams; i++)
    345345        {
    346346            QMutexLocker locker(&avcodeclock);
    347347            AVStream *st = ic->streams[i];
     
    403403    getrawframes = false;
    404404
    405405    AVStream *st = NULL;
    406     int i;
     406    unsigned int i;
    407407    for (i = 0; i < ic->nb_streams; i++)
    408408    {
    409409        AVStream *st1 = ic->streams[i];
     
    508508
    509509        // Flush the avcodec buffers
    510510        VERBOSE(VB_PLAYBACK, LOC + "SeekReset() flushing");
    511         for (int i = 0; i < ic->nb_streams; i++)
     511        for (unsigned int i = 0; i < ic->nb_streams; i++)
    512512        {
    513513            AVCodecContext *enc = ic->streams[i]->codec;
    514514            if (enc->codec)
     
    12761276    map<int,uint> lang_sub_cnt;
    12771277    map<int,uint> lang_aud_cnt;
    12781278
    1279     for (int i = 0; i < ic->nb_streams; i++)
     1279    for (unsigned int i = 0; i < ic->nb_streams; i++)
    12801280    {
    12811281        AVCodecContext *enc = ic->streams[i]->codec;
    12821282        VERBOSE(VB_PLAYBACK, LOC +
     
    13811381                    selectedVideoIndex = i;
    13821382                }
    13831383
    1384                 InitVideoCodec(ic->streams[i], enc, selectedVideoIndex == i);
     1384                InitVideoCodec(ic->streams[i], enc, selectedVideoIndex == (int)i);
    13851385
    13861386                ScanATSCCaptionStreams(i);
    13871387
     
    23962396
    23972397bool AvFormatDecoder::SetVideoByComponentTag(int tag)
    23982398{
    2399     for (int i = 0; i < ic->nb_streams; i++)
     2399    for (unsigned int i = 0; i < ic->nb_streams; i++)
    24002400    {
    24012401        AVStream *s  = ic->streams[i];
    24022402        if (s)
     
    27782778                    delete pkt;
    27792779                return false;
    27802780            }
    2781 
    27822781            if (waitingForChange && pkt->pos >= readAdjust)
    27832782                FileChanged();
    27842783
     
    27862785                pkt->pos -= readAdjust;
    27872786        }
    27882787
    2789         if (pkt->stream_index > ic->nb_streams)
     2788        if (pkt->stream_index > (int)ic->nb_streams)
    27902789        {
    27912790            VERBOSE(VB_IMPORTANT, LOC_ERR + "Bad stream");
    27922791            av_free_packet(pkt);
     
    34193418    AudioInfo old_out = audioOut;
    34203419
    34213420    if ((currentTrack[kTrackTypeAudio] >= 0) &&
    3422         (selectedTrack[kTrackTypeAudio].av_stream_index <= ic->nb_streams) &&
     3421        (selectedTrack[kTrackTypeAudio].av_stream_index <= (int)ic->nb_streams) &&
    34233422        (curstream = ic->streams[selectedTrack[kTrackTypeAudio]
    34243423                                 .av_stream_index]))
    34253424    {
  • libs/libmythtv/avfringbuffer.cpp

     
    2627{
    2728    AVFRingBuffer *avfr = (AVFRingBuffer *)h->priv_data;
    2829
     30    if (whence == AVSEEK_SIZE)
     31        return -1; // not supported /*avfr->GetRingBuffer()->GetRealFileSize();
     32
    2933    if (whence == SEEK_END)
    3034        return avfr->GetRingBuffer()->GetRealFileSize() + offset;
    3135
    32     return avfr->GetRingBuffer()->Seek(offset, whence);
     36    if (!avfr->GetRingBuffer()->isDVD())
     37        return avfr->GetRingBuffer()->Seek(offset, whence);
    3338}
    3439
    3540int AVF_Close(URLContext *h)