Commit 9c40583e authored by Jean-Paul Saman's avatar Jean-Paul Saman

davinci: video_encoder.c: cleanup

parent db51e7a1
......@@ -61,7 +61,12 @@ struct xdm_sys_t
VIDENC_Handle handle;
XDM_BufDesc in;
VIDENC_InArgs in_args;
XDM_BufDesc out;
VIDENC_OutArgs out_args;
VIDENC_DynamicParams dparams;
};
/*****************************************************************************
......@@ -70,11 +75,22 @@ struct xdm_sys_t
int OpenEncoderVideo( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm;
p_sys->xdm = (xdm_sys_t *) calloc( 1, sizeof( xdm_sys_t ) );
p_sys->xdm = xdm = (xdm_sys_t *) calloc( 1, sizeof( xdm_sys_t ) );
if( !p_sys->xdm )
return VLC_ENOMEM;
/* */
xdm->dparams.size = sizeof( xdm->dparams );
memset( &xdm->in_args, 0, sizeof( xdm->in_args ) );
xdm->in_args.size = sizeof( xdm->in_args );
memset( &xdm->out_args, 0, sizeof( xdm->out_args ) );
xdm->out_args.size = sizeof( xdm->out_args );
/* */
if( GetVideoEncoderSettings( p_enc, p_sys->psz_codec ) != VLC_SUCCESS )
goto error;
......@@ -206,34 +222,32 @@ static int davinci_SetDynamicParams( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
VIDENC_DynamicParams dparams;
VIDENC_Status status;
dparams.size = sizeof( dparams );
memset( &status, 0, sizeof( status ) );
status.size = sizeof( status );
/* Configue the encoder */
dparams.inputHeight = p_enc->fmt_in.video.i_height;
dparams.inputWidth = p_enc->fmt_in.video.i_width;
dparams.refFrameRate = (p_enc->fmt_out.video.i_frame_rate_base != 0) ?
xdm->dparams.inputHeight = p_enc->fmt_in.video.i_height;
xdm->dparams.inputWidth = p_enc->fmt_in.video.i_width;
xdm->dparams.refFrameRate = (p_enc->fmt_out.video.i_frame_rate_base != 0) ?
(p_enc->fmt_out.video.i_frame_rate * 1000) /
p_enc->fmt_out.video.i_frame_rate_base :
p_enc->i_iframes * 1000; /* Frames per 1000 seconds */
dparams.targetFrameRate = dparams.refFrameRate; /* input fps = output fps */
dparams.targetBitRate = p_enc->fmt_out.i_bitrate;
dparams.intraFrameInterval = p_enc->i_iframes;
dparams.generateHeader = XDM_ENCODE_AU; /* don't encode only the header */
dparams.captureWidth = 0;
dparams.forceIFrame = 1;
xdm->dparams.targetFrameRate = xdm->dparams.refFrameRate; /* input fps = output fps */
xdm->dparams.targetBitRate = p_enc->fmt_out.i_bitrate;
xdm->dparams.intraFrameInterval = p_enc->i_iframes;
xdm->dparams.generateHeader = XDM_ENCODE_AU; /* don't encode only the header */
xdm->dparams.captureWidth = 0;
xdm->dparams.forceIFrame = 1;
msg_Dbg( p_enc, "using %dx%d at %.3f fps (bitrate %d kBps, I-Frame interval %d)\n",
(int)dparams.inputWidth, (int)dparams.inputHeight,
((float)dparams.targetFrameRate)/1000.,
((int)dparams.targetBitRate) >> 13 /* / (8*1024)*/,
(int)dparams.intraFrameInterval );
(int)xdm->dparams.inputWidth, (int)xdm->dparams.inputHeight,
((float)xdm->dparams.targetFrameRate)/1000.,
((int)xdm->dparams.targetBitRate) >> 13 /* / (8*1024)*/,
(int)xdm->dparams.intraFrameInterval );
if( VIDENC_control( xdm->handle, XDM_SETPARAMS, &dparams, &status )
if( VIDENC_control( xdm->handle, XDM_SETPARAMS, &xdm->dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to set encoder parameters." );
......@@ -248,43 +262,13 @@ static int davinci_InitVideoBuffers( encoder_t *p_enc )
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
int i_ret = VLC_SUCCESS;
VIDENC_DynamicParams dparams;
VIDENC_Status status;
dparams.size = sizeof( dparams );
memset( &status, 0, sizeof( status ) );
status.size = sizeof( status );
/* Configue the encoder */
dparams.inputHeight = p_enc->fmt_in.video.i_height;
dparams.inputWidth = p_enc->fmt_in.video.i_width;
dparams.refFrameRate = (p_enc->fmt_out.video.i_frame_rate_base != 0) ?
(p_enc->fmt_out.video.i_frame_rate * 1000) /
p_enc->fmt_out.video.i_frame_rate_base :
p_enc->i_iframes * 1000; /* Frames per 1000 seconds */
dparams.targetFrameRate = dparams.refFrameRate; /* input fps = output fps */
dparams.targetBitRate = p_enc->fmt_out.i_bitrate;
dparams.intraFrameInterval = p_enc->i_iframes;
dparams.generateHeader = XDM_ENCODE_AU; /* don't encode only the header */
dparams.captureWidth = 0;
dparams.forceIFrame = 1;
msg_Info( p_enc, "using %dx%d at %.3f fps (bitrate %d kBps, I-Frame interval %d)\n",
(int)dparams.inputWidth, (int)dparams.inputHeight,
((float)dparams.targetFrameRate)/1000.,
((int)dparams.targetBitRate) >> 13 /* / (8*1024)*/,
(int)dparams.intraFrameInterval );
if( VIDENC_control( xdm->handle, XDM_SETPARAMS, &dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to set encoder parameters." );
return VLC_EGENERIC;
}
/* Configure buffers */
if( VIDENC_control( xdm->handle, XDM_GETBUFINFO, &dparams, &status )
if( VIDENC_control( xdm->handle, XDM_GETBUFINFO, &xdm->dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to get buffer info" );
......@@ -317,12 +301,12 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
block_t *p_block;
VIDENC_InArgs in_args;
VIDENC_OutArgs out_args;
int i;
int i_ret;
if( xdm->in.numBufs == 0 || xdm->out.numBufs == 0 )
{
if( davinci_SetDynamicParams( p_enc ) != VLC_SUCCESS )
msg_Err( p_enc, "Encoding continues with previous settings" );
if( davinci_InitVideoBuffers( p_enc ) != VLC_SUCCESS )
return NULL;
}
......@@ -336,20 +320,13 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
davinci_CopyPictureToXDM( p_enc, &xdm->in, p_pic );
/* Configure input */
in_args.size = sizeof( in_args );
/* Configure output */
memset( &out_args, 0, sizeof( out_args ) );
out_args.size = sizeof( out_args );
/* Encode the video */
i = VIDENC_process( xdm->handle, &xdm->in, &xdm->out,
&in_args, &out_args );
if( i != VIDENC_EOK )
i_ret = VIDENC_process( xdm->handle, &xdm->in, &xdm->out,
&xdm->in_args, &xdm->out_args );
if( i_ret != VIDENC_EOK )
{
msg_Err( p_enc, "Video encoding failed (%d): %s", i,
davinci_GetExtendedError( out_args.extendedError ) );
msg_Err( p_enc, "Video encoding failed (%d): %s", i_ret,
davinci_GetExtendedError( xdm->out_args.extendedError ) );
return NULL;
}
......@@ -360,16 +337,16 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
#endif
/* Put everything in the block */
if( out_args.bytesGenerated <= 0 )
if( xdm->out_args.bytesGenerated <= 0 )
return NULL;
p_block = block_New( p_enc, out_args.bytesGenerated );
p_block = block_New( p_enc, xdm->out_args.bytesGenerated );
if( !p_block )
return NULL;
memcpy( p_block->p_buffer, xdm->out.bufs[0], out_args.bytesGenerated );
memcpy( p_block->p_buffer, xdm->out.bufs[0], xdm->out_args.bytesGenerated );
switch( out_args.encodedFrameType )
switch( xdm->out_args.encodedFrameType )
{
case IVIDEO_I_FRAME:
case IVIDEO_II_FRAME:
......
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