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.
Showing the changes to libavcodec (2 of 3 files). Show all
Unified · Split
| @@ -802,9 +802,17 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) · 801 unmodified lines | |||
| 802 | goto error; | 802 | goto error; |
| 803 | } | 803 | } |
| 804 | } else { | 804 | } else { |
| 805 | ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); | 805 | if (avctx->hw_device_ctx) { |
| 806 | if (ret < 0) | 806 | ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx); |
| 807 | goto error; | 807 | if (!ctx->hwdevice) { |
| 808 | ret = AVERROR(ENOMEM); | ||
| 809 | goto error; | ||
| 810 | } | ||
| 811 | } else { | ||
| 812 | ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0); | ||
| 813 | if (ret < 0) | ||
| 814 | goto error; | ||
| 815 | } | ||
| 808 | 816 | ||
| 809 | ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice); | 817 | ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice); |
| 810 | if (!ctx->hwframe) { | 818 | if (!ctx->hwframe) { |
| @@ -28,7 +28,7 @@ · 27 unmodified lines | |||
| 28 | #include "libavutil/version.h" | 28 | #include "libavutil/version.h" |
| 29 | 29 | ||
| 30 | #define LIBAVCODEC_VERSION_MAJOR 57 | 30 | #define LIBAVCODEC_VERSION_MAJOR 57 |
| 31 | #define LIBAVCODEC_VERSION_MINOR 93 | 31 | #define LIBAVCODEC_VERSION_MINOR 94 |
| 32 | #define LIBAVCODEC_VERSION_MICRO 100 | 32 | #define LIBAVCODEC_VERSION_MICRO 100 |
| 33 | 33 | ||
| 34 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | 34 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |