diff options
author | Mark Thompson <sw@jkqxz.net> | 2020-04-13 18:33:19 +0300 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2020-04-26 20:38:25 +0300 |
commit | e2542124059f5960ac2bbd94183012814263f20d (patch) | |
tree | b8e1f4a4df7d616e3c42012f91abf7273d27569f /fftools/ffmpeg_hw.c | |
parent | 344e6c3ff1b47279ffb360aba3f5e10183bc4eb4 (diff) |
ffmpeg: Make filter hardware device selection clearer
Also move it into a dedicated function in the hardware file.
Diffstat (limited to 'fftools/ffmpeg_hw.c')
-rw-r--r-- | fftools/ffmpeg_hw.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c index 962d8f7d5a..40739fc320 100644 --- a/fftools/ffmpeg_hw.c +++ b/fftools/ffmpeg_hw.c @@ -480,3 +480,31 @@ int hwaccel_decode_init(AVCodecContext *avctx) return 0; } + +int hw_device_setup_for_filter(FilterGraph *fg) +{ + HWDevice *dev; + int i; + + // If the user has supplied exactly one hardware device then just + // give it straight to every filter for convenience. If more than + // one device is available then the user needs to pick one explcitly + // with the filter_hw_device option. + if (filter_hw_device) + dev = filter_hw_device; + else if (nb_hw_devices == 1) + dev = hw_devices[0]; + else + dev = NULL; + + if (dev) { + for (i = 0; i < fg->graph->nb_filters; i++) { + fg->graph->filters[i]->hw_device_ctx = + av_buffer_ref(dev->device_ref); + if (!fg->graph->filters[i]->hw_device_ctx) + return AVERROR(ENOMEM); + } + } + + return 0; +} |