• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2018 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 ******************************************************************************
22 * \file vbr_storage_vbv.h
23 *
24 * \brief
25 *    This file contains all the necessary declarations for
26 *    vbr buffer control functions
27 *
28 * \date
29 *
30 * \author
31 *    ittiam
32 *
33 ******************************************************************************
34 */
35 #ifndef _VBR_STORAGE_VBV_H_
36 #define _VBR_STORAGE_VBV_H_
37 /******************************************************************************
38 VBR STORAGE (VBV):
39 Max. buffer filling rate: Rmax
40 Max. buffer size: Bmax (as specified by level and profile)
41 Current Buffer Level: Bcur
42 Frame Rate: F
43 
44 For a storage scenario, the initial buffer size is assumed to be max. For every
45 frame the Maximum bits filled in to the buffer is given by Rmaxfrm = Rmax/F. If
46 the buffer overflows then the buffer is thresholded to the max buffer size.
47 
48                (overflow)
49    B(0)            /|
50 ---|--------------/-|------------------------------ Bmax
51    |             /  |
52    |          /|/   |
53    |  /|     /      |
54    | / |  /|/       |
55    |/  | /          | /|
56        |/           |/ |
57                        |
58                        |
59 -----------------------|---------------------------
60    |<->|               |
61 (1/F)=>1/frame_rate (underflow)
62 
63 
64    B"(i) - Bits in buffer just before decoding a frame.
65    B'(i) - Bits in buffer just after decoding a frame.
66 
67 
68    B(0) (initBuffer size) = Bmax.
69    B'(i) = B"(i) - bits_decoded
70    B"(i) = Min( Bmax, B'(i-1) + Rmaxfrm)
71 
72 Overflow Scenario: In VBR case, since we have only a max filling rate (or input bit rate)
73 buffer overflow is not a issue (since the buffer filling rate can be reduced to any value
74 below this rate)
75 
76 Underflow Scenario: B'(i) should always be > 0. If not then, the buffer underflows. To
77 prevent this condition the number bits that needs to be decoded must be equal to B"(i)
78 which is equal to Min( Bmax, B'(i-1) + Rmaxfrm)
79 ****************************************************************************************/
80 
81 /*****************************************************************************/
82 /* Function Declarations                                                     */
83 /*****************************************************************************/
84 
85 typedef struct vbr_storage_vbv_t *vbr_storage_vbv_handle;
86 
87 WORD32 vbr_vbv_num_fill_use_free_memtab(
88     vbr_storage_vbv_handle *pps_vbr_storage_vbv,
89     itt_memtab_t *ps_memtab,
90     ITT_FUNC_TYPE_E e_func_type);
91 
92 /* Initalises the vbv buffer status */
93 void init_vbr_vbv(
94     vbr_storage_vbv_handle ps_vbr_storage_vbv,
95     WORD32 max_bit_rate, /* In bits/sec*/
96     WORD32 max_frm_rate, /* In frames/1000 sec*/
97     WORD32 i4_max_vbv_buff_size); /* in bits*/
98 
99 /* Updates the buffer after decoding a frame */
100 void update_vbr_vbv(vbr_storage_vbv_handle ps_vbr_storage_vbv, WORD32 i4_total_bits_decoded);
101 
102 /* gets the max_number of bits that can be decoded out of the VBV without underflow */
103 WORD32 get_max_target_bits(vbr_storage_vbv_handle ps_vbr_storage_vbv);
104 WORD32 get_max_bits_inflow_per_frm_periode(vbr_storage_vbv_handle ps_vbr_storage_vbv);
105 WORD32 get_cur_vbv_buf_size(vbr_storage_vbv_handle ps_vbr_storage_vbv);
106 
107 /* Queries the VBV buffer for the buffer status */
108 vbv_buf_status_e get_vbv_buffer_status(
109     vbr_storage_vbv_handle ps_vbr_storage_vbv,
110     WORD32 i4_total_frame_bits, /* Total frame bits consumed */
111     WORD32 *
112         pi4_num_bits_to_prevent_vbv_underflow); /* num bits to prevent from underflow after update */
113 
114 WORD32 get_max_vbv_buf_size(vbr_storage_vbv_handle ps_vbr_storage_vbv);
115 WORD32 get_vbv_buf_fullness(vbr_storage_vbv_handle ps_vbr_storage_vbv, UWORD32 u4_bits);
116 WORD32 get_max_tgt_bits_dvd_comp(
117     vbr_storage_vbv_handle ps_vbr_storage_vbv,
118     WORD32 i4_rem_bits_in_gop,
119     WORD32 i4_rem_frms_in_gop,
120     picture_type_e e_pic_type);
121 /* Changing input values at run time */
122 void change_vbr_vbv_bit_rate(vbr_storage_vbv_handle ps_vbr_storage_vbv, WORD32 i4_max_bit_rate);
123 void change_vbr_vbv_frame_rate(vbr_storage_vbv_handle ps_vbr_storage_vbv, WORD32 i4_frm_rate);
124 #endif
125