Commit c61b433a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

avcodec: pass AVCodecContext to VA setup callback

parent ee961d8f
......@@ -309,28 +309,28 @@ static void DxCreateVideoConversion(vlc_va_sys_t *);
static void DxDestroyVideoConversion(vlc_va_sys_t *);
/* */
static int Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *chroma,
int width, int height)
static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chroma)
{
vlc_va_sys_t *sys = va->sys;
if (sys->width == width && sys->height == height && sys->decoder)
if (sys->width == avctx->coded_width && sys->height == avctx->coded_height
&& sys->decoder != NULL)
goto ok;
/* */
DxDestroyVideoConversion(sys);
DxDestroyVideoDecoder(sys);
*hw = NULL;
avctx->hwaccel_context = NULL;
*chroma = 0;
if (width <= 0 || height <= 0)
if (avctx->coded_width <= 0 || avctx->coded_height <= 0)
return VLC_EGENERIC;
/* FIXME transmit a video_format_t by VaSetup directly */
video_format_t fmt;
memset(&fmt, 0, sizeof(fmt));
fmt.i_width = width;
fmt.i_height = height;
fmt.i_width = avctx->coded_width;
fmt.i_height = avctx->coded_height;
if (DxCreateVideoDecoder(va, sys->codec_id, &fmt))
return VLC_EGENERIC;
......@@ -345,7 +345,7 @@ static int Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *chroma,
/* */
ok:
*hw = &sys->hw;
avctx->hwaccel_context = &sys->hw;
const d3d_format_t *output = D3dFindFormat(sys->output);
*chroma = output->codec;
......
......@@ -35,8 +35,7 @@ struct vlc_va_t {
const char *description;
int pix_fmt;
int (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output,
int width, int height);
int (*setup)(vlc_va_t *, AVCodecContext *, vlc_fourcc_t *output);
int (*get)(vlc_va_t *, void **opaque, uint8_t **data);
void (*release)(void *opaque, uint8_t *surface);
int (*extract)(vlc_va_t *, picture_t *dst, void *opaque, uint8_t *data);
......@@ -52,16 +51,14 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *, const es_format_t *fmt
/**
* Initializes the acceleration video decoding back-end for libavcodec.
* @param hw pointer to libavcodec hardware context pointer [OUT]
* @param avctx libavcodec codec context
* @param output pointer to video chroma output by the back-end [OUT]
* @param width coded video width in pixels
* @param height coded video height in pixels
* @return VLC_SUCCESS on success, otherwise an error code.
*/
static inline int vlc_va_Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *output,
int width, int height)
static inline int vlc_va_Setup(vlc_va_t *va, AVCodecContext *avctx,
vlc_fourcc_t *output)
{
return va->setup(va, hw, output, width, height);
return va->setup(va, avctx, output);
}
/**
......
......@@ -392,28 +392,28 @@ static void Release( void *opaque, uint8_t *data )
(void) data;
}
static int Setup( vlc_va_t *va, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
int i_width, int i_height )
static int Setup( vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *pi_chroma )
{
vlc_va_sys_t *sys = va->sys;
if( sys->i_surface_width == i_width &&
sys->i_surface_height == i_height )
if( sys->i_surface_width == avctx->coded_width &&
sys->i_surface_height == avctx->coded_height )
{
*pp_hw_ctx = &sys->hw_ctx;
avctx->hwaccel_context = &sys->hw_ctx;
*pi_chroma = sys->i_surface_chroma;
return VLC_SUCCESS;
}
*pp_hw_ctx = NULL;
avctx->hwaccel_context = NULL;
*pi_chroma = 0;
if( sys->i_surface_width || sys->i_surface_height )
DestroySurfaces( sys );
if( i_width > 0 && i_height > 0 )
return CreateSurfaces( sys, pp_hw_ctx, pi_chroma, i_width, i_height );
if( avctx->coded_width <= 0 && avctx->coded_height <= 0 )
return VLC_EGENERIC;
return VLC_EGENERIC;
return CreateSurfaces( sys, &avctx->hwaccel_context, pi_chroma,
avctx->coded_width, avctx->coded_height );
}
static void Delete( vlc_va_t *va, AVCodecContext *avctx )
......
......@@ -169,16 +169,16 @@ static void Close( vlc_va_t *external, AVCodecContext *ctx )
(void) ctx;
}
static int Setup( vlc_va_t *external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
int i_width, int i_height )
static int Setup( vlc_va_t *external, AVCodecContext *avctx,
vlc_fourcc_t *pi_chroma )
{
vlc_va_vda_t *p_va = vlc_va_vda_Get( external );
if( p_va->hw_ctx.width == i_width
&& p_va->hw_ctx.height == i_height
if( p_va->hw_ctx.width == avctx->coded_width
&& p_va->hw_ctx.height == avctx->codec_height
&& p_va->hw_ctx.decoder )
{
*pp_hw_ctx = &p_va->hw_ctx;
avctx->hwaccel_context = &p_va->hw_ctx;
*pi_chroma = p_va->i_chroma;
return VLC_SUCCESS;
}
......@@ -206,17 +206,17 @@ static int Setup( vlc_va_t *external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
default :
p_va->hw_ctx.cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8Planar;
p_va->i_chroma = VLC_CODEC_I420;
CopyInitCache( &p_va->image_cache, i_width );
CopyInitCache( &p_va->image_cache, avctx->coded_width );
msg_Dbg(p_va->p_log, "using pixel format 420YpCbCr8Planar");
}
ok:
/* Setup the libavcodec hardware context */
*pp_hw_ctx = &p_va->hw_ctx;
avctx->hwaccel_context = &p_va->hw_ctx;
*pi_chroma = p_va->i_chroma;
p_va->hw_ctx.width = i_width;
p_va->hw_ctx.height = i_height;
p_va->hw_ctx.width = avctx->coded_width;
p_va->hw_ctx.height = avctx->coded_height;
/* create the decoder */
int status = ff_vda_create_decoder( &p_va->hw_ctx,
......@@ -374,22 +374,14 @@ static void Close( vlc_va_t *external, AVCodecContext *avctx )
(void) external;
}
static int Setup( vlc_va_t *external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
int i_width, int i_height )
static int Setup( vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *p_chroma )
{
VLC_UNUSED( pp_hw_ctx );
vlc_va_vda_t *p_va = vlc_va_vda_Get( external );
*pi_chroma = VLC_CODEC_UYVY;
av_vda_default_free(p_va->avctx);
if( av_vda_default_init(p_va->avctx) < 0 )
return VLC_EGENERIC;
av_vda_default_free(avctx);
(void)i_width; (void)i_height;
(void) va;
*p_chroma = VLC_CODEC_UYVY;
return VLC_SUCCESS;
return (av_vda_default_init(avctx) < 0) ? VLC_EGENERIC : VLC_SUCCESS;
}
// Never called
......
......@@ -959,8 +959,7 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
decoder_sys_t *sys = dec->p_sys;
vlc_va_t *va = sys->p_va;
if (vlc_va_Setup(va, &ctx->hwaccel_context, &dec->fmt_out.video.i_chroma,
ctx->coded_width, ctx->coded_height))
if (vlc_va_Setup(va, ctx, &dec->fmt_out.video.i_chroma))
{
msg_Err(dec, "hardware acceleration setup failed");
return -1;
......@@ -1154,9 +1153,7 @@ static int ffmpeg_va_GetFrameBuf( struct AVCodecContext *p_context, AVFrame *p_f
vlc_va_t *p_va = p_sys->p_va;
/* hwaccel_context is not present in old ffmpeg version */
if( vlc_va_Setup( p_va,
&p_context->hwaccel_context, &p_dec->fmt_out.video.i_chroma,
p_context->coded_width, p_context->coded_height ) )
if( vlc_va_Setup( p_va, p_context, &p_dec->fmt_out.video.i_chroma ) )
{
msg_Err( p_dec, "vlc_va_Setup failed" );
return -1;
......@@ -1362,9 +1359,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
/* We try to call vlc_va_Setup when possible to detect errors when
* possible (later is too late) */
if( p_context->width > 0 && p_context->height > 0
&& vlc_va_Setup( p_va, &p_context->hwaccel_context,
&p_dec->fmt_out.video.i_chroma,
p_context->width, p_context->height ) )
&& vlc_va_Setup( p_va, p_context, &p_dec->fmt_out.video.i_chroma ) )
{
msg_Err( p_dec, "acceleration setup failure" );
break;
......
......@@ -108,16 +108,13 @@ static int Copy(vlc_va_t *va, picture_t *pic, void *opaque, uint8_t *data)
return VLC_SUCCESS;
}
static int Init(vlc_va_t *va, void **ctxp, vlc_fourcc_t *chromap,
int width, int height)
static int Init(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chromap)
{
vlc_va_sys_t *sys = va->sys;
VdpStatus err;
width = (width + 1) & ~1;
height = (height + 3) & ~3;
sys->width = width;
sys->height = height;
sys->width = (avctx->coded_width + 1) & ~1;
sys->height = (avctx->coded_height + 3) & ~3;
unsigned surfaces = 2;
switch (sys->profile)
......@@ -129,8 +126,8 @@ static int Init(vlc_va_t *va, void **ctxp, vlc_fourcc_t *chromap,
break;
}
err = vdp_decoder_create(sys->vdp, sys->device, sys->profile, width,
height, surfaces, &sys->context->decoder);
err = vdp_decoder_create(sys->vdp, sys->device, sys->profile, sys->width,
sys->height, surfaces, &sys->context->decoder);
if (err != VDP_STATUS_OK)
{
msg_Err(va, "%s creation failure: %s", "decoder",
......@@ -139,7 +136,7 @@ static int Init(vlc_va_t *va, void **ctxp, vlc_fourcc_t *chromap,
return VLC_EGENERIC;
}
*ctxp = sys->context;
avctx->hwaccel_context = sys->context;
/* TODO: select better chromas when appropriate */
*chromap = VLC_CODEC_VDPAU_VIDEO_420;
return VLC_SUCCESS;
......@@ -153,20 +150,20 @@ static void Deinit(vlc_va_t *va)
vdp_decoder_destroy(sys->vdp, sys->context->decoder);
}
static int Setup(vlc_va_t *va, void **ctxp, vlc_fourcc_t *chromap,
int width, int height)
static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chromap)
{
vlc_va_sys_t *sys = va->sys;
if (sys->context->decoder != VDP_INVALID_HANDLE)
{
if (sys->width == width && sys->height == height)
if (sys->width == avctx->coded_width
&& sys->height == avctx->coded_height)
return VLC_SUCCESS;
Deinit(va);
sys->context->decoder = VDP_INVALID_HANDLE;
}
return Init(va, ctxp, chromap, width, height);
return Init(va, avctx, chromap);
}
static int Open(vlc_va_t *va, AVCodecContext *ctx, const es_format_t *fmt)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment