159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ------------------------------------------------------------------ 259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Copyright (C) 1998-2009 PacketVideo 359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * you may not use this file except in compliance with the License. 659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * You may obtain a copy of the License at 759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * http://www.apache.org/licenses/LICENSE-2.0 959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 1059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Unless required by applicable law or agreed to in writing, software 1159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * distributed under the License is distributed on an "AS IS" BASIS, 1259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 1359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * express or implied. 1459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * See the License for the specific language governing permissions 1559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * and limitations under the License. 1659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * ------------------------------------------------------------------- 1759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong */ 1859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef _RATE_CONTROL_H_ 1959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define _RATE_CONTROL_H_ 2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4def.h" 2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dongtypedef struct tagdataPointArray 2459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 2559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Qp; 2659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rp; 2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float Mp; /* for MB-based RC, 3/14/01 */ 2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong struct tagdataPointArray *next; 2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong struct tagdataPointArray *prev; 3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} dataPointArray; 3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dongtypedef struct 3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int alpha; /* weight for I frame */ 3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rs; /*bit rate for the sequence (or segment) e.g., 24000 bits/sec */ 3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rc; /*bits used for the current frame. It is the bit count obtained after encoding. */ 3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rp; /*bits to be removed from the buffer per picture. */ 3959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*? is this the average one, or just the bits coded for the previous frame */ 4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rps; /*bit to be removed from buffer per src frame */ 4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float Ts; /*number of seconds for the sequence (or segment). e.g., 10 sec */ 4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float Ep; 4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float Ec; /*mean absolute difference for the current frame after motion compensation.*/ 4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*If the macroblock is intra coded, the original spatial pixel values are summed.*/ 4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Qc; /*quantization level used for the current frame. */ 4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Nr; /*number of P frames remaining for encoding.*/ 4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rr; /*number of bits remaining for encoding this sequence (or segment).*/ 4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Rr_Old;/* 12/24/00 */ 4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int T; /*target bit to be used for the current frame.*/ 5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int S; /*number of bits used for encoding the previous frame.*/ 5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Hc; /*header and motion vector bits used in the current frame. It includes all the information except to the residual information.*/ 5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Hp; /*header and motion vector bits used in the previous frame. It includes all the information except to the residual information.*/ 5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Ql; /*quantization level used in the previous frame */ 5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Bs; /*buffer size e.g., R/2 */ 5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int B; /*current buffer level e.g., R/4 - start from the middle of the buffer */ 5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float X1; 5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float X2; 5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float X11; 5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float M; /*safe margin for the buffer */ 6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float smTick; /*ratio of src versus enc frame rate */ 6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong double remnant; /*remainder frame of src/enc frame for fine frame skipping */ 6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int timeIncRes; /* vol->timeIncrementResolution */ 6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dataPointArray *end; /*quantization levels for the past (20) frames */ 6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int frameNumber; /* ranging from 0 to 20 nodes*/ 6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int w; 6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Nr_Original; 6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Nr_Old, Nr_Old2; 7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int skip_next_frame; 7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int Qdep; /* smooth Q adjustment */ 7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int fine_frame_skip; 7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int VBR_Enabled; 7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int no_frame_skip; 7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int no_pre_skip; 7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int totalFrameNumber; /* total coded frames, for debugging!!*/ 7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong char oFirstTime; 8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* BX rate control */ 8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int TMN_W; 8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int TMN_TH; 8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int VBV_fullness; 8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int max_BitVariance_num; /* the number of the maximum bit variance within the given buffer with the unit of 10% of bitrate/framerate*/ 8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int encoded_frames; /* counter for all encoded frames */ 8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float framerate; 8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int bitrate; 8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int low_bound; /* bound for underflow detection, usually low_bound=-Bs/2, but could be changed in H.263 mode */ 9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int VBV_fullness_offset; /* offset of VBV_fullness, usually is zero, but can be changed in H.263 mode*/ 9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* End BX */ 9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} rateControl; 9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* _RATE_CONTROL_H_ */ 97