90 gstclock_class = (GstClockClass *) klass; |
93 gstclock_class = (GstClockClass *) klass; |
91 |
94 |
92 parent_class = g_type_class_peek_parent (klass); |
95 parent_class = g_type_class_peek_parent (klass); |
93 |
96 |
94 gstclock_class->get_internal_time = gst_audio_clock_get_internal_time; |
97 gstclock_class->get_internal_time = gst_audio_clock_get_internal_time; |
|
98 |
|
99 GST_DEBUG_CATEGORY_INIT (gst_audio_clock_debug, "audioclock", 0, |
|
100 "audioclock"); |
95 } |
101 } |
96 |
102 |
97 static void |
103 static void |
98 gst_audio_clock_init (GstAudioClock * clock) |
104 gst_audio_clock_init (GstAudioClock * clock) |
99 { |
105 { |
100 clock->last_time = 0; |
106 clock->last_time = 0; |
|
107 clock->abidata.ABI.time_offset = 0; |
101 GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER); |
108 GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER); |
102 } |
109 } |
103 |
110 |
104 /** |
111 /** |
105 * gst_audio_clock_new: |
112 * gst_audio_clock_new: |
128 aclock->user_data = user_data; |
135 aclock->user_data = user_data; |
129 |
136 |
130 return (GstClock *) aclock; |
137 return (GstClock *) aclock; |
131 } |
138 } |
132 |
139 |
|
140 /** |
|
141 * gst_audio_clock_reset: |
|
142 * @clock: a #GstAudioClock |
|
143 * @time: a #GstClockTime |
|
144 * |
|
145 * Inform @clock that future calls to #GstAudioClockGetTimeFunc will return values |
|
146 * starting from @time. The clock will update an internal offset to make sure that |
|
147 * future calls to internal_time will return an increasing result as required by |
|
148 * the #GstClock object. |
|
149 */ |
|
150 #ifdef __SYMBIAN32__ |
|
151 EXPORT_C |
|
152 #endif |
|
153 |
|
154 void |
|
155 gst_audio_clock_reset (GstAudioClock * clock, GstClockTime time) |
|
156 { |
|
157 GstClockTimeDiff time_offset; |
|
158 |
|
159 if (clock->last_time >= time) |
|
160 time_offset = clock->last_time - time; |
|
161 else |
|
162 time_offset = -(time - clock->last_time); |
|
163 |
|
164 clock->abidata.ABI.time_offset = time_offset; |
|
165 |
|
166 GST_DEBUG_OBJECT (clock, |
|
167 "reset clock to %" GST_TIME_FORMAT ", offset %" GST_TIME_FORMAT, |
|
168 GST_TIME_ARGS (time), GST_TIME_ARGS (time_offset)); |
|
169 } |
|
170 |
133 static GstClockTime |
171 static GstClockTime |
134 gst_audio_clock_get_internal_time (GstClock * clock) |
172 gst_audio_clock_get_internal_time (GstClock * clock) |
135 { |
173 { |
136 GstAudioClock *aclock = GST_AUDIO_CLOCK (clock); |
174 GstAudioClock *aclock; |
137 GstClockTime result; |
175 GstClockTime result; |
138 |
176 |
|
177 aclock = GST_AUDIO_CLOCK_CAST (clock); |
|
178 |
139 result = aclock->func (clock, aclock->user_data); |
179 result = aclock->func (clock, aclock->user_data); |
140 if (result == GST_CLOCK_TIME_NONE) |
180 if (result == GST_CLOCK_TIME_NONE) { |
141 result = aclock->last_time; |
181 result = aclock->last_time; |
142 else |
182 } else { |
143 aclock->last_time = result; |
183 result += aclock->abidata.ABI.time_offset; |
|
184 /* clock must be increasing */ |
|
185 if (aclock->last_time < result) |
|
186 aclock->last_time = result; |
|
187 else |
|
188 result = aclock->last_time; |
|
189 } |
|
190 |
|
191 GST_DEBUG_OBJECT (clock, |
|
192 "result %" GST_TIME_FORMAT ", last_time %" GST_TIME_FORMAT, |
|
193 GST_TIME_ARGS (result), GST_TIME_ARGS (aclock->last_time)); |
144 |
194 |
145 return result; |
195 return result; |
146 } |
196 } |
|
197 |
|
198 /** |
|
199 * gst_audio_clock_get_time: |
|
200 * @clock: a #GstAudioClock |
|
201 * |
|
202 * Report the time as returned by the #GstAudioClockGetTimeFunc without applying |
|
203 * any offsets. |
|
204 * |
|
205 * Returns: the time as reported by the time function of the audio clock |
|
206 * |
|
207 * Since: 0.10.23 |
|
208 */ |
|
209 #ifdef __SYMBIAN32__ |
|
210 EXPORT_C |
|
211 #endif |
|
212 |
|
213 GstClockTime |
|
214 gst_audio_clock_get_time (GstClock * clock) |
|
215 { |
|
216 GstAudioClock *aclock; |
|
217 GstClockTime result; |
|
218 |
|
219 aclock = GST_AUDIO_CLOCK_CAST (clock); |
|
220 |
|
221 result = aclock->func (clock, aclock->user_data); |
|
222 if (result == GST_CLOCK_TIME_NONE) { |
|
223 result = aclock->last_time - aclock->abidata.ABI.time_offset; |
|
224 } |
|
225 |
|
226 return result; |
|
227 } |
|
228 |
|
229 /** |
|
230 * gst_audio_clock_adjust: |
|
231 * @clock: a #GstAudioClock |
|
232 * @time: a #GstClockTime |
|
233 * |
|
234 * Adjust @time with the internal offset of the audio clock. |
|
235 * |
|
236 * Returns: @time adjusted with the internal offset. |
|
237 * |
|
238 * Since: 0.10.23 |
|
239 */ |
|
240 #ifdef __SYMBIAN32__ |
|
241 EXPORT_C |
|
242 #endif |
|
243 |
|
244 GstClockTime |
|
245 gst_audio_clock_adjust (GstClock * clock, GstClockTime time) |
|
246 { |
|
247 GstAudioClock *aclock; |
|
248 GstClockTime result; |
|
249 |
|
250 aclock = GST_AUDIO_CLOCK_CAST (clock); |
|
251 |
|
252 result = time + aclock->abidata.ABI.time_offset; |
|
253 |
|
254 return result; |
|
255 } |