| 182 | } |
| 183 | |
| 184 | static int nvdec_decoder_create(NVDECDecoder **out, AVBufferRef *hw_device_ref, |
| 185 | CUVIDDECODECREATEINFO *params, void *logctx) |
| 186 | { |
| 187 | AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)hw_device_ref->data; |
| 188 | AVCUDADeviceContext *device_hwctx = hw_device_ctx->hwctx; |
| 189 | |
| 190 | NVDECDecoder *decoder; |
| 191 | |
| 192 | CUcontext dummy; |
| 193 | int ret; |
| 194 | |
| 195 | decoder = av_refstruct_alloc_ext(sizeof(*decoder), 0, |
| 196 | NULL, nvdec_decoder_free); |
| 197 | if (!decoder) |
| 198 | return AVERROR(ENOMEM); |
| 199 | |
| 200 | decoder->hw_device_ref = av_buffer_ref(hw_device_ref); |
| 201 | if (!decoder->hw_device_ref) { |
| 202 | ret = AVERROR(ENOMEM); |
| 203 | goto fail; |
| 204 | } |
| 205 | decoder->cuda_ctx = device_hwctx->cuda_ctx; |
| 206 | decoder->cudl = device_hwctx->internal->cuda_dl; |
| 207 | decoder->stream = device_hwctx->stream; |
| 208 | |
| 209 | ret = cuvid_load_functions(&decoder->cvdl, logctx); |
| 210 | if (ret < 0) { |
| 211 | av_log(logctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n"); |
| 212 | goto fail; |
| 213 | } |
| 214 | |
| 215 | ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx)); |
| 216 | if (ret < 0) |
| 217 | goto fail; |
| 218 | |
| 219 | ret = nvdec_test_capabilities(decoder, params, logctx); |
| 220 | if (ret < 0) { |
| 221 | CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy)); |
| 222 | goto fail; |
| 223 | } |
| 224 | |
| 225 | ret = CHECK_CU(decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params)); |
| 226 | |
| 227 | CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy)); |
| 228 | |
| 229 | if (ret < 0) { |
| 230 | goto fail; |
| 231 | } |
| 232 | |
| 233 | *out = decoder; |
| 234 | |
| 235 | return 0; |
| 236 | fail: |
| 237 | av_refstruct_unref(&decoder); |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | static int nvdec_decoder_frame_init(AVRefStructOpaque opaque, void *obj) |
no test coverage detected