Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #ifndef _RATE_CONTROL_H_
     19 #define _RATE_CONTROL_H_
     20 
     21 #include "mp4def.h"
     22 
     23 typedef struct tagdataPointArray
     24 {
     25     Int Qp;
     26     Int Rp;
     27     float Mp;   /* for MB-based RC, 3/14/01 */
     28     struct tagdataPointArray *next;
     29     struct tagdataPointArray *prev;
     30 } dataPointArray;
     31 
     32 
     33 typedef struct
     34 {
     35     Int alpha;  /* weight for I frame */
     36     Int Rs;     /*bit rate for the sequence (or segment) e.g., 24000 bits/sec */
     37     Int Rc;     /*bits used for the current frame. It is the bit count obtained after encoding. */
     38     Int Rp;     /*bits to be removed from the buffer per picture. */
     39     /*? is this the average one, or just the bits coded for the previous frame */
     40     Int Rps;    /*bit to be removed from buffer per src frame */
     41     float Ts;   /*number of seconds for the sequence  (or segment). e.g., 10 sec */
     42     float Ep;
     43     float Ec;   /*mean absolute difference for the current frame after motion compensation.*/
     44     /*If the macroblock is intra coded, the original spatial pixel values are summed.*/
     45     Int Qc;     /*quantization level used for the current frame. */
     46     Int Nr;     /*number of P frames remaining for encoding.*/
     47     Int Rr; /*number of bits remaining for encoding this sequence (or segment).*/
     48     Int Rr_Old;/* 12/24/00 */
     49     Int T;      /*target bit to be used for the current frame.*/
     50     Int S;      /*number of bits used for encoding the previous frame.*/
     51     Int Hc; /*header and motion vector bits used in the current frame. It includes all the  information except to the residual information.*/
     52     Int Hp; /*header and motion vector bits used in the previous frame. It includes all the     information except to the residual information.*/
     53     Int Ql; /*quantization level used in the previous frame */
     54     Int Bs; /*buffer size e.g., R/2 */
     55     Int B;      /*current buffer level e.g., R/4 - start from the middle of the buffer */
     56     float X1;
     57     float X2;
     58     float X11;
     59     float M;            /*safe margin for the buffer */
     60     float smTick;    /*ratio of src versus enc frame rate */
     61     double remnant;  /*remainder frame of src/enc frame for fine frame skipping */
     62     Int timeIncRes; /* vol->timeIncrementResolution */
     63 
     64     dataPointArray   *end; /*quantization levels for the past (20) frames */
     65 
     66     Int     frameNumber; /* ranging from 0 to 20 nodes*/
     67     Int     w;
     68     Int     Nr_Original;
     69     Int     Nr_Old, Nr_Old2;
     70     Int     skip_next_frame;
     71     Int     Qdep;       /* smooth Q adjustment */
     72     Int     fine_frame_skip;
     73     Int     VBR_Enabled;
     74     Int     no_frame_skip;
     75     Int     no_pre_skip;
     76 
     77     Int totalFrameNumber; /* total coded frames, for debugging!!*/
     78 
     79     char    oFirstTime;
     80 
     81     /* BX rate control */
     82     Int     TMN_W;
     83     Int     TMN_TH;
     84     Int     VBV_fullness;
     85     Int     max_BitVariance_num; /* the number of the maximum bit variance within the given buffer with the unit of 10% of bitrate/framerate*/
     86     Int     encoded_frames; /* counter for all encoded frames */
     87     float   framerate;
     88     Int     bitrate;
     89     Int     low_bound;              /* bound for underflow detection, usually low_bound=-Bs/2, but could be changed in H.263 mode */
     90     Int     VBV_fullness_offset;    /* offset of VBV_fullness, usually is zero, but can be changed in H.263 mode*/
     91     /* End BX */
     92 
     93 } rateControl;
     94 
     95 
     96 #endif /* _RATE_CONTROL_H_ */
     97