X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_filter_graph.cc;h=4e3052d57c519eccc3f390e01d5f3e4c3ad6da5f;hb=1671e097a24cd169f1ad4ea89b0cb3ae105b1e70;hp=0eeeb3c4ae5858b094ffd4f5da58ab659f9d3b75;hpb=2c4102e14362ef445d1b97a3aa26a889c05578c2;p=dcpomatic.git diff --git a/src/lib/audio_filter_graph.cc b/src/lib/audio_filter_graph.cc index 0eeeb3c4a..4e3052d57 100644 --- a/src/lib/audio_filter_graph.cc +++ b/src/lib/audio_filter_graph.cc @@ -18,21 +18,28 @@ */ -#include "audio_filter_graph.h" + #include "audio_buffers.h" +#include "audio_filter_graph.h" #include "compose.hpp" +#include "dcpomatic_assert.h" +#include "exceptions.h" extern "C" { #include #include #include +#include } #include #include "i18n.h" -using std::string; + using std::cout; -using boost::shared_ptr; +using std::make_shared; +using std::shared_ptr; +using std::string; + AudioFilterGraph::AudioFilterGraph (int sample_rate, int channels) : _sample_rate (sample_rate) @@ -48,6 +55,9 @@ AudioFilterGraph::AudioFilterGraph (int sample_rate, int channels) } _in_frame = av_frame_alloc (); + if (_in_frame == nullptr) { + throw std::bad_alloc(); + } } AudioFilterGraph::~AudioFilterGraph() @@ -70,28 +80,24 @@ AudioFilterGraph::src_parameters () const return buffer; } -void * -AudioFilterGraph::sink_parameters () const -{ - AVABufferSinkParams* sink_params = av_abuffersink_params_alloc (); - - AVSampleFormat* sample_fmts = new AVSampleFormat[2]; - sample_fmts[0] = AV_SAMPLE_FMT_FLTP; - sample_fmts[1] = AV_SAMPLE_FMT_NONE; - sink_params->sample_fmts = sample_fmts; - int64_t* channel_layouts = new int64_t[2]; - channel_layouts[0] = _channel_layout; - channel_layouts[1] = -1; - sink_params->channel_layouts = channel_layouts; +void +AudioFilterGraph::set_parameters (AVFilterContext* context) const +{ + AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }; + int r = av_opt_set_int_list (context, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN); + DCPOMATIC_ASSERT (r >= 0); - sink_params->sample_rates = new int[2]; - sink_params->sample_rates[0] = _sample_rate; - sink_params->sample_rates[1] = -1; + int64_t channel_layouts[] = { _channel_layout, -1 }; + r = av_opt_set_int_list (context, "channel_layouts", channel_layouts, -1, AV_OPT_SEARCH_CHILDREN); + DCPOMATIC_ASSERT (r >= 0); - return sink_params; + int sample_rates[] = { _sample_rate, -1 }; + r = av_opt_set_int_list (context, "sample_rates", sample_rates, -1, AV_OPT_SEARCH_CHILDREN); + DCPOMATIC_ASSERT (r >= 0); } + string AudioFilterGraph::src_name () const { @@ -105,7 +111,7 @@ AudioFilterGraph::sink_name () const } void -AudioFilterGraph::process (shared_ptr buffers) +AudioFilterGraph::process (shared_ptr buffers) { DCPOMATIC_ASSERT (buffers->frames() > 0); int const process_channels = av_get_channel_layout_nb_channels (_channel_layout); @@ -116,7 +122,7 @@ AudioFilterGraph::process (shared_ptr buffers) the constructor) so we need to create new buffers with some extra silent channels. */ - shared_ptr extended_buffers (new AudioBuffers (process_channels, buffers->frames())); + auto extended_buffers = make_shared(process_channels, buffers->frames()); for (int i = 0; i < buffers->channels(); ++i) { extended_buffers->copy_channel_from (buffers.get(), i, i); }