vlc | branch: master | Steve Lhomme <[email protected]> | Mon Sep 2 08:31:42 2019 +0200| [bbcd07ff2120ca4154ba977f2c44c5dcfe22d2ce] | committer: Steve Lhomme
directx_va: group the pool/device callbacks in a const structure > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bbcd07ff2120ca4154ba977f2c44c5dcfe22d2ce --- modules/codec/avcodec/d3d11va.c | 22 ++++++++++++--------- modules/codec/avcodec/directx_va.c | 4 ++-- modules/codec/avcodec/directx_va.h | 2 +- modules/codec/avcodec/dxva2.c | 25 +++++++++++++----------- modules/codec/avcodec/va_surface.c | 30 +++++++++++++++-------------- modules/codec/avcodec/va_surface_internal.h | 10 +++++++--- 6 files changed, 53 insertions(+), 40 deletions(-) diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c index 4999639db5..80311d27d4 100644 --- a/modules/codec/avcodec/d3d11va.c +++ b/modules/codec/avcodec/d3d11va.c @@ -341,14 +341,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, dx_sys = &sys->dx_sys; - dx_sys->va_pool.pf_create_device = D3dCreateDevice; - dx_sys->va_pool.pf_destroy_device = D3dDestroyDevice; - dx_sys->va_pool.pf_create_video_service = DxCreateVideoService; - dx_sys->va_pool.pf_destroy_video_service = DxDestroyVideoService; - dx_sys->va_pool.pf_create_decoder_surfaces = DxCreateDecoderSurfaces; - dx_sys->va_pool.pf_destroy_surfaces = DxDestroySurfaces; - dx_sys->va_pool.pf_setup_avcodec_ctx = SetupAVCodecContext; - dx_sys->va_pool.pf_new_surface_context = NewSurfacePicContext; dx_sys->pf_get_input_list = DxGetInputList; dx_sys->pf_setup_output = DxSetupOutput; @@ -387,7 +379,19 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, } } - err = directx_va_Open(va, &sys->dx_sys); + static const struct va_pool_cfg pool_cfg = { + D3dCreateDevice, + D3dDestroyDevice, + NULL, NULL, + DxCreateVideoService, + DxDestroyVideoService, + DxCreateDecoderSurfaces, + DxDestroySurfaces, + SetupAVCodecContext, + NewSurfacePicContext, + }; + + err = directx_va_Open(va, &pool_cfg, &sys->dx_sys); if (err!=VLC_SUCCESS) goto error; diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c index fd93aeec15..f2cb60e10b 100644 --- a/modules/codec/avcodec/directx_va.c +++ b/modules/codec/avcodec/directx_va.c @@ -339,9 +339,9 @@ void directx_va_Close(vlc_va_t *va, directx_sys_t *dx_sys) va_pool_Close(va, &dx_sys->va_pool); } -int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys) +int directx_va_Open(vlc_va_t *va, const struct va_pool_cfg *cbs, directx_sys_t *dx_sys) { - return va_pool_Open(va, &dx_sys->va_pool); + return va_pool_Open(va, cbs, &dx_sys->va_pool); } static bool profile_supported(const directx_va_mode_t *mode, const es_format_t *fmt, diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h index 88a6af2e1b..e66ea87b05 100644 --- a/modules/codec/avcodec/directx_va.h +++ b/modules/codec/avcodec/directx_va.h @@ -77,7 +77,7 @@ typedef struct } directx_sys_t; -int directx_va_Open(vlc_va_t *, directx_sys_t *); +int directx_va_Open(vlc_va_t *, const struct va_pool_cfg *, directx_sys_t *); void directx_va_Close(vlc_va_t *, directx_sys_t *); int directx_va_Setup(vlc_va_t *, directx_sys_t *, const AVCodecContext *avctx, const es_format_t *, int flag_xbox); char *directx_va_GetDecoderName(const GUID *guid); diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c index 8f777b05a7..8257fce703 100644 --- a/modules/codec/avcodec/dxva2.c +++ b/modules/codec/avcodec/dxva2.c @@ -303,22 +303,25 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, dx_sys = &sys->dx_sys; - dx_sys->va_pool.pf_create_device = D3dCreateDevice; - dx_sys->va_pool.pf_destroy_device = D3dDestroyDevice; - dx_sys->va_pool.pf_create_device_manager = D3dCreateDeviceManager; - dx_sys->va_pool.pf_destroy_device_manager = D3dDestroyDeviceManager; - dx_sys->va_pool.pf_create_video_service = DxCreateVideoService; - dx_sys->va_pool.pf_destroy_video_service = DxDestroyVideoService; - dx_sys->va_pool.pf_create_decoder_surfaces = DxCreateVideoDecoder; - dx_sys->va_pool.pf_destroy_surfaces = DxDestroyVideoDecoder; - dx_sys->va_pool.pf_setup_avcodec_ctx = SetupAVCodecContext; - dx_sys->va_pool.pf_new_surface_context = NewSurfacePicContext; + static const struct va_pool_cfg pool_cfg = { + D3dCreateDevice, + D3dDestroyDevice, + D3dCreateDeviceManager, + D3dDestroyDeviceManager, + DxCreateVideoService, + DxDestroyVideoService, + DxCreateVideoDecoder, + DxDestroyVideoDecoder, + SetupAVCodecContext, + NewSurfacePicContext, + }; + dx_sys->pf_get_input_list = DxGetInputList; dx_sys->pf_setup_output = DxSetupOutput; va->sys = sys; - err = directx_va_Open(va, &sys->dx_sys); + err = directx_va_Open(va, &pool_cfg, &sys->dx_sys); if (err!=VLC_SUCCESS) goto error; diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c index a91878f1a6..61bf4157ac 100644 --- a/modules/codec/avcodec/va_surface.c +++ b/modules/codec/avcodec/va_surface.c @@ -48,7 +48,7 @@ static void DestroyVideoDecoder(vlc_va_sys_t *sys, va_pool_t *va_pool) { for (unsigned i = 0; i < va_pool->surface_count; i++) va_surface_Release(va_pool->surface[i]->va_surface); - va_pool->pf_destroy_surfaces(sys); + va_pool->callbacks->pf_destroy_surfaces(sys); va_pool->surface_count = 0; } @@ -97,7 +97,7 @@ int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext fmt.i_frame_rate = avctx->framerate.num; fmt.i_frame_rate_base = avctx->framerate.den; - err = va_pool->pf_create_decoder_surfaces(va, avctx->codec_id, &fmt, count); + err = va_pool->callbacks->pf_create_decoder_surfaces(va, avctx->codec_id, &fmt, count); if (err == VLC_SUCCESS) { va_pool->surface_width = surface_width; @@ -107,7 +107,7 @@ int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext done: va_pool->surface_count = i; if (err == VLC_SUCCESS) - va_pool->pf_setup_avcodec_ctx(va->sys); + va_pool->callbacks->pf_setup_avcodec_ctx(va->sys); return err; } @@ -121,7 +121,7 @@ int va_pool_SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count) struct vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface)); if (unlikely(p_surface==NULL)) goto done; - va_pool->surface[i] = va_pool->pf_new_surface_context(va, i); + va_pool->surface[i] = va_pool->callbacks->pf_new_surface_context(va, i); if (unlikely(va_pool->surface[i]==NULL)) { free(p_surface); @@ -135,7 +135,7 @@ int va_pool_SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count) done: va_pool->surface_count = i; if (err == VLC_SUCCESS) - va_pool->pf_setup_avcodec_ctx(va->sys); + va_pool->callbacks->pf_setup_avcodec_ctx(va->sys); return err; } @@ -191,32 +191,34 @@ void va_surface_Release(vlc_va_surface_t *surface) void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool) { DestroyVideoDecoder(va->sys, va_pool); - va_pool->pf_destroy_video_service(va); - if (va_pool->pf_destroy_device_manager) - va_pool->pf_destroy_device_manager(va); - va_pool->pf_destroy_device(va->sys); + va_pool->callbacks->pf_destroy_video_service(va); + if (va_pool->callbacks->pf_destroy_device_manager) + va_pool->callbacks->pf_destroy_device_manager(va); + va_pool->callbacks->pf_destroy_device(va->sys); } -int va_pool_Open(vlc_va_t *va, va_pool_t *va_pool) +int va_pool_Open(vlc_va_t *va, const struct va_pool_cfg *cbs, va_pool_t *va_pool) { /* */ - if (va_pool->pf_create_device(va)) { + if (cbs->pf_create_device(va)) { msg_Err(va, "Failed to create device"); goto error; } msg_Dbg(va, "CreateDevice succeed"); - if (va_pool->pf_create_device_manager && - va_pool->pf_create_device_manager(va) != VLC_SUCCESS) { + if (cbs->pf_create_device_manager && + cbs->pf_create_device_manager(va) != VLC_SUCCESS) { msg_Err(va, "CreateDeviceManager failed"); goto error; } - if (va_pool->pf_create_video_service(va)) { + if (cbs->pf_create_video_service(va)) { msg_Err(va, "CreateVideoService failed"); goto error; } + va_pool->callbacks = cbs; + return VLC_SUCCESS; error: diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h index df55ff5dc6..0ffc28c99d 100644 --- a/modules/codec/avcodec/va_surface_internal.h +++ b/modules/codec/avcodec/va_surface_internal.h @@ -43,6 +43,11 @@ typedef struct struct va_pic_context *surface[MAX_SURFACE_COUNT]; + const struct va_pool_cfg *callbacks; + +} va_pool_t; + +struct va_pool_cfg { int (*pf_create_device)(vlc_va_t *); void (*pf_destroy_device)(vlc_va_sys_t *); @@ -71,10 +76,9 @@ typedef struct * Create a new context for the surface being acquired */ struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, int surface_index); +}; -} va_pool_t; - -int va_pool_Open(vlc_va_t *, va_pool_t *); +int va_pool_Open(vlc_va_t *, const struct va_pool_cfg *, va_pool_t *); void va_pool_Close(vlc_va_t *va, va_pool_t *); int va_pool_SetupDecoder(vlc_va_t *, va_pool_t *, const AVCodecContext *, unsigned count, int alignment); int va_pool_SetupSurfaces(vlc_va_t *, va_pool_t *, unsigned count); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
