| 325 | } |
| 326 | |
| 327 | int ff_nvdec_decode_init(AVCodecContext *avctx) |
| 328 | { |
| 329 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; |
| 330 | |
| 331 | NVDECDecoder *decoder; |
| 332 | AVBufferRef *real_hw_frames_ref; |
| 333 | NVDECFramePool *pool; |
| 334 | AVHWFramesContext *frames_ctx; |
| 335 | const AVPixFmtDescriptor *sw_desc; |
| 336 | |
| 337 | CUVIDDECODECREATEINFO params = { 0 }; |
| 338 | |
| 339 | cudaVideoSurfaceFormat output_format; |
| 340 | int cuvid_codec_type, cuvid_chroma_format, chroma_444; |
| 341 | int ret = 0; |
| 342 | |
| 343 | int unsafe_output = !!(avctx->hwaccel_flags & AV_HWACCEL_FLAG_UNSAFE_OUTPUT); |
| 344 | |
| 345 | sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); |
| 346 | if (!sw_desc) |
| 347 | return AVERROR_BUG; |
| 348 | |
| 349 | cuvid_codec_type = map_avcodec_id(avctx->codec_id); |
| 350 | if (cuvid_codec_type < 0) { |
| 351 | av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n"); |
| 352 | return AVERROR_BUG; |
| 353 | } |
| 354 | |
| 355 | cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt); |
| 356 | if (cuvid_chroma_format < 0) { |
| 357 | av_log(avctx, AV_LOG_ERROR, "Unsupported chroma format\n"); |
| 358 | return AVERROR(ENOSYS); |
| 359 | } |
| 360 | chroma_444 = ctx->supports_444 && cuvid_chroma_format == cudaVideoChromaFormat_444; |
| 361 | |
| 362 | if (!avctx->hw_frames_ctx) { |
| 363 | ret = nvdec_init_hwframes(avctx, &avctx->hw_frames_ctx, 1); |
| 364 | if (ret < 0) |
| 365 | return ret; |
| 366 | |
| 367 | ret = nvdec_init_hwframes(avctx, &real_hw_frames_ref, 0); |
| 368 | if (ret < 0) |
| 369 | return ret; |
| 370 | } else { |
| 371 | real_hw_frames_ref = av_buffer_ref(avctx->hw_frames_ctx); |
| 372 | if (!real_hw_frames_ref) |
| 373 | return AVERROR(ENOMEM); |
| 374 | } |
| 375 | |
| 376 | switch (sw_desc->comp[0].depth) { |
| 377 | case 8: |
| 378 | if (chroma_444) { |
| 379 | output_format = cudaVideoSurfaceFormat_YUV444; |
| 380 | #ifdef NVDEC_HAVE_422_SUPPORT |
| 381 | } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { |
| 382 | output_format = cudaVideoSurfaceFormat_NV16; |
| 383 | #endif |
| 384 | } else { |
no test coverage detected