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

📄 mp4esynt.c

📁 Intel提供的在PCA(例如Sitsang开发板)使用IPP4.0库的MPEG-4编码源程序
💻 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:    Stream syntax generation functions of MPEG-4 video encoder//                  sample code for Intel(R) Integrated Performance Primitives.//  Functions List://		create_voandvol_header_mpeg4()//		create_vop_header_mpeg4()//		create_mb_mpeg4()******************************************************************************/#include "sampmp4.h"/******************************************************************************// Name:            create_voandvol_header_mpeg4// Description:     Create visual object and visual object layer header in//                  bitstream// Input Arguments://      enc_state   - Pointer to the general state structure of MPEG-4 encoder////  Output Arguments://      stream_buf  - Pointer to the updated output video stream after the VO//                    and VOL header is generated//      enc_state   - Pointer to the updated general state structure of MPEG-4//                    encoder////  Returns:    //      SAMPLE_STATUS_NOERR             If succeeds//******************************************************************************/sample_status create_voandvol_header_mpeg4(sample_bitstream *stream_buf,                                           mp4_enc_state    *enc_state){    Ipp32u code;             /* video_object_start_code */        code = MPEG4_VOSC | 0x01;    put_bits_mpeg4(stream_buf, code, 32);            enc_state->short_head = 0;    /* video_object_layer_start_code */    code = MPEG4_VOLSC | 0x0;    put_bits_mpeg4(stream_buf, code, 32);    /* random_accessible_vol */    code = 0;    put_bits_mpeg4(stream_buf, code , 1);    /* video_object_type_indication */    code = 4; /* Main Object Type */    put_bits_mpeg4(stream_buf, code, 8);    if (2 == enc_state->vol_verid) {        /* is_object_layer_identifier */        code = 1;                put_bits_mpeg4(stream_buf, code, 1);        /* video_object_layer_verid */        code = enc_state->vol_verid;        put_bits_mpeg4(stream_buf, code, 4);        /* video_object_layer_priority */        code = 1;   /* highest priority */        put_bits_mpeg4(stream_buf, code, 3);    } else {        /* is_object_layer_identifier */        code = 0;        put_bits_mpeg4(stream_buf, code, 1);    }    /* aspect_ratio_info */    code = 1; /* 1:1 (square) */    put_bits_mpeg4(stream_buf, code, 4);    /* vol_control_parameters */    code = 0;    put_bits_mpeg4(stream_buf, code, 1);    /* video_object_layer_shape */    code = enc_state->vol_shape_type;    put_bits_mpeg4(stream_buf, code, 2);    /* marker_bit */    INSERT_MARKER_BIT(stream_buf);        /* vop_time_increment_resolution */    code = enc_state->frame_rate;    put_bits_mpeg4(stream_buf, code, 16);        enc_state->numbits_time_incr = 1;    if (1 < code) {        code -= 1;        while (1 < code) {            code = code >> 1;            enc_state->numbits_time_incr ++;        }    }    /* marker_bit */    INSERT_MARKER_BIT(stream_buf);    /* fixed_vop_rate */    code = 0;    put_bits_mpeg4(stream_buf, code, 1);    if (BINARYONLY != enc_state->vol_shape_type) {                if (RECTANGULAR == enc_state->vol_shape_type) {            /* marker_bit */            INSERT_MARKER_BIT(stream_buf);            /* video_object_layer_width */            code = enc_state->vol_display_width;            put_bits_mpeg4(stream_buf, code, 13);            /* marker_bit */            INSERT_MARKER_BIT(stream_buf);            /* video_object_layer_height */            code = enc_state->vol_display_height;            put_bits_mpeg4(stream_buf, code, 13);            /* marker_bit */            INSERT_MARKER_BIT(stream_buf);                    }                /* interlaced */        code = 0;        put_bits_mpeg4(stream_buf, code, 1);        /* obmc_disable */        code = enc_state->obmc_disabled;        put_bits_mpeg4(stream_buf, code, 1);        code = enc_state->sprite_type;        if (1 == enc_state->vol_verid) {            put_bits_mpeg4(stream_buf, code, 1);        } else {            put_bits_mpeg4(stream_buf, code, 2);        }        if (enc_state->sprite_type) {            /* add extra source codes if sprite_enable == "static" || "GMC" */        }                if ((1 != enc_state->vol_verid) && (RECTANGULAR            != enc_state->vol_shape_type)) {            /* sadct_disable */            code = enc_state->sadct_disabled;            put_bits_mpeg4(stream_buf, code, 1);        }        /* not_8_bit */        code = 0;        put_bits_mpeg4(stream_buf, code, 1);        if (code) {            /* add extra source codes if not 8 bits per pixel */        }        if (GRAYSCALE == enc_state->vol_shape_type) {            /* add extra source codes if vol_shape_type == "grayscale" */        }                /* quant_type */        code = enc_state->quant_type;        put_bits_mpeg4(stream_buf, code, 1);        if (Q_MPEG4 == enc_state->quant_type) {            /* load_intra_quant_mat */            code = 0; /* use default intra_quant_mat */            put_bits_mpeg4(stream_buf, code, 1);                        /* load_nonintra_quant_mat */            code = 0; /* use default nonintra_quant_mat */            put_bits_mpeg4(stream_buf, code, 1);            if (GRAYSCALE == enc_state->vol_shape_type) {                /* add extra source codes if vol_shape_type == "grayscale" */            }        }        if (1 != enc_state->vol_verid) {            /* quater_sample */            code = enc_state->quater_sample;            put_bits_mpeg4(stream_buf, code, 1);        }        /* complexity_estimation_disable */        code = enc_state->complex_est_disable;        put_bits_mpeg4(stream_buf, code, 1);        /* resync_marker_disable */        code = enc_state->resync_disabled;        put_bits_mpeg4(stream_buf, code, 1);        /* data_partitioned */        code = enc_state->data_patitioned;        put_bits_mpeg4(stream_buf, code, 1);        if (enc_state->data_patitioned) {            /* add extra source codes if data_partitioned == 1 */        }        if (1 != enc_state->vol_verid) {            /* newpred_enable */            code = enc_state->new_pred;            put_bits_mpeg4(stream_buf, code, 1);            if (enc_state->new_pred) {                /* add extra source codes if newpred_enable == 1 */            }                        /* reduced_resolution_vop_enable */            code = enc_state->reduced_resolution;            put_bits_mpeg4(stream_buf, code, 1);        }                /* scalability */        code = enc_state->scalable;        put_bits_mpeg4(stream_buf, code, 1);        if (enc_state->scalable) {            /* add extra source codes if scalability == 1 */        }    } else {        /* add extra source code if video_object_shape_type == "binary only" */    }    /* fill stuffing bits */    if (stream_buf->bs_cur_bitoffset) {        stream_buf->bs_cur_byte[0] |=             bits_stuf_tbl[7 - stream_buf->bs_cur_bitoffset];        stream_buf->bs_cur_bitoffset = 0;        stream_buf->bs_cur_byte++;    }    return SAMPLE_STATUS_NOERR;}/******************************************************************************// Name:            create_vop_header_mpeg4// Description:     Create video object plane header in bitstream// Input Arguments: //      enc_state   - Pointer to the general state struct of MPEG-4 encoder//      vop_infor   - Pointer to the vop information struct////  Output Arguments://      stream_buf  - Pointer to the updated output video stream after the VOP//                    header is generated//      enc_state   - Pointer to the updated general state struct of MPEG-4//                    encoder//      vop_infor   - Pointer to the updated vop information struct////  Returns://      SAMPLE_STATUS_NOERR             If succeeds******************************************************************************/sample_status create_vop_header_mpeg4 (sample_bitstream  *stream_buf,                                       mp4_enc_state     *enc_state,                                       mp4_enc_vop_infor *vop_infor){    Ipp32u  code;    int     cur_sec, modulo_frame, modulo_time_base;    /* 32 bit vop_start_code */    code = (MPEG4_PREFIX_SC << 8) | (MPEG4_SUFFIX_VOPSC);    put_bits_mpeg4(stream_buf, code, 32);    /* 2 bit vop_coding_type */    code = enc_state->vop_coding_type;    put_bits_mpeg4(stream_buf, code, 2);    /* modulo_time_base */    cur_sec = 0;    modulo_frame = enc_state->vop_indx;    while (modulo_frame >= enc_state->frame_rate) {        modulo_frame -= enc_state->frame_rate;        cur_sec ++;    }    modulo_time_base = cur_sec - enc_state->modulo_base_decd;    while (modulo_time_base--) {        put_bits_mpeg4(stream_buf, 1, 1);    }    put_bits_mpeg4(stream_buf, 0, 1);    enc_state->modulo_base_disp = enc_state->modulo_base_decd;    enc_state->modulo_base_decd = cur_sec;    /* marker_bit */    INSERT_MARKER_BIT(stream_buf);    /* vop_time_increment */    code = modulo_frame;    put_bits_mpeg4(stream_buf, code, enc_state->numbits_time_incr);    /* marker_bit */    INSERT_MARKER_BIT(stream_buf);    /* 1 bit vop_coded */    code = enc_state->vop_coded;    put_bits_mpeg4(stream_buf, code, 1);    if (0 == code) {        return SAMPLE_STATUS_NOERR;    }    /* 1 bit vop_rounding_type */    /* video_object_layer_shape can't be "binary only" and vop_coding_type    // can't be "SVOP" */    if (PVOP == enc_state->vop_coding_type) {        code = enc_state->rounding;        put_bits_mpeg4(stream_buf, code, 1);    }    if (BINARYONLY != enc_state->vol_shape_type) {        /* 3 bit intra_dc_vlc_thr */        code = enc_state->intra_dc_thr;        put_bits_mpeg4(stream_buf, code, 3);    }    if (BINARYONLY != enc_state->vol_shape_type) {                /* 5 bit vop_quant if not_8_bit is zero */        code = vop_infor->cur_qp;        put_bits_mpeg4(stream_buf, code, 5);        if (IVOP != enc_state->vop_coding_type) {            /* 3 bit vop_fcode_forward */            code = vop_infor->fcode_fwd;            put_bits_mpeg4(stream_buf, code, 3);        }    }    return SAMPLE_STATUS_NOERR;}/******************************************************************************// Name:            create_mb_mpeg4// Description:     Create the MB header in bitstream// Input Arguments: //      vop_infor   - Pointer to the vop information struct////  Output Arguments://      stream_buf  - Pointer to the updated output video stream after the MB//                    header is generated//      vop_infor   - Pointer to the updated vop information struct////  Returns:    //      SAMPLE_STATUS_NOERR     If succeeds//      SAMPLE_STATUS_ERR       If stream parsing error occurs******************************************************************************/sample_status create_mb_mpeg4(sample_bitstream  *stream_buf,                              mp4_enc_state     *enc_state,                              mp4_enc_vop_infor *vop_infor){    Ipp32u code = 0;    int    size = 0, dquant = 0;    if (BINARYONLY != enc_state->vol_shape_type) {                /* RECTANGULAR shape only */        if (IVOP != enc_state->vop_coding_type) {                        /* 1 bit not_coded */            code = vop_infor->mb_not_coded;            put_bits_mpeg4(stream_buf, code, 1);        }        if ((IVOP == enc_state->vop_coding_type) || (!vop_infor->mb_not_coded))        {            /* mcbpc */            if (IVOP == enc_state->vop_coding_type) {                                code = vlc_mcbpc_ivop_tbl[(vop_infor->mb_type - 3) * 4                    + vop_infor->cbpc].value;                size = vlc_mcbpc_ivop_tbl[(vop_infor->mb_type - 3) * 4                    + vop_infor->cbpc].numbit;                put_bits_mpeg4(stream_buf, code, size);            } else {                code = vlc_mcbpc_pvop_tbl[vop_infor->mb_type * 4                    + vop_infor->cbpc].value;                size = vlc_mcbpc_pvop_tbl[vop_infor->mb_type * 4                    + vop_infor->cbpc].numbit;                put_bits_mpeg4(stream_buf, code, size);            }            if ((IPP_VIDEO_INTRA == vop_infor->mb_type) || (IPP_VIDEO_INTRA_Q                == vop_infor->mb_type)) {                /* 1 bit ac_pred_flag */                code = vop_infor->ac_pred_flag;                size = 1;                put_bits_mpeg4(stream_buf, code, size);                /* cbpy */                /* four non_tranparent blocks in each macroblock */                code = vlc_cbpy_tbl[vop_infor->cbpy].value;                size = vlc_cbpy_tbl[vop_infor->cbpy].numbit;                put_bits_mpeg4(stream_buf, code, size);            } else {                /* cbpy */                /* four non_tranparent blocks in each macroblock */                code = vlc_cbpy_tbl[15 - vop_infor->cbpy].value;                size = vlc_cbpy_tbl[15 - vop_infor->cbpy].numbit;                put_bits_mpeg4(stream_buf, code, size);            }            if ((IPP_VIDEO_INTER_Q == vop_infor->mb_type)                || (IPP_VIDEO_INTRA_Q == vop_infor->mb_type)) {                /* 2 bit dquant */                dquant = vop_infor->delta_qp;                if (dquant) {                    if (0 < dquant) {                        code =  1 + dquant;                    } else {                        code = -1 - dquant;                    }                }                                size = 2;                put_bits_mpeg4(stream_buf, code, size);            }        }    }    return SAMPLE_STATUS_NOERR;}

⌨️ 快捷键说明

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