@@ -50,6 +50,8 @@ typedef struct NVDECFramePool {
5050 unsigned int nb_allocated ;
5151} NVDECFramePool ;
5252
53+ #define CHECK_CU (x ) AV_CUDA_CHECK_DL(logctx, decoder->cudl, x)
54+
5355static int map_avcodec_id (enum AVCodecID id )
5456{
5557 switch (id ) {
@@ -86,7 +88,7 @@ static int map_chroma_format(enum AVPixelFormat pix_fmt)
8688static int nvdec_test_capabilities (NVDECDecoder * decoder ,
8789 CUVIDDECODECREATEINFO * params , void * logctx )
8890{
89- CUresult err ;
91+ int ret ;
9092 CUVIDDECODECAPS caps = { 0 };
9193
9294 caps .eCodecType = params -> CodecType ;
@@ -105,11 +107,9 @@ static int nvdec_test_capabilities(NVDECDecoder *decoder,
105107 return 0 ;
106108 }
107109
108- err = decoder -> cvdl -> cuvidGetDecoderCaps (& caps );
109- if (err != CUDA_SUCCESS ) {
110- av_log (logctx , AV_LOG_ERROR , "Failed querying decoder capabilities\n" );
111- return AVERROR_UNKNOWN ;
112- }
110+ ret = CHECK_CU (decoder -> cvdl -> cuvidGetDecoderCaps (& caps ));
111+ if (ret < 0 )
112+ return ret ;
113113
114114 av_log (logctx , AV_LOG_VERBOSE , "NVDEC capabilities:\n" );
115115 av_log (logctx , AV_LOG_VERBOSE , "format supported: %s, max_mb_count: %d\n" ,
@@ -150,10 +150,11 @@ static void nvdec_decoder_free(void *opaque, uint8_t *data)
150150 NVDECDecoder * decoder = (NVDECDecoder * )data ;
151151
152152 if (decoder -> decoder ) {
153+ void * logctx = decoder -> hw_device_ref -> data ;
153154 CUcontext dummy ;
154- decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx );
155- decoder -> cvdl -> cuvidDestroyDecoder (decoder -> decoder );
156- decoder -> cudl -> cuCtxPopCurrent (& dummy );
155+ CHECK_CU ( decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx ) );
156+ CHECK_CU ( decoder -> cvdl -> cuvidDestroyDecoder (decoder -> decoder ) );
157+ CHECK_CU ( decoder -> cudl -> cuCtxPopCurrent (& dummy ) );
157158 }
158159
159160 av_buffer_unref (& decoder -> hw_device_ref );
@@ -173,7 +174,6 @@ static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref,
173174 NVDECDecoder * decoder ;
174175
175176 CUcontext dummy ;
176- CUresult err ;
177177 int ret ;
178178
179179 decoder = av_mallocz (sizeof (* decoder ));
@@ -202,25 +202,21 @@ static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref,
202202 goto fail ;
203203 }
204204
205- err = decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx );
206- if (err != CUDA_SUCCESS ) {
207- ret = AVERROR_UNKNOWN ;
205+ ret = CHECK_CU (decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx ));
206+ if (ret < 0 )
208207 goto fail ;
209- }
210208
211209 ret = nvdec_test_capabilities (decoder , params , logctx );
212210 if (ret < 0 ) {
213- decoder -> cudl -> cuCtxPopCurrent (& dummy );
211+ CHECK_CU ( decoder -> cudl -> cuCtxPopCurrent (& dummy ) );
214212 goto fail ;
215213 }
216214
217- err = decoder -> cvdl -> cuvidCreateDecoder (& decoder -> decoder , params );
215+ ret = CHECK_CU ( decoder -> cvdl -> cuvidCreateDecoder (& decoder -> decoder , params ) );
218216
219- decoder -> cudl -> cuCtxPopCurrent (& dummy );
217+ CHECK_CU ( decoder -> cudl -> cuCtxPopCurrent (& dummy ) );
220218
221- if (err != CUDA_SUCCESS ) {
222- av_log (logctx , AV_LOG_ERROR , "Error creating a NVDEC decoder: %d\n" , err );
223- ret = AVERROR_UNKNOWN ;
219+ if (ret < 0 ) {
224220 goto fail ;
225221 }
226222
@@ -364,21 +360,18 @@ static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
364360{
365361 NVDECFrame * unmap_data = (NVDECFrame * )data ;
366362 NVDECDecoder * decoder = (NVDECDecoder * )unmap_data -> decoder_ref -> data ;
363+ void * logctx = decoder -> hw_device_ref -> data ;
367364 CUdeviceptr devptr = (CUdeviceptr )opaque ;
368- CUresult err ;
365+ int ret ;
369366 CUcontext dummy ;
370367
371- err = decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx );
372- if (err != CUDA_SUCCESS ) {
373- av_log (NULL , AV_LOG_ERROR , "cuCtxPushCurrent failed\n" );
368+ ret = CHECK_CU (decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx ));
369+ if (ret < 0 )
374370 goto finish ;
375- }
376371
377- err = decoder -> cvdl -> cuvidUnmapVideoFrame (decoder -> decoder , devptr );
378- if (err != CUDA_SUCCESS )
379- av_log (NULL , AV_LOG_ERROR , "cuvidUnmapVideoFrame failed\n" );
372+ CHECK_CU (decoder -> cvdl -> cuvidUnmapVideoFrame (decoder -> decoder , devptr ));
380373
381- decoder -> cudl -> cuCtxPopCurrent (& dummy );
374+ CHECK_CU ( decoder -> cudl -> cuCtxPopCurrent (& dummy ) );
382375
383376finish :
384377 av_buffer_unref (& unmap_data -> idx_ref );
@@ -395,7 +388,6 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
395388 CUVIDPROCPARAMS vpp = { 0 };
396389 NVDECFrame * unmap_data = NULL ;
397390
398- CUresult err ;
399391 CUcontext dummy ;
400392 CUdeviceptr devptr ;
401393
@@ -406,18 +398,15 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
406398 vpp .progressive_frame = 1 ;
407399 vpp .output_stream = decoder -> stream ;
408400
409- err = decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx );
410- if (err != CUDA_SUCCESS )
411- return AVERROR_UNKNOWN ;
401+ ret = CHECK_CU ( decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx ) );
402+ if (ret < 0 )
403+ return ret ;
412404
413- err = decoder -> cvdl -> cuvidMapVideoFrame (decoder -> decoder , cf -> idx , & devptr ,
414- & pitch , & vpp );
415- if (err != CUDA_SUCCESS ) {
416- av_log (logctx , AV_LOG_ERROR , "Error mapping a picture with CUVID: %d\n" ,
417- err );
418- ret = AVERROR_UNKNOWN ;
405+ ret = CHECK_CU (decoder -> cvdl -> cuvidMapVideoFrame (decoder -> decoder ,
406+ cf -> idx , & devptr ,
407+ & pitch , & vpp ));
408+ if (ret < 0 )
419409 goto finish ;
420- }
421410
422411 unmap_data = av_mallocz (sizeof (* unmap_data ));
423412 if (!unmap_data ) {
@@ -447,14 +436,14 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
447436
448437copy_fail :
449438 if (!frame -> buf [1 ]) {
450- decoder -> cvdl -> cuvidUnmapVideoFrame (decoder -> decoder , devptr );
439+ CHECK_CU ( decoder -> cvdl -> cuvidUnmapVideoFrame (decoder -> decoder , devptr ) );
451440 av_freep (& unmap_data );
452441 } else {
453442 av_buffer_unref (& frame -> buf [1 ]);
454443 }
455444
456445finish :
457- decoder -> cudl -> cuCtxPopCurrent (& dummy );
446+ CHECK_CU ( decoder -> cudl -> cuCtxPopCurrent (& dummy ) );
458447 return ret ;
459448}
460449
@@ -504,9 +493,9 @@ int ff_nvdec_end_frame(AVCodecContext *avctx)
504493{
505494 NVDECContext * ctx = avctx -> internal -> hwaccel_priv_data ;
506495 NVDECDecoder * decoder = (NVDECDecoder * )ctx -> decoder_ref -> data ;
496+ void * logctx = avctx ;
507497 CUVIDPICPARAMS * pp = & ctx -> pic_params ;
508498
509- CUresult err ;
510499 CUcontext dummy ;
511500
512501 int ret = 0 ;
@@ -516,20 +505,16 @@ int ff_nvdec_end_frame(AVCodecContext *avctx)
516505 pp -> nNumSlices = ctx -> nb_slices ;
517506 pp -> pSliceDataOffsets = ctx -> slice_offsets ;
518507
519- err = decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx );
520- if (err != CUDA_SUCCESS )
521- return AVERROR_UNKNOWN ;
508+ ret = CHECK_CU ( decoder -> cudl -> cuCtxPushCurrent (decoder -> cuda_ctx ) );
509+ if (ret < 0 )
510+ return ret ;
522511
523- err = decoder -> cvdl -> cuvidDecodePicture (decoder -> decoder , & ctx -> pic_params );
524- if (err != CUDA_SUCCESS ) {
525- av_log (avctx , AV_LOG_ERROR , "Error decoding a picture with NVDEC: %d\n" ,
526- err );
527- ret = AVERROR_UNKNOWN ;
512+ ret = CHECK_CU (decoder -> cvdl -> cuvidDecodePicture (decoder -> decoder , & ctx -> pic_params ));
513+ if (ret < 0 )
528514 goto finish ;
529- }
530515
531516finish :
532- decoder -> cudl -> cuCtxPopCurrent (& dummy );
517+ CHECK_CU ( decoder -> cudl -> cuCtxPopCurrent (& dummy ) );
533518
534519 return ret ;
535520}
0 commit comments