📄 mp4_enc_headers.cpp
字号:
/* ///////////////////////////////////////////////////////////////////////
//
// 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-2007 Intel Corporation. All Rights Reserved.
//
// Description: class ippVideoEncoderMPEG4 (put headers to bitstream)
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_MPEG4_VIDEO_ENCODER)
#include "mp4_enc.hpp"
#include <stdio.h>
namespace MPEG4_ENC
{
inline void ippVideoEncoderMPEG4::EncodeStartCode(Ipp8u sc)
{
cBS.PutBits(256 + sc, 32);
}
void ippVideoEncoderMPEG4::EncodeZeroBitsAlign()
{
if (cBS.mBitOff != 0)
cBS.PutBits(0, 8 - cBS.mBitOff);
}
void ippVideoEncoderMPEG4::EncodeStuffingBitsAlign()
{
cBS.PutBits(0xFF >> (cBS.mBitOff + 1), 8 - cBS.mBitOff);
}
void ippVideoEncoderMPEG4::EncodeVideoPacketHeader(ippBitStream &cBS, Ipp32s mbn, Ipp32s quant)
{
Ipp32s rml;
if (VOP.vop_coding_type == MP4_VOP_TYPE_I)
rml = 17;
else if (VOP.vop_coding_type == MP4_VOP_TYPE_B)
rml = 16 + IPP_MAX(VOP.vop_fcode_forward, VOP.vop_fcode_backward);
else
rml = 16 + VOP.vop_fcode_forward;
//f EncodeStuffingBitsAlign();
cBS.PutBits(1, rml);
cBS.PutBits(mbn, mMBNlength);
cBS.PutBits(quant, VOL.quant_precision);
cBS.PutZeroBit();
}
void ippVideoEncoderMPEG4::EncodeGOBHeader(ippBitStream &cBS, Ipp32s gob_number, Ipp32s quant)
{
cBS.PutBits(1, 17);
cBS.PutBits(gob_number, 5);
cBS.PutBits(VOP.gob_frame_id, 2);
cBS.PutBits(quant, 5);
}
void ippVideoEncoderMPEG4::EncodeVOS_Header()
{
if (!VOL.short_video_header) {
EncodeStartCode(MP4_VISUAL_OBJECT_SEQUENCE_SC);
cBS.PutBits(VOS.profile_and_level_indication, 8);
//f EncodeStartCode(MP4_USER_DATA_SC);
//f user_data
}
}
void ippVideoEncoderMPEG4::EncodeVO_Header()
{
EncodeStartCode(MP4_VISUAL_OBJECT_SC);
cBS.PutBits(VO.is_visual_object_identifier, 1);
if (VO.is_visual_object_identifier) {
cBS.PutBits(VO.visual_object_verid, 4);
cBS.PutBits(VO.visual_object_priority, 3);
}
cBS.PutBits(VO.visual_object_type, 4);
if (VO.visual_object_type == MP4_VISUAL_OBJECT_TYPE_VIDEO || VO.visual_object_type == MP4_VISUAL_OBJECT_TYPE_TEXTURE) {
cBS.PutBits(VO.video_signal_type, 1);
if (VO.video_signal_type) {
cBS.PutBits(VO.video_format, 3);
cBS.PutBits(VO.video_range, 1);
cBS.PutBits(VO.colour_description, 1);
if (VO.colour_description) {
cBS.PutBits(VO.colour_primaries, 8);
cBS.PutBits(VO.transfer_characteristics, 8);
cBS.PutBits(VO.matrix_coefficients, 8);
}
}
}
EncodeStuffingBitsAlign();
//f EncodeStartCode(MP4_USER_DATA_SC);
//f user_data
if (VO.visual_object_type == MP4_VISUAL_OBJECT_TYPE_VIDEO)
EncodeStartCode(MP4_VIDEO_OBJECT_MIN_SC + 2);
}
void ippVideoEncoderMPEG4::EncodeVOL_Header()
{
EncodeStartCode(MP4_VIDEO_OBJECT_LAYER_MIN_SC + 2);
cBS.PutBits(VOL.random_accessible_vol, 1);
cBS.PutBits(VOL.video_object_type_indication, 8);
cBS.PutBits(VOL.is_object_layer_identifier, 1);
if (VOL.is_object_layer_identifier) {
cBS.PutBits(VOL.video_object_layer_verid, 4);
cBS.PutBits(VOL.video_object_layer_priority, 3);
}
cBS.PutBits(VOL.aspect_ratio_info, 4);
if (VOL.aspect_ratio_info == MP4_ASPECT_RATIO_EXTPAR) {
cBS.PutBits(VOL.par_width, 8);
cBS.PutBits(VOL.par_height, 8);
}
cBS.PutBits(VOL.vol_control_parameters, 1);
if (VOL.vol_control_parameters) {
cBS.PutBits(VOL.chroma_format, 2);
cBS.PutBits(VOL.low_delay, 1);
cBS.PutBits(VOL.vbv_parameters, 1);
if (VOL.vbv_parameters) {
cBS.PutBits(VOL.first_half_bit_rate, 15);
cBS.PutMarkerBit();
cBS.PutBits(VOL.latter_half_bit_rate, 5);
cBS.PutMarkerBit();
cBS.PutBits(VOL.first_half_vbv_buffer_size, 15);
cBS.PutMarkerBit();
cBS.PutBits(VOL.latter_half_vbv_buffer_size, 3);
cBS.PutBits(VOL.first_half_vbv_occupancy, 11);
cBS.PutMarkerBit();
cBS.PutBits(VOL.latter_half_vbv_occupancy, 15);
cBS.PutMarkerBit();
}
}
cBS.PutBits(VOL.video_object_layer_shape, 2);
if (VOL.video_object_layer_shape == MP4_SHAPE_TYPE_GRAYSCALE && VOL.video_object_layer_verid != 1)
cBS.PutBits(VOL.video_object_layer_shape_extension, 4);
cBS.PutMarkerBit();
cBS.PutBits(VOL.vop_time_increment_resolution, 16);
cBS.PutMarkerBit();
cBS.PutBits(VOL.fixed_vop_rate, 1);
if (VOL.fixed_vop_rate)
cBS.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) {
cBS.PutMarkerBit();
cBS.PutBits(VOL.video_object_layer_width, 13);
cBS.PutMarkerBit();
cBS.PutBits(VOL.video_object_layer_height, 13);
cBS.PutMarkerBit();
}
cBS.PutBits(VOL.interlaced, 1);
cBS.PutBits(VOL.obmc_disable, 1);
cBS.PutBits(VOL.sprite_enable, (VOL.video_object_layer_verid == 1) ? 1 : 2);
if (VOL.sprite_enable == MP4_SPRITE_STATIC || VOL.sprite_enable == MP4_SPRITE_GMC) {
if (VOL.sprite_enable != MP4_SPRITE_GMC) {
cBS.PutBits(VOL.sprite_width, 13);
cBS.PutMarkerBit();
cBS.PutBits(VOL.sprite_height, 13);
cBS.PutMarkerBit();
cBS.PutBits(VOL.sprite_left_coordinate, 13);
cBS.PutMarkerBit();
cBS.PutBits(VOL.sprite_top_coordinate, 13);
cBS.PutMarkerBit();
}
cBS.PutBits(VOL.no_of_sprite_warping_points, 6);
cBS.PutBits(VOL.sprite_warping_accuracy, 2);
cBS.PutBits(VOL.sprite_brightness_change, 1);
if (VOL.sprite_enable != MP4_SPRITE_GMC)
cBS.PutBits(VOL.low_latency_sprite_enable, 1);
}
if (VOL.video_object_layer_verid != 1 && VOL.video_object_layer_shape != MP4_SHAPE_TYPE_RECTANGULAR)
cBS.PutBits(VOL.sadct_disable, 1);
cBS.PutBits(VOL.not_8_bit, 1);
if (VOL.not_8_bit) {
cBS.PutBits(VOL.quant_precision, 4);
cBS.PutBits(VOL.bits_per_pixel, 4);
}
if (VOL.video_object_layer_shape == MP4_SHAPE_TYPE_GRAYSCALE) {
cBS.PutBits(VOL.no_gray_quant_update, 1);
cBS.PutBits(VOL.composition_method, 1);
cBS.PutBits(VOL.linear_composition, 1);
}
cBS.PutBits(VOL.quant_type, 1);
if (VOL.quant_type) {
Ipp32s i;
cBS.PutBits(VOL.load_intra_quant_mat, 1);
if (VOL.load_intra_quant_mat) {
for (i = 0; i < VOL.load_intra_quant_mat_len; i ++)
cBS.PutBits(VOL.intra_quant_mat[mp4_ZigZagScan[i]], 8);
if (VOL.load_intra_quant_mat_len < 64)
cBS.PutBits(0, 8);
}
cBS.PutBits(VOL.load_nonintra_quant_mat, 1);
if (VOL.load_nonintra_quant_mat) {
for (i = 0; i < VOL.load_nonintra_quant_mat_len; i ++)
cBS.PutBits(VOL.nonintra_quant_mat[mp4_ZigZagScan[i]], 8);
if (VOL.load_nonintra_quant_mat_len < 64)
cBS.PutBits(0, 8);
}
if (VOL.video_object_layer_shape == MP4_SHAPE_TYPE_GRAYSCALE) {
//f for(i=0; i<aux_comp_count; i++) {
//f load_intra_quant_mat_grayscale 1
//f if(load_intra_quant_mat_grayscale)
//f intra_quant_mat_grayscale[i] 8*[2-64]
//f load_nonintra_quant_mat_grayscale 1
//f if(load_nonintra_quant_mat_grayscale)
//f nonintra_quant_mat_grayscale[i] 8*[2-64]
//f }
}
}
if (VOL.video_object_layer_verid != 1)
cBS.PutBits(VOL.quarter_sample, 1);
cBS.PutBits(VOL.complexity_estimation_disable, 1);
if (!VOL.complexity_estimation_disable) {
//f define_vop_complexity_estimation_header()
}
cBS.PutBits(VOL.resync_marker_disable, 1);
cBS.PutBits(VOL.data_partitioned, 1);
if (VOL.data_partitioned)
cBS.PutBits(VOL.reversible_vlc, 1);
if (VOL.video_object_layer_verid != 1) {
cBS.PutBits(VOL.newpred_enable, 1);
if (VOL.newpred_enable) {
cBS.PutBits(VOL.requested_upstream_message_type, 2);
cBS.PutBits(VOL.newpred_segment_type, 1);
}
cBS.PutBits(VOL.reduced_resolution_vop_enable, 1);
}
cBS.PutBits(VOL.scalability, 1);
if (VOL.scalability) {
cBS.PutBits(VOL.hierarchy_type, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -