📄 mp4dvops.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: VOP or frame decoding functions of MPEG-4 video decoder// sample code for Intel(R) Integrated Performance Primitives.// Functions List:// decode_pvop_mpeg4()// decode_ivop_mpeg4()// decode_mpeg4()******************************************************************************/#include "sampmp4.h"/******************************************************************************// Name: decode_pvop_mpeg4// Desicription:// Decode the PVOP data in non-ER mode//// Input Arguments:// stream_buf - Pointer to the source video bitstream // dec_state - Pointer to the general state struct of MPEG-4 decoder// vop_infor - Pointer to the vop information struct of MPEG-4 decoder//// Output Arguments:// stream_buf - Pointer to the updated video bitstream//// dec_state - Pointer to the updated general state struct of MPEG-4// decoder// vop_infor - Pointer to the updated vop information struct of MPEG-4// decoder//// Returns:// SAMPLE_STATUS_NOERR If succeeds// SAMPLE_STATUS_ERR If decoding fails// Note:// ******************************************************************************/sample_status decode_pvop_mpeg4(sample_bitstream *stream_buf, mp4_dec_state *dec_state, mp4_dec_vop_infor *vop_infor){ int mbx_indx = 0; int mby_indx = 0; int i = 0; sample_status ret_code; /* init vop information each time before frame decoding */ init_vop_infor_dec_mpeg4(dec_state, vop_infor); /* loop for each column */ for (mby_indx = 0; mby_indx < dec_state->mb_per_col; mby_indx ++) { /* loop for each row */ for (mbx_indx = 0; mbx_indx < dec_state->mb_per_row; mbx_indx ++) { /* decode the MacroBlock */ ret_code = decode_mb_pvop_mpeg4(stream_buf, dec_state, vop_infor, mbx_indx, mby_indx); if (ret_code != SAMPLE_STATUS_NOERR) { return ret_code; } vop_infor->mb_indx ++; vop_infor->cur_mb.y_ptr += SAMPLE_VIDEO_MB_SIZE; vop_infor->cur_mb.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->cur_mb.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->fwd_ref_mb.y_ptr += SAMPLE_VIDEO_MB_SIZE; vop_infor->fwd_ref_mb.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->fwd_ref_mb.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->coef_buf_row.y_ptr += SAMPLE_VIDEO_MB_SIZE; vop_infor->coef_buf_row.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->coef_buf_row.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE; /* update tranp_buf ptr */ vop_infor->tranp_buf += 4; if (0 == mby_indx) { for (i = 0; i < 4; i++){ vop_infor->tranp_buf[i] = IPP_VIDEO_OPAQUE; } } /* update qp_buf ptr */ vop_infor->qp_buf++; vop_infor->qp_buf[0] = vop_infor->cur_qp; } /* position the 1st MB in the next row of the VOP */ vop_infor->cur_mb.y_ptr += dec_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_MB_SIZE; vop_infor->cur_mb.cb_ptr += dec_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->cur_mb.cr_ptr += dec_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_BLOCK_SIZE; /* position the 1st ref MB in the next row of the ref VOP */ vop_infor->fwd_ref_mb.y_ptr += dec_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_MB_SIZE; vop_infor->fwd_ref_mb.cb_ptr += dec_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->fwd_ref_mb.cr_ptr += dec_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_BLOCK_SIZE; /* update dc coefficient of the 4th block in the last MB per row */ vop_infor->coef_buf_row.y_ptr[-8] = vop_infor->coef_buf_col.y_ptr[8]; /* restore ac/dc prediction coefficient row buffer ptrs */ vop_infor->coef_buf_row.y_ptr = dec_state->coef_buf_row.y_ptr + SAMPLE_VIDEO_MB_SIZE; vop_infor->coef_buf_row.cb_ptr = dec_state->coef_buf_row.cb_ptr + SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->coef_buf_row.cr_ptr = dec_state->coef_buf_row.cr_ptr + SAMPLE_VIDEO_BLOCK_SIZE; /* restore the dc coefficient on the left border */ vop_infor->coef_buf_col.y_ptr[0] = -1; vop_infor->coef_buf_col.y_ptr[8] = -1; vop_infor->coef_buf_col.cb_ptr[0] = -1; vop_infor->coef_buf_col.cr_ptr[0] = -1; /* restore qp_buf ptr */ vop_infor->qp_buf = dec_state->qp_buf; vop_infor->qp_buf[0] = dec_state->qp_buf[dec_state->mb_per_row]; /* restore mv_buf ptr */ vop_infor->mv_buf = dec_state->mv_buf; /* restore tranp_buf ptr */ vop_infor->tranp_buf = dec_state->tranp_buf; } return SAMPLE_STATUS_NOERR; }/******************************************************************************// Name: decode_ivop_mpeg4// Desicription:// Decode the IVOP data in non-ER mode//// Input Arguments:// stream_buf - Pointer to the source video bitstream // dec_state - Pointer to the general state struct of MPEG-4 decoder// vop_infor - Pointer to the vop information struct of MPEG-4 decoder//// Output Arguments:// stream_buf - Pointer to the updated video bitstream//// dec_state - Pointer to the updated general state struct of MPEG-4// decoder// vop_infor - Pointer to the updated vop information struct of MPEG-4// decoder//// Returns:// SAMPLE_STATUS_NOERR If succeeds// SAMPLE_STATUS_ERR If decoding fails// Note:// ******************************************************************************/sample_status decode_ivop_mpeg4(sample_bitstream *stream_buf, mp4_dec_state *dec_state, mp4_dec_vop_infor *vop_infor){ sample_status ret_code; int mbx_indx = 0; int mby_indx = 0; /* init vop information each time before frame decoding */ init_vop_infor_dec_mpeg4(dec_state, vop_infor); /* loop for each column */ for (mby_indx = 0; mby_indx < dec_state->mb_per_col; mby_indx ++) { /* loop for each row */ for (mbx_indx = 0; mbx_indx < dec_state->mb_per_row; mbx_indx++) { /* decode the MacroBlock */ ret_code = decode_mb_ivop_mpeg4(stream_buf, dec_state, vop_infor); if (SAMPLE_STATUS_NOERR != ret_code) { return ret_code; } vop_infor->mb_indx++; vop_infor->cur_mb.y_ptr += SAMPLE_VIDEO_MB_SIZE; vop_infor->cur_mb.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->cur_mb.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->coef_buf_row.y_ptr += SAMPLE_VIDEO_MB_SIZE; vop_infor->coef_buf_row.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->coef_buf_row.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE; /* update qp_buf ptr */ vop_infor->qp_buf++; vop_infor->qp_buf[0] = vop_infor->cur_qp; } /* position the 1st MB in the next row of the VOP */ vop_infor->cur_mb.y_ptr += dec_state->frame_step_set.y_step * SAMPLE_VIDEO_MB_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_MB_SIZE; vop_infor->cur_mb.cb_ptr += dec_state->frame_step_set.cb_step * SAMPLE_VIDEO_BLOCK_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->cur_mb.cr_ptr += dec_state->frame_step_set.cr_step * SAMPLE_VIDEO_BLOCK_SIZE - dec_state->mb_per_row * SAMPLE_VIDEO_BLOCK_SIZE; /* update dc coefficient of the 4th block in the last MB each row */ vop_infor->coef_buf_row.y_ptr[-8] = vop_infor->coef_buf_col.y_ptr[8]; /* restore ac/dc prediction coefficient row buffer ptrs */ vop_infor->coef_buf_row.y_ptr = dec_state->coef_buf_row.y_ptr + SAMPLE_VIDEO_MB_SIZE; vop_infor->coef_buf_row.cb_ptr = dec_state->coef_buf_row.cb_ptr + SAMPLE_VIDEO_BLOCK_SIZE; vop_infor->coef_buf_row.cr_ptr = dec_state->coef_buf_row.cr_ptr + SAMPLE_VIDEO_BLOCK_SIZE; /* restore the dc coefficient on the left border */ vop_infor->coef_buf_col.y_ptr[0] = -1; vop_infor->coef_buf_col.y_ptr[8] = -1; vop_infor->coef_buf_col.cb_ptr[0] = -1; vop_infor->coef_buf_col.cr_ptr[0] = -1; /* restore qp_buf ptr */ vop_infor->qp_buf = dec_state->qp_buf; vop_infor->qp_buf[0] = dec_state->qp_buf[dec_state->mb_per_row]; } return SAMPLE_STATUS_NOERR; }/******************************************************************************// Name: decode_mpeg4// Description: Frame decoding function for MPEG-4 simple profile decoder,// it includes preprocess for preparing VOP decoding,// VOP decoding and postprocess for preparing output//// Input Arguments: // stream_buf Pointer to the source compressed video bitstream// dec_state Pointer to the general state struct of MPEG-4 decoder//// Output Arguments:// stream_buf Pointer to the updated video bitstream// dec_state Pointer to the updated general state struct of MPEG-4// decoder.//// Returns: // SAMPLE_STATUS_NOERR If succeeds// SAMPLE_STATUS_ERR If decoding fails// SAMPLE_STATUS_SYNCNOTFOUND_ERR If cannot find next sync code// SAMPLE_STATUS_NOTSUPPORTED_ERR If stream syntax is not supported by// current sample decoder******************************************************************************/sample_status decode_mpeg4(sample_bitstream *stream_buf, sample_picture *picture, mp4_dec_state *dec_state){ mp4_dec_vop_infor vop_infor; sample_status ret_code; Ipp32u code; Ipp8u* next_sync_pos = NULL; int i; /* seek the next_start_code to ensure the current object has been resident // in the buffer completely */ ret_code = search_next_sc_mpeg4(stream_buf, &next_sync_pos); if (SAMPLE_STATUS_NOERR != ret_code) { return ret_code; } /* identify the type of the current sync code */ code = get_bits_mpeg4(stream_buf, 8); /* seek until vop_start_code is found */ while (MPEG4_SUFFIX_VOPSC != code) { /* group_of_vop_start_code */ if (MPEG4_SUFFIX_GOVSC == code) { /* process gov data here */ parse_gov_mpeg4(stream_buf, dec_state); } else if (MPEG4_SUFFIX_UDSC == code) { /* user_data_start_code */ /* process user defined data here */ } /* go on with the next object */ stream_buf->bs_cur_bitoffset = 0; stream_buf->bs_cur_byte = next_sync_pos; ret_code = search_next_sc_mpeg4(stream_buf, &next_sync_pos); if (SAMPLE_STATUS_NOERR != ret_code) { return ret_code; } code = get_bits_mpeg4(stream_buf, 8); } /* parse vop header information */ ret_code = parse_vop_header_mpeg4(stream_buf, dec_state, &vop_infor); if (SAMPLE_STATUS_NOERR != ret_code) { return ret_code; } /* if vop coded */ if (dec_state->vop_coded) { dec_state->info_pic->pic_plane[0] = dec_state->cur_frame.y_ptr; dec_state->info_pic->pic_plane[1] = dec_state->cur_frame.cb_ptr; dec_state->info_pic->pic_plane[2] = dec_state->cur_frame.cr_ptr; if ((PVOP == dec_state->vop_coding_type) && (0 != dec_state->vop_indx)) { /* expand reference frame for unrestricted motion compensation */ expand_frame_dec_mpeg4 (dec_state); } switch(dec_state->vop_coding_type) { case IVOP: ret_code = decode_ivop_mpeg4(stream_buf, dec_state, &vop_infor); if (SAMPLE_STATUS_NOERR != ret_code) { stream_buf->bs_cur_bitoffset = 0; stream_buf->bs_cur_byte = next_sync_pos; return ret_code; } break; case PVOP: ret_code = decode_pvop_mpeg4(stream_buf, dec_state, &vop_infor); if (SAMPLE_STATUS_NOERR != ret_code) { stream_buf->bs_cur_bitoffset = 0; stream_buf->bs_cur_byte = next_sync_pos; return ret_code; } break; default: stream_buf->bs_cur_bitoffset = 0; stream_buf->bs_cur_byte = next_sync_pos; return SAMPLE_STATUS_NOTSUPPORTED_ERR; } set_ref_frame_dec_mpeg4(dec_state); } else { /* vop not coded */ /* directly copy the previous reference picture plane */ dec_state->info_pic->pic_plane[0] = dec_state->fwd_ref_frame.y_ptr; dec_state->info_pic->pic_plane[1] = dec_state->fwd_ref_frame.cb_ptr; dec_state->info_pic->pic_plane[2] = dec_state->fwd_ref_frame.cr_ptr; } /* copy to output picture struct */ picture->pic_plane_num = dec_state->info_pic->pic_plane_num; picture->pic_channel_num = dec_state->info_pic->pic_channel_num; picture->pic_height = dec_state->info_pic->pic_height; picture->pic_width = dec_state->info_pic->pic_width; picture->pic_format = dec_state->info_pic->pic_format; for ( i = 0; i < SAMPLE_MAXPLANENUM; i++ ) { picture->pic_plane[i] = dec_state->info_pic->pic_plane[i]; picture->pic_plane_step[i] = dec_state->info_pic->pic_plane_step[i]; } dec_state->vop_indx ++; stream_buf->bs_cur_bitoffset = 0; stream_buf->bs_cur_byte = next_sync_pos; return SAMPLE_STATUS_NOERR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -