From e5df57c7554da08c812252c5c2d8bf5d372e19e3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 20 Feb 2017 13:42:08 +0100 Subject: lavfi: support hwdec filters for --lavfi-complex Not so important by itself, but important for when we replace the vf libavfilter wrapper with the common implementation. (Which will hopefully happen, but not too soon.) --- player/lavfi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'player/lavfi.c') diff --git a/player/lavfi.c b/player/lavfi.c index 953ccc5956..2573a92833 100644 --- a/player/lavfi.c +++ b/player/lavfi.c @@ -40,6 +40,7 @@ #include "video/mp_image.h" #include "audio/fmt-conversion.h" #include "video/fmt-conversion.h" +#include "video/hwdec.h" #include "lavfi.h" @@ -52,6 +53,8 @@ struct lavfi { struct mp_log *log; char *graph_string; + struct mp_hwdec_devices *hwdec_devs; + AVFilterGraph *graph; // Set to true once all inputs have been initialized, and the graph is // linked. @@ -423,6 +426,7 @@ static bool init_pads(struct lavfi *c) params->height = pad->in_fmt_v->h; params->sample_aspect_ratio.num = pad->in_fmt_v->params.p_w; params->sample_aspect_ratio.den = pad->in_fmt_v->params.p_h; + params->hw_frames_ctx = pad->in_fmt_v->hwctx; filter_name = "buffer"; } else { assert(0); @@ -471,6 +475,11 @@ static void dump_graph(struct lavfi *c) #endif } +void lavfi_set_hwdec_devs(struct lavfi *c, struct mp_hwdec_devices *hwdevs) +{ + c->hwdec_devs = hwdevs; +} + // Initialize the graph if all inputs have formats set. If it's already // initialized, or can't be initialized yet, do nothing. static void init_graph(struct lavfi *c) @@ -478,6 +487,15 @@ static void init_graph(struct lavfi *c) assert(!c->initialized); if (init_pads(c)) { + if (c->hwdec_devs) { + struct mp_hwdec_ctx *hwdec = hwdec_devices_get_first(c->hwdec_devs); + for (int n = 0; n < c->graph->nb_filters; n++) { + AVFilterContext *filter = c->graph->filters[n]; + if (hwdec && hwdec->av_device_ref) + filter->hw_device_ctx = av_buffer_ref(hwdec->av_device_ref); + } + } + // And here the actual libavfilter initialization happens. if (avfilter_graph_config(c->graph, NULL) < 0) { MP_FATAL(c, "failed to configure the filter graph\n"); -- cgit v1.2.3