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

📄 samph263.h

📁 基于intel ipp的h263_decoder
💻 H
字号:
/********************************************************************************
//               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 Definitions
//
********************************************************************************/

#ifndef _SAMPH263_H_
#define _SAMPH263_H_

#include "sampvc.h"
#include <stdio.h>

/****************************************
/ Consts
****************************************/
/* File Name Max Length */
#define MAX_FILENAME_LEN                255

/* Stream Syntax */
#define H263_STREAM_PSC                 0x000020
#define H263_STREAM_EOS                 0x00003f
#define H263_STREAM_PTYPE               0x0

#define H263_STREAM_GBSC                0x00001


#define H263_STREAM_PSC_LEN             22
#define H263_STREAM_EOS_LEN             22
#define H263_STREAM_TR_LEN              8
#define H263_STREAM_PTYPE_LEN           13
#define H263_STREAM_PQUANT_LEN          5
#define H263_STREAM_CPM_LEN             1
#define H263_STREAM_PEI_LEN             1
#define H263_STREAM_PSUPP_LEN           8

#define H263_STREAM_GBSC_LEN            17
#define H263_STREAM_GN_LEN              5
#define H263_STREAM_GFID_LEN            2
#define H263_STREAM_GQUANT_LEN          5

#define H263_STREAM_COD_LEN             1

#define H263_STREAM_DQUANT_LEN          2

#define H263_STREAM_INTRADC_LEN         8

/*************************************
/ Structure for H263 Decoder 
*************************************/
/* Coding Type */
typedef enum _h263_picture_coding_type {
    H263_I_PICTURE              = 0,
    H263_P_PICTURE              = 1,
    H263_PB_FRAME               = 2
} h263_picture_coding_type;

/* Macro Block Type */
typedef enum _h263_macroblock_type {
    H263_INTER                  = 0,    /* P picture */
    H263_INTER_Q                = 1,    /* P picture with DQUANT */
    H263_INTER4V                = 2,    /* P picture with 4MV */
    H263_INTRA                  = 3,    /* I picture */
    H263_INTRA_Q                = 4,    /* I picture with DQUANT */
    H263_INTER4V_Q              = 5,    /* P picture with DQUANT and 4MV */
    H263_STUFFING               = 6     /* Stuffing MB */
} h263_macroblock_type;

/* Source Coding Format */
typedef enum _h263_source_format {
    H263_SOURCE_FORBIDDEN       = 0,    /* forbidden */
    H263_SOURCE_SUBQCIF         = 1,    /* sub-QCIF */
    H263_SOURCE_QCIF            = 2,    /* QCIF */
    H263_SOURCE_CIF             = 3,    /* CIF */
    H263_SOURCE_4CIF            = 4,    /* 4CIF */
    H263_SOURCE_16CIF           = 5,    /* 16CIF */
    H263_SOURCE_EXT_PTYPE       = 7     /* extended PTYPE */
} h263_source_format;

/* User Access Parameters */
typedef struct _h263_dec_param {
    char    in_file_name[MAX_FILENAME_LEN];
    char    out_file_name[MAX_FILENAME_LEN];
} h263_dec_param;

/* Decoder state */
typedef struct _h263_dec_state {
    sample_picture *cur_picture;    /* Current picture */
    sample_picture *ref_picture;    /* Reference picture */

    /* general info */
    int     picture_index;          /* count of decoded picture by decoder */
    int     mb_per_row;             /* count of MB per row */
    int     gob_per_picture;        /* count of GOB per picture */
    int     gob_has_header;         /* Indicator if current GOB has header */

    /* picture header info */
    int     tr;                     /* temporal reference */
    int     is_last_picture;        /* Indicator if is last output picture */
    int     coding_type;            /* picture type (I/P/PB) */
    int     source_format;          /* format: CIF/QCIF/sub-QCIF */
    int     rounding_type;          /* RCONTROL: Rounding On/Off */
    int     pquant;                 /* quantization parameter */

    /* Motion vector buffer */
    IppMotionVector  *mv_buffer;    /* MV buffer for one GOB */
    IppMotionVector  mvd;           /* Difference of MV */

    /* Work buffer */
    unsigned char*   work_buf;

    /* Current Infomation */
    sample_spacial_ptrset cur_gob;  /* Current GOB */
    sample_spacial_ptrset ref_gob;  /* Reference GOB */
    sample_spacial_ptrset cur_mb;   /* Current macroblock */
    sample_spacial_ptrset ref_mb;   /* Reference macroblock */
    sample_spacial_ptrset cur_block;/* Current block */
    sample_spacial_ptrset ref_block;/* Reference block */
    IppMotionVector       *cur_mv;  /* Current mv buffer */

    /* Current MB head info */
    int mb_type;                    /* Macroblock type */
    int mb_index;                   /* Index of current macroblock */
    int quant;                      /* Quantization */
    int dquant;                     /* Difference of quant */
    int cod;                        /* flag of coded/not-coded */
    int cbpc;                       /* Coded block pattern for chrominance */
    int cbpy;                       /* Coded block pattern for luminance */

} h263_dec_state;

/****************************************
/ Tables
****************************************/
extern const unsigned short mcbpc_tbl_ipic_h263[];
extern const unsigned short mcbpc_tbl1_ppic_h263[];
extern const unsigned short mcbpc_tbl2_ppic_h263[];
extern const unsigned short cbpy_tbl_h263[];
extern const int            dquant_mb_h263[4];
extern const char           mv_quarter_round_h263[4]; 


/****************************************
/ Macros
****************************************/
/* Create MCBPC Table Entry */
#define MCBPC_ENTRY(mbtype, cbpc, num_bits) \
    ((mbtype)<<10 | (cbpc)<<8 | (num_bits))

/* Get each element from one MCBPC table entry */
#define MCBPC_MBTYPE(mcbpc)     (((mcbpc)>>10) & 0x7)
#define MCBPC_CBPC(mcbpc)       (((mcbpc)>>8)  & 0x3)
#define MCBPC_NUMBITS(mcbpc)    ((mcbpc)&0xff)

/* Create CBPY Table Entry */
#define CBPY_ENTRY(cbpy_intra, cbpy_inter, num_bits) \
    ((cbpy_intra)<<12 | (cbpy_inter)<<8 | (num_bits))

/* Get each element from one CBPY table entry */
#define CBPY_INTRA(cbpy)        ((cbpy)>>12&0xf)
#define CBPY_INTER(cbpy)        ((cbpy)>>8 & 0xf)
#define CBPY_NUMBITS(cbpy)      ((cbpy)&0xff)

/* Get element from one MVD table entry */
#define MVD_NUMBITS(mvd)        ((mvd)&0xff)

/* Clip quant to [1, 31] */
#define QUANT_CLIP(quant)  (((quant)<1)?1:((quant)>31?31:(quant)))

/* Stream utilites */
/* Align stream pointer to next byte */
#define STREAM_BYTE_ALIGN(stream)   \
{                                   \
    (stream)->bs_cur_bitoffset = 0; \
    (stream)->bs_cur_byte ++;       \
}

/* Check if current stream position is byte aligned */
#define STREAM_CHECK_BYTE_ALIGN(stream) ((stream)->bs_cur_bitoffset==0)

/* Buffer size */
/* Buffer size for motion vectors in one GOB */
#define MV_BUFSIZE(mbnum)             (((mbnum) + 2) * sizeof(IppMotionVector))

/* Y Plane size */
#define YPLANE_BUFSIZE(pic)  \
    ((pic)->pic_plane_step[0]*(pic)->pic_height)

/* Cb Plane size */
#define CBPLANE_BUFSIZE(pic) \
    (((pic)->pic_plane_step[0]*(pic)->pic_height)/4)

/* Cr Plane size */
#define CRPLANE_BUFSIZE(pic) \
    (((pic)->pic_plane_step[0]*(pic)->pic_height)/4)



/****************************************
/ Function Declarations
****************************************/

/*********** Codec Level Function *********************/
extern sample_status decoder_init_alloc_h263(sample_bitstream  *stream,  
                                             h263_dec_state    *state);

extern sample_status decode_h263(sample_bitstream   *stream,   
                                 h263_dec_state     *state,
                                 sample_picture     **out_picture);

extern sample_status decoder_free_h263(h263_dec_state *state);

/*********** Other subroutines ***********************/
/* GOB Level Decoding */
extern sample_status decode_gob_ipic_h263(sample_bitstream  *stream, 
                                          h263_dec_state    *state);

extern sample_status decode_gob_ppic_h263(sample_bitstream  *stream, 
                                          h263_dec_state    *state);

/* MB Level Decoding */
extern sample_status decode_mb_ipic_h263(sample_bitstream   *stream, 
                                         h263_dec_state     *state);

extern sample_status decode_mb_ppic_h263(sample_bitstream   *stream, 
                                         h263_dec_state     *state);

/* Header Parsing & Start Code Searching Functions */
extern sample_status parse_picture_header_h263(sample_bitstream  *stream, 
                                               h263_dec_state    *state);

extern sample_status parse_gob_header_h263(sample_bitstream  *stream, 
                                           h263_dec_state    *state);

extern sample_status parse_mb_header_h263(sample_bitstream  *stream, 
                                          h263_dec_state    *state);


/* Auxiliary Stream Subroutines */
extern SAMPLE_BOOL read_stream_bits(sample_bitstream *stream,
                                    int              bits_len, 
                                    unsigned int     *data);

extern SAMPLE_BOOL preview_stream_bits(sample_bitstream *stream,
                                       int              bits_len, 
                                       unsigned int     *data);

extern SAMPLE_BOOL skip_stream_bits(sample_bitstream *stream,
                                    int              bits_len);

extern SAMPLE_BOOL seek_next_sync_code_h263(sample_bitstream  *stream, 
                                            unsigned int      sync_code, 
                                            int               sync_code_len,
                                            int               is_byte_aligned,
                                            int               seek_byte_offset,
                                            int               seek_byte_len);

extern SAMPLE_BOOL insert_stream_bits_bytealign(sample_bitstream *stream, 
                                                int              bits_len,
                                                unsigned int     data);


#endif  //_SAMPH263_H_
/* EOF */

⌨️ 快捷键说明

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