summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-07-01 15:18:36 +0100
committerCarl Hetherington <cth@carlh.net>2014-07-01 15:18:36 +0100
commita668653ae1229ff5574fb42b151d6289ddf6bb02 (patch)
tree5ddd7ed3546fb6d9fa9f945ac47718d5c9a523a6 /src
parent6f071ce94bb7cff1106e2ef6d8eb4363694435f2 (diff)
Tidy up a bit.
Diffstat (limited to 'src')
-rw-r--r--src/lib/decoder.h9
-rw-r--r--src/lib/ffmpeg_decoder.cc37
-rw-r--r--src/lib/ffmpeg_decoder.h2
3 files changed, 20 insertions, 28 deletions
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 18f612e53..583a92636 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -43,10 +43,11 @@ public:
protected:
/** Seek so that the next pass() will yield the next thing
* (video/sound frame, subtitle etc.) at or after the requested
- * time. Pass accurate = true to try harder to get close to
- * the request. Note that seeking to time t may mean that
- * the next pass() yields, for example, audio at time t and then
- * video before it.
+ * time. Pass accurate = true to try harder to ensure that, at worst,
+ * the next thing we yield comes before `time'. This may entail
+ * seeking some way before `time' to be on the safe side.
+ * Alternatively, if seeking is 100% accurate for this decoder,
+ * it may seek to just the right spot.
*/
virtual void seek (ContentTime time, bool accurate) = 0;
virtual bool pass () = 0;
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index dfd8786b3..ce6fb1984 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -283,9 +283,22 @@ FFmpegDecoder::bytes_per_audio_sample () const
}
void
-FFmpegDecoder::seek_and_flush (ContentTime t)
+FFmpegDecoder::seek (ContentTime time, bool accurate)
{
- ContentTime const u = t - _pts_offset;
+ VideoDecoder::seek (time, accurate);
+ AudioDecoder::seek (time, accurate);
+
+ /* If we are doing an `accurate' seek, we need to use pre-roll, as
+ we don't really know what the seek will give us.
+ */
+
+ ContentTime pre_roll = accurate ? ContentTime::from_seconds (2) : ContentTime (0);
+ time - pre_roll;
+ if (time < ContentTime (0)) {
+ time = ContentTime (0);
+ }
+
+ ContentTime const u = time - _pts_offset;
int64_t s = u.seconds() / av_q2d (_format_context->streams[_video_stream]->time_base);
if (_ffmpeg_content->audio_stream ()) {
@@ -312,26 +325,6 @@ FFmpegDecoder::seek_and_flush (ContentTime t)
}
void
-FFmpegDecoder::seek (ContentTime time, bool accurate)
-{
- VideoDecoder::seek (time, accurate);
- AudioDecoder::seek (time, accurate);
-
- /* If we are doing an accurate seek, our initial shot will be 2s (2 being
- a number plucked from the air) earlier than we want to end up. The loop below
- will hopefully then step through to where we want to be.
- */
-
- ContentTime pre_roll = accurate ? ContentTime::from_seconds (2) : ContentTime (0);
- ContentTime initial_seek = time - pre_roll;
- if (initial_seek < ContentTime (0)) {
- initial_seek = ContentTime (0);
- }
-
- seek_and_flush (initial_seek);
-}
-
-void
FFmpegDecoder::decode_audio_packet ()
{
/* Audio packets can contain multiple frames, so we may have to call avcodec_decode_audio4
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index e44ac152f..d6cb8c246 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -66,8 +66,6 @@ private:
void maybe_add_subtitle ();
boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t** data, int size);
- void seek_and_flush (ContentTime);
-
bool has_subtitle_during (ContentTimePeriod) const;
boost::shared_ptr<Log> _log;