📄 mp4dinit.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: Decoder initialization functions of MPEG-4 video decoder
// sample code for Intel(R) Integrated Performance Primitives.
// Functions List:
// free_align_mem_mpeg4()
// alloc_align_mem_mpeg4()
// get_working_buffer_mpeg4()
// decoder_init_alloc_mpeg4()
// decoder_free_mpeg4()
// init_vop_infor_dec_mpeg4()
******************************************************************************/
#include <stdlib.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 decoder
//
// Input Arguments:
// dec_state Pointer to the general state structure of MPEG-4 decoder
//
// Output Arguments:
// dec_state Pointer to the updated general state structure of MPEG-4
// decoder
//
// Returns:
// SAMPLE_STATUS_NOERR If succeeds
// SAMPLE_STATUS_NOMEM_ERR If memory allocation fails
******************************************************************************/
sample_status get_working_buffer_mpeg4 (mp4_dec_state *dec_state)
{
int size = 0, align = 0;
/* cur_frame.y_ptr */
align = 8;
size = (dec_state->frame_dimension.width + SAMPLE_VIDEO_MB_SIZE * 2)
* (dec_state->frame_dimension.height + SAMPLE_VIDEO_MB_SIZE * 2);
if (alloc_align_mem_mpeg4((void*)&dec_state->cur_frame.y_ptr, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
dec_state->cur_frame.y_ptr += dec_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*)&dec_state->fwd_ref_frame.y_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
dec_state->fwd_ref_frame.y_ptr += dec_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*)&dec_state->cur_frame.cb_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
dec_state->cur_frame.cb_ptr += dec_state->frame_step_set.cb_step
* SAMPLE_VIDEO_MB_SIZE / 2 + SAMPLE_VIDEO_MB_SIZE / 2;
/* fwd_ref_frame.cb_ptr */
if (alloc_align_mem_mpeg4((void*)&dec_state->fwd_ref_frame.cb_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
dec_state->fwd_ref_frame.cb_ptr += dec_state->frame_step_set.cb_step
* SAMPLE_VIDEO_MB_SIZE / 2 +SAMPLE_VIDEO_MB_SIZE / 2;
/* cur_frame.cr_ptr */
if (alloc_align_mem_mpeg4((void*)&dec_state->cur_frame.cr_ptr, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
dec_state->cur_frame.cr_ptr += dec_state->frame_step_set.cr_step
* SAMPLE_VIDEO_MB_SIZE / 2 + SAMPLE_VIDEO_MB_SIZE / 2;
/* fwd_ref_frame.cr_ptr */
if (alloc_align_mem_mpeg4((void*)&dec_state->fwd_ref_frame.cr_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
dec_state->fwd_ref_frame.cr_ptr += dec_state->frame_step_set.cr_step
* SAMPLE_VIDEO_MB_SIZE / 2 + SAMPLE_VIDEO_MB_SIZE / 2;
/* coef_buf_row.y_ptr */
align = 4;
size = (dec_state->mb_per_row + 1) * sizeof(short) * SAMPLE_VIDEO_MB_SIZE;
if (alloc_align_mem_mpeg4((void*)&dec_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*)&dec_state->coef_buf_col.y_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* coef_buf_row.cb_ptr */
size = (dec_state->mb_per_row + 1) * sizeof(short) * SAMPLE_VIDEO_MB_SIZE
/ 2;
if (alloc_align_mem_mpeg4((void*)&dec_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*)&dec_state->coef_buf_col.cb_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* coef_buf_row.cr_ptr */
size = (dec_state->mb_per_row + 1) * sizeof(short) * SAMPLE_VIDEO_MB_SIZE
/ 2;
if (alloc_align_mem_mpeg4((void*)&dec_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*)&dec_state->coef_buf_col.cr_ptr, size,
align) != SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* mv_buf */
align = 4;
size = (dec_state->mb_per_row + 2) * 4 * sizeof(IppMotionVector);
if (alloc_align_mem_mpeg4((void*)&dec_state->mv_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* tranp_buf */
size = (dec_state->mb_per_row + 2) * 4;
if (alloc_align_mem_mpeg4((void*)&dec_state->tranp_buf, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
/* qp_buf */
align = 8;
size = dec_state->mb_per_row + 1;
if (alloc_align_mem_mpeg4((void*)&dec_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*)&dec_state->info_pic, size, align)
!= SAMPLE_STATUS_NOERR) {
return SAMPLE_STATUS_NOMEM_ERR;
}
return SAMPLE_STATUS_NOERR;
}
/******************************************************************************
// Name: decoder_init_alloc_mpeg4
// Description: Init function for MPEG-4 simple profile decoder, it parses
// the stream vo and vol header information, initialize the
// decoder state structure and its working buffer, it also
// locates the position of first vop synchronization code
// Input Arguments:
// stream_buf Pointer to the source compressed video bitstream
// dec_state Pointer to the general state structure of MPEG-4 decoder.
//
// Output Arguments:
// stream_buf Pointer to the updated video stream
// dec_state Pointer to the updated state structure of MPEG-4 decoder.
//
// Returns:
// SAMPLE_STATUS_NOERR If succeeds
// SAMPLE_STATUS_NOMEM_ERR If memory allocation fails
// SAMPLE_STATUS_ERR If stream parsing error occurs
// SAMPLE_STATUS_SYNCNOTFOUND_ERR If cannot find sync code
// SAMPLE_STATUS_NOTSUPPORTED_ERR If stream syntax is not supported by
// current sample decoder
******************************************************************************/
sample_status decoder_init_alloc_mpeg4(sample_bitstream *stream_buf,
mp4_dec_state *dec_state)
{
Ipp8u* next_sc_pos = NULL;
sample_status ret_code;
/* reset all the state members to zero */
memset((void*)dec_state, 0, sizeof(mp4_dec_state));
/* parse vo and vol information from bitstream */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -