summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-02-15 22:34:31 +0000
committerCarl Hetherington <cth@carlh.net>2016-02-15 22:34:31 +0000
commit57c49675889c0e0ad8cebece7a60bba08ba782d2 (patch)
tree5385f944a796892cd682bb60d132dec80e3d743e
parenta5e9116f3e2ac7dd9f226c5e26673caf3085a781 (diff)
Hacky workaround for FFmpeg not having a channel layout for any counts between 8 and 16.
-rw-r--r--ChangeLog5
-rw-r--r--src/lib/analyse_audio_job.cc2
-rw-r--r--src/lib/audio_filter_graph.cc36
-rw-r--r--src/lib/audio_filter_graph.h3
-rw-r--r--test/audio_analysis_test.cc30
5 files changed, 70 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index ac5fe0333..a96740d1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-15 Carl Hetherington <cth@carlh.net>
+
+ * Fix exception when analysing audio of projects with more
+ than 8 DCP channels.
+
2016-02-12 Carl Hetherington <cth@carlh.net>
* Add basic support for SSA (SubStation Alpha) subtitles (#128).
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index 769f3762b..d17c4c30b 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -56,7 +56,7 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const
, _sample_peak (0)
, _sample_peak_frame (0)
#ifdef DCPOMATIC_HAVE_PATCHED_FFMPEG
- , _ebur128 (new AudioFilterGraph (film->audio_frame_rate(), av_get_default_channel_layout(film->audio_channels())))
+ , _ebur128 (new AudioFilterGraph (film->audio_frame_rate(), film->audio_channels()))
#endif
{
#ifdef DCPOMATIC_HAVE_PATCHED_FFMPEG
diff --git a/src/lib/audio_filter_graph.cc b/src/lib/audio_filter_graph.cc
index fd2492d3b..a43f1881e 100644
--- a/src/lib/audio_filter_graph.cc
+++ b/src/lib/audio_filter_graph.cc
@@ -31,10 +31,19 @@ using std::string;
using std::cout;
using boost::shared_ptr;
-AudioFilterGraph::AudioFilterGraph (int sample_rate, int64_t channel_layout)
+AudioFilterGraph::AudioFilterGraph (int sample_rate, int channels)
: _sample_rate (sample_rate)
- , _channel_layout (channel_layout)
+ , _channels (channels)
{
+ /* FFmpeg doesn't know any channel layouts for any counts between 8 and 16,
+ so we need to tell it we're using 16 channels if we are using more than 8.
+ */
+ if (_channels > 8) {
+ _channel_layout = av_get_default_channel_layout (16);
+ } else {
+ _channel_layout = av_get_default_channel_layout (_channels);
+ }
+
_in_frame = av_frame_alloc ();
}
@@ -95,7 +104,26 @@ AudioFilterGraph::sink_name () const
void
AudioFilterGraph::process (shared_ptr<const AudioBuffers> buffers)
{
- _in_frame->extended_data = new uint8_t*[buffers->channels()];
+ int const process_channels = av_get_channel_layout_nb_channels (_channel_layout);
+ DCPOMATIC_ASSERT (process_channels >= buffers->channels());
+
+ if (buffers->channels() < process_channels) {
+ /* We are processing more data than we actually have (see the hack in
+ the constructor) so we need to create new buffers with some extra
+ silent channels.
+ */
+ shared_ptr<AudioBuffers> extended_buffers (new AudioBuffers (process_channels, buffers->frames()));
+ for (int i = 0; i < buffers->channels(); ++i) {
+ extended_buffers->copy_channel_from (buffers.get(), i, i);
+ }
+ for (int i = buffers->channels(); i < process_channels; ++i) {
+ extended_buffers->make_silent (i);
+ }
+
+ buffers = extended_buffers;
+ }
+
+ _in_frame->extended_data = new uint8_t*[process_channels];
for (int i = 0; i < buffers->channels(); ++i) {
if (i < AV_NUM_DATA_POINTERS) {
_in_frame->data[i] = reinterpret_cast<uint8_t*> (buffers->data(i));
@@ -107,7 +135,7 @@ AudioFilterGraph::process (shared_ptr<const AudioBuffers> buffers)
_in_frame->format = AV_SAMPLE_FMT_FLTP;
_in_frame->sample_rate = _sample_rate;
_in_frame->channel_layout = _channel_layout;
- _in_frame->channels = av_get_channel_layout_nb_channels (_channel_layout);
+ _in_frame->channels = process_channels;
int r = av_buffersrc_write_frame (_buffer_src_context, _in_frame);
diff --git a/src/lib/audio_filter_graph.h b/src/lib/audio_filter_graph.h
index 8efff5d8d..90518e2ed 100644
--- a/src/lib/audio_filter_graph.h
+++ b/src/lib/audio_filter_graph.h
@@ -27,7 +27,7 @@ class AudioBuffers;
class AudioFilterGraph : public FilterGraph
{
public:
- AudioFilterGraph (int sample_rate, int64_t channel_layout);
+ AudioFilterGraph (int sample_rate, int channels);
~AudioFilterGraph ();
void process (boost::shared_ptr<const AudioBuffers> audio);
@@ -40,6 +40,7 @@ protected:
private:
int _sample_rate;
+ int _channels;
int64_t _channel_layout;
AVFrame* _in_frame;
};
diff --git a/test/audio_analysis_test.cc b/test/audio_analysis_test.cc
index c2c06734a..83ed458ca 100644
--- a/test/audio_analysis_test.cc
+++ b/test/audio_analysis_test.cc
@@ -135,3 +135,33 @@ BOOST_AUTO_TEST_CASE (audio_analysis_test2)
JobManager::instance()->add (job);
wait_for_jobs ();
}
+
+
+static bool done = false;
+
+static void
+analysis_finished ()
+{
+ done = true;
+}
+
+/* Test a case which was reported to throw an exception; analysing
+ * a 12-channel DCP's audio.
+ */
+BOOST_AUTO_TEST_CASE (audio_analysis_test3)
+{
+ shared_ptr<Film> film = new_test_film ("analyse_audio_test");
+ film->set_container (Ratio::from_id ("185"));
+ film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
+ film->set_name ("frobozz");
+
+ shared_ptr<SndfileContent> content (new SndfileContent (film, "test/data/white.wav"));
+ film->examine_and_add_content (content);
+ wait_for_jobs ();
+
+ film->set_audio_channels (12);
+ boost::signals2::connection connection;
+ JobManager::instance()->analyse_audio (film, film->playlist(), connection, boost::bind (&analysis_finished));
+ wait_for_jobs ();
+ BOOST_CHECK (done);
+}