X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_filter_graph.cc;h=d9e4e244fd23aa4527d25f1840a21ec37a7b3512;hb=182b9d2e2feb6545592868606aaf0f0146095481;hp=a43f1881ea515755ed34176bc43784d82807867e;hpb=57c49675889c0e0ad8cebece7a60bba08ba782d2;p=dcpomatic.git diff --git a/src/lib/audio_filter_graph.cc b/src/lib/audio_filter_graph.cc index a43f1881e..d9e4e244f 100644 --- a/src/lib/audio_filter_graph.cc +++ b/src/lib/audio_filter_graph.cc @@ -1,35 +1,43 @@ /* Copyright (C) 2015 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ -#include "audio_filter_graph.h" + #include "audio_buffers.h" +#include "audio_filter_graph.h" #include "compose.hpp" 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) @@ -55,40 +63,36 @@ AudioFilterGraph::~AudioFilterGraph() string AudioFilterGraph::src_parameters () const { - SafeStringStream a; - - char buffer[64]; - av_get_channel_layout_string (buffer, sizeof(buffer), 0, _channel_layout); + char layout[64]; + av_get_channel_layout_string (layout, sizeof(layout), 0, _channel_layout); - a << "time_base=1/1:sample_rate=" << _sample_rate << ":" - << "sample_fmt=" << av_get_sample_fmt_name(AV_SAMPLE_FMT_FLTP) << ":" - << "channel_layout=" << buffer; + char buffer[256]; + snprintf ( + buffer, sizeof(buffer), "time_base=1/1:sample_rate=%d:sample_fmt=%s:channel_layout=%s", + _sample_rate, av_get_sample_fmt_name(AV_SAMPLE_FMT_FLTP), layout + ); - return a.str (); + 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 { @@ -102,8 +106,9 @@ 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); DCPOMATIC_ASSERT (process_channels >= buffers->channels()); @@ -112,7 +117,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); } @@ -148,7 +153,7 @@ AudioFilterGraph::process (shared_ptr buffers) if (r < 0) { char buffer[256]; av_strerror (r, buffer, sizeof(buffer)); - throw DecodeError (String::compose (N_("could not push buffer into filter chain (%1)"), buffer)); + throw DecodeError (String::compose (N_("could not push buffer into filter chain (%1)"), &buffer[0])); } while (true) {