Commit 02e90c97 authored by Jean-Paul Saman's avatar Jean-Paul Saman

davinci encoder: cleanup

parent a2fa9288
......@@ -64,7 +64,6 @@ struct encoder_sys_t
/*****************************************************************************
*
*****************************************************************************/
int OpenVideoEncoder( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t *)p_this;
......@@ -239,79 +238,91 @@ static inline void davinci_CopyPictureToXDM( encoder_t *p_enc, XDM_BufDesc *p_bu
}
}
static int davinci_InitBuffers( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
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 ?
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 = 0;
if( VIDENC_control( p_sys->c, XDM_SETPARAMS, &dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to set encoder parameters: %dx%d @%d fps, "
"%d kBps, I-frame interval %d",
(int)dparams.inputWidth, (int)dparams.inputHeight,
(int)dparams.refFrameRate / 1000,
(int)dparams.targetBitRate >> 13 /* / (1024 * 8) */,
(int)dparams.intraFrameInterval );
return VLC_EGENERIC;
}
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 );
/* Configure buffers */
if( VIDENC_control( p_sys->c, XDM_GETBUFINFO, &dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to get buffer info" );
return VLC_EGENERIC;
}
/* Allocate input buffer(s) */
if( i_ret = AllocateBuffer( p_enc, status.bufInfo.minNumInBufs,
status.bufInfo.minInBufSize, &p_sys->in )
!= VLC_SUCCESS )
{
msg_Err( p_enc, "Failed to allocate input buffers" );
return i_ret;
}
/* Allocate output buffer */
if( i_ret = AllocateBuffer( p_enc, status.bufInfo.minNumOutBufs,
status.bufInfo.minOutBufSize, &p_sys->out )
!= VLC_SUCCESS )
{
msg_Err( p_enc, "Failed to allocate input buffers" );
return i_ret;
}
return i_ret;
}
static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
{
encoder_sys_t *p_sys = p_enc->p_sys;
block_t *p_block;
int i;
VIDENC_InArgs in_args;
VIDENC_OutArgs out_args;
int i;
if( p_sys->in.numBufs == 0 || p_sys->out.numBufs == 0 )
{
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 ?
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 = 0;
if( VIDENC_control( p_sys->c, XDM_SETPARAMS, &dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to set encoder parameters: %dx%d @%d fps, "
"%d kBps, I-frame interval %d",
(int)dparams.inputWidth, (int)dparams.inputHeight,
(int)dparams.refFrameRate / 1000,
(int)dparams.targetBitRate >> 13/* / (1024 * 8) */,
(int)dparams.intraFrameInterval );
return NULL;
}
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 );
/* Configure buffers */
if( VIDENC_control( p_sys->c, XDM_GETBUFINFO, &dparams, &status )
!= VIDENC_EOK )
{
msg_Err( p_enc, "Failed to get buffer info" );
return NULL;
}
/* Allocate input buffer(s) */
if( AllocateBuffer( p_enc, status.bufInfo.minNumInBufs,
status.bufInfo.minInBufSize, &p_sys->in )
!= VLC_SUCCESS )
{
msg_Err( p_enc, "Failed to allocate input buffers" );
return NULL;
}
/* Allocate output buffer */
if( AllocateBuffer( p_enc, status.bufInfo.minNumOutBufs,
status.bufInfo.minOutBufSize, &p_sys->out )
!= VLC_SUCCESS )
{
msg_Err( p_enc, "Failed to allocate input buffers" );
if( davinci_InitBuffers( p_enc ) != VLC_SUCCESS )
return NULL;
}
}
davinci_CopyPictureToXDM( p_enc, &p_sys->in, p_pic );
......
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