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