📄 mp4einit.c
字号:
/******************************************************************************// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2003 Intel Corporation. All Rights Reserved.//// Description: Encoder initialization functions of MPEG-4 video encoder// sample code for Intel(R) Integrated Performance Primitives.// Functions List:// alloc_align_mem_mpeg4()// free_align_mem_mpeg4()// get_working_buffer_mpeg4()// encoder_init_alloc_mpeg4()// encoder_free_mpeg4()// init_vop_infor_enc_mpeg4()******************************************************************************/#include <malloc.h>#include <memory.h>#include "sampmp4.h"/******************************************************************************// Name: free_align_mem_mpeg4// Description: Free aligned memory blocks//// Input Arguments:// buf_addr_ptr Pointer to the void pointer to the allocated space// with alignment offset.//// Output Arguments:// buf_addr_ptr Pointer to a NULL void pointer//// Returns:// SAMPLE_STATUS_NOERR If succeeds******************************************************************************/sample_status free_align_mem_mpeg4(void **buf_addr_ptr) { Ipp8u offset = 0; Ipp8u *addr = NULL; addr = (Ipp8u*)(*buf_addr_ptr); offset = *(addr - 1); addr -= offset; free((void*)addr); *buf_addr_ptr = NULL; return SAMPLE_STATUS_NOERR;}/******************************************************************************// Name: alloc_align_mem_mpeg4// Description: Allocate aligned memory blocks//// Input Arguments:// buf_addr_ptr Pointer to the void pointer to the allocated space// size Number of bytes to be allocated// alignstatus Number of bytes to be aligned, e.g., 2 for half// word aligned, 4 for word aligned, 8 for double word// aligned//// Output Arguments:// buf_addr_ptr Pointer to the void pointer to the allocated space//// Returns:// SAMPLE_STATUS_NOERR If succeeds// SAMPLE_STATUS_NOMEM_ERR If memory allocation fails******************************************************************************/sample_status alloc_align_mem_mpeg4(void **buf_addr_ptr, int size, int alignstatus){ Ipp8u *addr = NULL; Ipp8u tmp = 0; size += alignstatus; addr = malloc(size); if (!addr) { *buf_addr_ptr = NULL; return SAMPLE_STATUS_NOMEM_ERR; } tmp = (Ipp8u)((Ipp32u)(addr) & (alignstatus - 1)); tmp = (Ipp8u)(alignstatus - tmp); addr += tmp; *(addr - 1) = tmp; *buf_addr_ptr = (void*)addr; return SAMPLE_STATUS_NOERR;}/******************************************************************************// Name: get_working_buffer_mpeg4// Description: Allocate working buffer for MPEG4 encoder//// Input Arguments:// enc_state Pointer to the general state structure of MPEG-4 encoder//// Output Arguments:// enc_state Pointer to the updated general state structure of MPEG-4// encoder//// Returns:// SAMPLE_STATUS_NOERR If succeeds// SAMPLE_STATUS_NOMEM_ERR If memory allocation fails******************************************************************************/sample_status get_working_buffer_mpeg4(mp4_enc_state *enc_state){ int size = 0, align = 0; /* cur_frame.y_ptr */ align = 8; size = (enc_state->frame_dimension.width + SAMPLE_VIDEO_MB_SIZE * 2) * (enc_state->frame_dimension.height + SAMPLE_VIDEO_MB_SIZE * 2); if (alloc_align_mem_mpeg4((void*)&enc_state->cur_frame.y_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->cur_frame.y_ptr += enc_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE; /* fwd_ref_frame.y_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->fwd_ref_frame.y_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->fwd_ref_frame.y_ptr += enc_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE; /* fwd_ref_rec_frame.y_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->fwd_ref_rec_frame.y_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->fwd_ref_rec_frame.y_ptr += enc_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE; /* rec_frame.y_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->rec_frame.y_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->rec_frame.y_ptr += enc_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE + SAMPLE_VIDEO_MB_SIZE; /* cur_frame.cb_ptr */ size = size / 4; if (alloc_align_mem_mpeg4((void*)&enc_state->cur_frame.cb_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->cur_frame.cb_ptr += enc_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* fwd_ref_frame.cb_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->fwd_ref_frame.cb_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->fwd_ref_frame.cb_ptr += enc_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* fwd_ref_rec_frame.cb_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->fwd_ref_rec_frame.cb_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->fwd_ref_rec_frame.cb_ptr += enc_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* rec_frame.cb_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->rec_frame.cb_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->rec_frame.cb_ptr += enc_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* cur_frame.cr_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->cur_frame.cr_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->cur_frame.cr_ptr += enc_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* fwd_ref_frame.cr_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->fwd_ref_frame.cr_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->fwd_ref_frame.cr_ptr += enc_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* fwd_ref_rec_frame.cr_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->fwd_ref_rec_frame.cr_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->fwd_ref_rec_frame.cr_ptr += enc_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* rec_frame.cr_ptr */ if (alloc_align_mem_mpeg4((void*)&enc_state->rec_frame.cr_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } enc_state->rec_frame.cr_ptr += enc_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE + SAMPLE_VIDEO_BLOCK_SIZE; /* coef_buf_row.y_ptr */ align = 4; size = (enc_state->mb_per_row + 1) * SAMPLE_VIDEO_MB_SIZE * sizeof(short); if (alloc_align_mem_mpeg4((void*)&enc_state->coef_buf_row.y_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* coef_buf_col.y_ptr */ size = SAMPLE_VIDEO_MB_SIZE * sizeof(short); if (alloc_align_mem_mpeg4((void*)&enc_state->coef_buf_col.y_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* coef_buf_row.cb_ptr */ size = (enc_state->mb_per_row + 1) * SAMPLE_VIDEO_BLOCK_SIZE * sizeof(short); if (alloc_align_mem_mpeg4((void*)&enc_state->coef_buf_row.cb_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* coef_buf_col.cb_ptr */ size = (SAMPLE_VIDEO_BLOCK_SIZE) * sizeof(short); if (alloc_align_mem_mpeg4((void*)&enc_state->coef_buf_col.cb_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* coef_buf_row.cr_ptr */ size = (enc_state->mb_per_row + 1) * SAMPLE_VIDEO_BLOCK_SIZE * sizeof(short); if (alloc_align_mem_mpeg4((void*)&enc_state->coef_buf_row.cr_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* coef_buf_col.cr_ptr */ size = (SAMPLE_VIDEO_BLOCK_SIZE) * sizeof(short); if (alloc_align_mem_mpeg4((void*)&enc_state->coef_buf_col.cr_ptr, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* mv_buf */ align = 4; size = (enc_state->mb_per_row + 2) * 4 * sizeof(IppMotionVector); if (alloc_align_mem_mpeg4((void*)&enc_state->mv_buf, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* tranp_buf */ size = (enc_state->mb_per_row + 2) * 4; if (alloc_align_mem_mpeg4((void*)&enc_state->tranp_buf, size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* qp_buf */ 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -