📄 header.c
字号:
/*
*****************************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2003, Advanced Audio Video Coding Standard, Part II
*
* DISCLAIMER OF WARRANTY
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
* The AVS Working Group doesn't represent or warrant that the programs
* furnished here under are free of infringement of any third-party patents.
* Commercial implementations of AVS, including shareware, may be
* subject to royalty fees to patent holders. Information regarding
* the AVS patent policy for standardization procedure is available at
* AVS Web site http://www.avs.org.cn. Patent Licensing is outside
* of AVS Working Group.
*
* The Original Code is Reference Software for China National Standard
* GB/T 20090.2-2006 (short for AVS-P2 or AVS Video) at version RM52J.
*
* The Initial Developer of the Original Code is Video subgroup of AVS
* Workinggroup (Audio and Video coding Standard Working Group of China).
* Contributors: Guoping Li, Siwei Ma, Jian Lou, Qiang Wang ,
* Jianwen Chen,Haiwu Zhao, Xiaozhen Zheng, Junhao Zheng, Zhiming Wang
*
******************************************************************************
*/
/*
*************************************************************************************
* File name:
* Function:
*
*************************************************************************************
*/
#include <math.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "header.h"
#include "mbuffer.h"
#include "defines.h"
#include "vlc.h"
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
int frametotc(int frame, int dropflag)
{
int fps, pict, sec, minute, hour, tc;
fps = (int)(frame_rate+0.5);
pict = frame%fps;
frame = (frame-pict)/fps;
sec = frame%60;
frame = (frame-sec)/60;
minute = frame%60;
frame = (frame-minute)/60;
hour = frame%24;
tc = (dropflag<<23) | (hour<<18) | (minute<<12) | (sec<<6) | pict;
return tc;
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
int IPictureHeader(int frame)
{
Bitstream *bitstream = currBitStream;
int len = 0;
int tc;
int time_code_flag;
marker_bit=1;
time_code_flag = 0;
len += u_v(32, "I picture start code",0x1B3,bitstream);
//rate control
if(input->RCEnable&&img->BasicUnit<=img->Frame_Total_Number_MB)
input->fixed_picture_qp = 0;// [5/8/2007 Leeswan]
else
input->fixed_picture_qp = 1;
//added by mz, 2008.04
if(input->slice_set_enable)
input->fixed_picture_qp = 0;
//xyji 12.23
len+=u_v(16,"bbv delay",0xffff/*img->bbv_delay*/,bitstream);
len += u_v(1, "time_code_flag",0,bitstream);
if (time_code_flag)
{
tc = frametotc(tc0+frame,img->dropflag);
len += u_v(24, "time_code",tc,bitstream);
}
len+=u_1("marker_bit",1,bitstream); //add by wuzhongmou 0610
len+=u_v(8,"picture_distance",picture_distance,bitstream);
if(input->low_delay)
{
len+=ue_v("bbv check times",bbv_check_times,bitstream);
}
len+=u_v(1,"progressive frame",img->progressive_frame,bitstream);
if(!img->progressive_frame)
len+=u_v(1,"picture_structure",img->picture_structure,bitstream);
len+=u_v(1,"top field first",input->top_field_first,bitstream);
len+=u_v(1,"repeat first field",input->repeat_first_field,bitstream);
len+=u_v(1,"fixed picture qp",input->fixed_picture_qp,bitstream);
//rate control
if(input->RCEnable)
len+=u_v(6,"I picture QP",img->qp,bitstream);
else
{
len+=u_v(6,"I picture QP",input->qp0,bitstream);
img->qp = input->qp0;
}
//xyji 12.23
if(img->progressive_frame==0) //by oliver according to 1658
if(img->picture_structure == 0)
{
len+=u_v(1,"skip mode flag",input->skip_mode_flag,bitstream);
}
len+=u_v(4,"reserved bits",0,bitstream);
len+=u_v(1,"loop filter disable",input->loop_filter_disable,bitstream);
if (!input->loop_filter_disable)
{
len+=u_v(1,"loop filter parameter flag",input->loop_filter_parameter_flag,bitstream);
if (input->loop_filter_parameter_flag)
{
len+=se_v("alpha offset",input->alpha_c_offset,bitstream);
len+=se_v("beta offset",input->beta_offset,bitstream);
}
}
//兼容AVS-P2 WANGJP START
if (input->profile_id == _S_PROFILE_ID)
{
if(input->background)
{
if(img->typeb == BACKGROUND_IMG)
{
len+=u_v(1,"picture_coding_type",1,bitstream);
len+= u_v(1, "picture_output_flag", input->backgroundOutput, bitstream);
}
else
len+=u_v(1,"picture_coding_type",0,bitstream);
}
if(core_frame_enable_flag)
{
len+=u_v(1, "Is_coreframe_flag", cur_core_frame_flag, bitstream);
if(cur_core_frame_flag)
{
len+=u_v(log2_core_frame_buffer_size, "Coreframe_num", core_frame_num, bitstream);
}
}
}
//WANGJP END
picture_reference_flag = 0;
return len;
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
int PBPictureHeader()
{
Bitstream *bitstream = currBitStream;
int len = 0;
if (img->type == INTER_IMG)
{
// img->count_PAFF=img->count_PAFF+1; //Commented by qihuafei, 20070925
picture_coding_type = 1;
if((input->InterlaceCodingOption == FRAME_CODING)||(input->InterlaceCodingOption == FIELD_CODING)) //add by wuzhongmou
{
// Add by cjw, 20070327, Begin
if(img->Seqheader_flag==1)
{
img->buf_cycle=1;
img->Seqheader_flag=0;
}
// Add by cjw, 20070327, End
}
//Commented by qihuafei, 20070925
/* if(input->InterlaceCodingOption == PAFF_CODING)
{
// Add by cjw, 20070327, Begin
if(img->Seqheader_flag==1)
{
img->buf_cycle=1;
if(img->count_PAFF==2)
img->Seqheader_flag=0;
}
// Add by cjw, 20070327, End
}//add by wuzhongmou
*/
}
else
picture_coding_type = 2; //add by wuzhongmou
//rate control
if(input->RCEnable&&img->BasicUnit<=img->Frame_Total_Number_MB)
input->fixed_picture_qp = 0;// [5/8/2007 Leeswan]
else
input->fixed_picture_qp = 1;
if(input->slice_set_enable) //added by mz, 2008.04
input->fixed_picture_qp = 0;
if (img->nb_references==1)
picture_reference_flag = 1;
else if (img->nb_references>1)
picture_reference_flag = 0;
#ifdef BACKGROUND
if(img->typeb == BP_IMG)
picture_coding_type = 3;
#endif
len+=u_v(24,"start code prefix",1,bitstream);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -