Browse Source

directx_va: group the pool/device callbacks in a const structure

pull/94/head
Steve Lhomme 7 years ago
parent
commit
bbcd07ff21
  1. 22
      modules/codec/avcodec/d3d11va.c
  2. 4
      modules/codec/avcodec/directx_va.c
  3. 2
      modules/codec/avcodec/directx_va.h
  4. 25
      modules/codec/avcodec/dxva2.c
  5. 30
      modules/codec/avcodec/va_surface.c
  6. 10
      modules/codec/avcodec/va_surface_internal.h

22
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 = &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_get_input_list = DxGetInputList;
dx_sys->pf_setup_output = DxSetupOutput; 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) if (err!=VLC_SUCCESS)
goto error; goto error;

4
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); 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, static bool profile_supported(const directx_va_mode_t *mode, const es_format_t *fmt,

2
modules/codec/avcodec/directx_va.h

@ -77,7 +77,7 @@ typedef struct
} directx_sys_t; } 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 *); 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); 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); char *directx_va_GetDecoderName(const GUID *guid);

25
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 = &sys->dx_sys;
dx_sys->va_pool.pf_create_device = D3dCreateDevice; static const struct va_pool_cfg pool_cfg = {
dx_sys->va_pool.pf_destroy_device = D3dDestroyDevice; D3dCreateDevice,
dx_sys->va_pool.pf_create_device_manager = D3dCreateDeviceManager; D3dDestroyDevice,
dx_sys->va_pool.pf_destroy_device_manager = D3dDestroyDeviceManager; D3dCreateDeviceManager,
dx_sys->va_pool.pf_create_video_service = DxCreateVideoService; D3dDestroyDeviceManager,
dx_sys->va_pool.pf_destroy_video_service = DxDestroyVideoService; DxCreateVideoService,
dx_sys->va_pool.pf_create_decoder_surfaces = DxCreateVideoDecoder; DxDestroyVideoService,
dx_sys->va_pool.pf_destroy_surfaces = DxDestroyVideoDecoder; DxCreateVideoDecoder,
dx_sys->va_pool.pf_setup_avcodec_ctx = SetupAVCodecContext; DxDestroyVideoDecoder,
dx_sys->va_pool.pf_new_surface_context = NewSurfacePicContext; SetupAVCodecContext,
NewSurfacePicContext,
};
dx_sys->pf_get_input_list = DxGetInputList; dx_sys->pf_get_input_list = DxGetInputList;
dx_sys->pf_setup_output = DxSetupOutput; dx_sys->pf_setup_output = DxSetupOutput;
va->sys = sys; 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) if (err!=VLC_SUCCESS)
goto error; goto error;

30
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++) for (unsigned i = 0; i < va_pool->surface_count; i++)
va_surface_Release(va_pool->surface[i]->va_surface); 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; 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 = avctx->framerate.num;
fmt.i_frame_rate_base = avctx->framerate.den; 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) if (err == VLC_SUCCESS)
{ {
va_pool->surface_width = surface_width; 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: done:
va_pool->surface_count = i; va_pool->surface_count = i;
if (err == VLC_SUCCESS) if (err == VLC_SUCCESS)
va_pool->pf_setup_avcodec_ctx(va->sys); va_pool->callbacks->pf_setup_avcodec_ctx(va->sys);
return err; 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)); struct vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
if (unlikely(p_surface==NULL)) if (unlikely(p_surface==NULL))
goto done; 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)) if (unlikely(va_pool->surface[i]==NULL))
{ {
free(p_surface); free(p_surface);
@ -135,7 +135,7 @@ int va_pool_SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count)
done: done:
va_pool->surface_count = i; va_pool->surface_count = i;
if (err == VLC_SUCCESS) if (err == VLC_SUCCESS)
va_pool->pf_setup_avcodec_ctx(va->sys); va_pool->callbacks->pf_setup_avcodec_ctx(va->sys);
return err; 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) void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool)
{ {
DestroyVideoDecoder(va->sys, va_pool); DestroyVideoDecoder(va->sys, va_pool);
va_pool->pf_destroy_video_service(va); va_pool->callbacks->pf_destroy_video_service(va);
if (va_pool->pf_destroy_device_manager) if (va_pool->callbacks->pf_destroy_device_manager)
va_pool->pf_destroy_device_manager(va); va_pool->callbacks->pf_destroy_device_manager(va);
va_pool->pf_destroy_device(va->sys); 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"); msg_Err(va, "Failed to create device");
goto error; goto error;
} }
msg_Dbg(va, "CreateDevice succeed"); msg_Dbg(va, "CreateDevice succeed");
if (va_pool->pf_create_device_manager && if (cbs->pf_create_device_manager &&
va_pool->pf_create_device_manager(va) != VLC_SUCCESS) { cbs->pf_create_device_manager(va) != VLC_SUCCESS) {
msg_Err(va, "CreateDeviceManager failed"); msg_Err(va, "CreateDeviceManager failed");
goto error; goto error;
} }
if (va_pool->pf_create_video_service(va)) { if (cbs->pf_create_video_service(va)) {
msg_Err(va, "CreateVideoService failed"); msg_Err(va, "CreateVideoService failed");
goto error; goto error;
} }
va_pool->callbacks = cbs;
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:

10
modules/codec/avcodec/va_surface_internal.h

@ -43,6 +43,11 @@ typedef struct
struct va_pic_context *surface[MAX_SURFACE_COUNT]; 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 *); int (*pf_create_device)(vlc_va_t *);
void (*pf_destroy_device)(vlc_va_sys_t *); void (*pf_destroy_device)(vlc_va_sys_t *);
@ -71,10 +76,9 @@ typedef struct
* Create a new context for the surface being acquired * Create a new context for the surface being acquired
*/ */
struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, int surface_index); struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, int surface_index);
};
} va_pool_t; int va_pool_Open(vlc_va_t *, const struct va_pool_cfg *, va_pool_t *);
int va_pool_Open(vlc_va_t *, va_pool_t *);
void va_pool_Close(vlc_va_t *va, 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_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); int va_pool_SetupSurfaces(vlc_va_t *, va_pool_t *, unsigned count);

Loading…
Cancel
Save