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

📄 h263mb.c

📁 Linux下的基于intel的ipp库的h.263解码源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
//               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_mb_ipic_h263()
//    decode_mb_ppic_h263()
//
******************************************************************************/
#include "samph263.h"

/******************************************************************************
// Function Name:   decode_block_intradc_only_h263
//
// Description:     Decode an INTRA block with only INTRADC coded in stream
//
// Parameter:
// Input:
//        stream:   Pointer to sample_bitstream structure holding input stream
//          step:   Step for output picture plane
// Output:
//        stream:   Pointer to sample_bitstream structure holding input stream
//                  Stream position pointer is updated to next available byte
//     pic_plane:   Pointer to output block buffer
//
// Return:
// sample_status:   
//  [SAMPLE_STATUS_NOERR]:            Succeeds
//  [SAMPLE_STATUS_BITSTREAM_ERR]:    Stream read error or invalid code occurs
//
// Notes:   None
******************************************************************************/
static sample_status decode_block_intradc_only_h263(sample_bitstream *stream, 
                                                    unsigned char    *pic_plane,
                                                    int              step)
{
    unsigned int intradc = 0;
    int          i, j;

    if(!read_stream_bits(stream, H263_STREAM_INTRADC_LEN, &intradc)) {
        return SAMPLE_STATUS_BITSTREAM_ERR;
    }

    if(0 == intradc || 0x80 == intradc) {
        /* Invalid Code */
        return SAMPLE_STATUS_BITSTREAM_ERR;
    }

    if(0xff == intradc) {
        intradc = 128;
    }

    /* One Coeff IDCT */
    for(i=0; i<8; i++, pic_plane += step) {
        for(j=0; j<8; j++) {
            pic_plane[j] = (unsigned char)intradc;
        }
    }

    return SAMPLE_STATUS_NOERR;
}

/******************************************************************************
// Function Name:   decode_intra_mb_h263
//
// Description:     Decode one INTRA MB 
//
// 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]:  Succeeds
//  [SAMPLE_STATUS_ERR]:    Error occurs during decoding
//
// Notes:   None
******************************************************************************/
static sample_status decode_intra_mb_h263(sample_bitstream    *stream, 
                                          h263_dec_state      *state)
{
    sample_picture *cur_picture = state->cur_picture;
    int cbp = state->cbpy;
    int i;

    /***********************************
    // Decode 4 Y Blocks
    ***********************************/
    for(i=0;i<4;i++) {
        if(cbp & 0x8) {
            /* Decode Coefficients */
            if (ippStsNoErr != ippiDecodeBlockCoef_Intra_H263_1u8u (
                                        &stream->bs_cur_byte, 
                                        &stream->bs_cur_bitoffset, 
                                        state->cur_block.y_ptr,
                                        cur_picture->pic_plane_step[0],
                                        state->quant)) {
                return  SAMPLE_STATUS_ERR;
            }
        } else {
            /* Decode Only INTRADC */
            if (SAMPLE_STATUS_NOERR != decode_block_intradc_only_h263(
                                        stream, 
                                        state->cur_block.y_ptr,
                                        cur_picture->pic_plane_step[0])) {
                return  SAMPLE_STATUS_ERR;
            }
        }
        state->cur_block.y_ptr += 8;
        if(i&1) {
            state->cur_block.y_ptr += 
                SAMPLE_VIDEO_BLOCK_SIZE * state->cur_picture->pic_plane_step[0]
                - 2*SAMPLE_VIDEO_BLOCK_SIZE;
        }
        cbp <<= 1;
    }
    
    cbp = state->cbpc;

    /***********************************
    // Decode Cb block
    ***********************************/
    if(cbp & 0x2) {
        /* Decode Coefficients */
        if (ippStsNoErr != ippiDecodeBlockCoef_Intra_H263_1u8u(
                                        &stream->bs_cur_byte, 
                                        &stream->bs_cur_bitoffset, 
                                        state->cur_block.cb_ptr,
                                        cur_picture->pic_plane_step[1],
                                        state->quant)) {
            return  SAMPLE_STATUS_ERR;
        }
    } else {
        /* Decode Only INTRADC */
        if (SAMPLE_STATUS_NOERR != decode_block_intradc_only_h263(
                                        stream, 
                                        state->cur_block.cb_ptr, 
                                        cur_picture->pic_plane_step[1])) {
            return  SAMPLE_STATUS_ERR;
        }
    }

    /***********************************
    // Decode Cr block
    ***********************************/
    if(cbp & 0x1) {
        /* Decode Coefficients */
        if (ippStsNoErr != ippiDecodeBlockCoef_Intra_H263_1u8u(
                                        &stream->bs_cur_byte, 
                                        &stream->bs_cur_bitoffset, 
                                        state->cur_block.cr_ptr,
                                        cur_picture->pic_plane_step[2],
                                        state->quant)) {
            return  SAMPLE_STATUS_ERR;
        }
    } else {
        /* Decode Only INTRADC */
        if (SAMPLE_STATUS_NOERR != decode_block_intradc_only_h263(
                                        stream, 
                                        state->cur_block.cr_ptr,
                                        cur_picture->pic_plane_step[2])) {
            return  SAMPLE_STATUS_ERR;
        }
    }

    return SAMPLE_STATUS_NOERR;
}


/******************************************************************************
// Function Name:   decode_mb_ipic_h263
//
// Description:     Decode one MB in I Picture. This function does the 
//                  following steps:
//                  1) Parse MB header, update quantizer if MB type is INTRA_Q.
//                  2) Initialize block pointer to beginning of current MB.
//                  3) Call decode_intra_mb_h263 to decode one INTRA MB.
//
// 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]:            Succeeds
//  [SAMPLE_STATUS_BITSTREAM_ERR]:    Stream parsing error occurs
//  [SAMPLE_STATUS_ERR]:              Error occurs during decoding
//
// Notes:   None
******************************************************************************/
sample_status decode_mb_ipic_h263(sample_bitstream    *stream, 
                                  h263_dec_state      *state)
{
    sample_status  ret;

    /***********************************************************
    // Parse MB header 
    ***********************************************************/
    ret = parse_mb_header_h263(stream, state);
    if(SAMPLE_STATUS_NOERR != ret) {
        return ret;
    }

    /***********************************************************
    // If MB type is INTRA_Q, 
    // update quantization param according to GQUANT and DQUANT 
    ***********************************************************/
    if(H263_INTRA_Q == state->mb_type) {
        state->quant = QUANT_CLIP(state->quant+state->dquant);
    }

    /***********************************************************
    // Initialize block pointers 
    ***********************************************************/
    state->cur_block.y_ptr  = state->cur_mb.y_ptr;
    state->cur_block.cb_ptr = state->cur_mb.cb_ptr;
    state->cur_block.cr_ptr = state->cur_mb.cr_ptr;

    /***********************************************************
    // Decode one INTRA MB 
    ***********************************************************/
    return decode_intra_mb_h263(stream, state);

}

/******************************************************************************
// Function Name:   decode_mb_ppic_h263
//
// Description:     Decode one MB in P Picture. This function does the 
//                  following steps:
//                  1) Parse MB header, update quantizer if MB type is INTRA_Q
//                     or INTER_Q.
//                  2) Initialize block pointer to beginning of current MB.
//                  3) If the block is not coded, copy reference block to 
//                     current block directly and zero current motion vector.
//                  4) If it's coded as INTRA block, call decode_intra_mb_h263
//                     to decode and zero current motion vector.
//                  5) If coded as INTER block, decode motion vector and do 
//                     motion compensation.
//
// 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:   

⌨️ 快捷键说明

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