summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-11-18 21:03:32 +0000
committerCarl Hetherington <cth@carlh.net>2012-11-18 21:03:32 +0000
commit454478fa52d97a5590a05ae0222d582a3ec2f1dc (patch)
treee8ba6a21f53fd2b455dbd0a634524fdd31b49994 /src/lib
parentcafa76a2b52449ce3c9eecfd0ea53b7318814951 (diff)
Call processor process_end methods as required. Remove questionable padding of audio length up to the nearest second. Don't emit audio in big blocks as it seems to crash FFmpeg. Fix a few things.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/external_audio_decoder.cc8
-rw-r--r--src/lib/j2k_wav_encoder.cc6
-rw-r--r--src/lib/matcher.cc19
-rw-r--r--src/lib/transcoder.cc14
4 files changed, 31 insertions, 16 deletions
diff --git a/src/lib/external_audio_decoder.cc b/src/lib/external_audio_decoder.cc
index 29668d922..136e00fb2 100644
--- a/src/lib/external_audio_decoder.cc
+++ b/src/lib/external_audio_decoder.cc
@@ -106,9 +106,10 @@ ExternalAudioDecoder::pass ()
return true;
}
- sf_count_t const block = 65536;
-
- cout << frames << " audio frames.\n";
+ /* Do things in half second blocks as I think there may be limits
+ to what FFmpeg (and in particular the resampler) can cope with.
+ */
+ sf_count_t const block = _audio_stream->sample_rate() / 2;
shared_ptr<AudioBuffers> audio (new AudioBuffers (_audio_stream->channels(), block));
while (frames > 0) {
@@ -121,6 +122,7 @@ ExternalAudioDecoder::pass ()
}
}
+ audio->set_frames (this_time);
Audio (audio);
frames -= this_time;
}
diff --git a/src/lib/j2k_wav_encoder.cc b/src/lib/j2k_wav_encoder.cc
index be1f96fd4..134d74623 100644
--- a/src/lib/j2k_wav_encoder.cc
+++ b/src/lib/j2k_wav_encoder.cc
@@ -337,12 +337,6 @@ J2KWAVEncoder::process_end ()
#endif
if (_film->audio_stream()) {
- int const dcp_sr = dcp_audio_sample_rate (_film->audio_stream()->sample_rate ());
- int64_t const extra_audio_frames = dcp_sr - (_audio_frames_written % dcp_sr);
- shared_ptr<AudioBuffers> silence (new AudioBuffers (_film->audio_stream()->channels(), extra_audio_frames));
- silence->make_silent ();
- write_audio (silence);
-
close_sound_files ();
/* Rename .wav.tmp files to .wav */
diff --git a/src/lib/matcher.cc b/src/lib/matcher.cc
index 24514bee2..7b4434539 100644
--- a/src/lib/matcher.cc
+++ b/src/lib/matcher.cc
@@ -21,6 +21,7 @@
#include "image.h"
#include "log.h"
+using std::min;
using boost::shared_ptr;
Matcher::Matcher (Log* log, int sample_rate, float frames_per_second)
@@ -92,9 +93,21 @@ Matcher::process_end ()
if (audio_short_by_frames > 0) {
_log->log (String::compose ("Emitted %1 too few audio frames", audio_short_by_frames));
- shared_ptr<AudioBuffers> b (new AudioBuffers (_channels.get(), audio_short_by_frames));
+
+ /* Do things in half second blocks as I think there may be limits
+ to what FFmpeg (and in particular the resampler) can cope with.
+ */
+ int64_t const block = _sample_rate / 2;
+ shared_ptr<AudioBuffers> b (new AudioBuffers (_channels.get(), block));
b->make_silent ();
- Audio (b);
- _audio_frames += b->frames ();
+
+ int64_t to_do = audio_short_by_frames;
+ while (to_do > 0) {
+ int64_t const this_time = min (to_do, block);
+ b->set_frames (this_time);
+ Audio (b);
+ _audio_frames += b->frames ();
+ to_do -= this_time;
+ }
}
}
diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc
index cad76af6e..537b9b664 100644
--- a/src/lib/transcoder.cc
+++ b/src/lib/transcoder.cc
@@ -109,12 +109,18 @@ Transcoder::go ()
}
} catch (...) {
- /* process_end() is important as the decoder may have worker
- threads that need to be cleaned up.
- */
_encoder->process_end ();
throw;
}
-
+
+ if (_delay_line) {
+ _delay_line->process_end ();
+ }
+ if (_matcher) {
+ _matcher->process_end ();
+ }
+ if (_gain) {
+ _gain->process_end ();
+ }
_encoder->process_end ();
}