skip any audio before first vpts for smoother play start From: Mark Spieth --- mythtv/libs/libmythtv/avformatdecoder.cpp | 23 +++++++++++++++++++++++ mythtv/libs/libmythtv/avformatdecoder.h | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp index ae4a017..676c999 100644 --- a/mythtv/libs/libmythtv/avformatdecoder.cpp +++ b/mythtv/libs/libmythtv/avformatdecoder.cpp @@ -262,6 +262,7 @@ AvFormatDecoder::AvFormatDecoder(MythPlayer *parent, start_code_state(0xffffffff), lastvpts(0), lastapts(0), lastccptsu(0), + firstvpts(0), firstvptsinuse(false), faulty_pts(0), faulty_dts(0), last_pts_for_fault_detection(0), last_dts_for_fault_detection(0), @@ -716,6 +717,12 @@ void AvFormatDecoder::SeekReset(long long newKey, uint skipFrames, if (decoded_video_frame) m_parent->DiscardVideoFrame(decoded_video_frame); } + + if (doflush) + { + firstvpts = 0; + firstvptsinuse = true; + } } void AvFormatDecoder::Reset(bool reset_video_data, bool seek_reset) @@ -2765,7 +2772,9 @@ void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt) gopset = false; prevgoppos = 0; + firstvpts = lastapts = lastvpts = lastccptsu = 0; + firstvptsinuse = true; faulty_pts = faulty_dts = 0; last_pts_for_fault_detection = 0; last_dts_for_fault_detection = 0; @@ -2871,7 +2880,9 @@ bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt) gopset = false; prevgoppos = 0; + firstvpts = lastapts = lastvpts = lastccptsu = 0; + firstvptsinuse = true; faulty_pts = faulty_dts = 0; last_pts_for_fault_detection = 0; last_dts_for_fault_detection = 0; @@ -3141,6 +3152,8 @@ bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt) framesPlayed++; lastvpts = temppts; + if (!firstvpts && firstvptsinuse) + firstvpts = temppts; return true; } @@ -4020,6 +4033,16 @@ bool AvFormatDecoder::ProcessAudioPacket(AVStream *curstream, AVPacket *pkt, skipaudio = false; } + // skip any audio frames preceding first video frame + if (firstvptsinuse && firstvpts && (lastapts < firstvpts)) + { + VERBOSE(VB_PLAYBACK+VB_TIMESTAMP, + LOC + QString("discarding early audio timecode %1 %2 %3") + .arg(pkt->pts).arg(pkt->dts).arg(lastapts)); + break; + } + firstvptsinuse = false; + avcodeclock->lock(); data_size = 0; diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h index d3947e5..55ae68a 100644 --- a/mythtv/libs/libmythtv/avformatdecoder.h +++ b/mythtv/libs/libmythtv/avformatdecoder.h @@ -276,6 +276,8 @@ class AvFormatDecoder : public DecoderBase long long lastvpts; long long lastapts; long long lastccptsu; + long long firstvpts; + bool firstvptsinuse; int64_t faulty_pts; int64_t faulty_dts;