2017-02-11 17:49:34 +02:00
|
|
|
/*
|
|
|
|
* HW decode acceleration through NVDEC
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Anton Khirnov
|
|
|
|
*
|
2017-11-11 02:06:58 +02:00
|
|
|
* This file is part of FFmpeg.
|
2017-02-11 17:49:34 +02:00
|
|
|
*
|
2017-11-11 02:06:58 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2017-02-11 17:49:34 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2017-11-11 02:06:58 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2017-02-11 17:49:34 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2017-11-11 02:06:58 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2017-02-11 17:49:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
#include "libavutil/common.h"
|
|
|
|
#include "libavutil/error.h"
|
|
|
|
#include "libavutil/hwcontext.h"
|
|
|
|
#include "libavutil/hwcontext_cuda_internal.h"
|
2018-11-11 08:47:28 +02:00
|
|
|
#include "libavutil/cuda_check.h"
|
2017-02-11 17:49:34 +02:00
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
#include "libavutil/pixfmt.h"
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
#include "decode.h"
|
|
|
|
#include "nvdec.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
2018-10-07 03:11:52 +02:00
|
|
|
#if !NVDECAPI_CHECK_VERSION(9, 0)
|
|
|
|
#define cudaVideoSurfaceFormat_YUV444 2
|
|
|
|
#define cudaVideoSurfaceFormat_YUV444_16Bit 3
|
|
|
|
#endif
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
typedef struct NVDECDecoder {
|
|
|
|
CUvideodecoder decoder;
|
|
|
|
|
|
|
|
AVBufferRef *hw_device_ref;
|
2020-03-20 17:43:34 +02:00
|
|
|
AVBufferRef *real_hw_frames_ref;
|
2017-02-11 17:49:34 +02:00
|
|
|
CUcontext cuda_ctx;
|
2018-05-08 00:07:31 +02:00
|
|
|
CUstream stream;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
CudaFunctions *cudl;
|
|
|
|
CuvidFunctions *cvdl;
|
|
|
|
} NVDECDecoder;
|
|
|
|
|
|
|
|
typedef struct NVDECFramePool {
|
|
|
|
unsigned int dpb_size;
|
|
|
|
unsigned int nb_allocated;
|
|
|
|
} NVDECFramePool;
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
#define CHECK_CU(x) FF_CUDA_CHECK_DL(logctx, decoder->cudl, x)
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
static int map_avcodec_id(enum AVCodecID id)
|
|
|
|
{
|
|
|
|
switch (id) {
|
2020-10-17 18:16:54 +02:00
|
|
|
#if CONFIG_AV1_NVDEC_HWACCEL
|
|
|
|
case AV_CODEC_ID_AV1: return cudaVideoCodec_AV1;
|
|
|
|
#endif
|
2017-11-16 17:35:17 +02:00
|
|
|
case AV_CODEC_ID_H264: return cudaVideoCodec_H264;
|
|
|
|
case AV_CODEC_ID_HEVC: return cudaVideoCodec_HEVC;
|
2018-02-19 01:53:33 +02:00
|
|
|
case AV_CODEC_ID_MJPEG: return cudaVideoCodec_JPEG;
|
2017-11-16 17:38:10 +02:00
|
|
|
case AV_CODEC_ID_MPEG1VIDEO: return cudaVideoCodec_MPEG1;
|
2017-11-16 17:35:17 +02:00
|
|
|
case AV_CODEC_ID_MPEG2VIDEO: return cudaVideoCodec_MPEG2;
|
2017-11-16 06:59:29 +02:00
|
|
|
case AV_CODEC_ID_MPEG4: return cudaVideoCodec_MPEG4;
|
2017-11-16 17:35:17 +02:00
|
|
|
case AV_CODEC_ID_VC1: return cudaVideoCodec_VC1;
|
2017-11-19 18:42:39 +02:00
|
|
|
case AV_CODEC_ID_VP8: return cudaVideoCodec_VP8;
|
2017-11-16 17:35:17 +02:00
|
|
|
case AV_CODEC_ID_VP9: return cudaVideoCodec_VP9;
|
|
|
|
case AV_CODEC_ID_WMV3: return cudaVideoCodec_VC1;
|
2017-02-11 17:49:34 +02:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int map_chroma_format(enum AVPixelFormat pix_fmt)
|
|
|
|
{
|
|
|
|
int shift_h = 0, shift_v = 0;
|
|
|
|
|
2020-12-06 06:25:29 +02:00
|
|
|
if (av_pix_fmt_count_planes(pix_fmt) == 1)
|
|
|
|
return cudaVideoChromaFormat_Monochrome;
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
av_pix_fmt_get_chroma_sub_sample(pix_fmt, &shift_h, &shift_v);
|
|
|
|
|
|
|
|
if (shift_h == 1 && shift_v == 1)
|
|
|
|
return cudaVideoChromaFormat_420;
|
|
|
|
else if (shift_h == 1 && shift_v == 0)
|
|
|
|
return cudaVideoChromaFormat_422;
|
|
|
|
else if (shift_h == 0 && shift_v == 0)
|
|
|
|
return cudaVideoChromaFormat_444;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-11-11 17:08:53 +02:00
|
|
|
static int nvdec_test_capabilities(NVDECDecoder *decoder,
|
|
|
|
CUVIDDECODECREATEINFO *params, void *logctx)
|
|
|
|
{
|
2018-11-11 08:47:28 +02:00
|
|
|
int ret;
|
2017-11-11 17:08:53 +02:00
|
|
|
CUVIDDECODECAPS caps = { 0 };
|
|
|
|
|
|
|
|
caps.eCodecType = params->CodecType;
|
|
|
|
caps.eChromaFormat = params->ChromaFormat;
|
|
|
|
caps.nBitDepthMinus8 = params->bitDepthMinus8;
|
|
|
|
|
2017-11-30 22:35:50 +02:00
|
|
|
if (!decoder->cvdl->cuvidGetDecoderCaps) {
|
|
|
|
av_log(logctx, AV_LOG_WARNING, "Used Nvidia driver is too old to perform a capability check.\n");
|
|
|
|
av_log(logctx, AV_LOG_WARNING, "The minimum required version is "
|
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
|
|
"378.66"
|
|
|
|
#else
|
|
|
|
"378.13"
|
|
|
|
#endif
|
|
|
|
". Continuing blind.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cvdl->cuvidGetDecoderCaps(&caps));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-11-11 17:08:53 +02:00
|
|
|
|
|
|
|
av_log(logctx, AV_LOG_VERBOSE, "NVDEC capabilities:\n");
|
|
|
|
av_log(logctx, AV_LOG_VERBOSE, "format supported: %s, max_mb_count: %d\n",
|
|
|
|
caps.bIsSupported ? "yes" : "no", caps.nMaxMBCount);
|
|
|
|
av_log(logctx, AV_LOG_VERBOSE, "min_width: %d, max_width: %d\n",
|
|
|
|
caps.nMinWidth, caps.nMaxWidth);
|
|
|
|
av_log(logctx, AV_LOG_VERBOSE, "min_height: %d, max_height: %d\n",
|
|
|
|
caps.nMinHeight, caps.nMaxHeight);
|
|
|
|
|
|
|
|
if (!caps.bIsSupported) {
|
|
|
|
av_log(logctx, AV_LOG_ERROR, "Hardware is lacking required capabilities\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params->ulWidth > caps.nMaxWidth || params->ulWidth < caps.nMinWidth) {
|
|
|
|
av_log(logctx, AV_LOG_ERROR, "Video width %d not within range from %d to %d\n",
|
|
|
|
(int)params->ulWidth, caps.nMinWidth, caps.nMaxWidth);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params->ulHeight > caps.nMaxHeight || params->ulHeight < caps.nMinHeight) {
|
|
|
|
av_log(logctx, AV_LOG_ERROR, "Video height %d not within range from %d to %d\n",
|
|
|
|
(int)params->ulHeight, caps.nMinHeight, caps.nMaxHeight);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((params->ulWidth * params->ulHeight) / 256 > caps.nMaxMBCount) {
|
|
|
|
av_log(logctx, AV_LOG_ERROR, "Video macroblock count %d exceeds maximum of %d\n",
|
|
|
|
(int)(params->ulWidth * params->ulHeight) / 256, caps.nMaxMBCount);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
static void nvdec_decoder_free(void *opaque, uint8_t *data)
|
|
|
|
{
|
|
|
|
NVDECDecoder *decoder = (NVDECDecoder*)data;
|
|
|
|
|
2018-10-24 19:39:13 +02:00
|
|
|
if (decoder->decoder) {
|
2018-11-11 08:47:28 +02:00
|
|
|
void *logctx = decoder->hw_device_ref->data;
|
2018-10-24 19:39:13 +02:00
|
|
|
CUcontext dummy;
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
|
|
|
|
CHECK_CU(decoder->cvdl->cuvidDestroyDecoder(decoder->decoder));
|
|
|
|
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
|
2018-10-24 19:39:13 +02:00
|
|
|
}
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2020-03-20 17:43:34 +02:00
|
|
|
av_buffer_unref(&decoder->real_hw_frames_ref);
|
2017-02-11 17:49:34 +02:00
|
|
|
av_buffer_unref(&decoder->hw_device_ref);
|
|
|
|
|
|
|
|
cuvid_free_functions(&decoder->cvdl);
|
|
|
|
|
|
|
|
av_freep(&decoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref,
|
|
|
|
CUVIDDECODECREATEINFO *params, void *logctx)
|
|
|
|
{
|
|
|
|
AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)hw_device_ref->data;
|
|
|
|
AVCUDADeviceContext *device_hwctx = hw_device_ctx->hwctx;
|
|
|
|
|
|
|
|
AVBufferRef *decoder_ref;
|
|
|
|
NVDECDecoder *decoder;
|
|
|
|
|
|
|
|
CUcontext dummy;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
decoder = av_mallocz(sizeof(*decoder));
|
|
|
|
if (!decoder)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
decoder_ref = av_buffer_create((uint8_t*)decoder, sizeof(*decoder),
|
|
|
|
nvdec_decoder_free, NULL, AV_BUFFER_FLAG_READONLY);
|
|
|
|
if (!decoder_ref) {
|
|
|
|
av_freep(&decoder);
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder->hw_device_ref = av_buffer_ref(hw_device_ref);
|
|
|
|
if (!decoder->hw_device_ref) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
decoder->cuda_ctx = device_hwctx->cuda_ctx;
|
|
|
|
decoder->cudl = device_hwctx->internal->cuda_dl;
|
2018-05-08 00:07:31 +02:00
|
|
|
decoder->stream = device_hwctx->stream;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2017-11-18 19:16:14 +02:00
|
|
|
ret = cuvid_load_functions(&decoder->cvdl, logctx);
|
2017-02-11 17:49:34 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
av_log(logctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
|
|
|
|
if (ret < 0)
|
2017-02-11 17:49:34 +02:00
|
|
|
goto fail;
|
|
|
|
|
2017-11-11 17:08:53 +02:00
|
|
|
ret = nvdec_test_capabilities(decoder, params, logctx);
|
|
|
|
if (ret < 0) {
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
|
2017-11-11 17:08:53 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params));
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
if (ret < 0) {
|
2017-02-11 17:49:34 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = decoder_ref;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
av_buffer_unref(&decoder_ref);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:59:32 +02:00
|
|
|
static AVBufferRef *nvdec_decoder_frame_alloc(void *opaque, size_t size)
|
2017-02-11 17:49:34 +02:00
|
|
|
{
|
|
|
|
NVDECFramePool *pool = opaque;
|
|
|
|
AVBufferRef *ret;
|
|
|
|
|
|
|
|
if (pool->nb_allocated >= pool->dpb_size)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = av_buffer_alloc(sizeof(unsigned int));
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*(unsigned int*)ret->data = pool->nb_allocated++;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
|
|
|
|
av_freep(&ctx->bitstream);
|
2020-10-17 18:16:54 +02:00
|
|
|
av_freep(&ctx->bitstream_internal);
|
2017-02-11 17:49:34 +02:00
|
|
|
ctx->bitstream_len = 0;
|
|
|
|
ctx->bitstream_allocated = 0;
|
|
|
|
|
|
|
|
av_freep(&ctx->slice_offsets);
|
|
|
|
ctx->nb_slices = 0;
|
|
|
|
ctx->slice_offsets_allocated = 0;
|
|
|
|
|
|
|
|
av_buffer_unref(&ctx->decoder_ref);
|
|
|
|
av_buffer_pool_uninit(&ctx->decoder_pool);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:43:34 +02:00
|
|
|
static void nvdec_free_dummy(struct AVHWFramesContext *ctx)
|
|
|
|
{
|
|
|
|
av_buffer_pool_uninit(&ctx->pool);
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:59:32 +02:00
|
|
|
static AVBufferRef *nvdec_alloc_dummy(size_t size)
|
2020-03-20 17:43:34 +02:00
|
|
|
{
|
|
|
|
return av_buffer_create(NULL, 0, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nvdec_init_hwframes(AVCodecContext *avctx, AVBufferRef **out_frames_ref, int dummy)
|
|
|
|
{
|
|
|
|
AVHWFramesContext *frames_ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = avcodec_get_hw_frames_parameters(avctx,
|
|
|
|
avctx->hw_device_ctx,
|
|
|
|
avctx->hwaccel->pix_fmt,
|
|
|
|
out_frames_ref);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
frames_ctx = (AVHWFramesContext*)(*out_frames_ref)->data;
|
|
|
|
|
|
|
|
if (dummy) {
|
|
|
|
// Copied from ff_decode_get_hw_frames_ctx for compatibility
|
|
|
|
frames_ctx->initial_pool_size += 3;
|
|
|
|
|
|
|
|
frames_ctx->free = nvdec_free_dummy;
|
|
|
|
frames_ctx->pool = av_buffer_pool_init(0, nvdec_alloc_dummy);
|
|
|
|
|
|
|
|
if (!frames_ctx->pool) {
|
|
|
|
av_buffer_unref(out_frames_ref);
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is normally not used to actually allocate frames from
|
|
|
|
frames_ctx->initial_pool_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = av_hwframe_ctx_init(*out_frames_ref);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_buffer_unref(out_frames_ref);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-28 19:53:38 +02:00
|
|
|
int ff_nvdec_decode_init(AVCodecContext *avctx)
|
2017-02-11 17:49:34 +02:00
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
|
2020-03-20 17:43:34 +02:00
|
|
|
NVDECDecoder *decoder;
|
|
|
|
AVBufferRef *real_hw_frames_ref;
|
2017-02-11 17:49:34 +02:00
|
|
|
NVDECFramePool *pool;
|
|
|
|
AVHWFramesContext *frames_ctx;
|
|
|
|
const AVPixFmtDescriptor *sw_desc;
|
|
|
|
|
|
|
|
CUVIDDECODECREATEINFO params = { 0 };
|
|
|
|
|
2018-10-07 03:11:52 +02:00
|
|
|
cudaVideoSurfaceFormat output_format;
|
|
|
|
int cuvid_codec_type, cuvid_chroma_format, chroma_444;
|
2017-02-11 17:49:34 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
|
|
|
|
if (!sw_desc)
|
|
|
|
return AVERROR_BUG;
|
|
|
|
|
|
|
|
cuvid_codec_type = map_avcodec_id(avctx->codec_id);
|
|
|
|
if (cuvid_codec_type < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n");
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);
|
|
|
|
if (cuvid_chroma_format < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported chroma format\n");
|
|
|
|
return AVERROR(ENOSYS);
|
|
|
|
}
|
2018-10-07 05:20:58 +02:00
|
|
|
chroma_444 = ctx->supports_444 && cuvid_chroma_format == cudaVideoChromaFormat_444;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
if (!avctx->hw_frames_ctx) {
|
2020-03-20 17:43:34 +02:00
|
|
|
ret = nvdec_init_hwframes(avctx, &avctx->hw_frames_ctx, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = nvdec_init_hwframes(avctx, &real_hw_frames_ref, 0);
|
2017-10-28 19:53:38 +02:00
|
|
|
if (ret < 0)
|
2017-02-11 17:49:34 +02:00
|
|
|
return ret;
|
2020-03-20 17:43:34 +02:00
|
|
|
} else {
|
|
|
|
real_hw_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
|
|
|
|
if (!real_hw_frames_ref)
|
|
|
|
return AVERROR(ENOMEM);
|
2017-02-11 17:49:34 +02:00
|
|
|
}
|
2017-10-28 19:53:38 +02:00
|
|
|
|
2018-10-07 03:11:52 +02:00
|
|
|
switch (sw_desc->comp[0].depth) {
|
|
|
|
case 8:
|
|
|
|
output_format = chroma_444 ? cudaVideoSurfaceFormat_YUV444 :
|
|
|
|
cudaVideoSurfaceFormat_NV12;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
case 12:
|
|
|
|
output_format = chroma_444 ? cudaVideoSurfaceFormat_YUV444_16Bit :
|
|
|
|
cudaVideoSurfaceFormat_P016;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth\n");
|
2020-03-20 17:43:34 +02:00
|
|
|
av_buffer_unref(&real_hw_frames_ref);
|
2018-10-07 03:11:52 +02:00
|
|
|
return AVERROR(ENOSYS);
|
|
|
|
}
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
|
|
|
|
|
|
|
|
params.ulWidth = avctx->coded_width;
|
|
|
|
params.ulHeight = avctx->coded_height;
|
|
|
|
params.ulTargetWidth = avctx->coded_width;
|
|
|
|
params.ulTargetHeight = avctx->coded_height;
|
|
|
|
params.bitDepthMinus8 = sw_desc->comp[0].depth - 8;
|
2018-10-07 03:11:52 +02:00
|
|
|
params.OutputFormat = output_format;
|
2017-02-11 17:49:34 +02:00
|
|
|
params.CodecType = cuvid_codec_type;
|
|
|
|
params.ChromaFormat = cuvid_chroma_format;
|
2017-10-28 19:53:38 +02:00
|
|
|
params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
|
2018-05-07 18:23:38 +02:00
|
|
|
params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, ¶ms, avctx);
|
2017-11-12 19:09:31 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
if (params.ulNumDecodeSurfaces > 32) {
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "Using more than 32 (%d) decode surfaces might cause nvdec to fail.\n",
|
|
|
|
(int)params.ulNumDecodeSurfaces);
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "Try lowering the amount of threads. Using %d right now.\n",
|
|
|
|
avctx->thread_count);
|
|
|
|
}
|
2020-03-20 17:43:34 +02:00
|
|
|
av_buffer_unref(&real_hw_frames_ref);
|
2017-02-11 17:49:34 +02:00
|
|
|
return ret;
|
2017-11-12 19:09:31 +02:00
|
|
|
}
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2020-03-20 17:43:34 +02:00
|
|
|
decoder = (NVDECDecoder*)ctx->decoder_ref->data;
|
|
|
|
decoder->real_hw_frames_ref = real_hw_frames_ref;
|
|
|
|
real_hw_frames_ref = NULL;
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
pool = av_mallocz(sizeof(*pool));
|
|
|
|
if (!pool) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
2017-10-28 19:53:38 +02:00
|
|
|
pool->dpb_size = frames_ctx->initial_pool_size;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
ctx->decoder_pool = av_buffer_pool_init2(sizeof(int), pool,
|
|
|
|
nvdec_decoder_frame_alloc, av_free);
|
|
|
|
if (!ctx->decoder_pool) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
ff_nvdec_decode_uninit(avctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nvdec_fdd_priv_free(void *priv)
|
|
|
|
{
|
|
|
|
NVDECFrame *cf = priv;
|
|
|
|
|
|
|
|
if (!cf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
av_buffer_unref(&cf->idx_ref);
|
|
|
|
av_buffer_unref(&cf->decoder_ref);
|
2020-10-17 18:16:36 +02:00
|
|
|
av_buffer_unref(&cf->ref_idx_ref);
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
av_freep(&priv);
|
|
|
|
}
|
|
|
|
|
2018-05-07 18:23:38 +02:00
|
|
|
static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
|
|
|
|
{
|
|
|
|
NVDECFrame *unmap_data = (NVDECFrame*)data;
|
|
|
|
NVDECDecoder *decoder = (NVDECDecoder*)unmap_data->decoder_ref->data;
|
2018-11-11 08:47:28 +02:00
|
|
|
void *logctx = decoder->hw_device_ref->data;
|
2018-05-07 18:23:38 +02:00
|
|
|
CUdeviceptr devptr = (CUdeviceptr)opaque;
|
2018-11-11 08:47:28 +02:00
|
|
|
int ret;
|
2018-05-07 18:23:38 +02:00
|
|
|
CUcontext dummy;
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
|
|
|
|
if (ret < 0)
|
2018-05-07 18:23:38 +02:00
|
|
|
goto finish;
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr));
|
2018-05-07 18:23:38 +02:00
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
|
2018-05-07 18:23:38 +02:00
|
|
|
|
|
|
|
finish:
|
|
|
|
av_buffer_unref(&unmap_data->idx_ref);
|
|
|
|
av_buffer_unref(&unmap_data->decoder_ref);
|
2020-10-17 18:16:36 +02:00
|
|
|
av_buffer_unref(&unmap_data->ref_idx_ref);
|
2018-05-07 18:23:38 +02:00
|
|
|
av_free(unmap_data);
|
|
|
|
}
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
|
|
|
|
{
|
|
|
|
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
|
|
|
|
NVDECFrame *cf = (NVDECFrame*)fdd->hwaccel_priv;
|
|
|
|
NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
|
|
|
|
|
2018-10-07 03:11:52 +02:00
|
|
|
AVHWFramesContext *hwctx = (AVHWFramesContext *)frame->hw_frames_ctx->data;
|
|
|
|
|
2018-05-08 00:07:31 +02:00
|
|
|
CUVIDPROCPARAMS vpp = { 0 };
|
2018-05-07 18:23:38 +02:00
|
|
|
NVDECFrame *unmap_data = NULL;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
CUcontext dummy;
|
|
|
|
CUdeviceptr devptr;
|
|
|
|
|
|
|
|
unsigned int pitch, i;
|
|
|
|
unsigned int offset = 0;
|
2018-10-07 03:11:52 +02:00
|
|
|
int shift_h = 0, shift_v = 0;
|
2017-02-11 17:49:34 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
2018-05-08 00:07:31 +02:00
|
|
|
vpp.progressive_frame = 1;
|
|
|
|
vpp.output_stream = decoder->stream;
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cvdl->cuvidMapVideoFrame(decoder->decoder,
|
|
|
|
cf->idx, &devptr,
|
|
|
|
&pitch, &vpp));
|
|
|
|
if (ret < 0)
|
2017-02-11 17:49:34 +02:00
|
|
|
goto finish;
|
|
|
|
|
2018-05-07 18:23:38 +02:00
|
|
|
unmap_data = av_mallocz(sizeof(*unmap_data));
|
|
|
|
if (!unmap_data) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto copy_fail;
|
|
|
|
}
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2018-05-07 18:23:38 +02:00
|
|
|
frame->buf[1] = av_buffer_create((uint8_t *)unmap_data, sizeof(*unmap_data),
|
|
|
|
nvdec_unmap_mapped_frame, (void*)devptr,
|
|
|
|
AV_BUFFER_FLAG_READONLY);
|
|
|
|
if (!frame->buf[1]) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto copy_fail;
|
2017-02-11 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
2022-08-06 09:18:29 +02:00
|
|
|
ret = av_buffer_replace(&frame->hw_frames_ctx, decoder->real_hw_frames_ref);
|
|
|
|
if (ret < 0)
|
2020-03-20 17:43:34 +02:00
|
|
|
goto copy_fail;
|
|
|
|
|
2018-05-07 18:23:38 +02:00
|
|
|
unmap_data->idx = cf->idx;
|
2022-08-06 09:14:11 +02:00
|
|
|
if (!(unmap_data->idx_ref = av_buffer_ref(cf->idx_ref)) ||
|
|
|
|
!(unmap_data->decoder_ref = av_buffer_ref(cf->decoder_ref))) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto copy_fail;
|
|
|
|
}
|
2018-05-07 18:23:38 +02:00
|
|
|
|
2018-10-07 03:11:52 +02:00
|
|
|
av_pix_fmt_get_chroma_sub_sample(hwctx->sw_format, &shift_h, &shift_v);
|
2018-05-07 18:23:38 +02:00
|
|
|
for (i = 0; frame->linesize[i]; i++) {
|
|
|
|
frame->data[i] = (uint8_t*)(devptr + offset);
|
|
|
|
frame->linesize[i] = pitch;
|
2018-10-07 03:11:52 +02:00
|
|
|
offset += pitch * (frame->height >> (i ? shift_v : 0));
|
2018-05-07 18:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
goto finish;
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
copy_fail:
|
2018-05-07 18:23:38 +02:00
|
|
|
if (!frame->buf[1]) {
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr));
|
2018-05-07 18:23:38 +02:00
|
|
|
av_freep(&unmap_data);
|
|
|
|
} else {
|
|
|
|
av_buffer_unref(&frame->buf[1]);
|
|
|
|
}
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
finish:
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
|
2017-02-11 17:49:34 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
|
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
|
|
|
|
NVDECFrame *cf = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ctx->bitstream_len = 0;
|
|
|
|
ctx->nb_slices = 0;
|
|
|
|
|
|
|
|
if (fdd->hwaccel_priv)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cf = av_mallocz(sizeof(*cf));
|
|
|
|
if (!cf)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
cf->decoder_ref = av_buffer_ref(ctx->decoder_ref);
|
2017-11-12 22:04:57 +02:00
|
|
|
if (!cf->decoder_ref) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2017-02-11 17:49:34 +02:00
|
|
|
goto fail;
|
2017-11-12 22:04:57 +02:00
|
|
|
}
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
cf->idx_ref = av_buffer_pool_get(ctx->decoder_pool);
|
|
|
|
if (!cf->idx_ref) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n");
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
2020-10-17 18:16:36 +02:00
|
|
|
cf->ref_idx = cf->idx = *(unsigned int*)cf->idx_ref->data;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
fdd->hwaccel_priv = cf;
|
|
|
|
fdd->hwaccel_priv_free = nvdec_fdd_priv_free;
|
|
|
|
fdd->post_process = nvdec_retrieve_data;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
nvdec_fdd_priv_free(cf);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-17 18:16:36 +02:00
|
|
|
int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_sep_ref)
|
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
|
|
|
|
NVDECFrame *cf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ff_nvdec_start_frame(avctx, frame);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
cf = fdd->hwaccel_priv;
|
|
|
|
|
|
|
|
if (has_sep_ref) {
|
|
|
|
if (!cf->ref_idx_ref) {
|
|
|
|
cf->ref_idx_ref = av_buffer_pool_get(ctx->decoder_pool);
|
|
|
|
if (!cf->ref_idx_ref) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n");
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cf->ref_idx = *(unsigned int*)cf->ref_idx_ref->data;
|
|
|
|
} else {
|
|
|
|
av_buffer_unref(&cf->ref_idx_ref);
|
|
|
|
cf->ref_idx = cf->idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
nvdec_fdd_priv_free(cf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
int ff_nvdec_end_frame(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
NVDECDecoder *decoder = (NVDECDecoder*)ctx->decoder_ref->data;
|
2018-11-11 08:47:28 +02:00
|
|
|
void *logctx = avctx;
|
2017-02-11 17:49:34 +02:00
|
|
|
CUVIDPICPARAMS *pp = &ctx->pic_params;
|
|
|
|
|
|
|
|
CUcontext dummy;
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pp->nBitstreamDataLen = ctx->bitstream_len;
|
|
|
|
pp->pBitstreamData = ctx->bitstream;
|
|
|
|
pp->nNumSlices = ctx->nb_slices;
|
|
|
|
pp->pSliceDataOffsets = ctx->slice_offsets;
|
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
2018-11-11 08:47:28 +02:00
|
|
|
ret = CHECK_CU(decoder->cvdl->cuvidDecodePicture(decoder->decoder, &ctx->pic_params));
|
|
|
|
if (ret < 0)
|
2017-02-11 17:49:34 +02:00
|
|
|
goto finish;
|
|
|
|
|
|
|
|
finish:
|
2018-11-11 08:47:28 +02:00
|
|
|
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2017-10-28 19:53:38 +02:00
|
|
|
|
2017-11-19 06:29:15 +02:00
|
|
|
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
int ret = ff_nvdec_end_frame(avctx);
|
|
|
|
ctx->bitstream = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
|
|
|
|
uint32_t size)
|
|
|
|
{
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
|
|
|
|
(ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
ctx->slice_offsets = tmp;
|
|
|
|
|
|
|
|
if (!ctx->bitstream)
|
|
|
|
ctx->bitstream = (uint8_t*)buffer;
|
|
|
|
|
|
|
|
ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream;
|
|
|
|
ctx->bitstream_len += size;
|
|
|
|
ctx->nb_slices++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-28 19:53:38 +02:00
|
|
|
int ff_nvdec_frame_params(AVCodecContext *avctx,
|
|
|
|
AVBufferRef *hw_frames_ctx,
|
2018-10-07 05:20:58 +02:00
|
|
|
int dpb_size,
|
|
|
|
int supports_444)
|
2017-10-28 19:53:38 +02:00
|
|
|
{
|
|
|
|
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
|
|
|
|
const AVPixFmtDescriptor *sw_desc;
|
2018-10-07 03:11:52 +02:00
|
|
|
int cuvid_codec_type, cuvid_chroma_format, chroma_444;
|
2017-10-28 19:53:38 +02:00
|
|
|
|
|
|
|
sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
|
|
|
|
if (!sw_desc)
|
|
|
|
return AVERROR_BUG;
|
|
|
|
|
|
|
|
cuvid_codec_type = map_avcodec_id(avctx->codec_id);
|
|
|
|
if (cuvid_codec_type < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n");
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);
|
|
|
|
if (cuvid_chroma_format < 0) {
|
|
|
|
av_log(avctx, AV_LOG_VERBOSE, "Unsupported chroma format\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2018-10-07 05:20:58 +02:00
|
|
|
chroma_444 = supports_444 && cuvid_chroma_format == cudaVideoChromaFormat_444;
|
2017-10-28 19:53:38 +02:00
|
|
|
|
|
|
|
frames_ctx->format = AV_PIX_FMT_CUDA;
|
avcodec/nvdec: Round up odd width/height values
nvdec will not produce odd width/height output, and while this is
basically never an issue with most codecs, due to internal alignment
requirements, you can get odd sized jpegs.
If an odd-sized jpeg is encountered, nvdec will actually round down
internally and produce output that is slightly smaller. This isn't
the end of the world, as long as you know the output size doesn't
match the original image resolution.
However, with an hwaccel, we don't know. The decoder controls
the reported output size and the hwaccel cannot change it. I was
able to trigger an error in mpv where it tries to copy the output
surface as part of rendering and triggers a cuda error because
cuda knows the output frame is smaller than expected.
To fix this, we can round up the configured width/height passed
to nvdec so that the frames are always at least as large as the
decoder's reported size, and data can be copied out safely.
In this particular jpeg case, you end up with a blank (green) line
at the bottom due to nvdec refusing to decode the last line, but
the behaviour matches cuviddec, so it's as good as you're going to
get.
2017-11-24 20:05:49 +02:00
|
|
|
frames_ctx->width = (avctx->coded_width + 1) & ~1;
|
|
|
|
frames_ctx->height = (avctx->coded_height + 1) & ~1;
|
2018-10-25 03:38:44 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
2017-10-28 19:53:38 +02:00
|
|
|
|
2017-11-11 16:07:41 +02:00
|
|
|
switch (sw_desc->comp[0].depth) {
|
|
|
|
case 8:
|
2018-10-07 03:11:52 +02:00
|
|
|
frames_ctx->sw_format = chroma_444 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_NV12;
|
2017-11-11 16:07:41 +02:00
|
|
|
break;
|
|
|
|
case 10:
|
2018-10-07 03:11:52 +02:00
|
|
|
frames_ctx->sw_format = chroma_444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P010;
|
2017-11-11 16:07:41 +02:00
|
|
|
break;
|
|
|
|
case 12:
|
2018-10-07 03:11:52 +02:00
|
|
|
frames_ctx->sw_format = chroma_444 ? AV_PIX_FMT_YUV444P16 : AV_PIX_FMT_P016;
|
2017-11-11 16:07:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2017-10-28 19:53:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-11-19 06:29:15 +02:00
|
|
|
|
|
|
|
int ff_nvdec_get_ref_idx(AVFrame *frame)
|
|
|
|
{
|
|
|
|
FrameDecodeData *fdd;
|
|
|
|
NVDECFrame *cf;
|
|
|
|
|
|
|
|
if (!frame || !frame->private_ref)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fdd = (FrameDecodeData*)frame->private_ref->data;
|
|
|
|
cf = (NVDECFrame*)fdd->hwaccel_priv;
|
|
|
|
if (!cf)
|
|
|
|
return -1;
|
|
|
|
|
2020-10-17 18:16:36 +02:00
|
|
|
return cf->ref_idx;
|
2017-11-19 06:29:15 +02:00
|
|
|
}
|