1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gstreamer.Segment;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gstreamerc.gstreamer;
30 public  import gstreamerc.gstreamertypes;
31 
32 
33 /**
34  * This helper structure holds the relevant values for tracking the region of
35  * interest in a media file, called a segment.
36  * 
37  * The structure can be used for two purposes:
38  * 
39  * * performing seeks (handling seek events)
40  * * tracking playback regions (handling newsegment events)
41  * 
42  * The segment is usually configured by the application with a seek event which
43  * is propagated upstream and eventually handled by an element that performs the seek.
44  * 
45  * The configured segment is then propagated back downstream with a newsegment event.
46  * This information is then used to clip media to the segment boundaries.
47  * 
48  * A segment structure is initialized with gst_segment_init(), which takes a #GstFormat
49  * that will be used as the format of the segment values. The segment will be configured
50  * with a start value of 0 and a stop/duration of -1, which is undefined. The default
51  * rate and applied_rate is 1.0.
52  * 
53  * The public duration field contains the duration of the segment. When using
54  * the segment for seeking, the start and time members should normally be left
55  * to their default 0 value. The stop position is left to -1 unless explicitly
56  * configured to a different value after a seek event.
57  * 
58  * The current position in the segment should be set by changing the position
59  * member in the structure.
60  * 
61  * For elements that perform seeks, the current segment should be updated with the
62  * gst_segment_do_seek() and the values from the seek event. This method will update
63  * all the segment fields. The position field will contain the new playback position.
64  * If the start_type was different from GST_SEEK_TYPE_NONE, playback continues from
65  * the position position, possibly with updated flags or rate.
66  * 
67  * For elements that want to use #GstSegment to track the playback region,
68  * update the segment fields with the information from the newsegment event.
69  * The gst_segment_clip() method can be used to check and clip
70  * the media data to the segment boundaries.
71  * 
72  * For elements that want to synchronize to the pipeline clock, gst_segment_to_running_time()
73  * can be used to convert a timestamp to a value that can be used to synchronize
74  * to the clock. This function takes into account the base as well as
75  * any rate or applied_rate conversions.
76  * 
77  * For elements that need to perform operations on media data in stream_time,
78  * gst_segment_to_stream_time() can be used to convert a timestamp and the segment
79  * info to stream time (which is always between 0 and the duration of the stream).
80  */
81 public class Segment
82 {
83 	/** the main Gtk struct */
84 	protected GstSegment* gstSegment;
85 	protected bool ownedRef;
86 
87 	/** Get the main Gtk struct */
88 	public GstSegment* getSegmentStruct()
89 	{
90 		return gstSegment;
91 	}
92 
93 	/** the main Gtk struct as a void* */
94 	protected void* getStruct()
95 	{
96 		return cast(void*)gstSegment;
97 	}
98 
99 	/**
100 	 * Sets our main struct and passes it to the parent class.
101 	 */
102 	public this (GstSegment* gstSegment, bool ownedRef = false)
103 	{
104 		this.gstSegment = gstSegment;
105 		this.ownedRef = ownedRef;
106 	}
107 
108 
109 	/** */
110 	public static GType getType()
111 	{
112 		return gst_segment_get_type();
113 	}
114 
115 	/**
116 	 * Allocate a new #GstSegment structure and initialize it using
117 	 * gst_segment_init().
118 	 *
119 	 * Free-function: gst_segment_free
120 	 *
121 	 * Returns: a new #GstSegment, free with gst_segment_free().
122 	 *
123 	 * Throws: ConstructionException GTK+ fails to create the object.
124 	 */
125 	public this()
126 	{
127 		auto p = gst_segment_new();
128 		
129 		if(p is null)
130 		{
131 			throw new ConstructionException("null returned by new");
132 		}
133 		
134 		this(cast(GstSegment*) p);
135 	}
136 
137 	/**
138 	 * Clip the given @start and @stop values to the segment boundaries given
139 	 * in @segment. @start and @stop are compared and clipped to @segment
140 	 * start and stop values.
141 	 *
142 	 * If the function returns %FALSE, @start and @stop are known to fall
143 	 * outside of @segment and @clip_start and @clip_stop are not updated.
144 	 *
145 	 * When the function returns %TRUE, @clip_start and @clip_stop will be
146 	 * updated. If @clip_start or @clip_stop are different from @start or @stop
147 	 * respectively, the region fell partially in the segment.
148 	 *
149 	 * Note that when @stop is -1, @clip_stop will be set to the end of the
150 	 * segment. Depending on the use case, this may or may not be what you want.
151 	 *
152 	 * Params:
153 	 *     format = the format of the segment.
154 	 *     start = the start position in the segment
155 	 *     stop = the stop position in the segment
156 	 *     clipStart = the clipped start position in the segment
157 	 *     clipStop = the clipped stop position in the segment
158 	 *
159 	 * Returns: %TRUE if the given @start and @stop times fall partially or
160 	 *     completely in @segment, %FALSE if the values are completely outside
161 	 *     of the segment.
162 	 */
163 	public bool clip(GstFormat format, ulong start, ulong stop, out ulong clipStart, out ulong clipStop)
164 	{
165 		return gst_segment_clip(gstSegment, format, start, stop, &clipStart, &clipStop) != 0;
166 	}
167 
168 	/**
169 	 * Create a copy of given @segment.
170 	 *
171 	 * Free-function: gst_segment_free
172 	 *
173 	 * Returns: a new #GstSegment, free with gst_segment_free().
174 	 */
175 	public Segment copy()
176 	{
177 		auto p = gst_segment_copy(gstSegment);
178 		
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 		
184 		return ObjectG.getDObject!(Segment)(cast(GstSegment*) p, true);
185 	}
186 
187 	/**
188 	 * Copy the contents of @src into @dest.
189 	 *
190 	 * Params:
191 	 *     dest = a #GstSegment
192 	 */
193 	public void copyInto(Segment dest)
194 	{
195 		gst_segment_copy_into(gstSegment, (dest is null) ? null : dest.getSegmentStruct());
196 	}
197 
198 	/**
199 	 * Update the segment structure with the field values of a seek event (see
200 	 * gst_event_new_seek()).
201 	 *
202 	 * After calling this method, the segment field position and time will
203 	 * contain the requested new position in the segment. The new requested
204 	 * position in the segment depends on @rate and @start_type and @stop_type.
205 	 *
206 	 * For positive @rate, the new position in the segment is the new @segment
207 	 * start field when it was updated with a @start_type different from
208 	 * #GST_SEEK_TYPE_NONE. If no update was performed on @segment start position
209 	 * (#GST_SEEK_TYPE_NONE), @start is ignored and @segment position is
210 	 * unmodified.
211 	 *
212 	 * For negative @rate, the new position in the segment is the new @segment
213 	 * stop field when it was updated with a @stop_type different from
214 	 * #GST_SEEK_TYPE_NONE. If no stop was previously configured in the segment, the
215 	 * duration of the segment will be used to update the stop position.
216 	 * If no update was performed on @segment stop position (#GST_SEEK_TYPE_NONE),
217 	 * @stop is ignored and @segment position is unmodified.
218 	 *
219 	 * The applied rate of the segment will be set to 1.0 by default.
220 	 * If the caller can apply a rate change, it should update @segment
221 	 * rate and applied_rate after calling this function.
222 	 *
223 	 * @update will be set to %TRUE if a seek should be performed to the segment
224 	 * position field. This field can be %FALSE if, for example, only the @rate
225 	 * has been changed but not the playback position.
226 	 *
227 	 * Params:
228 	 *     rate = the rate of the segment.
229 	 *     format = the format of the segment.
230 	 *     flags = the segment flags for the segment
231 	 *     startType = the seek method
232 	 *     start = the seek start value
233 	 *     stopType = the seek method
234 	 *     stop = the seek stop value
235 	 *     update = boolean holding whether position was updated.
236 	 *
237 	 * Returns: %TRUE if the seek could be performed.
238 	 */
239 	public bool doSeek(double rate, GstFormat format, GstSeekFlags flags, GstSeekType startType, ulong start, GstSeekType stopType, ulong stop, ref bool update)
240 	{
241 		int outupdate = (update ? 1 : 0);
242 		
243 		auto p = gst_segment_do_seek(gstSegment, rate, format, flags, startType, start, stopType, stop, &outupdate) != 0;
244 		
245 		update = (outupdate == 1);
246 		
247 		return p;
248 	}
249 
250 	/**
251 	 * Free the allocated segment @segment.
252 	 */
253 	public void free()
254 	{
255 		gst_segment_free(gstSegment);
256 	}
257 
258 	/**
259 	 * The start/position fields are set to 0 and the stop/duration
260 	 * fields are set to -1 (unknown). The default rate of 1.0 and no
261 	 * flags are set.
262 	 *
263 	 * Initialize @segment to its default values.
264 	 *
265 	 * Params:
266 	 *     format = the format of the segment.
267 	 */
268 	public void init(GstFormat format)
269 	{
270 		gst_segment_init(gstSegment, format);
271 	}
272 
273 	/**
274 	 * Checks for two segments being equal. Equality here is defined
275 	 * as perfect equality, including floating point values.
276 	 *
277 	 * Params:
278 	 *     s1 = a #GstSegment structure.
279 	 *
280 	 * Returns: %TRUE if the segments are equal, %FALSE otherwise.
281 	 *
282 	 * Since: 1.6
283 	 */
284 	public bool isEqual(Segment s1)
285 	{
286 		return gst_segment_is_equal(gstSegment, (s1 is null) ? null : s1.getSegmentStruct()) != 0;
287 	}
288 
289 	/**
290 	 * Adjust the values in @segment so that @offset is applied to all
291 	 * future running-time calculations.
292 	 *
293 	 * Params:
294 	 *     format = the format of the segment.
295 	 *     offset = the offset to apply in the segment
296 	 *
297 	 * Returns: %TRUE if the segment could be updated successfully. If %FALSE is
298 	 *     returned, @offset is not in @segment.
299 	 *
300 	 * Since: 1.2.3
301 	 */
302 	public bool offsetRunningTime(GstFormat format, long offset)
303 	{
304 		return gst_segment_offset_running_time(gstSegment, format, offset) != 0;
305 	}
306 
307 	/**
308 	 * Convert @running_time into a position in the segment so that
309 	 * gst_segment_to_running_time() with that position returns @running_time.
310 	 *
311 	 * Params:
312 	 *     format = the format of the segment.
313 	 *     runningTime = the running_time in the segment
314 	 *
315 	 * Returns: the position in the segment for @running_time. This function returns
316 	 *     -1 when @running_time is -1 or when it is not inside @segment.
317 	 *
318 	 * Since: 1.8
319 	 */
320 	public ulong positionFromRunningTime(GstFormat format, ulong runningTime)
321 	{
322 		return gst_segment_position_from_running_time(gstSegment, format, runningTime);
323 	}
324 
325 	/**
326 	 * Translate @running_time to the segment position using the currently configured
327 	 * segment. Compared to gst_segment_position_from_running_time() this function can
328 	 * return negative segment position.
329 	 *
330 	 * This function is typically used by elements that need to synchronize buffers
331 	 * against the clock or each other.
332 	 *
333 	 * @running_time can be any value and the result of this function for values
334 	 * outside of the segment is extrapolated.
335 	 *
336 	 * When 1 is returned, @running_time resulted in a positive position returned
337 	 * in @position.
338 	 *
339 	 * When this function returns -1, the returned @position should be negated
340 	 * to get the real negative segment position.
341 	 *
342 	 * Params:
343 	 *     format = the format of the segment.
344 	 *     runningTime = the running-time
345 	 *     position = the resulting position in the segment
346 	 *
347 	 * Returns: a 1 or -1 on success, 0 on failure.
348 	 *
349 	 * Since: 1.8
350 	 */
351 	public int positionFromRunningTimeFull(GstFormat format, ulong runningTime, ulong* position)
352 	{
353 		return gst_segment_position_from_running_time_full(gstSegment, format, runningTime, position);
354 	}
355 
356 	/**
357 	 * Convert @stream_time into a position in the segment so that
358 	 * gst_segment_to_stream_time() with that position returns @stream_time.
359 	 *
360 	 * Params:
361 	 *     format = the format of the segment.
362 	 *     streamTime = the stream_time in the segment
363 	 *
364 	 * Returns: the position in the segment for @stream_time. This function returns
365 	 *     -1 when @stream_time is -1 or when it is not inside @segment.
366 	 *
367 	 * Since: 1.8
368 	 */
369 	public ulong positionFromStreamTime(GstFormat format, ulong streamTime)
370 	{
371 		return gst_segment_position_from_stream_time(gstSegment, format, streamTime);
372 	}
373 
374 	/**
375 	 * Translate @stream_time to the segment position using the currently configured
376 	 * segment. Compared to gst_segment_position_from_stream_time() this function can
377 	 * return negative segment position.
378 	 *
379 	 * This function is typically used by elements that need to synchronize buffers
380 	 * against the clock or each other.
381 	 *
382 	 * @stream_time can be any value and the result of this function for values outside
383 	 * of the segment is extrapolated.
384 	 *
385 	 * When 1 is returned, @stream_time resulted in a positive position returned
386 	 * in @position.
387 	 *
388 	 * When this function returns -1, the returned @position should be negated
389 	 * to get the real negative segment position.
390 	 *
391 	 * Params:
392 	 *     format = the format of the segment.
393 	 *     streamTime = the stream-time
394 	 *     position = the resulting position in the segment
395 	 *
396 	 * Returns: a 1 or -1 on success, 0 on failure.
397 	 *
398 	 * Since: 1.8
399 	 */
400 	public int positionFromStreamTimeFull(GstFormat format, ulong streamTime, ulong* position)
401 	{
402 		return gst_segment_position_from_stream_time_full(gstSegment, format, streamTime, position);
403 	}
404 
405 	/**
406 	 * Adjust the start/stop and base values of @segment such that the next valid
407 	 * buffer will be one with @running_time.
408 	 *
409 	 * Params:
410 	 *     format = the format of the segment.
411 	 *     runningTime = the running_time in the segment
412 	 *
413 	 * Returns: %TRUE if the segment could be updated successfully. If %FALSE is
414 	 *     returned, @running_time is -1 or not in @segment.
415 	 */
416 	public bool setRunningTime(GstFormat format, ulong runningTime)
417 	{
418 		return gst_segment_set_running_time(gstSegment, format, runningTime) != 0;
419 	}
420 
421 	/**
422 	 * Convert @running_time into a position in the segment so that
423 	 * gst_segment_to_running_time() with that position returns @running_time.
424 	 *
425 	 * Params:
426 	 *     format = the format of the segment.
427 	 *     runningTime = the running_time in the segment
428 	 *
429 	 * Returns: the position in the segment for @running_time. This function returns
430 	 *     -1 when @running_time is -1 or when it is not inside @segment.
431 	 *
432 	 *     Deprecated. Use gst_segment_position_from_running_time() instead.
433 	 */
434 	public ulong toPosition(GstFormat format, ulong runningTime)
435 	{
436 		return gst_segment_to_position(gstSegment, format, runningTime);
437 	}
438 
439 	/**
440 	 * Translate @position to the total running time using the currently configured
441 	 * segment. Position is a value between @segment start and stop time.
442 	 *
443 	 * This function is typically used by elements that need to synchronize to the
444 	 * global clock in a pipeline. The running time is a constantly increasing value
445 	 * starting from 0. When gst_segment_init() is called, this value will reset to
446 	 * 0.
447 	 *
448 	 * This function returns -1 if the position is outside of @segment start and stop.
449 	 *
450 	 * Params:
451 	 *     format = the format of the segment.
452 	 *     position = the position in the segment
453 	 *
454 	 * Returns: the position as the total running time or -1 when an invalid position
455 	 *     was given.
456 	 */
457 	public ulong toRunningTime(GstFormat format, ulong position)
458 	{
459 		return gst_segment_to_running_time(gstSegment, format, position);
460 	}
461 
462 	/**
463 	 * Translate @position to the total running time using the currently configured
464 	 * segment. Compared to gst_segment_to_running_time() this function can return
465 	 * negative running-time.
466 	 *
467 	 * This function is typically used by elements that need to synchronize buffers
468 	 * against the clock or eachother.
469 	 *
470 	 * @position can be any value and the result of this function for values outside
471 	 * of the segment is extrapolated.
472 	 *
473 	 * When 1 is returned, @position resulted in a positive running-time returned
474 	 * in @running_time.
475 	 *
476 	 * When this function returns -1, the returned @running_time should be negated
477 	 * to get the real negative running time.
478 	 *
479 	 * Params:
480 	 *     format = the format of the segment.
481 	 *     position = the position in the segment
482 	 *     runningTime = result running-time
483 	 *
484 	 * Returns: a 1 or -1 on success, 0 on failure.
485 	 *
486 	 * Since: 1.6
487 	 */
488 	public int toRunningTimeFull(GstFormat format, ulong position, ulong* runningTime)
489 	{
490 		return gst_segment_to_running_time_full(gstSegment, format, position, runningTime);
491 	}
492 
493 	/**
494 	 * Translate @position to stream time using the currently configured
495 	 * segment. The @position value must be between @segment start and
496 	 * stop value.
497 	 *
498 	 * This function is typically used by elements that need to operate on
499 	 * the stream time of the buffers it receives, such as effect plugins.
500 	 * In those use cases, @position is typically the buffer timestamp or
501 	 * clock time that one wants to convert to the stream time.
502 	 * The stream time is always between 0 and the total duration of the
503 	 * media stream.
504 	 *
505 	 * Params:
506 	 *     format = the format of the segment.
507 	 *     position = the position in the segment
508 	 *
509 	 * Returns: the position in stream_time or -1 when an invalid position
510 	 *     was given.
511 	 *
512 	 * Since: 1.8
513 	 */
514 	public ulong toStreamTime(GstFormat format, ulong position)
515 	{
516 		return gst_segment_to_stream_time(gstSegment, format, position);
517 	}
518 
519 	/**
520 	 * Translate @position to the total stream time using the currently configured
521 	 * segment. Compared to gst_segment_to_stream_time() this function can return
522 	 * negative stream-time.
523 	 *
524 	 * This function is typically used by elements that need to synchronize buffers
525 	 * against the clock or eachother.
526 	 *
527 	 * @position can be any value and the result of this function for values outside
528 	 * of the segment is extrapolated.
529 	 *
530 	 * When 1 is returned, @position resulted in a positive stream-time returned
531 	 * in @stream_time.
532 	 *
533 	 * When this function returns -1, the returned @stream_time should be negated
534 	 * to get the real negative stream time.
535 	 *
536 	 * Params:
537 	 *     format = the format of the segment.
538 	 *     position = the position in the segment
539 	 *     streamTime = result stream-time
540 	 *
541 	 * Returns: a 1 or -1 on success, 0 on failure.
542 	 *
543 	 * Since: 1.8
544 	 */
545 	public int toStreamTimeFull(GstFormat format, ulong position, ulong* streamTime)
546 	{
547 		return gst_segment_to_stream_time_full(gstSegment, format, position, streamTime);
548 	}
549 }