From cafa76a2b52449ce3c9eecfd0ea53b7318814951 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 17 Nov 2012 22:06:12 +0000 Subject: Another attempt to do external audio moderately nicely. --- src/lib/external_audio_decoder.cc | 92 ++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 10 deletions(-) (limited to 'src/lib/external_audio_decoder.cc') diff --git a/src/lib/external_audio_decoder.cc b/src/lib/external_audio_decoder.cc index 2297ac4da..29668d922 100644 --- a/src/lib/external_audio_decoder.cc +++ b/src/lib/external_audio_decoder.cc @@ -24,19 +24,23 @@ using std::vector; using std::string; +using std::stringstream; using std::min; using std::cout; using boost::shared_ptr; +using boost::optional; ExternalAudioDecoder::ExternalAudioDecoder (shared_ptr f, shared_ptr o, Job* j) : Decoder (f, o, j) , AudioDecoder (f, o, j) { - + sf_count_t frames; + vector sf = open_files (frames); + close_files (sf); } -bool -ExternalAudioDecoder::pass () +vector +ExternalAudioDecoder::open_files (sf_count_t & frames) { vector const files = _film->external_audio (); @@ -48,11 +52,11 @@ ExternalAudioDecoder::pass () } if (N == 0) { - return true; + return vector (); } bool first = true; - sf_count_t frames = 0; + frames = 0; vector sndfiles; for (size_t i = 0; i < (size_t) N; ++i) { @@ -72,8 +76,12 @@ ExternalAudioDecoder::pass () sndfiles.push_back (s); if (first) { - /* XXX: nasty magic value */ - AudioStream st ("DVDOMATIC-EXTERNAL", -1, info.samplerate, av_get_default_channel_layout (N)); + shared_ptr st ( + new ExternalAudioStream ( + info.samplerate, av_get_default_channel_layout (N) + ) + ); + _audio_streams.push_back (st); _audio_stream = st; frames = info.frames; @@ -86,9 +94,23 @@ ExternalAudioDecoder::pass () } } + return sndfiles; +} + +bool +ExternalAudioDecoder::pass () +{ + sf_count_t frames; + vector sndfiles = open_files (frames); + if (sndfiles.empty()) { + return true; + } + sf_count_t const block = 65536; - shared_ptr audio (new AudioBuffers (_audio_stream.get().channels(), block)); + cout << frames << " audio frames.\n"; + + shared_ptr audio (new AudioBuffers (_audio_stream->channels(), block)); while (frames > 0) { sf_count_t const this_time = min (block, frames); for (size_t i = 0; i < sndfiles.size(); ++i) { @@ -103,9 +125,59 @@ ExternalAudioDecoder::pass () frames -= this_time; } + close_files (sndfiles); + + return true; +} + +void +ExternalAudioDecoder::close_files (vector const & sndfiles) +{ for (size_t i = 0; i < sndfiles.size(); ++i) { sf_close (sndfiles[i]); } - - return true; +} + +shared_ptr +ExternalAudioStream::create () +{ + return shared_ptr (new ExternalAudioStream); +} + +shared_ptr +ExternalAudioStream::create (string t, optional v) +{ + if (!v) { + /* version < 1; no type in the string, and there's only FFmpeg streams anyway */ + return shared_ptr (); + } + + stringstream s (t); + string type; + s >> type; + if (type != "external") { + return shared_ptr (); + } + + return shared_ptr (new ExternalAudioStream (t, v)); +} + +ExternalAudioStream::ExternalAudioStream (string t, optional v) +{ + assert (v); + + stringstream s (t); + string type; + s >> type >> _sample_rate >> _channel_layout; +} + +ExternalAudioStream::ExternalAudioStream () +{ + +} + +string +ExternalAudioStream::to_string () const +{ + return String::compose ("external %1 %2", _sample_rate, _channel_layout); } -- cgit v1.2.3