Ticket #11371: 0001-Detect-when-the-audio-timestamp-resets-to-ensure-we-.patch

File 0001-Detect-when-the-audio-timestamp-resets-to-ensure-we-.patch, 4.1 KB (added by peper03@…, 13 years ago)
  • mythtv/libs/libmythtv/avformatdecoder.cpp

    From c4590c33343beecbf0934fe9be60d85b4f9c8398 Mon Sep 17 00:00:00 2001
    From: Richard <peper03@yahoo.com>
    Date: Tue, 22 Jan 2013 21:59:21 +0100
    Subject: Detect when the audio timestamp resets to ensure we don't get stuck
     buffering video frames until we either hit the limit or the audio
     buffer is full.
    
    ---
     mythtv/libs/libmythtv/avformatdecoder.cpp |   29 +++++++++++++++++++++++++++++
     mythtv/libs/libmythtv/avformatdecoder.h   |    1 +
     2 files changed, 30 insertions(+)
    
    diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
    index ea21273..cadd09c 100644
    a b AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,  
    318318      pts_detected(false),
    319319      reordered_pts_detected(false),
    320320      pts_selected(true),
     321      wait_for_vpts_reset(false),
    321322      force_dts_timestamps(false),
    322323      playerFlags(flags),
    323324      video_codec_id(kCodec_NONE),
    void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt)  
    30483049                prevgoppos = 0;
    30493050                firstvpts = lastapts = lastvpts = lastccptsu = 0;
    30503051                firstvptsinuse = true;
     3052                wait_for_vpts_reset = false;
    30513053                faulty_pts = faulty_dts = 0;
    30523054                last_pts_for_fault_detection = 0;
    30533055                last_dts_for_fault_detection = 0;
    bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)  
    31513153            prevgoppos = 0;
    31523154            firstvpts = lastapts = lastvpts = lastccptsu = 0;
    31533155            firstvptsinuse = true;
     3156            wait_for_vpts_reset = false;
    31543157            faulty_pts = faulty_dts = 0;
    31553158            last_pts_for_fault_detection = 0;
    31563159            last_dts_for_fault_detection = 0;
    bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic)  
    34893492    gotVideoFrame = 1;
    34903493    framesPlayed++;
    34913494
     3495    // if vpts reset has happened, no need to wait for it any more
     3496    if (temppts < lastvpts)
     3497    {
     3498        LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_DEBUG, LOC + QString("vpts reset! %1->%2, apts %3")
     3499            .arg(lastvpts)
     3500            .arg(temppts)
     3501            .arg(lastapts));
     3502
     3503        wait_for_vpts_reset = false;
     3504    }
     3505
    34923506    lastvpts = temppts;
    34933507    if (!firstvpts && firstvptsinuse)
    34943508        firstvpts = temppts;
    bool AvFormatDecoder::ProcessAudioPacket(AVStream *curstream, AVPacket *pkt,  
    43844398            break;
    43854399
    43864400        if (firstloop && pkt->pts != (int64_t)AV_NOPTS_VALUE)
     4401        {
     4402            long long previous = lastapts;
    43874403            lastapts = (long long)(av_q2d(curstream->time_base) * pkt->pts * 1000);
    43884404
     4405            if ((previous > lastapts) && (lastapts < lastvpts))
     4406            {
     4407                wait_for_vpts_reset = true;
     4408
     4409                LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_DEBUG, LOC + QString("apts reset! %1->%2, pts %3, vpts %4")
     4410                    .arg(previous)
     4411                    .arg(lastapts)
     4412                    .arg(pkt->pts)
     4413                    .arg(lastvpts));
     4414            }
     4415        }
     4416
    43894417        if (skipaudio && selectedTrack[kTrackTypeVideo].av_stream_index > -1)
    43904418        {
    43914419            if ((lastapts < lastvpts - (10.0 / fps)) || lastvpts == 0)
    bool AvFormatDecoder::GetFrame(DecodeType decodetype)  
    45974625            else if (lowbuffers && ((decodetype & kDecodeAV) == kDecodeAV) &&
    45984626                     (storedPackets.count() < max_video_queue_size) &&
    45994627                     (lastapts < lastvpts + 100) &&
     4628                     !wait_for_vpts_reset &&
    46004629                     !ringBuffer->IsInStillFrame())
    46014630            {
    46024631                storevideoframes = true;
  • mythtv/libs/libmythtv/avformatdecoder.h

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
    index f76c26b..d5b64ac 100644
    a b class AvFormatDecoder : public DecoderBase  
    316316    bool pts_detected;
    317317    bool reordered_pts_detected;
    318318    bool pts_selected;
     319    bool wait_for_vpts_reset;
    319320
    320321    bool force_dts_timestamps;
    321322