Skip to content
Snippets Groups Projects
Commit d9ad18f3 authored by Timo Rothenpieler's avatar Timo Rothenpieler
Browse files

avcodec/cuvid: use dynamically loaded CUDA/CUVID

And remove the now obsolete compat headers.
parent e6464a44
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
/*
* This copyright notice applies to this header file only:
*
* Copyright (c) 2010-2016 NVIDIA Corporation
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the software, and to permit persons to whom the
* software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* \file nvcuvid.h
* NvCuvid API provides Video Decoding interface to NVIDIA GPU devices.
* \date 2015-2015
* This file contains the interface constants, structure definitions and function prototypes.
*/
#if !defined(__NVCUVID_H__)
#define __NVCUVID_H__
#include "compat/cuda/cuviddec.h"
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*********************************
** Initialization
*********************************/
CUresult CUDAAPI cuvidInit(unsigned int Flags);
////////////////////////////////////////////////////////////////////////////////////////////////
//
// High-level helper APIs for video sources
//
typedef void *CUvideosource;
typedef void *CUvideoparser;
typedef long long CUvideotimestamp;
/**
* \addtogroup VIDEO_PARSER Video Parser
* @{
*/
/*!
* \enum cudaVideoState
* Video Source State
*/
typedef enum {
cudaVideoState_Error = -1, /**< Error state (invalid source) */
cudaVideoState_Stopped = 0, /**< Source is stopped (or reached end-of-stream) */
cudaVideoState_Started = 1 /**< Source is running and delivering data */
} cudaVideoState;
/*!
* \enum cudaAudioCodec
* Audio compression
*/
typedef enum {
cudaAudioCodec_MPEG1=0, /**< MPEG-1 Audio */
cudaAudioCodec_MPEG2, /**< MPEG-2 Audio */
cudaAudioCodec_MP3, /**< MPEG-1 Layer III Audio */
cudaAudioCodec_AC3, /**< Dolby Digital (AC3) Audio */
cudaAudioCodec_LPCM /**< PCM Audio */
} cudaAudioCodec;
/*!
* \struct CUVIDEOFORMAT
* Video format
*/
typedef struct
{
cudaVideoCodec codec; /**< Compression format */
/**
* frame rate = numerator / denominator (for example: 30000/1001)
*/
struct {
unsigned int numerator; /**< frame rate numerator (0 = unspecified or variable frame rate) */
unsigned int denominator; /**< frame rate denominator (0 = unspecified or variable frame rate) */
} frame_rate;
unsigned char progressive_sequence; /**< 0=interlaced, 1=progressive */
unsigned char bit_depth_luma_minus8; /**< high bit depth Luma */
unsigned char bit_depth_chroma_minus8; /**< high bit depth Chroma */
unsigned char reserved1; /**< Reserved for future use */
unsigned int coded_width; /**< coded frame width */
unsigned int coded_height; /**< coded frame height */
/**
* area of the frame that should be displayed
* typical example:
* coded_width = 1920, coded_height = 1088
* display_area = { 0,0,1920,1080 }
*/
struct {
int left; /**< left position of display rect */
int top; /**< top position of display rect */
int right; /**< right position of display rect */
int bottom; /**< bottom position of display rect */
} display_area;
cudaVideoChromaFormat chroma_format; /**< Chroma format */
unsigned int bitrate; /**< video bitrate (bps, 0=unknown) */
/**
* Display Aspect Ratio = x:y (4:3, 16:9, etc)
*/
struct {
int x;
int y;
} display_aspect_ratio;
/**
* Video Signal Description
*/
struct {
unsigned char video_format : 3;
unsigned char video_full_range_flag : 1;
unsigned char reserved_zero_bits : 4;
unsigned char color_primaries;
unsigned char transfer_characteristics;
unsigned char matrix_coefficients;
} video_signal_description;
unsigned int seqhdr_data_length; /**< Additional bytes following (CUVIDEOFORMATEX) */
} CUVIDEOFORMAT;
/*!
* \struct CUVIDEOFORMATEX
* Video format including raw sequence header information
*/
typedef struct
{
CUVIDEOFORMAT format;
unsigned char raw_seqhdr_data[1024];
} CUVIDEOFORMATEX;
/*!
* \struct CUAUDIOFORMAT
* Audio Formats
*/
typedef struct
{
cudaAudioCodec codec; /**< Compression format */
unsigned int channels; /**< number of audio channels */
unsigned int samplespersec; /**< sampling frequency */
unsigned int bitrate; /**< For uncompressed, can also be used to determine bits per sample */
unsigned int reserved1; /**< Reserved for future use */
unsigned int reserved2; /**< Reserved for future use */
} CUAUDIOFORMAT;
/*!
* \enum CUvideopacketflags
* Data packet flags
*/
typedef enum {
CUVID_PKT_ENDOFSTREAM = 0x01, /**< Set when this is the last packet for this stream */
CUVID_PKT_TIMESTAMP = 0x02, /**< Timestamp is valid */
CUVID_PKT_DISCONTINUITY = 0x04 /**< Set when a discontinuity has to be signalled */
} CUvideopacketflags;
/*!
* \struct CUVIDSOURCEDATAPACKET
* Data Packet
*/
typedef struct _CUVIDSOURCEDATAPACKET
{
unsigned long flags; /**< Combination of CUVID_PKT_XXX flags */
unsigned long payload_size; /**< number of bytes in the payload (may be zero if EOS flag is set) */
const unsigned char *payload; /**< Pointer to packet payload data (may be NULL if EOS flag is set) */
CUvideotimestamp timestamp; /**< Presentation timestamp (10MHz clock), only valid if CUVID_PKT_TIMESTAMP flag is set */
} CUVIDSOURCEDATAPACKET;
// Callback for packet delivery
typedef int (CUDAAPI *PFNVIDSOURCECALLBACK)(void *, CUVIDSOURCEDATAPACKET *);
/*!
* \struct CUVIDSOURCEPARAMS
* Source Params
*/
typedef struct _CUVIDSOURCEPARAMS
{
unsigned int ulClockRate; /**< Timestamp units in Hz (0=default=10000000Hz) */
unsigned int uReserved1[7]; /**< Reserved for future use - set to zero */
void *pUserData; /**< Parameter passed in to the data handlers */
PFNVIDSOURCECALLBACK pfnVideoDataHandler; /**< Called to deliver audio packets */
PFNVIDSOURCECALLBACK pfnAudioDataHandler; /**< Called to deliver video packets */
void *pvReserved2[8]; /**< Reserved for future use - set to NULL */
} CUVIDSOURCEPARAMS;
/*!
* \enum CUvideosourceformat_flags
* CUvideosourceformat_flags
*/
typedef enum {
CUVID_FMT_EXTFORMATINFO = 0x100 /**< Return extended format structure (CUVIDEOFORMATEX) */
} CUvideosourceformat_flags;
#if !defined(__APPLE__)
/**
* \fn CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams)
* Create Video Source
*/
CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams);
/**
* \fn CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams)
* Create Video Source
*/
CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams);
/**
* \fn CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj)
* Destroy Video Source
*/
CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj);
/**
* \fn CUresult CUDAAPI cuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state)
* Set Video Source state
*/
CUresult CUDAAPI cuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state);
/**
* \fn cudaVideoState CUDAAPI cuvidGetVideoSourceState(CUvideosource obj)
* Get Video Source state
*/
cudaVideoState CUDAAPI cuvidGetVideoSourceState(CUvideosource obj);
/**
* \fn CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags)
* Get Video Source Format
*/
CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags);
/**
* \fn CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags)
* Set Video Source state
*/
CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags);
#endif
/**
* \struct CUVIDPARSERDISPINFO
*/
typedef struct _CUVIDPARSERDISPINFO
{
int picture_index; /**< */
int progressive_frame; /**< */
int top_field_first; /**< */
int repeat_first_field; /**< Number of additional fields (1=ivtc, 2=frame doubling, 4=frame tripling, -1=unpaired field) */
CUvideotimestamp timestamp; /**< */
} CUVIDPARSERDISPINFO;
//
// Parser callbacks
// The parser will call these synchronously from within cuvidParseVideoData(), whenever a picture is ready to
// be decoded and/or displayed.
//
typedef int (CUDAAPI *PFNVIDSEQUENCECALLBACK)(void *, CUVIDEOFORMAT *);
typedef int (CUDAAPI *PFNVIDDECODECALLBACK)(void *, CUVIDPICPARAMS *);
typedef int (CUDAAPI *PFNVIDDISPLAYCALLBACK)(void *, CUVIDPARSERDISPINFO *);
/**
* \struct CUVIDPARSERPARAMS
*/
typedef struct _CUVIDPARSERPARAMS
{
cudaVideoCodec CodecType; /**< cudaVideoCodec_XXX */
unsigned int ulMaxNumDecodeSurfaces; /**< Max # of decode surfaces (parser will cycle through these) */
unsigned int ulClockRate; /**< Timestamp units in Hz (0=default=10000000Hz) */
unsigned int ulErrorThreshold; /**< % Error threshold (0-100) for calling pfnDecodePicture (100=always call pfnDecodePicture even if picture bitstream is fully corrupted) */
unsigned int ulMaxDisplayDelay; /**< Max display queue delay (improves pipelining of decode with display) - 0=no delay (recommended values: 2..4) */
unsigned int uReserved1[5]; /**< Reserved for future use - set to 0 */
void *pUserData; /**< User data for callbacks */
PFNVIDSEQUENCECALLBACK pfnSequenceCallback; /**< Called before decoding frames and/or whenever there is a format change */
PFNVIDDECODECALLBACK pfnDecodePicture; /**< Called when a picture is ready to be decoded (decode order) */
PFNVIDDISPLAYCALLBACK pfnDisplayPicture; /**< Called whenever a picture is ready to be displayed (display order) */
void *pvReserved2[7]; /**< Reserved for future use - set to NULL */
CUVIDEOFORMATEX *pExtVideoInfo; /**< [Optional] sequence header data from system layer */
} CUVIDPARSERPARAMS;
/**
* \fn CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams)
*/
CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams);
/**
* \fn CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket)
*/
CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket);
/**
* \fn CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj)
*/
CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj);
/** @} */ /* END VIDEO_PARSER */
////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif // __NVCUVID_H__
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "compat/cuda/dynlink_loader.h"
#include "libavutil/buffer.h" #include "libavutil/buffer.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/hwcontext.h" #include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda.h" #include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/fifo.h" #include "libavutil/fifo.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
...@@ -30,8 +32,6 @@ ...@@ -30,8 +32,6 @@
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "compat/cuda/nvcuvid.h"
#define MAX_FRAME_COUNT 25 #define MAX_FRAME_COUNT 25
typedef struct CuvidContext typedef struct CuvidContext
...@@ -61,6 +61,9 @@ typedef struct CuvidContext ...@@ -61,6 +61,9 @@ typedef struct CuvidContext
CUVIDPARSERPARAMS cuparseinfo; CUVIDPARSERPARAMS cuparseinfo;
CUVIDEOFORMATEX cuparse_ext; CUVIDEOFORMATEX cuparse_ext;
CudaFunctions *cudl;
CuvidFunctions *cvdl;
} CuvidContext; } CuvidContext;
typedef struct CuvidParsedFrame typedef struct CuvidParsedFrame
...@@ -72,6 +75,7 @@ typedef struct CuvidParsedFrame ...@@ -72,6 +75,7 @@ typedef struct CuvidParsedFrame
static int check_cu(AVCodecContext *avctx, CUresult err, const char *func) static int check_cu(AVCodecContext *avctx, CUresult err, const char *func)
{ {
CuvidContext *ctx = avctx->priv_data;
const char *err_name; const char *err_name;
const char *err_string; const char *err_string;
...@@ -80,8 +84,8 @@ static int check_cu(AVCodecContext *avctx, CUresult err, const char *func) ...@@ -80,8 +84,8 @@ static int check_cu(AVCodecContext *avctx, CUresult err, const char *func)
if (err == CUDA_SUCCESS) if (err == CUDA_SUCCESS)
return 0; return 0;
cuGetErrorName(err, &err_name); ctx->cudl->cuGetErrorName(err, &err_name);
cuGetErrorString(err, &err_string); ctx->cudl->cuGetErrorString(err, &err_string);
av_log(avctx, AV_LOG_ERROR, "%s failed", func); av_log(avctx, AV_LOG_ERROR, "%s failed", func);
if (err_name && err_string) if (err_name && err_string)
...@@ -142,7 +146,7 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form ...@@ -142,7 +146,7 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
if (ctx->cudecoder) { if (ctx->cudecoder) {
av_log(avctx, AV_LOG_TRACE, "Re-initializing decoder\n"); av_log(avctx, AV_LOG_TRACE, "Re-initializing decoder\n");
ctx->internal_error = CHECK_CU(cuvidDestroyDecoder(ctx->cudecoder)); ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder));
if (ctx->internal_error < 0) if (ctx->internal_error < 0)
return 0; return 0;
ctx->cudecoder = NULL; ctx->cudecoder = NULL;
...@@ -199,7 +203,7 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form ...@@ -199,7 +203,7 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave) if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave)
avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1}); avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
ctx->internal_error = CHECK_CU(cuvidCreateDecoder(&ctx->cudecoder, &cuinfo)); ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
if (ctx->internal_error < 0) if (ctx->internal_error < 0)
return 0; return 0;
...@@ -225,7 +229,7 @@ static int CUDAAPI cuvid_handle_picture_decode(void *opaque, CUVIDPICPARAMS* pic ...@@ -225,7 +229,7 @@ static int CUDAAPI cuvid_handle_picture_decode(void *opaque, CUVIDPICPARAMS* pic
av_log(avctx, AV_LOG_TRACE, "pfnDecodePicture\n"); av_log(avctx, AV_LOG_TRACE, "pfnDecodePicture\n");
ctx->internal_error = CHECK_CU(cuvidDecodePicture(ctx->cudecoder, picparams)); ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidDecodePicture(ctx->cudecoder, picparams));
if (ctx->internal_error < 0) if (ctx->internal_error < 0)
return 0; return 0;
...@@ -291,7 +295,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt) ...@@ -291,7 +295,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
avpkt = &filtered_packet; avpkt = &filtered_packet;
} }
ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx)); ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
if (ret < 0) { if (ret < 0) {
av_packet_unref(&filtered_packet); av_packet_unref(&filtered_packet);
return ret; return ret;
...@@ -315,7 +319,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt) ...@@ -315,7 +319,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
ctx->decoder_flushing = 1; ctx->decoder_flushing = 1;
} }
ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &cupkt)); ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &cupkt));
av_packet_unref(&filtered_packet); av_packet_unref(&filtered_packet);
...@@ -330,7 +334,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt) ...@@ -330,7 +334,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
} }
error: error:
eret = CHECK_CU(cuCtxPopCurrent(&dummy)); eret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
if (eret < 0) if (eret < 0)
return eret; return eret;
...@@ -359,7 +363,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame) ...@@ -359,7 +363,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
return ret; return ret;
} }
ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx)); ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -377,7 +381,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame) ...@@ -377,7 +381,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
params.second_field = parsed_frame.second_field; params.second_field = parsed_frame.second_field;
params.top_field_first = parsed_frame.dispinfo.top_field_first; params.top_field_first = parsed_frame.dispinfo.top_field_first;
ret = CHECK_CU(cuvidMapVideoFrame(ctx->cudecoder, parsed_frame.dispinfo.picture_index, &mapped_frame, &pitch, &params)); ret = CHECK_CU(ctx->cvdl->cuvidMapVideoFrame(ctx->cudecoder, parsed_frame.dispinfo.picture_index, &mapped_frame, &pitch, &params));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -407,7 +411,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame) ...@@ -407,7 +411,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
.Height = avctx->height >> (i ? 1 : 0), .Height = avctx->height >> (i ? 1 : 0),
}; };
ret = CHECK_CU(cuMemcpy2D(&cpy)); ret = CHECK_CU(ctx->cudl->cuMemcpy2D(&cpy));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -492,9 +496,9 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -492,9 +496,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
error: error:
if (mapped_frame) if (mapped_frame)
eret = CHECK_CU(cuvidUnmapVideoFrame(ctx->cudecoder, mapped_frame)); eret = CHECK_CU(ctx->cvdl->cuvidUnmapVideoFrame(ctx->cudecoder, mapped_frame));
eret = CHECK_CU(cuCtxPopCurrent(&dummy)); eret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
if (eret < 0) if (eret < 0)
return eret; return eret;
...@@ -543,19 +547,24 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx) ...@@ -543,19 +547,24 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx)
av_bsf_free(&ctx->bsf); av_bsf_free(&ctx->bsf);
if (ctx->cuparser) if (ctx->cuparser)
cuvidDestroyVideoParser(ctx->cuparser); ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
if (ctx->cudecoder) if (ctx->cudecoder)
cuvidDestroyDecoder(ctx->cudecoder); ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
ctx->cudl = NULL;
av_buffer_unref(&ctx->hwframe); av_buffer_unref(&ctx->hwframe);
av_buffer_unref(&ctx->hwdevice); av_buffer_unref(&ctx->hwdevice);
cuvid_free_functions(&ctx->cvdl);
return 0; return 0;
} }
static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo) static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo)
{ {
CuvidContext *ctx = avctx->priv_data;
CUVIDDECODECREATEINFO cuinfo; CUVIDDECODECREATEINFO cuinfo;
CUvideodecoder cudec = 0; CUvideodecoder cudec = 0;
int ret = 0; int ret = 0;
...@@ -583,11 +592,11 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu ...@@ -583,11 +592,11 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu
cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave; cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave;
ret = CHECK_CU(cuvidCreateDecoder(&cudec, &cuinfo)); ret = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&cudec, &cuinfo));
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = CHECK_CU(cuvidDestroyDecoder(cudec)); ret = CHECK_CU(ctx->cvdl->cuvidDestroyDecoder(cudec));
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -615,6 +624,13 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) ...@@ -615,6 +624,13 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret); av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret);
return ret; return ret;
} }
avctx->pix_fmt = ret;
ret = cuvid_load_functions(&ctx->cvdl);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n");
goto error;
}
ctx->frame_queue = av_fifo_alloc(MAX_FRAME_COUNT * sizeof(CuvidParsedFrame)); ctx->frame_queue = av_fifo_alloc(MAX_FRAME_COUNT * sizeof(CuvidParsedFrame));
if (!ctx->frame_queue) { if (!ctx->frame_queue) {
...@@ -622,8 +638,6 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) ...@@ -622,8 +638,6 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
goto error; goto error;
} }
avctx->pix_fmt = ret;
if (avctx->hw_frames_ctx) { if (avctx->hw_frames_ctx) {
ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx); ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
if (!ctx->hwframe) { if (!ctx->hwframe) {
...@@ -655,7 +669,9 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) ...@@ -655,7 +669,9 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
device_ctx = hwframe_ctx->device_ctx; device_ctx = hwframe_ctx->device_ctx;
device_hwctx = device_ctx->hwctx; device_hwctx = device_ctx->hwctx;
cuda_ctx = device_hwctx->cuda_ctx; cuda_ctx = device_hwctx->cuda_ctx;
ctx->cudl = device_hwctx->internal->cuda_dl;
memset(&ctx->cuparseinfo, 0, sizeof(ctx->cuparseinfo)); memset(&ctx->cuparseinfo, 0, sizeof(ctx->cuparseinfo));
memset(&ctx->cuparse_ext, 0, sizeof(ctx->cuparse_ext)); memset(&ctx->cuparse_ext, 0, sizeof(ctx->cuparse_ext));
...@@ -750,7 +766,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) ...@@ -750,7 +766,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
ctx->cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode; ctx->cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode;
ctx->cuparseinfo.pfnDisplayPicture = cuvid_handle_picture_display; ctx->cuparseinfo.pfnDisplayPicture = cuvid_handle_picture_display;
ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx)); ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -758,7 +774,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) ...@@ -758,7 +774,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
if (ret < 0) if (ret < 0)
goto error; goto error;
ret = CHECK_CU(cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo)); ret = CHECK_CU(ctx->cvdl->cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -766,12 +782,12 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) ...@@ -766,12 +782,12 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
seq_pkt.payload_size = ctx->cuparse_ext.format.seqhdr_data_length; seq_pkt.payload_size = ctx->cuparse_ext.format.seqhdr_data_length;
if (seq_pkt.payload && seq_pkt.payload_size) { if (seq_pkt.payload && seq_pkt.payload_size) {
ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &seq_pkt)); ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &seq_pkt));
if (ret < 0) if (ret < 0)
goto error; goto error;
} }
ret = CHECK_CU(cuCtxPopCurrent(&dummy)); ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -796,7 +812,7 @@ static void cuvid_flush(AVCodecContext *avctx) ...@@ -796,7 +812,7 @@ static void cuvid_flush(AVCodecContext *avctx)
CUVIDSOURCEDATAPACKET seq_pkt = { 0 }; CUVIDSOURCEDATAPACKET seq_pkt = { 0 };
int ret; int ret;
ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx)); ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -809,16 +825,16 @@ static void cuvid_flush(AVCodecContext *avctx) ...@@ -809,16 +825,16 @@ static void cuvid_flush(AVCodecContext *avctx)
} }
if (ctx->cudecoder) { if (ctx->cudecoder) {
cuvidDestroyDecoder(ctx->cudecoder); ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
ctx->cudecoder = NULL; ctx->cudecoder = NULL;
} }
if (ctx->cuparser) { if (ctx->cuparser) {
cuvidDestroyVideoParser(ctx->cuparser); ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
ctx->cuparser = NULL; ctx->cuparser = NULL;
} }
ret = CHECK_CU(cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo)); ret = CHECK_CU(ctx->cvdl->cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo));
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -826,12 +842,12 @@ static void cuvid_flush(AVCodecContext *avctx) ...@@ -826,12 +842,12 @@ static void cuvid_flush(AVCodecContext *avctx)
seq_pkt.payload_size = ctx->cuparse_ext.format.seqhdr_data_length; seq_pkt.payload_size = ctx->cuparse_ext.format.seqhdr_data_length;
if (seq_pkt.payload && seq_pkt.payload_size) { if (seq_pkt.payload && seq_pkt.payload_size) {
ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &seq_pkt)); ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &seq_pkt));
if (ret < 0) if (ret < 0)
goto error; goto error;
} }
ret = CHECK_CU(cuCtxPopCurrent(&dummy)); ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
if (ret < 0) if (ret < 0)
goto error; goto error;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment