⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h263init.c

📁 基于intel ipp的h263_decoder
💻 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:
//    decoder_init_alloc_h263()
//
******************************************************************************/
#include "samph263.h"

#include <stdlib.h>
#include <string.h>

/******************************************************************************
// Function Name:   decoder_state_init_h263
//
// Description:     Initialize decoder state variables
//
// Parameter:
// Input:
//         state:   Pointer to h263_dec_state structure holding decode status
// Output:
//         state:   Pointer to h263_dec_state structure holding decode status
//
// Return:
// sample_status:   
//  [SAMPLE_STATUS_NOERR]:            Succeeds
//  [SAMPLE_STATUS_NOTSUPPORTED_ERR]: Stream syntax is not supported by 
//									  current sample decoder
//
// Notes:   None
******************************************************************************/
static sample_status decoder_state_init_h263(h263_dec_state *state)
{
	sample_picture *cur_pic = state->cur_picture;
	sample_picture *ref_pic = state->ref_picture;
	
    /* Source Format */
    switch (state->source_format) {
        case H263_SOURCE_SUBQCIF:
            cur_pic->pic_width  	=  128;
            cur_pic->pic_height 	=  96;
            state->mb_per_row       =  8;
            state->gob_per_picture  =  6;
            break;

        case H263_SOURCE_QCIF:
            cur_pic->pic_width  	=  176;
            cur_pic->pic_height 	=  144;
            state->mb_per_row       =  11;
            state->gob_per_picture  =  9;
            break;
            
        case H263_SOURCE_CIF:
            cur_pic->pic_width  	=  352;
            cur_pic->pic_height 	=  288;
            state->mb_per_row       =  22;
            state->gob_per_picture  =  18;
            break;

        default:
            cur_pic->pic_width  	=  -1;
            cur_pic->pic_height 	=  -1;
            state->mb_per_row       =  0;
            state->gob_per_picture  =  0;
            return SAMPLE_STATUS_NOTSUPPORTED_ERR;
    }

    /* Initialize current picture structure */
    cur_pic->pic_format        = SAMPLE_YCbCr411;
    cur_pic->pic_plane_num     = 3;
    cur_pic->pic_channel_num   = 3;
    cur_pic->pic_plane_step[0] = cur_pic->pic_width;
    cur_pic->pic_plane_step[1] = (cur_pic->pic_width >> 1);
    cur_pic->pic_plane_step[2] = (cur_pic->pic_width >> 1);

    /* Initialize reference picture structure */
    ref_pic->pic_format        = SAMPLE_YCbCr411;
    ref_pic->pic_plane_num     = 3;
    ref_pic->pic_channel_num   = 3;
    ref_pic->pic_plane_step[0] = cur_pic->pic_plane_step[0];
    ref_pic->pic_plane_step[1] = cur_pic->pic_plane_step[1];
    ref_pic->pic_plane_step[2] = cur_pic->pic_plane_step[2];
    ref_pic->pic_width         = cur_pic->pic_width ;
    ref_pic->pic_height        = cur_pic->pic_height ;
    
    /* Default Rounding is off */
    state->rounding_type = 0;

    /* Initialize picture index */
    state->picture_index   = 0;

    /* Initialize last frame indicator */
    state->is_last_picture = 0;

    return SAMPLE_STATUS_NOERR;
}

/******************************************************************************
// Function Name:   cal_bufsize_h263
//
// Description:     calculate work buffer size according to decoder state.
//                  Work buffer includes:
//                  1) Buffer for motion vectors
//                  2) Buffer for Y,Cb,Cr planes
//
// Parameter:
// Input:
//         state:   Pointer to h263_dec_state structure holding decode status
// Output:
//          size:   Pointer to an integer of caculated work buffer size
//
// Return:  None
//
// Notes:   None
******************************************************************************/
static void cal_bufsize_h263(h263_dec_state *state, int *size)
{
	sample_picture *cur_pic = state->cur_picture;
	sample_picture *ref_pic = state->ref_picture;

    /* MV Buffer */
    *size = MV_BUFSIZE(state->mb_per_row)+8;
    
    /* Current Picture Y, Cb, Cr Buffer */
    *size += YPLANE_BUFSIZE (cur_pic)+8;
    *size += CBPLANE_BUFSIZE(cur_pic)+8;
    *size += CRPLANE_BUFSIZE(cur_pic)+8;

    /* Reference Picture Y, Cb, Cr Buffer */
    *size += YPLANE_BUFSIZE (ref_pic)+8;
    *size += CBPLANE_BUFSIZE(ref_pic)+8;
    *size += CRPLANE_BUFSIZE(ref_pic)+8;

}

/******************************************************************************
// Function Name:   decoder_init_alloc_h263
//
// Description:     Initialize decoder state and allocate work buffer.
//                  This function does the following steps:
//                  1) Parse picture header and initialize state members.
//                  2) Caculate neccessary work buffer size and allocate buffer
//                  3) Seperate the whole work buffer into several parts and
//                     initialize the pointers.
//                  4) Zero the motion vectors on the border
//
// 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
//
// Return:
// sample_status:   
//  [SAMPLE_STATUS_NOERR]:            If succeed
//  [SAMPLE_STATUS_SYNCNOTFOUND_ERR]: If cannot find next sync code
//  [SAMPLE_STATUS_BITSTREAM_ERR]:    If stream parsing error occurs
//  [SAMPLE_STATUS_NOTSUPPORTED_ERR]: If stream syntax is not supported by 
//                                    current sample decoder
//  [SAMPLE_STATUS_ERR]:              Other error occurs during decoding
//
// Notes:   None
******************************************************************************/
sample_status decoder_init_alloc_h263(sample_bitstream  *stream,  
                                      h263_dec_state    *state)
{
    sample_status  ret;
    int            bufsize;
    Ipp8u          *work_buf;
	sample_picture *cur_pic = state->cur_picture;
	sample_picture *ref_pic = state->ref_picture;


    /******************************************************
    // Parse Picture Header
    ******************************************************/
    ret = parse_picture_header_h263(stream, state);
    if(SAMPLE_STATUS_NOERR != ret) {
        return ret;
    }

    /******************************************************
    // Init Decoder State Members
    ******************************************************/
    ret = decoder_state_init_h263(state);
    if(SAMPLE_STATUS_NOERR != ret) {
        return ret;
    }

    /******************************************************
    // Calculate Buffer Size
    ******************************************************/
    cal_bufsize_h263(state, &bufsize);

    /******************************************************
    // Allocate working buffer
    ******************************************************/
    state->work_buf = (Ipp8u*)malloc(bufsize);
    if(NULL == state->work_buf) {
        return SAMPLE_STATUS_NOMEM_ERR;
    }
    work_buf = state->work_buf;

    /******************************************************
    // Init buffer pointer and decoder state 
    ******************************************************/
    /* MV Buffer */
    state->mv_buffer = (IppMotionVector *)SAMPLE_ALIGN8(work_buf);
    work_buf += MV_BUFSIZE(state->mb_per_row);

    /* Current Picture Y, Cb, Cr Buffer */
    cur_pic->pic_plane[0] = (Ipp8u*)SAMPLE_ALIGN8(work_buf);
    //memset(cur_pic->pic_plane[0], 0,  YPLANE_BUFSIZE(cur_pic));
    work_buf += YPLANE_BUFSIZE(cur_pic);

    cur_pic->pic_plane[1] = (Ipp8u*)SAMPLE_ALIGN8(work_buf);
    //memset(cur_pic->pic_plane[1], 0,  CBPLANE_BUFSIZE(cur_pic));
    work_buf += CBPLANE_BUFSIZE(cur_pic);

    cur_pic->pic_plane[2] = (Ipp8u*)SAMPLE_ALIGN8(work_buf);
    //memset(cur_pic->pic_plane[2], 0,  CRPLANE_BUFSIZE(cur_pic));
    work_buf += CRPLANE_BUFSIZE(cur_pic);

    /* Reference Picture Y, Cb, Cr Buffer */
    ref_pic->pic_plane[0] = (Ipp8u*)SAMPLE_ALIGN8(work_buf);
    //memset(ref_pic->pic_plane[0], 0,  YPLANE_BUFSIZE(ref_pic));
    work_buf += YPLANE_BUFSIZE(ref_pic);

    ref_pic->pic_plane[1] = (Ipp8u*)SAMPLE_ALIGN8(work_buf);
    //memset(ref_pic->pic_plane[1], 0,  CBPLANE_BUFSIZE(ref_pic));
    work_buf += CBPLANE_BUFSIZE(ref_pic);

    ref_pic->pic_plane[2] = (Ipp8u*)SAMPLE_ALIGN8(work_buf);
    //memset(ref_pic->pic_plane[2], 0,  CRPLANE_BUFSIZE(ref_pic));
    work_buf += CRPLANE_BUFSIZE(ref_pic);

    /* Init MV */
    state->mv_buffer[0].dx = 0;
    state->mv_buffer[0].dy = 0;
    state->mv_buffer[state->mb_per_row+1].dx = 0;
    state->mv_buffer[state->mb_per_row+1].dy = 0;

    return SAMPLE_STATUS_NOERR;

}

/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -