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  * Conversion parameters:
26  * inFile  = gstreamer-GstSegment.html
27  * outPack = gstreamer
28  * outFile = Segment
29  * strct   = GstSegment
30  * realStrct=
31  * ctorStrct=
32  * clss    = Segment
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_segment_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * 	- GstSegment* -> Segment
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module gstreamer.Segment;
54 
55 public  import gstreamerc.gstreamertypes;
56 
57 private import gstreamerc.gstreamer;
58 private import glib.ConstructionException;
59 private import gobject.ObjectG;
60 
61 
62 
63 
64 /**
65  * This helper structure holds the relevant values for tracking the region of
66  * interest in a media file, called a segment.
67  *
68  * The structure can be used for two purposes:
69  *
70  * performing seeks (handling seek events)
71  *
72  * tracking playback regions (handling newsegment events)
73  *
74  * The segment is usually configured by the application with a seek event which
75  * is propagated upstream and eventually handled by an element that performs the seek.
76  *
77  * The configured segment is then propagated back downstream with a newsegment event.
78  * This information is then used to clip media to the segment boundaries.
79  *
80  * A segment structure is initialized with gst_segment_init(), which takes a GstFormat
81  * that will be used as the format of the segment values. The segment will be configured
82  * with a start value of 0 and a stop/duration of -1, which is undefined. The default
83  * rate and applied_rate is 1.0.
84  *
85  * The public duration field contains the duration of the segment. When using
86  * the segment for seeking, the start and time members should normally be left
87  * to their default 0 value. The stop position is left to -1 unless explicitly
88  * configured to a different value after a seek event.
89  *
90  * The current position in the segment should be set by changing the position
91  * member in the structure.
92  *
93  * For elements that perform seeks, the current segment should be updated with the
94  * gst_segment_do_seek() and the values from the seek event. This method will update
95  * all the segment fields. The position field will contain the new playback position.
96  * If the start_type was different from GST_SEEK_TYPE_NONE, playback continues from
97  * the position position, possibly with updated flags or rate.
98  *
99  * For elements that want to use GstSegment to track the playback region,
100  * update the segment fields with the information from the newsegment event.
101  * The gst_segment_clip() method can be used to check and clip
102  * the media data to the segment boundaries.
103  *
104  * For elements that want to synchronize to the pipeline clock, gst_segment_to_running_time()
105  * can be used to convert a timestamp to a value that can be used to synchronize
106  * to the clock. This function takes into account the base as well as
107  * any rate or applied_rate conversions.
108  *
109  * For elements that need to perform operations on media data in stream_time,
110  * gst_segment_to_stream_time() can be used to convert a timestamp and the segment
111  * info to stream time (which is always between 0 and the duration of the stream).
112  *
113  * Last reviewed on 2012-03-29 (0.11.3)
114  */
115 public class Segment
116 {
117 	
118 	/** the main Gtk struct */
119 	protected GstSegment* gstSegment;
120 	
121 	
122 	/** Get the main Gtk struct */
123 	public GstSegment* getSegmentStruct()
124 	{
125 		return gstSegment;
126 	}
127 	
128 	
129 	/** the main Gtk struct as a void* */
130 	protected void* getStruct()
131 	{
132 		return cast(void*)gstSegment;
133 	}
134 	
135 	/**
136 	 * Sets our main struct and passes it to the parent class
137 	 */
138 	public this (GstSegment* gstSegment)
139 	{
140 		this.gstSegment = gstSegment;
141 	}
142 	
143 	/**
144 	 */
145 	
146 	/**
147 	 * Clip the given start and stop values to the segment boundaries given
148 	 * in segment. start and stop are compared and clipped to segment
149 	 * start and stop values.
150 	 * If the function returns FALSE, start and stop are known to fall
151 	 * outside of segment and clip_start and clip_stop are not updated.
152 	 * When the function returns TRUE, clip_start and clip_stop will be
153 	 * updated. If clip_start or clip_stop are different from start or stop
154 	 * respectively, the region fell partially in the segment.
155 	 * Note that when stop is -1, clip_stop will be set to the end of the
156 	 * segment. Depending on the use case, this may or may not be what you want.
157 	 * Params:
158 	 * format = the format of the segment.
159 	 * start = the start position in the segment
160 	 * stop = the stop position in the segment
161 	 * clipStart = the clipped start position in the segment. [out][allow-none]
162 	 * clipStop = the clipped stop position in the segment. [out][allow-none]
163 	 * Returns: TRUE if the given start and stop times fall partially or completely in segment, FALSE if the values are completely outside of the segment.
164 	 */
165 	public int clip(GstFormat format, ulong start, ulong stop, ref ulong clipStart, ref ulong clipStop)
166 	{
167 		// gboolean gst_segment_clip (const GstSegment *segment,  GstFormat format,  guint64 start,  guint64 stop,  guint64 *clip_start,  guint64 *clip_stop);
168 		return gst_segment_clip(gstSegment, format, start, stop, &clipStart, &clipStop);
169 	}
170 	
171 	/**
172 	 * The start/position fields are set to 0 and the stop/duration
173 	 * fields are set to -1 (unknown). The default rate of 1.0 and no
174 	 * flags are set.
175 	 * Initialize segment to its default values.
176 	 * Params:
177 	 * format = the format of the segment.
178 	 */
179 	public void init(GstFormat format)
180 	{
181 		// void gst_segment_init (GstSegment *segment,  GstFormat format);
182 		gst_segment_init(gstSegment, format);
183 	}
184 	
185 	/**
186 	 * Allocate a new GstSegment structure and initialize it using
187 	 * gst_segment_init().
188 	 * Free-function: gst_segment_free
189 	 * Throws: ConstructionException GTK+ fails to create the object.
190 	 */
191 	public this ()
192 	{
193 		// GstSegment * gst_segment_new (void);
194 		auto p = gst_segment_new();
195 		if(p is null)
196 		{
197 			throw new ConstructionException("null returned by gst_segment_new()");
198 		}
199 		this(cast(GstSegment*) p);
200 	}
201 	
202 	/**
203 	 * Create a copy of given segment.
204 	 * Free-function: gst_segment_free
205 	 * Returns: a new GstSegment, free with gst_segment_free(). [transfer full]
206 	 */
207 	public Segment copy()
208 	{
209 		// GstSegment * gst_segment_copy (const GstSegment *segment);
210 		auto p = gst_segment_copy(gstSegment);
211 		
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 		
217 		return ObjectG.getDObject!(Segment)(cast(GstSegment*) p);
218 	}
219 	
220 	/**
221 	 * Free the allocated segment segment.
222 	 */
223 	public void free()
224 	{
225 		// void gst_segment_free (GstSegment *segment);
226 		gst_segment_free(gstSegment);
227 	}
228 	
229 	/**
230 	 * Update the segment structure with the field values of a seek event (see
231 	 * gst_event_new_seek()).
232 	 * After calling this method, the segment field position and time will
233 	 * contain the requested new position in the segment. The new requested
234 	 * position in the segment depends on rate and start_type and stop_type.
235 	 * For positive rate, the new position in the segment is the new segment
236 	 * start field when it was updated with a start_type different from
237 	 * GST_SEEK_TYPE_NONE. If no update was performed on segment start position
238 	 * (GST_SEEK_TYPE_NONE), start is ignored and segment position is
239 	 * unmodified.
240 	 * For negative rate, the new position in the segment is the new segment
241 	 * stop field when it was updated with a stop_type different from
242 	 * GST_SEEK_TYPE_NONE. If no stop was previously configured in the segment, the
243 	 * duration of the segment will be used to update the stop position.
244 	 * If no update was performed on segment stop position (GST_SEEK_TYPE_NONE),
245 	 * stop is ignored and segment position is unmodified.
246 	 * The applied rate of the segment will be set to 1.0 by default.
247 	 * If the caller can apply a rate change, it should update segment
248 	 * rate and applied_rate after calling this function.
249 	 * update will be set to TRUE if a seek should be performed to the segment
250 	 * position field. This field can be FALSE if, for example, only the rate
251 	 * has been changed but not the playback position.
252 	 * Params:
253 	 * rate = the rate of the segment.
254 	 * format = the format of the segment.
255 	 * flags = the segment flags for the segment
256 	 * startType = the seek method
257 	 * start = the seek start value
258 	 * stopType = the seek method
259 	 * stop = the seek stop value
260 	 * update = boolean holding whether position was updated.
261 	 * Returns: TRUE if the seek could be performed.
262 	 */
263 	public int doSeek(double rate, GstFormat format, GstSeekFlags flags, GstSeekType startType, ulong start, GstSeekType stopType, ulong stop, ref int update)
264 	{
265 		// gboolean gst_segment_do_seek (GstSegment *segment,  gdouble rate,  GstFormat format,  GstSeekFlags flags,  GstSeekType start_type,  guint64 start,  GstSeekType stop_type,  guint64 stop,  gboolean *update);
266 		return gst_segment_do_seek(gstSegment, rate, format, flags, startType, start, stopType, stop, &update);
267 	}
268 	
269 	/**
270 	 * Translate position to the total running time using the currently configured
271 	 * segment. Position is a value between segment start and stop time.
272 	 * This function is typically used by elements that need to synchronize to the
273 	 * global clock in a pipeline. The runnning time is a constantly increasing value
274 	 * starting from 0. When gst_segment_init() is called, this value will reset to
275 	 * 0.
276 	 * This function returns -1 if the position is outside of segment start and stop.
277 	 * Params:
278 	 * format = the format of the segment.
279 	 * position = the position in the segment
280 	 * Returns: the position as the total running time or -1 when an invalid position was given.
281 	 */
282 	public ulong toRunningTime(GstFormat format, ulong position)
283 	{
284 		// guint64 gst_segment_to_running_time (const GstSegment *segment,  GstFormat format,  guint64 position);
285 		return gst_segment_to_running_time(gstSegment, format, position);
286 	}
287 	
288 	/**
289 	 * Translate position to stream time using the currently configured
290 	 * segment. The position value must be between segment start and
291 	 * stop value.
292 	 * This function is typically used by elements that need to operate on
293 	 * the stream time of the buffers it receives, such as effect plugins.
294 	 * In those use cases, position is typically the buffer timestamp or
295 	 * clock time that one wants to convert to the stream time.
296 	 * The stream time is always between 0 and the total duration of the
297 	 * media stream.
298 	 * Params:
299 	 * format = the format of the segment.
300 	 * position = the position in the segment
301 	 * Returns: the position in stream_time or -1 when an invalid position was given.
302 	 */
303 	public ulong toStreamTime(GstFormat format, ulong position)
304 	{
305 		// guint64 gst_segment_to_stream_time (const GstSegment *segment,  GstFormat format,  guint64 position);
306 		return gst_segment_to_stream_time(gstSegment, format, position);
307 	}
308 	
309 	/**
310 	 * Convert running_time into a position in the segment so that
311 	 * gst_segment_to_running_time() with that position returns running_time.
312 	 * Params:
313 	 * format = the format of the segment.
314 	 * runningTime = the running_time in the segment
315 	 * Returns: the position in the segment for running_time. This function returns -1 when running_time is -1 or when it is not inside segment.
316 	 */
317 	public ulong toPosition(GstFormat format, ulong runningTime)
318 	{
319 		// guint64 gst_segment_to_position (const GstSegment *segment,  GstFormat format,  guint64 running_time);
320 		return gst_segment_to_position(gstSegment, format, runningTime);
321 	}
322 	
323 	/**
324 	 * Adjust the start/stop and base values of segment such that the next valid
325 	 * buffer will be one with running_time.
326 	 * Params:
327 	 * format = the format of the segment.
328 	 * runningTime = the running_time in the segment
329 	 * Returns: TRUE if the segment could be updated successfully. If FALSE is returned, running_time is -1 or not in segment.
330 	 */
331 	public int setRunningTime(GstFormat format, ulong runningTime)
332 	{
333 		// gboolean gst_segment_set_running_time (GstSegment *segment,  GstFormat format,  guint64 running_time);
334 		return gst_segment_set_running_time(gstSegment, format, runningTime);
335 	}
336 	
337 	/**
338 	 * Copy the contents of src into dest.
339 	 * Params:
340 	 * dest = a GstSegment. [transfer none]
341 	 */
342 	public void copyInto(Segment dest)
343 	{
344 		// void gst_segment_copy_into (const GstSegment *src,  GstSegment *dest);
345 		gst_segment_copy_into(gstSegment, (dest is null) ? null : dest.getSegmentStruct());
346 	}
347 }