Skip to content

Commit

Permalink
AvFormatDecoder: Discard any initial audio packets prior to initial v…
Browse files Browse the repository at this point in the history
…ideo timecode.

Refs #9120

Signed-off-by: Mark Kendall <mkendall@mythtv.org>
  • Loading branch information
Mark Spieth authored and Mark Kendall committed Mar 20, 2011
1 parent 7ebf5a6 commit caf431c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 23 additions & 2 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,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),
Expand Down Expand Up @@ -729,6 +730,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::SetEof(bool eof)
Expand Down Expand Up @@ -2628,7 +2635,8 @@ void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt)

gopset = false;
prevgoppos = 0;
lastapts = lastvpts = lastccptsu = 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;
Expand Down Expand Up @@ -2735,7 +2743,8 @@ bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)

gopset = false;
prevgoppos = 0;
lastapts = lastvpts = lastccptsu = 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;
Expand Down Expand Up @@ -3006,6 +3015,8 @@ bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic)
framesPlayed++;

lastvpts = temppts;
if (!firstvpts && firstvptsinuse)
firstvpts = temppts;

return true;
}
Expand Down Expand Up @@ -3810,6 +3821,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;

Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythtv/avformatdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ class AvFormatDecoder : public DecoderBase
uint32_t start_code_state;

long long lastvpts;
long long lastapts;
long long lastapts;
long long lastccptsu;
long long firstvpts;
bool firstvptsinuse;

int64_t faulty_pts;
int64_t faulty_dts;
Expand Down

0 comments on commit caf431c

Please sign in to comment.