Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2015 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 
     21 #ifndef _VBR_STORAGE_VBV_H_
     22 #define _VBR_STORAGE_VBV_H_
     23 /******************************************************************************
     24 VBR STORAGE (VBV):
     25 Max. buffer filling rate: Rmax
     26 Max. buffer size: Bmax (as specified by level and profile)
     27 Current Buffer Level: Bcur
     28 Frame Rate: F
     29 
     30 For a storage scenario, the initial buffer size is assumed to be max. For every
     31 frame the Maximum bits filled in to the buffer is given by Rmaxfrm = Rmax/F. If
     32 the buffer overflows then the buffer is thresholded to the max buffer size.
     33 
     34                (overflow)
     35    B(0)            /|
     36 ---|--------------/-|------------------------------ Bmax
     37    |             /  |
     38    |          /|/   |
     39    |  /|     /      |
     40    | / |  /|/       |
     41    |/  | /          | /|
     42        |/           |/ |
     43                        |
     44                        |
     45 -----------------------|---------------------------
     46    |<->|               |
     47 (1/F)=>1/frame_rate (underflow)
     48 
     49 
     50    B"(i) - Bits in buffer just before decoding a frame.
     51    B'(i) - Bits in buffer just after decoding a frame.
     52 
     53 
     54    B(0) (initBuffer size) = Bmax.
     55    B'(i) = B"(i) - bits_decoded
     56    B"(i) = Min( Bmax, B'(i-1) + Rmaxfrm)
     57 
     58 Overflow Scenario: In VBR case, since we have only a max filling rate (or input bit rate)
     59 buffer overflow is not a issue (since the buffer filling rate can be reduced to any value
     60 below this rate)
     61 
     62 Underflow Scenario: B'(i) should always be > 0. If not then, the buffer underflows. To
     63 prevent this condition the number bits that needs to be decoded must be equal to B"(i)
     64 which is equal to Min( Bmax, B'(i-1) + Rmaxfrm)
     65 ****************************************************************************************/
     66 
     67 typedef struct vbr_storage_vbv_t* vbr_storage_vbv_handle;
     68 
     69 WORD32 irc_vbr_vbv_num_fill_use_free_memtab(vbr_storage_vbv_handle *pps_vbr_storage_vbv,
     70                                             itt_memtab_t *ps_memtab,
     71                                             ITT_FUNC_TYPE_E e_func_type);
     72 
     73 /* Initalises the vbv buffer status */
     74 void irc_init_vbr_vbv(vbr_storage_vbv_handle ps_vbr_storage_vbv,
     75                       WORD32 max_bit_rate, /* In bits/sec*/
     76                       WORD32 max_frm_rate, /* In frames/1000 sec*/
     77                       WORD32 i4_max_vbv_buff_size); /* in bits*/
     78 
     79 /* Updates the buffer after decoding a frame */
     80 void irc_update_vbr_vbv(vbr_storage_vbv_handle ps_vbr_storage_vbv,
     81                         WORD32 i4_total_bits_decoded);
     82 
     83 /* gets the max_number of bits that can be decoded out of the VBV without underflow */
     84 WORD32 irc_get_max_target_bits(vbr_storage_vbv_handle ps_vbr_storage_vbv);
     85 
     86 WORD32 irc_get_max_bits_inflow_per_frm_periode(vbr_storage_vbv_handle ps_vbr_storage_vbv);
     87 
     88 WORD32 irc_get_max_bits_per_tgt_frm(vbr_storage_vbv_handle ps_vbr_storage_vbv);
     89 
     90 WORD32 irc_get_cur_vbv_buf_size(vbr_storage_vbv_handle ps_vbr_storage_vbv);
     91 
     92 /* Queries the VBV buffer for the buffer status */
     93 vbv_buf_status_e irc_get_vbv_buffer_status(vbr_storage_vbv_handle ps_vbr_storage_vbv,
     94                                            WORD32 i4_total_frame_bits,
     95                                            WORD32 *pi4_num_bits_to_prevent_vbv_underflow);
     96 
     97 UWORD8 irc_restrict_swing_dvd_comp(vbr_storage_vbv_handle ps_vbr_storage_vbv);
     98 
     99 WORD32 irc_get_max_vbv_buf_size(vbr_storage_vbv_handle ps_vbr_storage_vbv);
    100 
    101 WORD32 irc_vbv_get_vbv_buf_fullness(vbr_storage_vbv_handle ps_vbr_storage_vbv,
    102                                     UWORD32 u4_bits);
    103 
    104 WORD32 irc_get_max_tgt_bits_dvd_comp(vbr_storage_vbv_handle ps_vbr_storage_vbv,
    105                                      WORD32 i4_rem_bits_in_gop,
    106                                      WORD32 i4_rem_frms_in_gop,
    107                                      picture_type_e e_pic_type);
    108 
    109 /* Changing input values at run time */
    110 void irc_change_vbr_vbv_bit_rate(vbr_storage_vbv_handle ps_vbr_storage_vbv,
    111                                  WORD32 i4_max_bit_rate);
    112 
    113 void irc_change_vbr_vbv_frame_rate(vbr_storage_vbv_handle ps_vbr_storage_vbv,
    114                                    WORD32 i4_frm_rate);
    115 
    116 void irc_change_vbr_max_bits_per_tgt_frm(vbr_storage_vbv_handle ps_vbr_storage_vbv,
    117                                          WORD32 i4_tgt_frm_rate);
    118 #endif
    119 
    120