📄 mp4einit.c
字号:
align = 8;
size = enc_state->mb_per_row + 1;
if (alloc_align_mem_mpeg4((void*)&enc_state->qp_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* info_pic */
size = sizeof(sample_picture);
if (alloc_align_mem_mpeg4((void*)&enc_state->info_pic, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
if (Q_H263 == enc_state->quant_type) {
enc_state->qmatrix_intra = NULL;
enc_state->qmatrix_inter = NULL;
} else {
/* qmatrix_intra */
align = 4;
size = SAMPLE_VIDEO_BLOCK_SQUARE_SIZE * 2 * sizeof(int);
if (alloc_align_mem_mpeg4((void*)&enc_state->qmatrix_intra, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* qmatrix_inter */
if (alloc_align_mem_mpeg4((void*)&enc_state->qmatrix_inter, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
}
/* mv_plane */
align = 8;
size = (enc_state->mb_per_row + 2) * (enc_state->mb_per_col + 1) * 4
* sizeof(IppMotionVector);
if (alloc_align_mem_mpeg4((void*)&enc_state->mv_plane, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
enc_state->mv_plane += (enc_state->mb_per_row + 2) * 4 + 4;
/* mb_type_plane */
align = 4;
size = enc_state->mb_per_row * enc_state->mb_per_col;
if (alloc_align_mem_mpeg4((void*)&enc_state->mb_type_plane, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* ysum_plane */
align = 8;
size = (enc_state->mb_per_row + 2) * (enc_state->mb_per_col + 2)
* SAMPLE_VIDEO_MB_SQUARE_SIZE * sizeof(Ipp16u);
if (alloc_align_mem_mpeg4((void*)&enc_state->ysum_plane, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* blk_ref_buf */
align = 8;
size = SAMPLE_VIDEO_BLOCK_SQUARE_SIZE * 6;
if (alloc_align_mem_mpeg4((void*)&enc_state->blk_ref_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* blk_coef_buf */
size = SAMPLE_VIDEO_BLOCK_SQUARE_SIZE * 6 * sizeof(Ipp16s);
if (alloc_align_mem_mpeg4((void*)&enc_state->blk_coef_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* resid_buf */
if (alloc_align_mem_mpeg4((void*)&enc_state->resid_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* rec_resid_buf */
if (alloc_align_mem_mpeg4((void*)&enc_state->rec_resid_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
return SAMPLE_STATUS_NOERR;
}
/******************************************************************************
// Name: encoder_init_alloc_mpeg4
// Description: Init function for MPEG-4 baseline encoder, it initialize
// the encoder state structure and its working buffer
// according to the configuration params parsed from command
// line.
// Input Arguments:
//
//
//
// Output Arguments:
//
//
//
// Returns:
// SAMPLE_STATUS_NOERR If succeeds
// SAMPLE_STATUS_NOMEM_ERR If memory allocation fails
// SAMPLE_STATUS_ERR If stream parsing error occurs
******************************************************************************/
sample_status encoder_init_alloc_mpeg4(mp4_enc_params *enc_config,
mp4_enc_state *enc_state)
{
sample_status ret_code;
int i;
memset((void*)enc_state, 0, sizeof(mp4_enc_state));
/* initialize encoder state from the configuration params directly */
enc_state->vol_verid = enc_config->vol_verid;
enc_state->vol_display_width = enc_config->vol_width;
enc_state->vol_display_height = enc_config->vol_height;
enc_state->color_format = enc_config->color_format;
enc_state->frame_rate = enc_config->frame_rate;
enc_state->quant_type = enc_config->quant_type;
enc_state->vop_quant = (Ipp8u)(enc_config->vop_quant);
enc_state->intra_dc_thr = enc_config->intra_dc_thr;
enc_state->ivop_interval = enc_config->ivop_interval;
enc_state->search_range = enc_config->search_range;
enc_state->use_src_me = enc_config->use_src_me;
/* initialize other attributes as default settings */
enc_state->scalable = 0;
enc_state->vol_shape_type = RECTANGULAR;
enc_state->complex_est_disable = 1;
enc_state->sadct_disabled = 1;
enc_state->sprite_type = 0; /* sprite not used */
enc_state->resync_disabled = 1;
enc_state->data_patitioned = 0;
enc_state->new_pred = 0;
enc_state->reduced_resolution = 0;
enc_state->obmc_disabled = 1;
enc_state->vop_coded = 1;
enc_state->quater_sample = 0;
enc_state->rounding = 0;
enc_state->modulo_base_decd = 0;
enc_state->modulo_base_disp = 0;
enc_state->vop_indx = 0;
/* determine the vop size */
enc_state->mb_per_row = (enc_state->vol_display_width + 15)
/ SAMPLE_VIDEO_MB_SIZE;
enc_state->mb_per_col = (enc_state->vol_display_height + 15)
/ SAMPLE_VIDEO_MB_SIZE;
enc_state->frame_dimension.width = (enc_state->mb_per_row
* SAMPLE_VIDEO_MB_SIZE);
enc_state->frame_dimension.height = (enc_state->mb_per_col
* SAMPLE_VIDEO_MB_SIZE);
enc_state->frame_step_set.y_step = enc_state->frame_dimension.width
+ 2 * SAMPLE_VIDEO_MB_SIZE;
enc_state->frame_step_set.cb_step = enc_state->frame_dimension.width / 2
+ 2 * SAMPLE_VIDEO_BLOCK_SIZE;
enc_state->frame_step_set.cr_step = enc_state->frame_dimension.width / 2
+ 2 * SAMPLE_VIDEO_BLOCK_SIZE;
/* allocate working buffer for encoder */
ret_code = get_working_buffer_mpeg4(enc_state);
if (SAMPLE_STATUS_NOERR != ret_code) {
encoder_free_mpeg4(enc_state);
return ret_code;
}
/* initialize the working buffer */
/* mv_buf[i] */
for (i = 0; i < (enc_state->mb_per_row + 2) * 4; i++) {
enc_state->mv_buf[i].dx = 0;
enc_state->mv_buf[i].dy = 0;
}
/* mv_plane[i] */
for (i = -4 - 4 * (enc_state->mb_per_row + 2); i <
(enc_state->mb_per_row + 2) * (enc_state->mb_per_col) * 4 - 4; i++) {
enc_state->mv_plane[i].dx = 0;
enc_state->mv_plane[i].dy = 0;
}
if (Q_MPEG4 == enc_state->quant_type) {
/* qmatrix_intra[i] */
for (i = 0; i < SAMPLE_VIDEO_BLOCK_SQUARE_SIZE; i++) {
enc_state->qmatrix_intra[i] = (int)default_qmat_intra_tbl[i];
enc_state->qmatrix_intra[i + SAMPLE_VIDEO_BLOCK_SQUARE_SIZE]
= (int)((1 << 21) / default_qmat_intra_tbl[i] + 1);
}
enc_state->qmatrix_intra[SAMPLE_VIDEO_BLOCK_SQUARE_SIZE]
= (int)((1 << 21) / default_qmat_intra_tbl[0]);
/* qmatrix_inter[i] */
for(i = 0; i < SAMPLE_VIDEO_BLOCK_SQUARE_SIZE; i++) {
enc_state->qmatrix_inter[i] = (int)default_qmat_inter_tbl[i];
enc_state->qmatrix_inter[i + SAMPLE_VIDEO_BLOCK_SQUARE_SIZE]
= (int)((1 << 21) / default_qmat_inter_tbl[i] + 1);
}
enc_state->qmatrix_inter[SAMPLE_VIDEO_BLOCK_SQUARE_SIZE]
= (int)((1 << 21) / default_qmat_inter_tbl[0]);
}
enc_state->info_pic->pic_plane[0] = enc_state->cur_frame.y_ptr;
enc_state->info_pic->pic_plane[1] = enc_state->cur_frame.cb_ptr;
enc_state->info_pic->pic_plane[2] = enc_state->cur_frame.cr_ptr;
enc_state->info_pic->pic_plane_step[0] = enc_state->frame_step_set.y_step;
enc_state->info_pic->pic_plane_step[1] = enc_state->frame_step_set.cb_step;
enc_state->info_pic->pic_plane_step[2] = enc_state->frame_step_set.cr_step;
enc_state->info_pic->pic_plane_num = 3;
enc_state->info_pic->pic_channel_num = 3;
enc_state->info_pic->pic_format = enc_state->color_format;
enc_state->info_pic->pic_width = enc_state->vol_display_width;
enc_state->info_pic->pic_height = enc_state->vol_display_height;
return SAMPLE_STATUS_NOERR;
}
/******************************************************************************
// Name: encoder_free_mpeg4
// Desicription:
// Free working buffer of the MPEG-4 encoder
// Input Arguments:
// enc_state Pointer to the general state struct of MPEG-4 encoder
//
// Output Arguments:
// enc_state Pointer to the updated state struct of MPEG-4 encoder
//
// Returns:
// SAMPLE_STATUS_NOERR If succeeds
// Note:
//
******************************************************************************/
sample_status encoder_free_mpeg4(mp4_enc_state *enc_state)
{
/* cur_frame.y_ptr */
if (enc_state->cur_frame.y_ptr) {
enc_state->cur_frame.y_ptr -= enc_state->frame_step_set.y_step
* SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE;
free_align_mem_mpeg4((void*)&enc_state->cur_frame.y_ptr);
}
/* fwd_ref_frame.y_ptr */
if (enc_state->fwd_ref_frame.y_ptr) {
enc_state->fwd_ref_frame.y_ptr -= enc_state->frame_step_set.y_step
* SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE;
free_align_mem_mpeg4((void*)&enc_state->fwd_ref_frame.y_ptr);
}
/* fwd_ref_rec_frame.y_ptr */
if (enc_state->fwd_ref_rec_frame.y_ptr) {
enc_state->fwd_ref_rec_frame.y_ptr -= enc_state->frame_step_set.y_step
* SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE;
free_align_mem_mpeg4((void*)&enc_state->fwd_ref_rec_frame.y_ptr);
}
/* rec_frame.y_ptr */
if (enc_state->rec_frame.y_ptr) {
enc_state->rec_frame.y_ptr -= enc_state->frame_step_set.y_step
* SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE;
free_align_mem_mpeg4((void*)&enc_state->rec_frame.y_ptr);
}
/* cur_frame.cb_ptr */
if (enc_state->cur_frame.cb_ptr) {
enc_state->cur_frame.cb_ptr -= enc_state->frame_step_set.cb_step
* SAMPLE_VIDEO_MB_SIZE / 2 + SAMPLE_VIDEO_MB_SIZE / 2;
free_align_mem_mpeg4((void*)&enc_state->cur_frame.cb_ptr);
}
/* fwd_ref_frame.cb_ptr */
if (enc_state->fwd_ref_frame.cb_ptr) {
enc_state->fwd_ref_frame.cb_ptr -= enc_state->frame_step_set.cb_step
* SAMPLE_VIDEO_MB_SIZE / 2 + SAMPLE_VIDEO_MB_SIZE / 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -