lib/ffmpeg/Filter: add ParseSingleInOut()
Merge some duplicate code.
This commit is contained in:
parent
71a5311b06
commit
7b4225aa1f
@ -47,17 +47,7 @@ PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
|
|||||||
|
|
||||||
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
||||||
|
|
||||||
Ffmpeg::FilterInOut io_sink("out", buffer_sink);
|
graph.ParseSingleInOut(graph_string, buffer_sink, buffer_src);
|
||||||
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.CheckAndConfigure();
|
graph.CheckAndConfigure();
|
||||||
|
|
||||||
const auto out_audio_format =
|
const auto out_audio_format =
|
||||||
|
@ -48,18 +48,7 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
|
|||||||
|
|
||||||
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
||||||
|
|
||||||
Ffmpeg::FilterInOut io_sink("out", buffer_sink);
|
graph.ParseSingleInOut(hdcd_graph, buffer_sink, buffer_src);
|
||||||
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.CheckAndConfigure();
|
graph.CheckAndConfigure();
|
||||||
|
|
||||||
auto out_audio_format = in_audio_format;
|
auto out_audio_format = in_audio_format;
|
||||||
|
@ -100,4 +100,17 @@ MakeAudioBufferSink(AVFilterGraph &graph_ctx)
|
|||||||
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
|
} // namespace Ffmpeg
|
||||||
|
@ -138,6 +138,9 @@ public:
|
|||||||
return std::make_pair(std::move(inputs), std::move(outputs));
|
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) {
|
std::pair<FilterInOut, FilterInOut> Parse(const char *filters) {
|
||||||
AVFilterInOut *inputs, *outputs;
|
AVFilterInOut *inputs, *outputs;
|
||||||
int err = avfilter_graph_parse2(graph, filters,
|
int err = avfilter_graph_parse2(graph, filters,
|
||||||
|
Loading…
Reference in New Issue
Block a user