Ticket #9120: 17-smoother_play_start

File 17-smoother_play_start, 3.3 KB (added by Mark Spieth, 16 years ago)

dump prior audio

Line 
1skip any audio before first vpts for smoother play start
2
3From: Mark Spieth <mspieth@digivation.com.au>
4
5
6---
7 mythtv/libs/libmythtv/avformatdecoder.cpp | 23 +++++++++++++++++++++++
8 mythtv/libs/libmythtv/avformatdecoder.h | 2 ++
9 2 files changed, 25 insertions(+), 0 deletions(-)
10
11diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
12index ae4a017..676c999 100644
13--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
14+++ b/mythtv/libs/libmythtv/avformatdecoder.cpp
15@@ -262,6 +262,7 @@ AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,
16 start_code_state(0xffffffff),
17 lastvpts(0), lastapts(0),
18 lastccptsu(0),
19+ firstvpts(0), firstvptsinuse(false),
20 faulty_pts(0), faulty_dts(0),
21 last_pts_for_fault_detection(0),
22 last_dts_for_fault_detection(0),
23@@ -716,6 +717,12 @@ void AvFormatDecoder::SeekReset(long long newKey, uint skipFrames,
24 if (decoded_video_frame)
25 m_parent->DiscardVideoFrame(decoded_video_frame);
26 }
27+
28+ if (doflush)
29+ {
30+ firstvpts = 0;
31+ firstvptsinuse = true;
32+ }
33 }
34
35 void AvFormatDecoder::Reset(bool reset_video_data, bool seek_reset)
36@@ -2765,7 +2772,9 @@ void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt)
37
38 gopset = false;
39 prevgoppos = 0;
40+ firstvpts =
41 lastapts = lastvpts = lastccptsu = 0;
42+ firstvptsinuse = true;
43 faulty_pts = faulty_dts = 0;
44 last_pts_for_fault_detection = 0;
45 last_dts_for_fault_detection = 0;
46@@ -2871,7 +2880,9 @@ bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)
47
48 gopset = false;
49 prevgoppos = 0;
50+ firstvpts =
51 lastapts = lastvpts = lastccptsu = 0;
52+ firstvptsinuse = true;
53 faulty_pts = faulty_dts = 0;
54 last_pts_for_fault_detection = 0;
55 last_dts_for_fault_detection = 0;
56@@ -3141,6 +3152,8 @@ bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt)
57 framesPlayed++;
58
59 lastvpts = temppts;
60+ if (!firstvpts && firstvptsinuse)
61+ firstvpts = temppts;
62
63 return true;
64 }
65@@ -4020,6 +4033,16 @@ bool AvFormatDecoder::ProcessAudioPacket(AVStream *curstream, AVPacket *pkt,
66 skipaudio = false;
67 }
68
69+ // skip any audio frames preceding first video frame
70+ if (firstvptsinuse && firstvpts && (lastapts < firstvpts))
71+ {
72+ VERBOSE(VB_PLAYBACK+VB_TIMESTAMP,
73+ LOC + QString("discarding early audio timecode %1 %2 %3")
74+ .arg(pkt->pts).arg(pkt->dts).arg(lastapts));
75+ break;
76+ }
77+ firstvptsinuse = false;
78+
79 avcodeclock->lock();
80 data_size = 0;
81
82diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
83index d3947e5..55ae68a 100644
84--- a/mythtv/libs/libmythtv/avformatdecoder.h
85+++ b/mythtv/libs/libmythtv/avformatdecoder.h
86@@ -276,6 +276,8 @@ class AvFormatDecoder : public DecoderBase
87 long long lastvpts;
88 long long lastapts;
89 long long lastccptsu;
90+ long long firstvpts;
91+ bool firstvptsinuse;
92
93 int64_t faulty_pts;
94 int64_t faulty_dts;