Coverage Report

Created: 2026-01-10 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/encoder/irc_vbr_str_prms.c
Line
Count
Source
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
/*****************************************************************************/
22
/* Includes */
23
/*****************************************************************************/
24
25
/* System include files */
26
#include <stdio.h>
27
28
/* User include files */
29
#include "irc_datatypes.h"
30
#include "irc_cntrl_param.h"
31
#include "irc_vbr_str_prms.h"
32
33
/******************************************************************************
34
 Function Name   : irc_init_vbv_str_prms
35
 Description     : Initializes and calculates the number of I frame and P frames
36
                   in the delay period
37
 Return Values   : void
38
 *****************************************************************************/
39
void irc_init_vbv_str_prms(vbr_str_prms_t *p_vbr_str_prms,
40
                           UWORD32 u4_intra_frm_interval,
41
                           UWORD32 u4_src_ticks,
42
                           UWORD32 u4_tgt_ticks,
43
                           UWORD32 u4_frms_in_delay_period)
44
0
{
45
46
0
    UWORD32 i4_num_i_frms_in_delay_per, i4_num_p_frms_in_delay_per;
47
48
0
    p_vbr_str_prms->u4_frms_in_delay_prd = u4_frms_in_delay_period;
49
0
    p_vbr_str_prms->u4_src_ticks = u4_src_ticks;
50
0
    p_vbr_str_prms->u4_tgt_ticks = u4_tgt_ticks;
51
0
    p_vbr_str_prms->u4_intra_frame_int = u4_intra_frm_interval;
52
53
    /*
54
     * Finding the number of I frames and P frames in delay period. This
55
     * value along with the drain rates for the corresponding picture types will
56
     * be used to calculate the buffer sizes
57
     */
58
0
    i4_num_i_frms_in_delay_per = ((u4_frms_in_delay_period * u4_src_ticks)
59
0
                    / (u4_intra_frm_interval * u4_tgt_ticks));
60
61
    /* Ceiling the above result*/
62
0
    if((i4_num_i_frms_in_delay_per * u4_intra_frm_interval * u4_tgt_ticks)
63
0
                    < (u4_frms_in_delay_period * u4_src_ticks))
64
0
    {
65
0
        i4_num_i_frms_in_delay_per++;
66
67
0
    }
68
0
    i4_num_p_frms_in_delay_per = u4_frms_in_delay_period
69
0
                    - i4_num_i_frms_in_delay_per;
70
71
0
    p_vbr_str_prms->u4_num_pics_in_delay_prd[I_PIC] =
72
0
                    i4_num_i_frms_in_delay_per;
73
0
    p_vbr_str_prms->u4_num_pics_in_delay_prd[P_PIC] =
74
0
                    i4_num_p_frms_in_delay_per;
75
0
    p_vbr_str_prms->u4_intra_prd_pos_in_tgt_ticks = (u4_intra_frm_interval
76
0
                    * (p_vbr_str_prms->u4_num_pics_in_delay_prd[I_PIC]))
77
0
                    * u4_tgt_ticks;
78
0
    p_vbr_str_prms->u4_pic_num = 0;
79
0
    p_vbr_str_prms->u4_cur_pos_in_src_ticks = 0;
80
0
}
81
82
WORD32 irc_get_vsp_num_pics_in_dly_prd(vbr_str_prms_t *p_vbr_str_prms,
83
                                       UWORD32 *pu4_num_pics_in_delay_prd)
84
0
{
85
0
    pu4_num_pics_in_delay_prd[I_PIC] =
86
0
                    p_vbr_str_prms->u4_num_pics_in_delay_prd[I_PIC];
87
0
    pu4_num_pics_in_delay_prd[P_PIC] =
88
0
                    p_vbr_str_prms->u4_num_pics_in_delay_prd[P_PIC];
89
0
    return (p_vbr_str_prms->u4_frms_in_delay_prd);
90
0
}
91
92
/******************************************************************************
93
 Function Name   : irc_update_vbr_str_prms
94
 Description     : update the number of I frames and P/B frames in the delay period
95
                   for buffer size calculations
96
 *****************************************************************************/
97
void irc_update_vbr_str_prms(vbr_str_prms_t *p_vbr_str_prms,
98
                             picture_type_e e_pic_type)
99
0
{
100
    /*
101
     * Updating the number of I frames and P frames after encoding every
102
     * picture. These values along with the drain rates for the corresponding
103
     * picture  types will be used to calculate the CBR buffer size every frame
104
     */
105
106
0
    if(e_pic_type == I_PIC)
107
0
    {
108
0
        p_vbr_str_prms->u4_num_pics_in_delay_prd[I_PIC]--;
109
0
    }
110
0
    else
111
0
    {
112
0
        p_vbr_str_prms->u4_num_pics_in_delay_prd[P_PIC]--;
113
0
    }
114
115
    /* If the next I frame falls within the delay period, we need to increment
116
     * the number of I frames in the period, else increment the number of P
117
     * frames
118
     */
119
0
    if((p_vbr_str_prms->u4_cur_pos_in_src_ticks
120
0
                    + (p_vbr_str_prms->u4_frms_in_delay_prd
121
0
                                    * p_vbr_str_prms->u4_src_ticks))
122
0
                    >= p_vbr_str_prms->u4_intra_prd_pos_in_tgt_ticks)
123
0
    {
124
0
        p_vbr_str_prms->u4_intra_prd_pos_in_tgt_ticks -=
125
0
                        p_vbr_str_prms->u4_cur_pos_in_src_ticks;
126
0
        p_vbr_str_prms->u4_intra_prd_pos_in_tgt_ticks +=
127
0
                        p_vbr_str_prms->u4_intra_frame_int
128
0
                                        * p_vbr_str_prms->u4_tgt_ticks;
129
0
        p_vbr_str_prms->u4_num_pics_in_delay_prd[I_PIC]++;
130
0
        p_vbr_str_prms->u4_pic_num = 0;
131
0
        p_vbr_str_prms->u4_cur_pos_in_src_ticks = 0;
132
0
    }
133
0
    else
134
0
    {
135
0
        p_vbr_str_prms->u4_num_pics_in_delay_prd[P_PIC]++;
136
0
    }
137
0
    p_vbr_str_prms->u4_pic_num++;
138
0
    p_vbr_str_prms->u4_cur_pos_in_src_ticks += p_vbr_str_prms->u4_src_ticks;
139
0
}
140
141
void irc_get_vsp_src_tgt_ticks(vbr_str_prms_t *p_vbr_str_prms,
142
                               UWORD32 *pu4_src_ticks,
143
                               UWORD32 *pu4_tgt_ticks)
144
0
{
145
0
    pu4_src_ticks[0] = p_vbr_str_prms->u4_src_ticks;
146
0
    pu4_tgt_ticks[0] = p_vbr_str_prms->u4_tgt_ticks;
147
0
}
148
149
/*******************************************************************************
150
 Function Name   : change_vbr_str_prms
151
 Description     : Takes in changes of Intra frame interval, source and target
152
                   ticks and recalculates the position of the  next I frame
153
 ******************************************************************************/
154
void irc_change_vsp_ifi(vbr_str_prms_t *p_vbr_str_prms,
155
                        UWORD32 u4_intra_frame_int)
156
0
{
157
0
    irc_init_vbv_str_prms(p_vbr_str_prms, u4_intra_frame_int,
158
0
                          p_vbr_str_prms->u4_src_ticks,
159
0
                          p_vbr_str_prms->u4_tgt_ticks,
160
0
                          p_vbr_str_prms->u4_frms_in_delay_prd);
161
0
}
162
163
void irc_change_vsp_tgt_ticks(vbr_str_prms_t *p_vbr_str_prms,
164
                              UWORD32 u4_tgt_ticks)
165
0
{
166
0
    UWORD32 u4_rem_intra_per_scaled;
167
0
    UWORD32 u4_prev_tgt_ticks = p_vbr_str_prms->u4_tgt_ticks;
168
169
    /*
170
     * If the target frame rate is changed, recalculate the position of the next
171
     * I frame based on the new target frame rate
172
     * LIMITATIONS :
173
     * Currently no support is available for dynamic change in source frame rate
174
     */
175
176
0
    u4_rem_intra_per_scaled = ((p_vbr_str_prms->u4_intra_prd_pos_in_tgt_ticks
177
0
                    - p_vbr_str_prms->u4_cur_pos_in_src_ticks)
178
0
                    / u4_prev_tgt_ticks) * u4_tgt_ticks;
179
180
0
    p_vbr_str_prms->u4_intra_prd_pos_in_tgt_ticks = u4_rem_intra_per_scaled
181
0
                    + p_vbr_str_prms->u4_cur_pos_in_src_ticks;
182
183
0
}
184
185
void irc_change_vsp_src_ticks(vbr_str_prms_t *p_vbr_str_prms,
186
                              UWORD32 u4_src_ticks)
187
0
{
188
0
    irc_init_vbv_str_prms(p_vbr_str_prms, p_vbr_str_prms->u4_intra_frame_int,
189
0
                          u4_src_ticks, p_vbr_str_prms->u4_tgt_ticks,
190
0
                          p_vbr_str_prms->u4_frms_in_delay_prd);
191
0
}
192
193
void irc_change_vsp_fidp(vbr_str_prms_t *p_vbr_str_prms,
194
                         UWORD32 u4_frms_in_delay_period)
195
0
{
196
0
    irc_init_vbv_str_prms(p_vbr_str_prms, p_vbr_str_prms->u4_intra_frame_int,
197
0
                          p_vbr_str_prms->u4_src_ticks,
198
0
                          p_vbr_str_prms->u4_tgt_ticks,
199
0
                          u4_frms_in_delay_period);
200
0
}