xref: /aosp_15_r20/external/libavc/encoder/ih264e_time_stamp.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker  *
5*495ae853SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker  *
9*495ae853SAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker  *
11*495ae853SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker  * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker  *
17*495ae853SAndroid Build Coastguard Worker  *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker 
21*495ae853SAndroid Build Coastguard Worker /**
22*495ae853SAndroid Build Coastguard Worker *******************************************************************************
23*495ae853SAndroid Build Coastguard Worker * @file
24*495ae853SAndroid Build Coastguard Worker *  ih264e_time_stamp.h
25*495ae853SAndroid Build Coastguard Worker *
26*495ae853SAndroid Build Coastguard Worker * @brief
27*495ae853SAndroid Build Coastguard Worker *  This file contains function declarations used for managing input and output
28*495ae853SAndroid Build Coastguard Worker *  frame time stamps
29*495ae853SAndroid Build Coastguard Worker *
30*495ae853SAndroid Build Coastguard Worker * @author
31*495ae853SAndroid Build Coastguard Worker *  ittiam
32*495ae853SAndroid Build Coastguard Worker *
33*495ae853SAndroid Build Coastguard Worker * @remarks
34*495ae853SAndroid Build Coastguard Worker *  none
35*495ae853SAndroid Build Coastguard Worker *
36*495ae853SAndroid Build Coastguard Worker *******************************************************************************
37*495ae853SAndroid Build Coastguard Worker */
38*495ae853SAndroid Build Coastguard Worker 
39*495ae853SAndroid Build Coastguard Worker #ifndef _IH264E_TIME_STAMP_H_
40*495ae853SAndroid Build Coastguard Worker #define _IH264E_TIME_STAMP_H_
41*495ae853SAndroid Build Coastguard Worker 
42*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
43*495ae853SAndroid Build Coastguard Worker /* Structures                                                                */
44*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
45*495ae853SAndroid Build Coastguard Worker 
46*495ae853SAndroid Build Coastguard Worker /**
47*495ae853SAndroid Build Coastguard Worker  * Parameters for Src/Tgt frames that are encoded
48*495ae853SAndroid Build Coastguard Worker  */
49*495ae853SAndroid Build Coastguard Worker typedef struct frame_time_t
50*495ae853SAndroid Build Coastguard Worker {
51*495ae853SAndroid Build Coastguard Worker     /* common time base(=LCM) between source and target frame rate (in ticks)*/
52*495ae853SAndroid Build Coastguard Worker     WORD32 common_time_base;
53*495ae853SAndroid Build Coastguard Worker 
54*495ae853SAndroid Build Coastguard Worker     /* number of ticks between two source frames */
55*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_src_frm_time_incr;
56*495ae853SAndroid Build Coastguard Worker 
57*495ae853SAndroid Build Coastguard Worker     /* number of ticks between two target frames */
58*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_tgt_frm_time_incr;
59*495ae853SAndroid Build Coastguard Worker 
60*495ae853SAndroid Build Coastguard Worker     /* Source frame time - measured as modulo of common time base
61*495ae853SAndroid Build Coastguard Worker      and incremented by src_frm_time_incr */
62*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_src_frm_time;
63*495ae853SAndroid Build Coastguard Worker 
64*495ae853SAndroid Build Coastguard Worker     /* Target frame time - measured as modulo of common time base
65*495ae853SAndroid Build Coastguard Worker      and incremented by tgt_frm_time_incr */
66*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_tgt_frm_time;
67*495ae853SAndroid Build Coastguard Worker 
68*495ae853SAndroid Build Coastguard Worker     /* Number of frames not to be skipped while maintaining
69*495ae853SAndroid Build Coastguard Worker      tgt_frm_rate due to delta_time_stamp  */
70*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_num_frms_dont_skip;
71*495ae853SAndroid Build Coastguard Worker 
72*495ae853SAndroid Build Coastguard Worker }frame_time_t;
73*495ae853SAndroid Build Coastguard Worker 
74*495ae853SAndroid Build Coastguard Worker typedef struct frame_time_t *frame_time_handle;
75*495ae853SAndroid Build Coastguard Worker 
76*495ae853SAndroid Build Coastguard Worker /**
77*495ae853SAndroid Build Coastguard Worker  *  Parameters that go in the bitstream based on tgt_frm_rate
78*495ae853SAndroid Build Coastguard Worker  *   1) Initialize the vop_time_incr_res with the max_frame_rate (in frames per 1000 bits)
79*495ae853SAndroid Build Coastguard Worker  *      - To represent all kinds of frame rates
80*495ae853SAndroid Build Coastguard Worker  *   2) Decide the vop_time_incr based on the source frame rate
81*495ae853SAndroid Build Coastguard Worker  *      - The decoder would like to know which source frame is encoded i.e. the source time
82*495ae853SAndroid Build Coastguard Worker  *    id of the target frame encoded and there by adjusting its time of delay
83*495ae853SAndroid Build Coastguard Worker  *   3) vop_time increments every source frame and whenever a frame is encoded (target frame),
84*495ae853SAndroid Build Coastguard Worker  *      the encoder queries the vop time of the source frame and sends it in the bit stream.
85*495ae853SAndroid Build Coastguard Worker  *   4) Since the Source frame skip logic is taken care by the frame_time module, whenever the
86*495ae853SAndroid Build Coastguard Worker  *      encoder queries the time stamp module (which gets updated outside the encoder) the
87*495ae853SAndroid Build Coastguard Worker  *      time stamp module would have the source time
88*495ae853SAndroid Build Coastguard Worker  */
89*495ae853SAndroid Build Coastguard Worker typedef struct time_stamp_t
90*495ae853SAndroid Build Coastguard Worker {
91*495ae853SAndroid Build Coastguard Worker     /*vop_time_incr_res is a integer that indicates
92*495ae853SAndroid Build Coastguard Worker      the number of evenly spaced subintervals, called ticks,
93*495ae853SAndroid Build Coastguard Worker      within one modulo time. */
94*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_vop_time_incr_res;
95*495ae853SAndroid Build Coastguard Worker 
96*495ae853SAndroid Build Coastguard Worker     /* number of bits to represent vop_time_incr_res */
97*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_vop_time_incr_range;
98*495ae853SAndroid Build Coastguard Worker 
99*495ae853SAndroid Build Coastguard Worker     /* The number of ticks elapsed between two source vops */
100*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_vop_time_incr;
101*495ae853SAndroid Build Coastguard Worker 
102*495ae853SAndroid Build Coastguard Worker     /* incremented by vop_time_incr for every source frame.
103*495ae853SAndroid Build Coastguard Worker      Represents the time offset after a modulo_time_base = 1 is sent
104*495ae853SAndroid Build Coastguard Worker      in bit stream*/
105*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_vop_time;
106*495ae853SAndroid Build Coastguard Worker 
107*495ae853SAndroid Build Coastguard Worker     /* A temporary buffer to copy of vop time and modulo time base
108*495ae853SAndroid Build Coastguard Worker      is stored since update is called before query (get time stamp) and
109*495ae853SAndroid Build Coastguard Worker      so these extra variables cur_tgt_vop_time,  */
110*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_cur_tgt_vop_time;
111*495ae853SAndroid Build Coastguard Worker 
112*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_prev_tgt_vop_time;
113*495ae853SAndroid Build Coastguard Worker 
114*495ae853SAndroid Build Coastguard Worker     /* This variable is set to 1 if we scale max frame rate by a factor of 2.
115*495ae853SAndroid Build Coastguard Worker      For mpeg4 standard, we just have 16bits and we can't accommodate more than 60000 as frame rate.
116*495ae853SAndroid Build Coastguard Worker      So we scale it and work with it */
117*495ae853SAndroid Build Coastguard Worker     WORD32 is_max_frame_rate_scaled;
118*495ae853SAndroid Build Coastguard Worker 
119*495ae853SAndroid Build Coastguard Worker } time_stamp_t;
120*495ae853SAndroid Build Coastguard Worker 
121*495ae853SAndroid Build Coastguard Worker typedef struct time_stamp_t *time_stamp_handle;
122*495ae853SAndroid Build Coastguard Worker 
123*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
124*495ae853SAndroid Build Coastguard Worker /* Function declarations                                                     */
125*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
126*495ae853SAndroid Build Coastguard Worker 
127*495ae853SAndroid Build Coastguard Worker void ih264e_init_frame_time(frame_time_t *ps_frame_time,
128*495ae853SAndroid Build Coastguard Worker                             UWORD32 u4_src_frm_rate,
129*495ae853SAndroid Build Coastguard Worker                             UWORD32 u4_tgt_frm_rate);
130*495ae853SAndroid Build Coastguard Worker 
131*495ae853SAndroid Build Coastguard Worker UWORD8 ih264e_should_src_be_skipped(frame_time_t *ps_frame_time,
132*495ae853SAndroid Build Coastguard Worker                                     UWORD32 u4_delta_time_stamp,
133*495ae853SAndroid Build Coastguard Worker                                     UWORD32 *pu4_frm_not_skipped_for_dts);
134*495ae853SAndroid Build Coastguard Worker 
135*495ae853SAndroid Build Coastguard Worker void ih264e_init_time_stamp(time_stamp_handle time_stamp,
136*495ae853SAndroid Build Coastguard Worker                             UWORD32 max_frm_rate,
137*495ae853SAndroid Build Coastguard Worker                             UWORD32 src_frm_rate);
138*495ae853SAndroid Build Coastguard Worker 
139*495ae853SAndroid Build Coastguard Worker void ih264e_update_time_stamp(time_stamp_handle time_stamp);
140*495ae853SAndroid Build Coastguard Worker 
141*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_init_free_memtab(frame_time_handle *pps_frame_time,
142*495ae853SAndroid Build Coastguard Worker                                               itt_memtab_t *ps_memtab,
143*495ae853SAndroid Build Coastguard Worker                                               ITT_FUNC_TYPE_E e_func_type);
144*495ae853SAndroid Build Coastguard Worker 
145*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_time_stamp_get_init_free_memtab(time_stamp_handle *pps_time_stamp,
146*495ae853SAndroid Build Coastguard Worker                                               itt_memtab_t *ps_memtab,
147*495ae853SAndroid Build Coastguard Worker                                               ITT_FUNC_TYPE_E e_func_type);
148*495ae853SAndroid Build Coastguard Worker 
149*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_src_frame_rate(frame_time_t *ps_frame_time);
150*495ae853SAndroid Build Coastguard Worker 
151*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_tgt_frame_rate(frame_time_t *ps_frame_time);
152*495ae853SAndroid Build Coastguard Worker 
153*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_src_ticks(frame_time_t *ps_frame_time);
154*495ae853SAndroid Build Coastguard Worker 
155*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_tgt_ticks(frame_time_t *ps_frame_time);
156*495ae853SAndroid Build Coastguard Worker 
157*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_src_time(frame_time_t *frame_time);
158*495ae853SAndroid Build Coastguard Worker 
159*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_frame_time_get_tgt_time(frame_time_t *frame_time);
160*495ae853SAndroid Build Coastguard Worker 
161*495ae853SAndroid Build Coastguard Worker void ih264e_frame_time_update_src_frame_rate(frame_time_t *ps_frame_time,
162*495ae853SAndroid Build Coastguard Worker                                              WORD32 src_frm_rate);
163*495ae853SAndroid Build Coastguard Worker 
164*495ae853SAndroid Build Coastguard Worker void ih264e_frame_time_update_tgt_frame_rate(frame_time_t *ps_frame_time,
165*495ae853SAndroid Build Coastguard Worker                                              WORD32 tgt_frm_rate);
166*495ae853SAndroid Build Coastguard Worker 
167*495ae853SAndroid Build Coastguard Worker void ih264_time_stamp_update_frame_rate(time_stamp_t *ps_time_stamp,
168*495ae853SAndroid Build Coastguard Worker                                         UWORD32 src_frm_rate);
169*495ae853SAndroid Build Coastguard Worker 
170*495ae853SAndroid Build Coastguard Worker #endif /*_IH264E_TIME_STAMP_H_ */
171*495ae853SAndroid Build Coastguard Worker 
172