#include "libavutil/error.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda_internal.h"
+#include "libavutil/cuda_check.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
unsigned int nb_allocated;
} NVDECFramePool;
+#define CHECK_CU(x) FF_CUDA_CHECK_DL(logctx, decoder->cudl, x)
+
static int map_avcodec_id(enum AVCodecID id)
{
switch (id) {
static int nvdec_test_capabilities(NVDECDecoder *decoder,
CUVIDDECODECREATEINFO *params, void *logctx)
{
- CUresult err;
+ int ret;
CUVIDDECODECAPS caps = { 0 };
caps.eCodecType = params->CodecType;
return 0;
}
- err = decoder->cvdl->cuvidGetDecoderCaps(&caps);
- if (err != CUDA_SUCCESS) {
- av_log(logctx, AV_LOG_ERROR, "Failed querying decoder capabilities\n");
- return AVERROR_UNKNOWN;
- }
+ ret = CHECK_CU(decoder->cvdl->cuvidGetDecoderCaps(&caps));
+ if (ret < 0)
+ return ret;
av_log(logctx, AV_LOG_VERBOSE, "NVDEC capabilities:\n");
av_log(logctx, AV_LOG_VERBOSE, "format supported: %s, max_mb_count: %d\n",
{
NVDECDecoder *decoder = (NVDECDecoder*)data;
- if (decoder->decoder)
- decoder->cvdl->cuvidDestroyDecoder(decoder->decoder);
+ if (decoder->decoder) {
+ void *logctx = decoder->hw_device_ref->data;
+ CUcontext dummy;
+ CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
+ CHECK_CU(decoder->cvdl->cuvidDestroyDecoder(decoder->decoder));
+ CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
+ }
av_buffer_unref(&decoder->hw_device_ref);
NVDECDecoder *decoder;
CUcontext dummy;
- CUresult err;
int ret;
decoder = av_mallocz(sizeof(*decoder));
goto fail;
}
- err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
- if (err != CUDA_SUCCESS) {
- ret = AVERROR_UNKNOWN;
+ ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
+ if (ret < 0)
goto fail;
- }
ret = nvdec_test_capabilities(decoder, params, logctx);
if (ret < 0) {
- decoder->cudl->cuCtxPopCurrent(&dummy);
+ CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
goto fail;
}
- err = decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params);
+ ret = CHECK_CU(decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params));
- decoder->cudl->cuCtxPopCurrent(&dummy);
+ CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
- if (err != CUDA_SUCCESS) {
- av_log(logctx, AV_LOG_ERROR, "Error creating a NVDEC decoder: %d\n", err);
- ret = AVERROR_UNKNOWN;
+ if (ret < 0) {
goto fail;
}
{
NVDECFrame *unmap_data = (NVDECFrame*)data;
NVDECDecoder *decoder = (NVDECDecoder*)unmap_data->decoder_ref->data;
+ void *logctx = decoder->hw_device_ref->data;
CUdeviceptr devptr = (CUdeviceptr)opaque;
- CUresult err;
+ int ret;
CUcontext dummy;
- err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
- if (err != CUDA_SUCCESS) {
- av_log(NULL, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
+ ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
+ if (ret < 0)
goto finish;
- }
- err = decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
- if (err != CUDA_SUCCESS)
- av_log(NULL, AV_LOG_ERROR, "cuvidUnmapVideoFrame failed\n");
+ CHECK_CU(decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr));
- decoder->cudl->cuCtxPopCurrent(&dummy);
+ CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
finish:
av_buffer_unref(&unmap_data->idx_ref);
CUVIDPROCPARAMS vpp = { 0 };
NVDECFrame *unmap_data = NULL;
- CUresult err;
CUcontext dummy;
CUdeviceptr devptr;
vpp.progressive_frame = 1;
vpp.output_stream = decoder->stream;
- err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
- if (err != CUDA_SUCCESS)
- return AVERROR_UNKNOWN;
+ ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
+ if (ret < 0)
+ return ret;
- err = decoder->cvdl->cuvidMapVideoFrame(decoder->decoder, cf->idx, &devptr,
- &pitch, &vpp);
- if (err != CUDA_SUCCESS) {
- av_log(logctx, AV_LOG_ERROR, "Error mapping a picture with CUVID: %d\n",
- err);
- ret = AVERROR_UNKNOWN;
+ ret = CHECK_CU(decoder->cvdl->cuvidMapVideoFrame(decoder->decoder,
+ cf->idx, &devptr,
+ &pitch, &vpp));
+ if (ret < 0)
goto finish;
- }
unmap_data = av_mallocz(sizeof(*unmap_data));
if (!unmap_data) {
copy_fail:
if (!frame->buf[1]) {
- decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
+ CHECK_CU(decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr));
av_freep(&unmap_data);
} else {
av_buffer_unref(&frame->buf[1]);
}
finish:
- decoder->cudl->cuCtxPopCurrent(&dummy);
+ CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
return ret;
}
{
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
NVDECDecoder *decoder = (NVDECDecoder*)ctx->decoder_ref->data;
+ void *logctx = avctx;
CUVIDPICPARAMS *pp = &ctx->pic_params;
- CUresult err;
CUcontext dummy;
int ret = 0;
pp->nNumSlices = ctx->nb_slices;
pp->pSliceDataOffsets = ctx->slice_offsets;
- err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
- if (err != CUDA_SUCCESS)
- return AVERROR_UNKNOWN;
+ ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
+ if (ret < 0)
+ return ret;
- err = decoder->cvdl->cuvidDecodePicture(decoder->decoder, &ctx->pic_params);
- if (err != CUDA_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Error decoding a picture with NVDEC: %d\n",
- err);
- ret = AVERROR_UNKNOWN;
+ ret = CHECK_CU(decoder->cvdl->cuvidDecodePicture(decoder->decoder, &ctx->pic_params));
+ if (ret < 0)
goto finish;
- }
finish:
- decoder->cudl->cuCtxPopCurrent(&dummy);
+ CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
return ret;
}
frames_ctx->format = AV_PIX_FMT_CUDA;
frames_ctx->width = (avctx->coded_width + 1) & ~1;
frames_ctx->height = (avctx->coded_height + 1) & ~1;
- frames_ctx->initial_pool_size = dpb_size;
+ /*
+ * We add two extra frames to the pool to account for deinterlacing filters
+ * holding onto their frames.
+ */
+ frames_ctx->initial_pool_size = dpb_size + 2;
frames_ctx->free = nvdec_free_dummy;
frames_ctx->pool = av_buffer_pool_init(0, nvdec_alloc_dummy);