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

📄 encodeheader.c

📁 adi bf533视频编码程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <string.h>

#include "ippVideoEncoderMPEG4.h"
#include "enum.h"

extern    struct ippBitStream                cBS;

//extern    struct mp4_VisualObjectSequence    VOS;		//----no vos header

extern     struct mp4_VisualObject            VO;
extern    struct mp4_VideoObjectLayer        VOL;
//extern    struct mp4_GroupOfVideoObjectPlane GOP;
extern    struct mp4_VideoObjectPlane        VOP;
/*******************************************************/

static unsigned int shifter;
static unsigned int empty_bits = 32;
/*
void PutBits(Ipp32u val, int n)
{
    val &= (0xFFFFFFFF >> (32-n));
    if(n <= empty_bits) {
        shifter += (val<<(empty_bits - n));
        empty_bits -= n;
    }
    else {
        shifter += (val >> (n-empty_bits));
        *cBS.mPtr ++ = (shifter >> 24);
        *cBS.mPtr ++ = (shifter >> 16);
        *cBS.mPtr ++ = (shifter >> 8);
        *cBS.mPtr ++ = shifter;
        //shifter = 0;
        shifter = (val << (32-n+empty_bits));
        empty_bits += 32 - n;
    }
    cBS.mBitOff = (cBS.mBitOff + n) & 7;
    
}
*/
void PutBits(Ipp32u val, int n)
{
    val <<= 32 - n;
    if(n <= empty_bits) {
        shifter |= (val>>(32-empty_bits));
        empty_bits -= n;
    }
    else {
        shifter |= (val >> (32-empty_bits));
        *cBS.mPtr ++ = (shifter >> 24);
        *cBS.mPtr ++ = (shifter >> 16);
        *cBS.mPtr ++ = (shifter >> 8);
        *cBS.mPtr ++ = shifter;
        //shifter = 0;
        shifter = (val << empty_bits);
        empty_bits += 32 - n;
    }
    cBS.mBitOff = (cBS.mBitOff + n) & 7;
    
}

void flush_shifter(void)
{
	int bytes = (32-empty_bits)/8;
	int i;
	for (i = 0; i < bytes; i++)
		*cBS.mPtr ++ = (shifter >> ((3-i)<<3));
	shifter = 0;
	empty_bits = 32;
}

/*
void PutBits(Ipp32u val, int n)
{
    val <<= 32 - n;
    if (cBS.mBitOff == 0) {
        cBS.mPtr[0] = (Ipp8u)(val >> 24);
        if (n > 8) {
            cBS.mPtr[1] = (Ipp8u)(val >> 16);
            if (n > 16) {
                cBS.mPtr[2] = (Ipp8u)(val >> 8);
                if (n > 24) {
                    cBS.mPtr[3] = (Ipp8u)(val);
                }
            }
        }
    } else {
        cBS.mPtr[0] = (Ipp8u)((cBS.mPtr[0] & (0xFF << (8 - cBS.mBitOff))) | (Ipp8u)(val >> (24 + cBS.mBitOff)));
        if (n > 8 - cBS.mBitOff) {
            val <<= 8 - cBS.mBitOff;
            cBS.mPtr[1] = (Ipp8u)(val >> 24);
            if (n > 16 - cBS.mBitOff) {
                cBS.mPtr[2] = (Ipp8u)(val >> 16);
                if (n > 24 - cBS.mBitOff) {
                    cBS.mPtr[3] = (Ipp8u)(val >> 8);
                    if (n > 32 - cBS.mBitOff) {
                        cBS.mPtr[4] = (Ipp8u)val;
                    }
                }
            }
        }
  	}
    cBS.mPtr += (cBS.mBitOff + n) >> 3;
    cBS.mBitOff = (cBS.mBitOff + n) & 7;
}
*/

static inline void PutZeroBit(void)
{
    PutBits(0, 1);
}

static inline void PutMarkerBit(void)
{
    PutBits(1, 1);
}

static inline void PutStr(char *str)
{
///////////////////////////////////    
    flush_shifter();
///////////////////////////////////    
    if (cBS.mBitOff > 0) {
        cBS.mBitOff = 0;
        cBS.mPtr ++;
    }
    strcpy((char*)cBS.mPtr, str);
    cBS.mPtr += strlen(str);
}

 void EncodeStuffingBitsAlign(void)
{
    PutBits(0xFF >> (cBS.mBitOff + 1), 8 - cBS.mBitOff);
}

 void EncodeZeroBitsAlign(void)
{
    if (cBS.mBitOff != 0)
     PutBits(0, 8 - cBS.mBitOff);
}






/*
void EncodeVOS_Header()
{
    PutBits(1, 24);
    PutBits(MP4_VISUAL_OBJECT_SEQUENCE_SC, 8);
    PutBits(VOS.profile_and_level_indication, 8);
    //f cBS.PutBits(1, 24);
    //f cBS.PutBits(MP4_USER_DATA_SC, 8);
    //f user_data
}

*/

void EncodeVOL_Header()
{
    PutBits(1, 24);
    PutBits(MP4_VIDEO_OBJECT_LAYER_MIN_SC + 2, 8);	//0x20+2
    PutBits(VOL.random_accessible_vol, 1);			//0
    PutBits(VOL.video_object_type_indication, 8);	//MP4_VIDEO_OBJECT_TYPE_SIMPLE=1
    PutBits(VOL.is_object_layer_identifier, 1);		//1
    if (VOL.is_object_layer_identifier) {    
        PutBits(VOL.video_object_layer_verid, 4);	//MP4_ISO_IEC_14496_2=1
        PutBits(VOL.video_object_layer_priority, 3);
    }
    PutBits(VOL.aspect_ratio_info, 4);
    if (VOL.aspect_ratio_info == MP4_ASPECT_RATIO_EXTPAR) {
        PutBits(VOL.par_width, 8);
        PutBits(VOL.par_height, 8);
    }
    PutBits(VOL.vol_control_parameters, 1);
    if (VOL.vol_control_parameters) {
        PutBits(VOL.chroma_format, 2);
        PutBits(VOL.low_delay, 1);
        PutBits(VOL.vbv_parameters, 1);
        if (VOL.vbv_parameters) {
            PutBits(VOL.first_half_bit_rate, 15);
            PutMarkerBit();
            PutBits(VOL.latter_half_bit_rate, 5);
            PutMarkerBit();
            PutBits(VOL.first_half_vbv_buffer_size, 15);
            PutMarkerBit();
            PutBits(VOL.latter_half_vbv_buffer_size, 3);
            PutBits(VOL.first_half_vbv_occupancy, 11);
            PutMarkerBit();
            PutBits(VOL.latter_half_vbv_occupancy, 15);
            PutMarkerBit();
        }
    }
    PutBits(VOL.video_object_layer_shape, 2);
    if (VOL.video_object_layer_shape == MP4_SHAPE_TYPE_GRAYSCALE && VOL.video_object_layer_verid != MP4_ISO_IEC_14496_2)
        PutBits(VOL.video_object_layer_shape_extension, 4);
    PutMarkerBit();
    PutBits(VOL.vop_time_increment_resolution, 16);
    PutMarkerBit();
    PutBits(VOL.fixed_vop_rate, 1);
    if (VOL.fixed_vop_rate)
        PutBits(VOL.fixed_vop_time_increment, VOL.vop_time_increment_resolution_bits);
    if (VOL.video_object_layer_shape != MP4_SHAPE_TYPE_BINARYONLY) {
        if (VOL.video_object_layer_shape == MP4_SHAPE_TYPE_RECTANGULAR) {
            PutMarkerBit();
            PutBits(VOL.video_object_layer_width, 13);
            PutMarkerBit();
            PutBits(VOL.video_object_layer_height, 13);
            PutMarkerBit();
        }
        PutBits(VOL.interlaced, 1);
        PutBits(VOL.obmc_disable, 1);
        if (VOL.video_object_layer_verid == MP4_ISO_IEC_14496_2)
            PutBits(VOL.sprite_enable, 1);
        else
            PutBits(VOL.sprite_enable, 2);
        if (VOL.sprite_enable == MP4_SPRITE_STATIC || VOL.sprite_enable == MP4_SPRITE_GMC) {
            if (VOL.sprite_enable != MP4_SPRITE_GMC) {
                PutBits(VOL.sprite_width, 13);
                PutMarkerBit();
                PutBits(VOL.sprite_height, 13);
                PutMarkerBit();
                PutBits(VOL.sprite_left_coordinate, 13);
                PutMarkerBit();
                PutBits(VOL.sprite_top_coordinate, 13);
                PutMarkerBit();
            }
            PutBits(VOL.no_of_sprite_warping_points, 6);
            PutBits(VOL.sprite_warping_accuracy, 2);
            PutBits(VOL.sprite_brightness_change, 1);
            if (VOL.sprite_enable != MP4_SPRITE_GMC)
                PutBits(VOL.low_latency_sprite_enable, 1);
        }
        if (VOL.video_object_layer_verid != MP4_ISO_IEC_14496_2 && VOL.video_object_layer_shape != MP4_SHAPE_TYPE_RECTANGULAR)
           PutBits(VOL.sadct_disable, 1);
           PutBits(VOL.not_8_bit, 1);
        if (VOL.not_8_bit) {    
           PutBits(VOL.quant_precision, 4);
           PutBits(VOL.bits_per_pixel, 4);
        }
        if (VOL.video_object_layer_shape == MP4_SHAPE_TYPE_GRAYSCALE) {
            PutBits(VOL.no_gray_quant_update, 1);
            PutBits(VOL.composition_method, 1);

⌨️ 快捷键说明

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