summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-12-18 12:09:35 +0000
committerCarl Hetherington <cth@carlh.net>2013-12-18 12:09:35 +0000
commit060a980527bc0b39e12494fec3c0baaab4c9d086 (patch)
tree82de7bbcf605543be583b2ed3daf22d8145f6657 /src/lib
parente0c59417c6a52dbd853114fbc0f88c6d8c1dd276 (diff)
Fix seek with respect to video/audio frame boundary alignment.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_merger.h2
-rw-r--r--src/lib/player.cc6
-rw-r--r--src/lib/util.cc7
-rw-r--r--src/lib/util.h1
4 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/audio_merger.h b/src/lib/audio_merger.h
index 2a1cc761b..f068b504e 100644
--- a/src/lib/audio_merger.h
+++ b/src/lib/audio_merger.h
@@ -37,6 +37,8 @@ public:
TimedAudioBuffers<T>
pull (T time)
{
+ assert (time >= _last_pull);
+
TimedAudioBuffers<T> out;
F const to_return = _t_to_f (time - _last_pull);
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 56bf0767d..d60dfb6a9 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -351,8 +351,10 @@ Player::seek (DCPTime t, bool accurate)
(*i)->decoder->seek (ct, accurate);
}
- _video_position = _audio_position = t;
- _audio_merger.clear (t);
+ _video_position = time_round_up (t, TIME_HZ / _film->video_frame_rate());
+ _audio_position = time_round_up (t, TIME_HZ / _film->audio_frame_rate());
+
+ _audio_merger.clear (_audio_position);
if (!accurate) {
/* We just did an inaccurate seek, so it's likely that the next thing seen
diff --git a/src/lib/util.cc b/src/lib/util.cc
index d5a07192c..381c47a9a 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -915,3 +915,10 @@ fit_ratio_within (float ratio, libdcp::Size full_frame)
return libdcp::Size (full_frame.width, rint (full_frame.width / ratio));
}
+
+DCPTime
+time_round_up (DCPTime t, DCPTime nearest)
+{
+ DCPTime const a = t + nearest - 1;
+ return a - (a % nearest);
+}
diff --git a/src/lib/util.h b/src/lib/util.h
index 9b201a50e..892b473f7 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -119,6 +119,7 @@ struct FrameRateChange
extern int dcp_audio_frame_rate (int);
extern int stride_round_up (int, int const *, int);
+extern DCPTime time_round_up (DCPTime, DCPTime);
extern std::multimap<std::string, std::string> read_key_value (std::istream& s);
extern int get_required_int (std::multimap<std::string, std::string> const & kv, std::string k);
extern float get_required_float (std::multimap<std::string, std::string> const & kv, std::string k);