summaryrefslogtreecommitdiffstats
path: root/encoder/ih264e_modify_frm_rate.c
blob: bc0e8732cc33475834a64d9716efb17d855f72de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/**
*******************************************************************************
* @file
*  ih264e_modify_frm_rate.c
*
* @brief
*  Functions used to modify frame rate
*
* @author
*  ittiam
*
* @par List of Functions:
*  - ih264e_pd_frm_rate_get_init_free_memtab()
*  - ih264e_init_pd_frm_rate()
*  - ih264e_update_pd_frm_rate()
*  - ih264e_get_pd_avg_frm_rate()
*
* @remarks
*  None
*
*******************************************************************************
*/

/*****************************************************************************/
/* File Includes                                                             */
/*****************************************************************************/

/* User include files */
#include "irc_datatypes.h"
#include "iv2.h"
#include "ive2.h"
#include "ih264_defs.h"
#include "ih264_structs.h"
#include "ih264_trans_quant_itrans_iquant.h"
#include "ih264_inter_pred_filters.h"
#include "ih264_mem_fns.h"
#include "ih264_padding.h"
#include "ih264_intra_pred_filters.h"
#include "ih264_deblk_edge_filters.h"
#include "ih264e_error.h"
#include "ih264e_bitstream.h"
#include "ih264e_defs.h"
#include "ime_distortion_metrics.h"
#include "ime_structs.h"
#include "irc_cntrl_param.h"
#include "irc_frame_info_collector.h"
#include "ih264e_rate_control.h"
#include "ih264e_structs.h"
#include "ih264e_rc_mem_interface.h"
#include "ih264e_time_stamp.h"
#include "ih264e_modify_frm_rate.h"


/*****************************************************************************/
/* Function Definitions                                                      */
/*****************************************************************************/

/**
*******************************************************************************
*
* @brief Function to init pd frame rate memtab
*
* @par Description
*  Function to init pull down frame rate memtab
*
* @param[in] pps_pd_frm_rate
*  pull down frame rate context
*
* @param[in] ps_memtab
*  Handle to memtab
*
* @param[in] e_func_type
*  Function type (get memtab/ update memtab)
*
* @returns  Number of memtabs used
*
* @remarks  None
*
*******************************************************************************
*/
WORD32 ih264e_pd_frm_rate_get_init_free_memtab(pd_frm_rate_handle *pps_pd_frm_rate,
                                               itt_memtab_t *ps_memtab,
                                               ITT_FUNC_TYPE_E e_func_type)
{
    WORD32 i4_mem_tab_idx = 0;
    static pd_frm_rate_t s_temp_pd_frm_rate_t;

    /* Hack for al alloc, during which we dont have any state memory.
     Dereferencing can cause issues */
    if (e_func_type == GET_NUM_MEMTAB || e_func_type == FILL_MEMTAB)
        (*pps_pd_frm_rate) = &s_temp_pd_frm_rate_t;

    /* for src rate control state structure */
    if (e_func_type != GET_NUM_MEMTAB)
    {
        fill_memtab(&ps_memtab[i4_mem_tab_idx], sizeof(pd_frm_rate_t),
                    ALIGN_128_BYTE, PERSISTENT, DDR);
        use_or_fill_base(&ps_memtab[0], (void**) pps_pd_frm_rate, e_func_type);
    }
    i4_mem_tab_idx++;

    return (i4_mem_tab_idx);
}

/**
*******************************************************************************
*
* @brief Initializes the pull down frame rate state structure based on input
*  frame rate
*
* @par Description
*  Initializes the pull down frame rate state structure based on input frame rate
*
* @param[in] ps_pd_frm_rate
*  Pull down frame rate context
*
* @param[in] u4_input_frm_rate
*  Input frame rate in frame per 1000sec
*
* @returns none
*
* @remarks
*
*******************************************************************************
*/
void ih264e_init_pd_frm_rate(pd_frm_rate_t *ps_pd_frm_rate,
                             UWORD32 u4_input_frm_rate)
{
    WORD32 i;

    ps_pd_frm_rate->u4_input_frm_rate = u4_input_frm_rate;

    for (i = 0; i < (WORD32) (u4_input_frm_rate / 1000); i++)
    {
        ps_pd_frm_rate->u4_cur_frm_rate[i] = u4_input_frm_rate;
    }

    ps_pd_frm_rate->u4_frm_num = 0;

    ps_pd_frm_rate->u4_tot_frm_encoded = 0;
}

/**
*******************************************************************************
*
* @brief Function to update pull down frame rate
*
* @par   Description
*  For each frame a run time frame rate value is sent based on whether a frame
*  is skipped or not. If it is skipped for pull down then the current frame
*  rate for the pull down period is signaled as 4/5th of the original frame
*  rate. Thus when this is averaged the frame rate gradually switches from the
*  input frame rate to 4/5th of input frame rate as and when more 3:2 pull
*  down patterns are detected
*
* @param[in] ps_pd_frm_rate
*  Pull down frame rate context
*
* @param[in] u4_input_frm_rate
*  Input frame rate in frame per 1000sec
*
* @returns none
*
* @remarks
*
*******************************************************************************
*/
void ih264e_update_pd_frm_rate(pd_frm_rate_t *ps_pd_frm_rate,
                               UWORD32 u4_cur_frm_rate)
{
    ps_pd_frm_rate->u4_cur_frm_rate[ps_pd_frm_rate->u4_frm_num] = u4_cur_frm_rate;

    ps_pd_frm_rate->u4_frm_num++;

    /* Increment the frame number */
    if (ps_pd_frm_rate->u4_tot_frm_encoded < (ps_pd_frm_rate->u4_input_frm_rate / 1000))
    {
        ps_pd_frm_rate->u4_tot_frm_encoded++;
    }

    /* Reset frm_num to zero  */
    if (ps_pd_frm_rate->u4_frm_num >= (ps_pd_frm_rate->u4_input_frm_rate / 1000))
    {
        ps_pd_frm_rate->u4_frm_num = 0;
    }
}

/**
*******************************************************************************
*
* @brief returns average frame rate in 1 sec duration
*
* @par Description
*  Averages the last N frame in period(1 sec) and then gives that
*  as the current frames frame rate. Thus this averages out the sudden
*  variation in frame rate
*
* @param[in] ps_pd_frm_rate
*  Handle to pull down frame rate context
*
* @returns average frame rate
*
* @remarks
*
*******************************************************************************
*/
UWORD32 ih264e_get_pd_avg_frm_rate(pd_frm_rate_t *ps_pd_frm_rate)
{
    WORD32 i;
    WORD32 i4_avg_frm_rate = 0;

    for (i = 0; i < (WORD32) ps_pd_frm_rate->u4_tot_frm_encoded; i++)
    {
        i4_avg_frm_rate += ps_pd_frm_rate->u4_cur_frm_rate[i];
    }

    i4_avg_frm_rate = i4_avg_frm_rate / ps_pd_frm_rate->u4_tot_frm_encoded;

    return i4_avg_frm_rate;
}