From 4ff5c21a9c3c2ea8ab3a253ef5658e3ee91e0bea Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 7 May 2013 10:18:33 +0100 Subject: Fix another bit of incorrect logic (this_is_first_audio was inverted). Also try to add _audio_starts_with_video mode to Matcher. --- src/lib/matcher.cc | 28 ++++++++++++++++++++++------ src/lib/matcher.h | 6 ++++++ 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'src/lib') 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, 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 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 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::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, int sample_rate, float frames_per_second); + + void set_audio_starts_with_video (bool); + void process_video (boost::shared_ptr i, bool, boost::shared_ptr s, double); void process_audio (boost::shared_ptr, double); void process_end (); @@ -55,9 +58,12 @@ private: std::list _pending_audio; boost::optional _first_input; + boost::optional _first_video; boost::shared_ptr _last_image; boost::shared_ptr _last_subtitle; bool _had_first_video; bool _had_first_audio; + + bool _audio_starts_with_video; }; -- cgit v1.2.3