Coverage Report

Created: 2026-01-10 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/encoder/irc_mb_model_based.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
/* File Includes                                                             */
23
/*****************************************************************************/
24
25
/* User include files */
26
#include "irc_datatypes.h"
27
#include "irc_cntrl_param.h"
28
#include "irc_mem_req_and_acq.h"
29
#include "irc_mb_model_based.h"
30
31
typedef struct mb_rate_control_t
32
{
33
    /* Frame Qp */
34
    UWORD8 u1_frm_qp;
35
36
    /*
37
     * Estimated average activity for the current frame (updated with the
38
     * previous frame activity since it is independent of picture type whether
39
     * it is I or P)
40
     */
41
    WORD32 i4_avg_activity;
42
43
} mb_rate_control_t;
44
45
WORD32 irc_mbrc_num_fill_use_free_memtab(mb_rate_control_t **pps_mb_rate_control,
46
                                         itt_memtab_t *ps_memtab,
47
                                         ITT_FUNC_TYPE_E e_func_type)
48
121k
{
49
121k
    WORD32 i4_mem_tab_idx = 0;
50
121k
    mb_rate_control_t s_mb_rate_control_temp;
51
52
    /*
53
     * Hack for al alloc, during which we don't have any state memory.
54
     * Dereferencing can cause issues
55
     */
56
121k
    if(e_func_type == GET_NUM_MEMTAB || e_func_type == FILL_MEMTAB)
57
101k
    {
58
101k
        (*pps_mb_rate_control) = &s_mb_rate_control_temp;
59
101k
    }
60
61
    /*For src rate control state structure*/
62
121k
    if(e_func_type != GET_NUM_MEMTAB)
63
60.6k
    {
64
60.6k
        fill_memtab(&ps_memtab[i4_mem_tab_idx], sizeof(mb_rate_control_t),
65
60.6k
                    ALIGN_128_BYTE, PERSISTENT, DDR);
66
60.6k
        use_or_fill_base(&ps_memtab[0], (void**)pps_mb_rate_control,
67
60.6k
                         e_func_type);
68
60.6k
    }
69
121k
    i4_mem_tab_idx++;
70
71
121k
    return (i4_mem_tab_idx);
72
121k
}
73
74
/*******************************************************************************
75
 MB LEVEL API FUNCTIONS
76
 ******************************************************************************/
77
78
/******************************************************************************
79
 Description     : Initialize the mb model and the average activity to default
80
                   values
81
 ******************************************************************************/
82
void irc_init_mb_level_rc(mb_rate_control_t *ps_mb_rate_control)
83
57.9k
{
84
    /* Set values to default */
85
57.9k
    ps_mb_rate_control->i4_avg_activity = 0;
86
57.9k
}
87
88
/******************************************************************************
89
 Description     : Initialize the mb state with frame level decisions
90
 *********************************************************************************/
91
void irc_mb_init_frame_level(mb_rate_control_t *ps_mb_rate_control,
92
                             UWORD8 u1_frame_qp)
93
0
{
94
    /* Update frame level QP */
95
0
    ps_mb_rate_control->u1_frm_qp = u1_frame_qp;
96
0
}
97
98
/******************************************************************************
99
 Description     : Reset the mb activity - Whenever there is SCD
100
                   the mb activity is reset
101
 *********************************************************************************/
102
void irc_reset_mb_activity(mb_rate_control_t *ps_mb_rate_control)
103
0
{
104
0
    ps_mb_rate_control->i4_avg_activity = 0;
105
0
}
106
107
/******************************************************************************
108
 Description     : Calculates the mb level qp
109
 *********************************************************************************/
110
void irc_get_mb_qp(mb_rate_control_t *ps_mb_rate_control,
111
                   WORD32 i4_cur_mb_activity,
112
                   WORD32 *pi4_mb_qp)
113
0
{
114
0
    WORD32 i4_qp;
115
    /* Initialize the mb level qp with the frame level qp */
116
0
    i4_qp = ps_mb_rate_control->u1_frm_qp;
117
118
    /*
119
     * Store the model based QP - This is used for updating the rate control model
120
     */
121
0
    pi4_mb_qp[0] = i4_qp;
122
123
    /* Modulate the Qp based on the activity */
124
0
    if((ps_mb_rate_control->i4_avg_activity) && (i4_qp < 100))
125
0
    {
126
0
        i4_qp =((((2 * i4_cur_mb_activity))
127
0
               + ps_mb_rate_control->i4_avg_activity)* i4_qp
128
0
               + ((i4_cur_mb_activity + 2 * ps_mb_rate_control->i4_avg_activity)
129
0
               >> 1))/ (i4_cur_mb_activity + 2 * ps_mb_rate_control->i4_avg_activity);
130
131
0
        if(i4_qp > ((3 * ps_mb_rate_control->u1_frm_qp) >> 1))
132
0
        {
133
0
            i4_qp = ((3 * ps_mb_rate_control->u1_frm_qp) >> 1);
134
0
        }
135
0
    }
136
137
    /* Store the qp modulated by mb activity - This is used for encoding the MB */
138
0
    pi4_mb_qp[1] = i4_qp;
139
0
}
140
141
/*******************************************************************************
142
 Description     : Returns the stored frame level QP
143
 ******************************************************************************/
144
UWORD8 irc_get_frm_level_qp(mb_rate_control_t *ps_mb_rate_control)
145
0
{
146
0
    return (ps_mb_rate_control->u1_frm_qp);
147
0
}
148
149
/*******************************************************************************
150
 Description     : Update the frame level info collected
151
 ******************************************************************************/
152
void irc_mb_update_frame_level(mb_rate_control_t *ps_mb_rate_control,
153
                               WORD32 i4_avg_activity)
154
0
{
155
     /* Update the Average Activity */
156
0
     ps_mb_rate_control->i4_avg_activity = i4_avg_activity;
157
0
}