summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-30 19:36:01 +0200
committerCarl Hetherington <cth@carlh.net>2021-04-30 20:39:03 +0200
commit6c24979c3b03cadaa232820e2da2ff1ab590dd64 (patch)
treec386c1c393b8765c98c0f4976bfef4cf08a58f4f
parent054ee2d2bdee16b40a0328efb0b34d464e2c075c (diff)
Port filter graphs to new FFmpeg API.new-ffmpeg-take2
-rw-r--r--src/lib/audio_filter_graph.cc31
-rw-r--r--src/lib/audio_filter_graph.h8
-rw-r--r--src/lib/filter_graph.cc24
-rw-r--r--src/lib/filter_graph.h2
-rw-r--r--src/lib/video_filter_graph.cc16
-rw-r--r--src/lib/video_filter_graph.h8
6 files changed, 44 insertions, 45 deletions
diff --git a/src/lib/audio_filter_graph.cc b/src/lib/audio_filter_graph.cc
index 6318c68ab..fc43b5a34 100644
--- a/src/lib/audio_filter_graph.cc
+++ b/src/lib/audio_filter_graph.cc
@@ -25,6 +25,7 @@ extern "C" {
#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
#include <libavutil/channel_layout.h>
+#include <libavutil/opt.h>
}
#include <iostream>
@@ -70,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
{
diff --git a/src/lib/audio_filter_graph.h b/src/lib/audio_filter_graph.h
index 91216c7c3..af438a7e7 100644
--- a/src/lib/audio_filter_graph.h
+++ b/src/lib/audio_filter_graph.h
@@ -34,10 +34,10 @@ public:
void process (std::shared_ptr<const AudioBuffers> audio);
protected:
- std::string src_parameters () const;
- std::string src_name () const;
- void* sink_parameters () const;
- std::string sink_name () const;
+ std::string src_parameters () const override;
+ std::string src_name () const override;
+ void set_parameters (AVFilterContext* context) const override;
+ std::string sink_name () const override;
private:
int _sample_rate;
diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc
index 2a690eeb9..ba0e01ed5 100644
--- a/src/lib/filter_graph.cc
+++ b/src/lib/filter_graph.cc
@@ -18,10 +18,12 @@
*/
+
/** @file src/lib/filter_graph.cc
* @brief A graph of FFmpeg filters.
*/
+
#include "filter_graph.h"
#include "filter.h"
#include "exceptions.h"
@@ -36,6 +38,7 @@ extern "C" {
#include "i18n.h"
+
using std::string;
using std::list;
using std::pair;
@@ -46,6 +49,7 @@ using std::shared_ptr;
using std::weak_ptr;
using dcp::Size;
+
/** Construct a FilterGraph for the settings in a piece of content */
FilterGraph::FilterGraph ()
: _graph (0)
@@ -73,12 +77,12 @@ FilterGraph::setup (vector<Filter const *> filters)
throw DecodeError (N_("could not create filter graph."));
}
- AVFilter const * buffer_src = avfilter_get_by_name (src_name().c_str());
+ auto const buffer_src = avfilter_get_by_name (src_name().c_str());
if (!buffer_src) {
throw DecodeError (N_("could not find buffer src filter"));
}
- AVFilter const * buffer_sink = avfilter_get_by_name (sink_name().c_str());
+ auto const buffer_sink = avfilter_get_by_name (sink_name().c_str());
if (!buffer_sink) {
throw DecodeError (N_("Could not create buffer sink filter"));
}
@@ -87,21 +91,19 @@ FilterGraph::setup (vector<Filter const *> filters)
throw DecodeError (N_("could not create buffer source"));
}
- void* sink_params = sink_parameters ();
-
- if (avfilter_graph_create_filter (&_buffer_sink_context, buffer_sink, N_("out"), 0, sink_params, _graph) < 0) {
+ if (avfilter_graph_create_filter (&_buffer_sink_context, buffer_sink, N_("out"), nullptr, nullptr, _graph) < 0) {
throw DecodeError (N_("could not create buffer sink."));
}
- av_free (sink_params);
+ set_parameters (_buffer_sink_context);
- AVFilterInOut* outputs = avfilter_inout_alloc ();
+ auto outputs = avfilter_inout_alloc ();
outputs->name = av_strdup(N_("in"));
outputs->filter_ctx = _buffer_src_context;
outputs->pad_idx = 0;
outputs->next = 0;
- AVFilterInOut* inputs = avfilter_inout_alloc ();
+ auto inputs = avfilter_inout_alloc ();
inputs->name = av_strdup(N_("out"));
inputs->filter_ctx = _buffer_sink_context;
inputs->pad_idx = 0;
@@ -113,10 +115,11 @@ FilterGraph::setup (vector<Filter const *> filters)
int e = avfilter_graph_config (_graph, 0);
if (e < 0) {
- throw DecodeError (String::compose (N_("could not configure filter graph (%1)"), e));
+ throw DecodeError (String::compose(N_("could not configure filter graph (%1)"), e));
}
}
+
FilterGraph::~FilterGraph ()
{
if (_frame) {
@@ -128,8 +131,9 @@ FilterGraph::~FilterGraph ()
}
}
+
AVFilterContext *
FilterGraph::get (string name)
{
- return avfilter_graph_get_filter (_graph, name.c_str ());
+ return avfilter_graph_get_filter (_graph, name.c_str());
}
diff --git a/src/lib/filter_graph.h b/src/lib/filter_graph.h
index 2b54d7829..eccfe4954 100644
--- a/src/lib/filter_graph.h
+++ b/src/lib/filter_graph.h
@@ -53,7 +53,7 @@ public:
protected:
virtual std::string src_parameters () const = 0;
virtual std::string src_name () const = 0;
- virtual void* sink_parameters () const = 0;
+ virtual void set_parameters (AVFilterContext* context) const = 0;
virtual std::string sink_name () const = 0;
AVFilterGraph* _graph;
diff --git a/src/lib/video_filter_graph.cc b/src/lib/video_filter_graph.cc
index c24d9673d..a61da6773 100644
--- a/src/lib/video_filter_graph.cc
+++ b/src/lib/video_filter_graph.cc
@@ -26,6 +26,7 @@
extern "C" {
#include <libavfilter/buffersrc.h>
#include <libavfilter/buffersink.h>
+#include <libavutil/opt.h>
}
#include "i18n.h"
@@ -70,7 +71,7 @@ VideoFilterGraph::process (AVFrame* frame)
break;
}
- images.push_back (make_pair(make_shared<Image>(_frame), _frame->best_effort_timestamp));
+ images.push_back (make_pair(make_shared<Image>(_frame), frame->best_effort_timestamp));
av_frame_unref (_frame);
}
}
@@ -105,15 +106,12 @@ VideoFilterGraph::src_parameters () const
}
-void *
-VideoFilterGraph::sink_parameters () const
+void
+VideoFilterGraph::set_parameters (AVFilterContext* context) const
{
- auto sink_params = av_buffersink_params_alloc ();
- auto pixel_fmts = new AVPixelFormat[2];
- pixel_fmts[0] = _pixel_format;
- pixel_fmts[1] = AV_PIX_FMT_NONE;
- sink_params->pixel_fmts = pixel_fmts;
- return sink_params;
+ AVPixelFormat pix_fmts[] = { _pixel_format, AV_PIX_FMT_NONE };
+ int r = av_opt_set_int_list (context, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
+ DCPOMATIC_ASSERT (r >= 0);
}
diff --git a/src/lib/video_filter_graph.h b/src/lib/video_filter_graph.h
index fb6c7eba1..d887e551b 100644
--- a/src/lib/video_filter_graph.h
+++ b/src/lib/video_filter_graph.h
@@ -31,10 +31,10 @@ public:
std::list<std::pair<std::shared_ptr<Image>, int64_t>> process (AVFrame * frame);
protected:
- std::string src_parameters () const;
- std::string src_name () const;
- void* sink_parameters () const;
- std::string sink_name () const;
+ std::string src_parameters () const override;
+ std::string src_name () const override;
+ void set_parameters (AVFilterContext* context) const override;
+ std::string sink_name () const override;
private:
dcp::Size _size; ///< size of the images that this chain can process