[vlc-commits] [Git][videolan/vlc][master] 6 commits: nvdec: rename nvdec_pool to hw_pool
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Wed Apr 13 15:30:08 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
2d0f393d by Steve Lhomme at 2022-04-13T14:30:53+00:00
nvdec: rename nvdec_pool to hw_pool
We may also move it in the core.
- - - - -
75d719f0 by Steve Lhomme at 2022-04-13T14:30:53+00:00
nvdec: always log issues in CUDA/nvdec calls
- - - - -
cef1adb3 by Steve Lhomme at 2022-04-13T14:30:53+00:00
nvdec: decide the number of decoder pictures later
Once the sequence is fully parsed we can tell the profile. The return value of
HandleVideoSequence() is how many pictures the decoder should use internally.
p_format->min_num_decode_surfaces contains the minimum for that value.
- - - - -
9a092bd8 by Steve Lhomme at 2022-04-13T14:30:53+00:00
contrib:nvcodec: update to the more recent version
It contains the cudaVideoCodec_AV1 definition.
- - - - -
44c37b18 by Steve Lhomme at 2022-04-13T14:30:53+00:00
nvdec: don't depend on p_sys for CALL_CUDA_DEC()
- - - - -
6d8a6416 by Steve Lhomme at 2022-04-13T14:30:53+00:00
nvdec: get the output pitch without mapping a null frame
- - - - -
7 changed files:
- − contrib/src/nvcodec/SHA512SUMS
- contrib/src/nvcodec/rules.mak
- modules/hw/nvdec/hw_pool.c
- modules/hw/nvdec/hw_pool.h
- modules/hw/nvdec/nvdec.c
- modules/hw/nvdec/nvdec_fmt.h
- modules/hw/nvdec/nvdec_gl.c
Changes:
=====================================
contrib/src/nvcodec/SHA512SUMS deleted
=====================================
@@ -1 +0,0 @@
-51e22b53fc9e0a3cb221219dcd7631262fd58b2d169fcb58a4bdaef4d788fe0d2ceb424c7cdd697bcdfb9e7c7fbb197404edd26021cc13a68d412c1b966fbce2 nvcodec-b6600f507de70d223101fe98f9c3c351b724e2fa.tar.xz
\ No newline at end of file
=====================================
contrib/src/nvcodec/rules.mak
=====================================
@@ -1,4 +1,4 @@
-NVCODEC_HASH := b6600f507de70d223101fe98f9c3c351b724e2fa
+NVCODEC_HASH := 84483da70d903239d4536763fde8c7e6c4e80784
NVCODEC_GITURL := https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
ifndef HAVE_DARWIN_OS
@@ -9,6 +9,8 @@ $(TARBALLS)/nvcodec-$(NVCODEC_HASH).tar.xz:
$(call download_git,$(NVCODEC_GITURL),,$(NVCODEC_HASH))
.sum-nvcodec: nvcodec-$(NVCODEC_HASH).tar.xz
+ $(call check_githash,$(NVCODEC_HASH))
+ touch $@
nvcodec: nvcodec-$(NVCODEC_HASH).tar.xz .sum-nvcodec
$(UNPACK)
=====================================
modules/hw/nvdec/hw_pool.c
=====================================
@@ -29,10 +29,10 @@
#include <vlc_atomic.h>
#include "hw_pool.h"
-struct nvdec_pool_t {
+struct hw_pool_t {
vlc_video_context *vctx;
- nvdec_pool_owner_t *owner;
+ hw_pool_owner_t *owner;
void *res[64];
size_t pool_size;
@@ -42,12 +42,12 @@ struct nvdec_pool_t {
vlc_atomic_rc_t rc;
};
-void nvdec_pool_AddRef(nvdec_pool_t *pool)
+void hw_pool_AddRef(hw_pool_t *pool)
{
vlc_atomic_rc_inc(&pool->rc);
}
-void nvdec_pool_Release(nvdec_pool_t *pool)
+void hw_pool_Release(hw_pool_t *pool)
{
if (!vlc_atomic_rc_dec(&pool->rc))
return;
@@ -58,11 +58,11 @@ void nvdec_pool_Release(nvdec_pool_t *pool)
vlc_video_context_Release(pool->vctx);
}
-nvdec_pool_t* nvdec_pool_Create(nvdec_pool_owner_t *owner,
- const video_format_t *fmt, vlc_video_context *vctx,
- void *buffers[], size_t pics_count)
+hw_pool_t* hw_pool_Create(hw_pool_owner_t *owner,
+ const video_format_t *fmt, vlc_video_context *vctx,
+ void *buffers[], size_t pics_count)
{
- nvdec_pool_t *pool = calloc(1, sizeof(*pool));
+ hw_pool_t *pool = calloc(1, sizeof(*pool));
if (unlikely(!pool))
return NULL;
@@ -103,7 +103,7 @@ error:
return NULL;
}
-picture_t* nvdec_pool_Wait(nvdec_pool_t *pool)
+picture_t* hw_pool_Wait(hw_pool_t *pool)
{
picture_t *pic = picture_pool_Wait(pool->picture_pool);
if (!pic)
=====================================
modules/hw/nvdec/hw_pool.h
=====================================
@@ -21,28 +21,33 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifndef HW_POOL_H
+#define HW_POOL_H
+
#include <vlc_picture.h>
#include <vlc_codec.h>
-typedef struct nvdec_pool_t nvdec_pool_t;
-typedef struct nvdec_pool_owner nvdec_pool_owner_t;
+typedef struct hw_pool_t hw_pool_t;
+typedef struct hw_pool_owner hw_pool_owner_t;
-struct nvdec_pool_owner
+struct hw_pool_owner
{
void *sys;
- void (*release_resources)(nvdec_pool_owner_t *, void *buffers[], size_t pics_count);
- picture_context_t * (*attach_picture)(nvdec_pool_owner_t *, nvdec_pool_t *, void *surface);
+ void (*release_resources)(hw_pool_owner_t *, void *buffers[], size_t pics_count);
+ picture_context_t * (*attach_picture)(hw_pool_owner_t *, hw_pool_t *, void *surface);
};
-nvdec_pool_t* nvdec_pool_Create(nvdec_pool_owner_t *,
- const video_format_t *, vlc_video_context *,
- void *buffers[], size_t pics_count);
-void nvdec_pool_AddRef(nvdec_pool_t *);
-void nvdec_pool_Release(nvdec_pool_t *);
+hw_pool_t* hw_pool_Create(hw_pool_owner_t *,
+ const video_format_t *, vlc_video_context *,
+ void *buffers[], size_t pics_count);
+void hw_pool_AddRef(hw_pool_t *);
+void hw_pool_Release(hw_pool_t *);
/**
* Wait for a new picture to be available from the pool.
*
* The picture.p_sys is always NULL.
*/
-picture_t* nvdec_pool_Wait(nvdec_pool_t *);
+picture_t* hw_pool_Wait(hw_pool_t *);
+
+#endif // HW_POOL_H
=====================================
modules/hw/nvdec/nvdec.c
=====================================
@@ -29,10 +29,6 @@
#include <vlc_codec.h>
#include <vlc_messages.h>
-#define FFNV_LOG_FUNC(logctx, msg, ...) msg_Err((vlc_object_t*)logctx, msg, __VA_ARGS__)
-#define FFNV_DEBUG_LOG_FUNC(logctx, msg, ...) msg_Dbg((vlc_object_t*)logctx, msg, __VA_ARGS__)
-
-#include <ffnvcodec/dynlink_loader.h>
#include "../../codec/hxxx_helper.h"
#include "nvdec_fmt.h"
#include "hw_pool.h"
@@ -80,7 +76,7 @@ typedef struct nvdec_ctx nvdec_ctx_t;
typedef struct pic_pool_context_nvdec_t {
pic_context_nvdec_t ctx;
- nvdec_pool_t *pool;
+ hw_pool_t *pool;
} pic_pool_context_nvdec_t;
struct nvdec_ctx {
@@ -94,7 +90,6 @@ struct nvdec_ctx {
int vc1_header_offset;
};
bool b_is_hxxx;
- int i_nb_surface; ///< number of GPU surfaces allocated
bool b_xps_pushed; ///< (for xvcC) parameter sets pushed (SPS/PPS/VPS)
block_t * (*process_block)(decoder_t *, block_t *);
cudaVideoDeinterlaceMode deintMode;
@@ -103,20 +98,20 @@ struct nvdec_ctx {
size_t decoderHeight;
unsigned int outputPitch;
- nvdec_pool_t *out_pool;
- nvdec_pool_owner_t pool_owner;
+ hw_pool_t *out_pool;
+ hw_pool_owner_t pool_owner;
vlc_video_context *vctx_out;
};
-#define CALL_CUDA_DEC(func, ...) CudaCheckErr(VLC_OBJECT(p_dec), p_sys->devsys->cudaFunctions, p_sys->devsys->cudaFunctions->func(__VA_ARGS__), #func)
+#define CALL_CUDA_DEC(func, ...) CudaCheckErr(VLC_OBJECT(p_dec), devsys->cudaFunctions, devsys->cudaFunctions->func(__VA_ARGS__), #func)
#define CALL_CUDA_DEV(func, ...) CudaCheckErr(VLC_OBJECT(device), p_sys->cudaFunctions, p_sys->cudaFunctions->func(__VA_ARGS__), #func)
#define CALL_CUVID(func, ...) CudaCheckErr(VLC_OBJECT(p_dec), p_sys->devsys->cudaFunctions, p_sys->cuvidFunctions->func(__VA_ARGS__), #func)
#define NVDEC_PICPOOLCTX_FROM_PICCTX(pic_ctx) \
container_of(NVDEC_PICCONTEXT_FROM_PICCTX(pic_ctx), pic_pool_context_nvdec_t, ctx)
-static void PoolRelease(nvdec_pool_owner_t *owner, void *buffers[], size_t pics_count)
+static void PoolRelease(hw_pool_owner_t *owner, void *buffers[], size_t pics_count)
{
nvdec_ctx_t *p_sys = container_of(owner, nvdec_ctx_t, pool_owner);
for (size_t i=0; i < pics_count; i++)
@@ -128,7 +123,7 @@ static void PoolRelease(nvdec_pool_owner_t *owner, void *buffers[], size_t pics_
static void nvdec_picture_CtxDestroy(struct picture_context_t *picctx)
{
pic_pool_context_nvdec_t *srcpic = NVDEC_PICPOOLCTX_FROM_PICCTX(picctx);
- nvdec_pool_Release(srcpic->pool);
+ hw_pool_Release(srcpic->pool);
free(srcpic);
}
@@ -141,11 +136,11 @@ static struct picture_context_t *nvdec_picture_CtxClone(struct picture_context_t
*clonectx = *srcpic;
vlc_video_context_Hold(clonectx->ctx.ctx.vctx);
- nvdec_pool_AddRef(clonectx->pool);
+ hw_pool_AddRef(clonectx->pool);
return &clonectx->ctx.ctx;
}
-static picture_context_t * PoolAttachPicture(nvdec_pool_owner_t *owner, nvdec_pool_t *pool, void *surface)
+static picture_context_t * PoolAttachPicture(hw_pool_owner_t *owner, hw_pool_t *pool, void *surface)
{
nvdec_ctx_t *p_sys = container_of(owner, nvdec_ctx_t, pool_owner);
pic_pool_context_nvdec_t *picctx = malloc(sizeof(*picctx));
@@ -161,7 +156,7 @@ static picture_context_t * PoolAttachPicture(nvdec_pool_owner_t *owner, nvdec_po
picctx->ctx.devicePtr = (CUdeviceptr)surface;
picctx->pool = pool;
- nvdec_pool_AddRef(picctx->pool);
+ hw_pool_AddRef(picctx->pool);
return &picctx->ctx.ctx;
}
@@ -253,13 +248,14 @@ static int CUDAAPI HandleVideoSequence(void *p_opaque, CUVIDEOFORMAT *p_format)
{
decoder_t *p_dec = (decoder_t *) p_opaque;
nvdec_ctx_t *p_sys = p_dec->p_sys;
+ decoder_device_nvdec_t *devsys = p_sys->devsys;
int ret;
if ( is_nvdec_opaque(p_dec->fmt_out.video.i_chroma) )
{
if (p_sys->out_pool)
{
- nvdec_pool_Release(p_sys->out_pool);
+ hw_pool_Release(p_sys->out_pool);
p_sys->out_pool = NULL;
}
}
@@ -283,6 +279,28 @@ static int CUDAAPI HandleVideoSequence(void *p_opaque, CUVIDEOFORMAT *p_format)
p_sys->cudecoder = NULL;
}
+ int i_nb_surface;
+ switch (p_dec->fmt_in.i_codec) {
+ case VLC_CODEC_H264:
+ case VLC_CODEC_HEVC:
+ case VLC_CODEC_VC1:
+ case VLC_CODEC_WMV3:
+ i_nb_surface = MAX_HXXX_SURFACES;
+ break;
+ case VLC_CODEC_MP1V:
+ case VLC_CODEC_MP2V:
+ case VLC_CODEC_MPGV:
+ case VLC_CODEC_MP4V:
+ case VLC_CODEC_VP8:
+ i_nb_surface = 3;
+ break;
+ case VLC_CODEC_VP9:
+ i_nb_surface = 10;
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
+
CUVIDDECODECREATEINFO dparams = {
.ulWidth = p_format->coded_width,
.ulHeight = p_format->coded_height,
@@ -292,7 +310,7 @@ static int CUDAAPI HandleVideoSequence(void *p_opaque, CUVIDEOFORMAT *p_format)
.OutputFormat = MapSurfaceFmt(p_dec->fmt_out.video.i_chroma),
.CodecType = p_format->codec,
.ChromaFormat = p_format->chroma_format,
- .ulNumDecodeSurfaces = p_sys->i_nb_surface,
+ .ulNumDecodeSurfaces = __MAX(i_nb_surface, p_format->min_num_decode_surfaces),
.ulNumOutputSurfaces = 1,
.DeinterlaceMode = p_sys->deintMode
};
@@ -303,16 +321,16 @@ static int CUDAAPI HandleVideoSequence(void *p_opaque, CUVIDEOFORMAT *p_format)
// ensure the output surfaces have the same pitch so copies can work properly
if ( is_nvdec_opaque(p_dec->fmt_out.video.i_chroma) )
{
- // get the real decoder pitch
- CUdeviceptr frameDevicePtr = 0;
- CUVIDPROCPARAMS params = {
- .progressive_frame = 1,
- .top_field_first = 1,
- };
- ret = CALL_CUVID( cuvidMapVideoFrame, p_sys->cudecoder, 0, &frameDevicePtr, &p_sys->outputPitch, ¶ms );
+ int tex_alignment;
+ CUdevice cuDev;
+ ret = CALL_CUDA_DEC(cuDeviceGet, &cuDev, 0); // this should come from devsys
if (ret != VLC_SUCCESS)
goto cuda_error;
- CALL_CUVID(cuvidUnmapVideoFrame, p_sys->cudecoder, frameDevicePtr);
+
+ ret = CALL_CUDA_DEC(cuDeviceGetAttribute, &tex_alignment, CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT, cuDev);
+ if (ret != VLC_SUCCESS || tex_alignment < 0)
+ goto cuda_error;
+ p_sys->outputPitch = (p_dec->fmt_out.video.i_width + tex_alignment - 1) / tex_alignment * tex_alignment;
unsigned int ByteWidth = p_sys->outputPitch;
unsigned int Height = p_dec->fmt_out.video.i_height;
@@ -352,16 +370,16 @@ static int CUDAAPI HandleVideoSequence(void *p_opaque, CUVIDEOFORMAT *p_format)
p_sys->out_pool = NULL;
if (outputDevicePtr[0])
{
- p_sys->pool_owner = (nvdec_pool_owner_t) {
+ p_sys->pool_owner = (hw_pool_owner_t) {
p_dec, PoolRelease, PoolAttachPicture,
};
void *bufferPtr[ARRAY_SIZE(outputDevicePtr)];
for (size_t i=0; i<ARRAY_SIZE(outputDevicePtr); i++)
bufferPtr[i] = (void*)(uintptr_t)outputDevicePtr[i];
- p_sys->out_pool = nvdec_pool_Create(&p_sys->pool_owner,
- &p_dec->fmt_out.video, p_sys->vctx_out,
- bufferPtr, ARRAY_SIZE(outputDevicePtr));
+ p_sys->out_pool = hw_pool_Create(&p_sys->pool_owner,
+ &p_dec->fmt_out.video, p_sys->vctx_out,
+ bufferPtr, ARRAY_SIZE(outputDevicePtr));
if (p_sys->out_pool == NULL)
PoolRelease(&p_sys->pool_owner, bufferPtr, ARRAY_SIZE(outputDevicePtr));
}
@@ -375,7 +393,7 @@ static int CUDAAPI HandleVideoSequence(void *p_opaque, CUVIDEOFORMAT *p_format)
CALL_CUDA_DEC(cuCtxPopCurrent, NULL);
ret = decoder_UpdateVideoOutput(p_dec, p_sys->vctx_out);
- return (ret == VLC_SUCCESS);
+ return (ret == VLC_SUCCESS) ? i_nb_surface : 0;
cuda_error:
CALL_CUDA_DEC(cuCtxPopCurrent, NULL);
@@ -388,9 +406,10 @@ static int CUDAAPI HandlePictureDecode(void *p_opaque, CUVIDPICPARAMS *p_picpara
{
decoder_t *p_dec = (decoder_t *) p_opaque;
nvdec_ctx_t *p_sys = p_dec->p_sys;
+ decoder_device_nvdec_t *devsys = p_sys->devsys;
int ret;
- ret = CALL_CUDA_DEC(cuCtxPushCurrent, p_sys->devsys->cuCtx);
+ ret = CALL_CUDA_DEC(cuCtxPushCurrent, devsys->cuCtx);
if (ret != VLC_SUCCESS)
return 0;
@@ -404,6 +423,7 @@ static int CUDAAPI HandlePictureDisplay(void *p_opaque, CUVIDPARSERDISPINFO *p_d
{
decoder_t *p_dec = (decoder_t *) p_opaque;
nvdec_ctx_t *p_sys = p_dec->p_sys;
+ decoder_device_nvdec_t *devsys = p_sys->devsys;
picture_t *p_pic = NULL;
CUdeviceptr frameDevicePtr = 0;
CUVIDPROCPARAMS params = {
@@ -416,7 +436,7 @@ static int CUDAAPI HandlePictureDisplay(void *p_opaque, CUVIDPARSERDISPINFO *p_d
if ( is_nvdec_opaque(p_dec->fmt_out.video.i_chroma) )
{
- p_pic = nvdec_pool_Wait(p_sys->out_pool);
+ p_pic = hw_pool_Wait(p_sys->out_pool);
if (unlikely(p_pic == NULL))
return 0;
pic_context_nvdec_t *picctx = NVDEC_PICCONTEXT_FROM_PICCTX(p_pic->context);
@@ -712,7 +732,8 @@ static cudaVideoChromaFormat MapChomaIDC(uint8_t chroma_idc)
static int ProbeDecoder(decoder_t *p_dec, uint8_t bitDepth, cudaVideoChromaFormat chroma)
{
nvdec_ctx_t *p_sys = p_dec->p_sys;
- int result = CALL_CUDA_DEC(cuCtxPushCurrent, p_sys->devsys->cuCtx);
+ decoder_device_nvdec_t *devsys = p_sys->devsys;
+ int result = CALL_CUDA_DEC(cuCtxPushCurrent, devsys->cuCtx);
if (unlikely(result != VLC_SUCCESS))
return result;
@@ -753,7 +774,6 @@ static int OpenDecoder(vlc_object_t *p_this)
case VLC_CODEC_H264:
case VLC_CODEC_HEVC:
p_sys->b_is_hxxx = true;
- p_sys->i_nb_surface = MAX_HXXX_SURFACES;
hxxx_helper_init(&p_sys->hh, VLC_OBJECT(p_dec),
p_dec->fmt_in.i_codec, 0, 0);
result = hxxx_helper_set_extra(&p_sys->hh, p_dec->fmt_in.p_extra,
@@ -780,7 +800,6 @@ static int OpenDecoder(vlc_object_t *p_this)
if (p_sys->vc1_header_offset < p_dec->fmt_in.i_extra - 4)
{
p_sys->process_block = ProcessVC1Block;
- p_sys->i_nb_surface = MAX_HXXX_SURFACES;
break;
}
}
@@ -790,7 +809,6 @@ static int OpenDecoder(vlc_object_t *p_this)
case VLC_CODEC_MPGV:
case VLC_CODEC_MP4V:
case VLC_CODEC_VP8:
- p_sys->i_nb_surface = 3;
break;
case VLC_CODEC_VP9:
if (p_dec->fmt_in.i_profile != 0 && p_dec->fmt_in.i_profile != 2)
@@ -798,7 +816,6 @@ static int OpenDecoder(vlc_object_t *p_this)
msg_Warn(p_dec, "Unsupported VP9 profile %d", p_dec->fmt_in.i_profile);
goto early_exit;
}
- p_sys->i_nb_surface = 10;
break;
default:
goto early_exit;
@@ -836,7 +853,7 @@ static int OpenDecoder(vlc_object_t *p_this)
.CodecType = MapCodecID(p_dec->fmt_in.i_codec),
.ulClockRate = CLOCK_FREQ,
.ulMaxDisplayDelay = NVDEC_DISPLAY_SURFACES,
- .ulMaxNumDecodeSurfaces = p_sys->i_nb_surface,
+ .ulMaxNumDecodeSurfaces = 1,
.pUserData = p_dec,
.pfnSequenceCallback = HandleVideoSequence,
.pfnDecodePicture = HandlePictureDecode,
@@ -1014,7 +1031,8 @@ static void CloseDecoder(vlc_object_t *p_this)
{
decoder_t *p_dec = (decoder_t *) p_this;
nvdec_ctx_t *p_sys = p_dec->p_sys;
- CALL_CUDA_DEC(cuCtxPushCurrent, p_sys->devsys->cuCtx);
+ decoder_device_nvdec_t *devsys = p_sys->devsys;
+ CALL_CUDA_DEC(cuCtxPushCurrent, devsys->cuCtx);
CALL_CUDA_DEC(cuCtxPopCurrent, NULL);
if (p_sys->cudecoder)
@@ -1026,7 +1044,7 @@ static void CloseDecoder(vlc_object_t *p_this)
if (p_sys->b_is_hxxx)
hxxx_helper_clean(&p_sys->hh);
if (p_sys->out_pool)
- nvdec_pool_Release(p_sys->out_pool);
+ hw_pool_Release(p_sys->out_pool);
else
{
cuvid_free_functions(&p_sys->cuvidFunctions);
=====================================
modules/hw/nvdec/nvdec_fmt.h
=====================================
@@ -23,6 +23,9 @@
#ifndef VLC_VIDEOCHROMA_NVDEC_FMT_H_
#define VLC_VIDEOCHROMA_NVDEC_FMT_H_
+#define FFNV_LOG_FUNC(logctx, msg, ...) msg_Err((vlc_object_t*)logctx, msg, __VA_ARGS__)
+#define FFNV_DEBUG_LOG_FUNC(logctx, msg, ...) msg_Dbg((vlc_object_t*)logctx, msg, __VA_ARGS__)
+
#include <ffnvcodec/dynlink_loader.h>
typedef struct {
=====================================
modules/hw/nvdec/nvdec_gl.c
=====================================
@@ -31,8 +31,6 @@
#include <vlc_codec.h>
#include <vlc_plugin.h>
-#include <ffnvcodec/dynlink_loader.h>
-
#include "nvdec_fmt.h"
#include "../../video_output/opengl/interop.h"
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/871efa3d88b14bdfe0c2bf09a9cdcb40262ccfbd...6d8a6416ae0c7a01690214362ee126573d2fcc79
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/871efa3d88b14bdfe0c2bf09a9cdcb40262ccfbd...6d8a6416ae0c7a01690214362ee126573d2fcc79
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list