Commit 7b4225aa authored by Max Kellermann's avatar Max Kellermann

lib/ffmpeg/Filter: add ParseSingleInOut()

Merge some duplicate code.
parent 71a5311b
......@@ -47,17 +47,7 @@ PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
Ffmpeg::FilterInOut io_sink("out", buffer_sink);
Ffmpeg::FilterInOut io_src("in", buffer_src);
auto io = graph.Parse(graph_string, std::move(io_sink),
std::move(io_src));
if (io.first.get() != nullptr)
throw std::runtime_error("FFmpeg filter has an open input");
if (io.second.get() != nullptr)
throw std::runtime_error("FFmpeg filter has an open output");
graph.ParseSingleInOut(graph_string, buffer_sink, buffer_src);
graph.CheckAndConfigure();
const auto out_audio_format =
......
......@@ -48,18 +48,7 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
Ffmpeg::FilterInOut io_sink("out", buffer_sink);
Ffmpeg::FilterInOut io_src("in", buffer_src);
auto io = graph.Parse(hdcd_graph, std::move(io_sink),
std::move(io_src));
if (io.first.get() != nullptr)
throw std::runtime_error("FFmpeg filter has an open input");
if (io.second.get() != nullptr)
throw std::runtime_error("FFmpeg filter has an open output");
graph.ParseSingleInOut(hdcd_graph, buffer_sink, buffer_src);
graph.CheckAndConfigure();
auto out_audio_format = in_audio_format;
......
......@@ -100,4 +100,17 @@ MakeAudioBufferSink(AVFilterGraph &graph_ctx)
graph_ctx);
}
void
FilterGraph::ParseSingleInOut(const char *filters, AVFilterContext &in,
AVFilterContext &out)
{
auto [inputs, outputs] = Parse(filters, {"out", in}, {"in", out});
if (inputs.get() != nullptr)
throw std::runtime_error("FFmpeg filter has an open input");
if (outputs.get() != nullptr)
throw std::runtime_error("FFmpeg filter has an open output");
}
} // namespace Ffmpeg
......@@ -138,6 +138,9 @@ public:
return std::make_pair(std::move(inputs), std::move(outputs));
}
void ParseSingleInOut(const char *filters, AVFilterContext &in,
AVFilterContext &out);
std::pair<FilterInOut, FilterInOut> Parse(const char *filters) {
AVFilterInOut *inputs, *outputs;
int err = avfilter_graph_parse2(graph, filters,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment