+ if (ctx->hwdevice_ref) {
+ /* We already have a specified device. */
+ } else if (avctx->hw_device_ctx) {
+ if (ctx->device_type) {
+ err = av_hwdevice_ctx_create_derived(
+ &ctx->hwdevice_ref,
+ av_hwdevice_find_type_by_name(ctx->device_type),
+ avctx->hw_device_ctx, 0);
+ if (err < 0)
+ return err;
+ } else {
+ ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx);
+ if (!ctx->hwdevice_ref)
+ return AVERROR(ENOMEM);
+ }
+ } else {