📄 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -