Read ISDCF Metadata from 2.14.x metadata (#2083).
[dcpomatic.git] / src / lib / audio_filter_graph.cc
index afbcf4921e9dde165e04914c81777697229cf275..fc43b5a344a972a9ef20d69e1257441024616412 100644 (file)
@@ -25,12 +25,15 @@ extern "C" {
 #include <libavfilter/buffersink.h>
 #include <libavfilter/buffersrc.h>
 #include <libavutil/channel_layout.h>
+#include <libavutil/opt.h>
 }
+#include <iostream>
 
 #include "i18n.h"
 
 using std::string;
-using boost::shared_ptr;
+using std::cout;
+using std::shared_ptr;
 
 AudioFilterGraph::AudioFilterGraph (int sample_rate, int channels)
        : _sample_rate (sample_rate)
@@ -68,28 +71,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,6 +104,7 @@ AudioFilterGraph::sink_name () const
 void
 AudioFilterGraph::process (shared_ptr<const AudioBuffers> buffers)
 {
+       DCPOMATIC_ASSERT (buffers->frames() > 0);
        int const process_channels = av_get_channel_layout_nb_channels (_channel_layout);
        DCPOMATIC_ASSERT (process_channels >= buffers->channels());