summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-03-07 10:11:52 +0000
committerCarl Hetherington <cth@carlh.net>2013-03-07 10:11:52 +0000
commitb9fb4a402b411ddf84c10587187e187bcea34a5e (patch)
treeed6a81b9b16d605c0c84be443b7326ff472b1f4c /src/lib
parent070e62d79b895c0b1ce31d69594973ced72f699b (diff)
Another attempt to fix up matching.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/matcher.cc26
-rw-r--r--src/lib/matcher.h3
2 files changed, 22 insertions, 7 deletions
diff --git a/src/lib/matcher.cc b/src/lib/matcher.cc
index a751e7297..a74eeabbb 100644
--- a/src/lib/matcher.cc
+++ b/src/lib/matcher.cc
@@ -34,6 +34,8 @@ Matcher::Matcher (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)
{
}
@@ -44,17 +46,20 @@ Matcher::process_video (boost::shared_ptr<Image> image, bool same, boost::shared
_pixel_format = image->pixel_format ();
_size = image->size ();
- _log->log(String::compose("Matcher video @ %1 (same=%2)", t, same));
+ _log->log(String::compose("Matcher video @ %1 [audio=%2, video=%3, pending_audio=%4]", t, _audio_frames, _video_frames, _pending_audio.size()));
if (!_first_input) {
_first_input = t;
}
- if (!_pending_audio.empty() && _video_frames == 0) {
+ bool const this_is_first_video = !_had_first_video;
+ _had_first_video = true;
+
+ if (this_is_first_video && _had_first_audio) {
/* First video since we got audio */
fix_start (t);
}
-
+
/* Video before audio is fine, since we can make up an arbitrary difference
with audio samples (contrasting with video which is quantised to frames)
*/
@@ -88,15 +93,20 @@ void
Matcher::process_audio (boost::shared_ptr<AudioBuffers> b, double t)
{
_channels = b->channels ();
-
+
+ _log->log (String::compose ("Matcher audio @ %1 [video=%2, audio=%3, pending_audio=%4]", t, _video_frames, _audio_frames, _pending_audio.size()));
+
if (!_first_input) {
_first_input = t;
}
+
+ bool const this_is_first_audio = _had_first_audio;
+ _had_first_audio = true;
- if (_video_frames == 0) {
+ if (!_had_first_video) {
/* No video yet; we must postpone these data until we have some */
_pending_audio.push_back (AudioRecord (b, t));
- } else if (_video_frames > 0 && _audio_frames == 0 && _pending_audio.empty()) {
+ } else if (this_is_first_audio && !_had_first_video) {
/* First audio since we got video */
_pending_audio.push_back (AudioRecord (b, t));
fix_start (_first_input.get ());
@@ -140,6 +150,8 @@ Matcher::fix_start (double first_video)
void
Matcher::match (double extra_video_needed)
{
+ _log->log (String::compose ("Match %1", extra_video_needed));
+
if (extra_video_needed > 0) {
/* Emit black video frames */
@@ -163,7 +175,7 @@ Matcher::match (double extra_video_needed)
/* Emit silence */
int64_t to_do = -extra_video_needed * _sample_rate;
- _log->log (String::compose (N_("Emitted %1 frames of silence"), to_do));
+ _log->log (String::compose (N_("Emitting %1 frames of silence"), to_do));
/* Do things in half second blocks as I think there may be limits
to what FFmpeg (and in particular the resampler) can cope with.
diff --git a/src/lib/matcher.h b/src/lib/matcher.h
index 4a387a3f9..a7054f540 100644
--- a/src/lib/matcher.h
+++ b/src/lib/matcher.h
@@ -57,4 +57,7 @@ private:
boost::optional<double> _first_input;
boost::shared_ptr<Image> _last_image;
boost::shared_ptr<Subtitle> _last_subtitle;
+
+ bool _had_first_video;
+ bool _had_first_audio;
};