Message ID | 20170502235626.30567-1-nfxjfg@googlemail.com |
---|---|
State | Accepted |
Headers | show |
On 2017-05-02 16:56, wm4 wrote: > This is a newer API that is intended for decoders like the cuvid > wrapper. Until now, the wrapper required to set an awkward > "incomplete" hw_frames_ctx to set the device. Now the device > can be set directly, and the user can get AV_PIX_FMT_CUDA output > for a specific device simply by setting hw_device_ctx. > > This still does a dummy ff_get_format() call at init time, and should > be fully backward compatible. > --- > Not sure how to test correctly - it worked with mpv even when I > accidentally didn't use the correct VO device. > --- > libavcodec/cuvid.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c > index 288083423e..3453003965 100644 > --- a/libavcodec/cuvid.c > +++ b/libavcodec/cuvid.c > @@ -802,9 +802,17 @@ static av_cold int > cuvid_decode_init(AVCodecContext *avctx) > goto error; > } > } else { > - ret = av_hwdevice_ctx_create(&ctx->hwdevice, > AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); > - if (ret < 0) > - goto error; > + if (avctx->hw_device_ctx) { > + ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx); > + if (!ctx->hwdevice) { > + ret = AVERROR(ENOMEM); > + goto error; > + } > + } else { > + ret = av_hwdevice_ctx_create(&ctx->hwdevice, > AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); > + if (ret < 0) > + goto error; > + } > > ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice); > if (!ctx->hwframe) { Makes sense to me. Ship it. --phil
> --- a/libavcodec/cuvid.c > +++ b/libavcodec/cuvid.c > @@ -802,9 +802,17 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) > goto error; > } > } else { > - ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); > - if (ret < 0) > - goto error; > + if (avctx->hw_device_ctx) { > + ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx); > + if (!ctx->hwdevice) { > + ret = AVERROR(ENOMEM); > + goto error; > + } > + } else { > + ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); > + if (ret < 0) > + goto error; > + } > > ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice); > if (!ctx->hwframe) { > Simple enough, LGTM
diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 288083423e..3453003965 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -802,9 +802,17 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) goto error; } } else { - ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); - if (ret < 0) - goto error; + if (avctx->hw_device_ctx) { + ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx); + if (!ctx->hwdevice) { + ret = AVERROR(ENOMEM); + goto error; + } + } else { + ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); + if (ret < 0) + goto error; + } ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice); if (!ctx->hwframe) {