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 ******************************************************************************* 23 * @file 24 * ih264e_time_stamp.h 25 * 26 * @brief 27 * This file contains function declarations used for managing input and output 28 * frame time stamps 29 * 30 * @author 31 * ittiam 32 * 33 * @remarks 34 * none 35 * 36 ******************************************************************************* 37 */ 38 39 #ifndef _IH264E_TIME_STAMP_H_ 40 #define _IH264E_TIME_STAMP_H_ 41 42 /*****************************************************************************/ 43 /* Structures */ 44 /*****************************************************************************/ 45 46 /** 47 * Parameters for Src/Tgt frames that are encoded 48 */ 49 typedef struct frame_time_t 50 { 51 /* common time base(=LCM) between source and target frame rate (in ticks)*/ 52 WORD32 common_time_base; 53 54 /* number of ticks between two source frames */ 55 UWORD32 u4_src_frm_time_incr; 56 57 /* number of ticks between two target frames */ 58 UWORD32 u4_tgt_frm_time_incr; 59 60 /* Source frame time - measured as modulo of common time base 61 and incremented by src_frm_time_incr */ 62 UWORD32 u4_src_frm_time; 63 64 /* Target frame time - measured as modulo of common time base 65 and incremented by tgt_frm_time_incr */ 66 UWORD32 u4_tgt_frm_time; 67 68 /* Number of frames not to be skipped while maintaining 69 tgt_frm_rate due to delta_time_stamp */ 70 UWORD32 u4_num_frms_dont_skip; 71 72 }frame_time_t; 73 74 typedef struct frame_time_t *frame_time_handle; 75 76 /** 77 * Parameters that go in the bitstream based on tgt_frm_rate 78 * 1) Initialize the vop_time_incr_res with the max_frame_rate (in frames per 1000 bits) 79 * - To represent all kinds of frame rates 80 * 2) Decide the vop_time_incr based on the source frame rate 81 * - The decoder would like to know which source frame is encoded i.e. the source time 82 * id of the target frame encoded and there by adjusting its time of delay 83 * 3) vop_time increments every source frame and whenever a frame is encoded (target frame), 84 * the encoder queries the vop time of the source frame and sends it in the bit stream. 85 * 4) Since the Source frame skip logic is taken care by the frame_time module, whenever the 86 * encoder queries the time stamp module (which gets updated outside the encoder) the 87 * time stamp module would have the source time 88 */ 89 typedef struct time_stamp_t 90 { 91 /*vop_time_incr_res is a integer that indicates 92 the number of evenly spaced subintervals, called ticks, 93 within one modulo time. */ 94 UWORD32 u4_vop_time_incr_res; 95 96 /* number of bits to represent vop_time_incr_res */ 97 UWORD32 u4_vop_time_incr_range; 98 99 /* The number of ticks elapsed between two source vops */ 100 UWORD32 u4_vop_time_incr; 101 102 /* incremented by vop_time_incr for every source frame. 103 Represents the time offset after a modulo_time_base = 1 is sent 104 in bit stream*/ 105 UWORD32 u4_vop_time; 106 107 /* A temporary buffer to copy of vop time and modulo time base 108 is stored since update is called before query (get time stamp) and 109 so these extra variables cur_tgt_vop_time, */ 110 UWORD32 u4_cur_tgt_vop_time; 111 112 UWORD32 u4_prev_tgt_vop_time; 113 114 /* This variable is set to 1 if we scale max frame rate by a factor of 2. 115 For mpeg4 standard, we just have 16bits and we can't accommodate more than 60000 as frame rate. 116 So we scale it and work with it */ 117 WORD32 is_max_frame_rate_scaled; 118 119 } time_stamp_t; 120 121 typedef struct time_stamp_t *time_stamp_handle; 122 123 /*****************************************************************************/ 124 /* Function declarations */ 125 /*****************************************************************************/ 126 127 void ih264e_init_frame_time(frame_time_t *ps_frame_time, 128 UWORD32 u4_src_frm_rate, 129 UWORD32 u4_tgt_frm_rate); 130 131 UWORD8 ih264e_should_src_be_skipped(frame_time_t *ps_frame_time, 132 UWORD32 u4_delta_time_stamp, 133 UWORD32 *pu4_frm_not_skipped_for_dts); 134 135 void ih264e_init_time_stamp(time_stamp_handle time_stamp, 136 UWORD32 max_frm_rate, 137 UWORD32 src_frm_rate); 138 139 void ih264e_update_time_stamp(time_stamp_handle time_stamp); 140 141 WORD32 ih264e_frame_time_get_init_free_memtab(frame_time_handle *pps_frame_time, 142 itt_memtab_t *ps_memtab, 143 ITT_FUNC_TYPE_E e_func_type); 144 145 WORD32 ih264e_time_stamp_get_init_free_memtab(time_stamp_handle *pps_time_stamp, 146 itt_memtab_t *ps_memtab, 147 ITT_FUNC_TYPE_E e_func_type); 148 149 WORD32 ih264e_frame_time_get_src_frame_rate(frame_time_t *ps_frame_time); 150 151 WORD32 ih264e_frame_time_get_tgt_frame_rate(frame_time_t *ps_frame_time); 152 153 WORD32 ih264e_frame_time_get_src_ticks(frame_time_t *ps_frame_time); 154 155 WORD32 ih264e_frame_time_get_tgt_ticks(frame_time_t *ps_frame_time); 156 157 WORD32 ih264e_frame_time_get_src_time(frame_time_t *frame_time); 158 159 WORD32 ih264e_frame_time_get_tgt_time(frame_time_t *frame_time); 160 161 void ih264e_frame_time_update_src_frame_rate(frame_time_t *ps_frame_time, 162 WORD32 src_frm_rate); 163 164 void ih264e_frame_time_update_tgt_frame_rate(frame_time_t *ps_frame_time, 165 WORD32 tgt_frm_rate); 166 167 void ih264_time_stamp_update_frame_rate(time_stamp_t *ps_time_stamp, 168 UWORD32 src_frm_rate); 169 170 #endif /*_IH264E_TIME_STAMP_H_ */ 171 172