📄 h263dec.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:
// Intel(R) Integrated Performance Primitives Sample Code H263 Decoder
//
// Function List:
// decode_h263()
//
******************************************************************************/
#include "samph263.h"
/******************************************************************************
// Function Name: decode_h263
//
// Description: Decode one picture from h263 stream. This function does
// the following things:
// 1) Seek next PSC code to check if current picture is
// complete (Last picture is excluded from this step).
// 2) Parse picture header and set h263_dec_state members.
// 3) Decode one picture according to its coding type.
// 4) Point the output picture pointer to current picture.
// 5) Switch current picture and reference picture pointer.
//
// Parameter:
// Input:
// stream: Pointer to sample_bitstream structure holding input stream
// state: Pointer to h263_dec_state structure holding decode status
// Output:
// stream: Pointer to sample_bitstream structure holding input stream
// Stream position pointer is updated to next available byte
// state: Pointer to h263_dec_state structure holding decode status
// out_picture: Pointer to sample_picture structure of output picture.
//
// Return:
// sample_status:
// [SAMPLE_STATUS_NOERR]: Succeeds
// [SAMPLE_STATUS_SYNCNOTFOUND_ERR]: Cannot find next sync code
// [SAMPLE_STATUS_BITSTREAM_ERR]: Stream parseing error occurs
// [SAMPLE_STATUS_NOTSUPPORTED_ERR]: Stream syntax is not supported by
// current sample decoder
// [SAMPLE_STATUS_ERR]: Other error occurs during decoding
//
// Notes: None
******************************************************************************/
sample_status decode_h263(sample_bitstream *stream,
h263_dec_state *state,
sample_picture **out_picture)
{
sample_status ret;
sample_picture *temp_pic;
int j;
int ref_y_step = state->ref_picture->pic_plane_step[0];
int ref_cb_step= state->ref_picture->pic_plane_step[1];
int ref_cr_step= state->ref_picture->pic_plane_step[2];
int cur_y_step = state->cur_picture->pic_plane_step[0];
int cur_cb_step= state->cur_picture->pic_plane_step[1];
int cur_cr_step= state->cur_picture->pic_plane_step[2];
/************************************************
// If it's not last picture, seek next sync code
// to ensure it's a complete picture
*************************************************/
if(!state->is_last_picture &&
!seek_next_sync_code_h263(stream, H263_STREAM_PSC,
H263_STREAM_PSC_LEN, 1,1, 0)) {
return SAMPLE_STATUS_SYNCNOTFOUND_ERR;
}
/************************************************
// Parse picture headers
*************************************************/
if(state->picture_index) {
ret = parse_picture_header_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
}
/************************************************
// Initialize decoder state variables
*************************************************/
state->mb_index = 0;
state->cur_gob.y_ptr = state->cur_picture->pic_plane[0];
state->cur_gob.cb_ptr = state->cur_picture->pic_plane[1];
state->cur_gob.cr_ptr = state->cur_picture->pic_plane[2];
state->ref_gob.y_ptr = state->ref_picture->pic_plane[0];
state->ref_gob.cb_ptr = state->ref_picture->pic_plane[1];
state->ref_gob.cr_ptr = state->ref_picture->pic_plane[2];
state->quant = state->pquant;
/*************************************************
// Decode pictures
*************************************************/
if(H263_I_PICTURE == state->coding_type) {
/******************************
// I Picture
*******************************/
/* First GOB in picture has no GOB header */
ret = decode_gob_ipic_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
for (j=1; j<state->gob_per_picture; j++) {
state->cur_gob.y_ptr += 16 * cur_y_step;
state->cur_gob.cb_ptr += 8 * cur_cb_step;
state->cur_gob.cr_ptr += 8 * cur_cr_step;
/* GOB header doesn't always exist, parse if any */
if(seek_next_sync_code_h263(stream,
H263_STREAM_GBSC,
H263_STREAM_GBSC_LEN,
0, 0, 1)) {
ret = parse_gob_header_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
}
/* Decode one GOB in I picture */
ret = decode_gob_ipic_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
}
} else { /* Coding Type = INTER */
/******************************
// P Picture
*******************************/
/* First GOB in picture has no GOB header */
ret = decode_gob_ppic_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
for (j=1;j<state->gob_per_picture;j++) {
/* Update GOB pointers */
state->cur_gob.y_ptr += SAMPLE_VIDEO_MB_SIZE * cur_y_step;
state->cur_gob.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE * cur_cb_step;
state->cur_gob.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE * cur_cr_step;
state->ref_gob.y_ptr += SAMPLE_VIDEO_MB_SIZE * ref_y_step;
state->ref_gob.cb_ptr += SAMPLE_VIDEO_BLOCK_SIZE * ref_cb_step;
state->ref_gob.cr_ptr += SAMPLE_VIDEO_BLOCK_SIZE * ref_cr_step;
/* GOB header doesn't always exist, parse if any */
state->gob_has_header = 0;
if(seek_next_sync_code_h263(stream,
H263_STREAM_GBSC,
H263_STREAM_GBSC_LEN,
0, 0, 1)) {
state->gob_has_header = 1;
ret = parse_gob_header_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
}
/* Decode one GOB in P Picture */
ret = decode_gob_ppic_h263(stream, state);
if(SAMPLE_STATUS_NOERR != ret) {
return ret;
}
} /* for */
} /* else */
/* Output Picture */
*out_picture = state->cur_picture;
/* Switch Reference/Current Picture */
temp_pic = state->cur_picture;
state->cur_picture = state->ref_picture;
state->ref_picture = temp_pic;
/* Update picture index */
state->picture_index ++;
return SAMPLE_STATUS_NOERR;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -