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 
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)
103 	{
104 		this.gstSegment = gstSegment;
105 	}
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 	 * Return: 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 	 * Return: %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 	 * Return: 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);
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 	 * Return: %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 	 * Adjust the values in @segment so that @offset is applied to all
275 	 * future running-time calculations.
276 	 *
277 	 * Params:
278 	 *     format = the format of the segment.
279 	 *     offset = the offset to apply in the segment
280 	 *
281 	 * Return: %TRUE if the segment could be updated successfully. If %FALSE is
282 	 *     returned, @offset is not in @segment.
283 	 *
284 	 * Since: 1.2.3
285 	 */
286 	public bool offsetRunningTime(GstFormat format, long offset)
287 	{
288 		return gst_segment_offset_running_time(gstSegment, format, offset) != 0;
289 	}
290 
291 	/**
292 	 * Adjust the start/stop and base values of @segment such that the next valid
293 	 * buffer will be one with @running_time.
294 	 *
295 	 * Params:
296 	 *     format = the format of the segment.
297 	 *     runningTime = the running_time in the segment
298 	 *
299 	 * Return: %TRUE if the segment could be updated successfully. If %FALSE is
300 	 *     returned, @running_time is -1 or not in @segment.
301 	 */
302 	public bool setRunningTime(GstFormat format, ulong runningTime)
303 	{
304 		return gst_segment_set_running_time(gstSegment, format, runningTime) != 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 	 * Return: 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 	public ulong toPosition(GstFormat format, ulong runningTime)
319 	{
320 		return gst_segment_to_position(gstSegment, format, runningTime);
321 	}
322 
323 	/**
324 	 * Translate @position to the total running time using the currently configured
325 	 * segment. Position is a value between @segment start and stop time.
326 	 *
327 	 * This function is typically used by elements that need to synchronize to the
328 	 * global clock in a pipeline. The running time is a constantly increasing value
329 	 * starting from 0. When gst_segment_init() is called, this value will reset to
330 	 * 0.
331 	 *
332 	 * This function returns -1 if the position is outside of @segment start and stop.
333 	 *
334 	 * Params:
335 	 *     format = the format of the segment.
336 	 *     position = the position in the segment
337 	 *
338 	 * Return: the position as the total running time or -1 when an invalid position
339 	 *     was given.
340 	 */
341 	public ulong toRunningTime(GstFormat format, ulong position)
342 	{
343 		return gst_segment_to_running_time(gstSegment, format, position);
344 	}
345 
346 	/**
347 	 * Translate @position to stream time using the currently configured
348 	 * segment. The @position value must be between @segment start and
349 	 * stop value.
350 	 *
351 	 * This function is typically used by elements that need to operate on
352 	 * the stream time of the buffers it receives, such as effect plugins.
353 	 * In those use cases, @position is typically the buffer timestamp or
354 	 * clock time that one wants to convert to the stream time.
355 	 * The stream time is always between 0 and the total duration of the
356 	 * media stream.
357 	 *
358 	 * Params:
359 	 *     format = the format of the segment.
360 	 *     position = the position in the segment
361 	 *
362 	 * Return: the position in stream_time or -1 when an invalid position
363 	 *     was given.
364 	 */
365 	public ulong toStreamTime(GstFormat format, ulong position)
366 	{
367 		return gst_segment_to_stream_time(gstSegment, format, position);
368 	}
369 }