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