summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-05-07 10:18:33 +0100
committerCarl Hetherington <cth@carlh.net>2013-05-07 10:18:33 +0100
commit4ff5c21a9c3c2ea8ab3a253ef5658e3ee91e0bea (patch)
treecacc56e60d0c565ba0a2141964a398ee11d82b3b /src/lib
parentaf671aa256ae0d2fa38a6740cea7fc0f6b45b5b8 (diff)
Fix another bit of incorrect logic (this_is_first_audio was inverted). Also try to add _audio_starts_with_video mode to Matcher.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/matcher.cc28
-rw-r--r--src/lib/matcher.h6
2 files changed, 28 insertions, 6 deletions
diff --git a/src/lib/matcher.cc b/src/lib/matcher.cc
index 2723f2a2d..3776d4fbc 100644
--- a/src/lib/matcher.cc
+++ b/src/lib/matcher.cc
@@ -34,7 +34,6 @@ Matcher::Matcher (shared_ptr<Log> log, int sample_rate, float frames_per_second)
, _frames_per_second (frames_per_second)
, _video_frames (0)
, _audio_frames (0)
- , _had_first_video (false)
, _had_first_audio (false)
{
@@ -52,8 +51,11 @@ Matcher::process_video (boost::shared_ptr<const Image> image, bool same, boost::
_first_input = t;
}
- bool const this_is_first_video = !_had_first_video;
- _had_first_video = true;
+ bool const this_is_first_video = !_first_video;
+
+ if (!_first_video) {
+ _first_video = t;
+ }
if (this_is_first_video && _had_first_audio) {
/* First video since we got audio */
@@ -104,13 +106,13 @@ Matcher::process_audio (boost::shared_ptr<const AudioBuffers> b, double t)
_first_input = t;
}
- bool const this_is_first_audio = _had_first_audio;
+ bool const this_is_first_audio = !_had_first_audio;
_had_first_audio = true;
- if (!_had_first_video) {
+ if (!_first_video) {
/* No video yet; we must postpone these data until we have some */
_pending_audio.push_back (AudioRecord (b, t));
- } else if (this_is_first_audio && _had_first_video) {
+ } else if (this_is_first_audio && _first_video) {
/* First audio since we got video */
_pending_audio.push_back (AudioRecord (b, t));
fix_start (_first_input.get ());
@@ -145,6 +147,11 @@ Matcher::fix_start (double first_video)
match (first_video - _pending_audio.front().time);
for (list<AudioRecord>::iterator i = _pending_audio.begin(); i != _pending_audio.end(); ++i) {
+ if (_audio_starts_with_video) {
+ assert (_first_video);
+ assert (_first_audio);
+ i->time += _first_video.get() - _first_audio.get();
+ }
process_audio (i->audio, i->time);
}
@@ -211,3 +218,12 @@ Matcher::repeat_last_video ()
++_video_frames;
}
+/** Set `audio starts with video' behaviour. If this is enabled,
+ * audio time stamps are adjusted so that the first audio is synced
+ * with the first video.
+ */
+void
+Matcher::set_audio_starts_with_video (bool a)
+{
+ _audio_starts_with_video = a;
+}
diff --git a/src/lib/matcher.h b/src/lib/matcher.h
index 41aa373a4..aab6adad9 100644
--- a/src/lib/matcher.h
+++ b/src/lib/matcher.h
@@ -25,6 +25,9 @@ class Matcher : public Processor, public TimedAudioSink, public TimedVideoSink,
{
public:
Matcher (boost::shared_ptr<Log> log, int sample_rate, float frames_per_second);
+
+ void set_audio_starts_with_video (bool);
+
void process_video (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s, double);
void process_audio (boost::shared_ptr<const AudioBuffers>, double);
void process_end ();
@@ -55,9 +58,12 @@ private:
std::list<AudioRecord> _pending_audio;
boost::optional<double> _first_input;
+ boost::optional<double> _first_video;
boost::shared_ptr<const Image> _last_image;
boost::shared_ptr<Subtitle> _last_subtitle;
bool _had_first_video;
bool _had_first_audio;
+
+ bool _audio_starts_with_video;
};