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 gst.base.BaseSrc;
26 
27 private import gobject.ObjectG;
28 private import gst.base.c.functions;
29 public  import gst.base.c.types;
30 private import gstreamer.AllocationParams;
31 private import gstreamer.Allocator;
32 private import gstreamer.BufferPool;
33 private import gstreamer.Caps;
34 private import gstreamer.Element;
35 
36 
37 /**
38  * This is a generic base class for source elements. The following
39  * types of sources are supported:
40  * 
41  * * random access sources like files
42  * * seekable sources
43  * * live sources
44  * 
45  * The source can be configured to operate in any #GstFormat with the
46  * gst_base_src_set_format() method. The currently set format determines
47  * the format of the internal #GstSegment and any %GST_EVENT_SEGMENT
48  * events. The default format for #GstBaseSrc is %GST_FORMAT_BYTES.
49  * 
50  * #GstBaseSrc always supports push mode scheduling. If the following
51  * conditions are met, it also supports pull mode scheduling:
52  * 
53  * * The format is set to %GST_FORMAT_BYTES (default).
54  * * #GstBaseSrcClass.is_seekable() returns %TRUE.
55  * 
56  * If all the conditions are met for operating in pull mode, #GstBaseSrc is
57  * automatically seekable in push mode as well. The following conditions must
58  * be met to make the element seekable in push mode when the format is not
59  * %GST_FORMAT_BYTES:
60  * 
61  * * #GstBaseSrcClass.is_seekable() returns %TRUE.
62  * * #GstBaseSrcClass.query() can convert all supported seek formats to the
63  * internal format as set with gst_base_src_set_format().
64  * * #GstBaseSrcClass.do_seek() is implemented, performs the seek and returns
65  * %TRUE.
66  * 
67  * When the element does not meet the requirements to operate in pull mode, the
68  * offset and length in the #GstBaseSrcClass.create() method should be ignored.
69  * It is recommended to subclass #GstPushSrc instead, in this situation. If the
70  * element can operate in pull mode but only with specific offsets and
71  * lengths, it is allowed to generate an error when the wrong values are passed
72  * to the #GstBaseSrcClass.create() function.
73  * 
74  * #GstBaseSrc has support for live sources. Live sources are sources that when
75  * paused discard data, such as audio or video capture devices. A typical live
76  * source also produces data at a fixed rate and thus provides a clock to publish
77  * this rate.
78  * Use gst_base_src_set_live() to activate the live source mode.
79  * 
80  * A live source does not produce data in the PAUSED state. This means that the
81  * #GstBaseSrcClass.create() method will not be called in PAUSED but only in
82  * PLAYING. To signal the pipeline that the element will not produce data, the
83  * return value from the READY to PAUSED state will be
84  * %GST_STATE_CHANGE_NO_PREROLL.
85  * 
86  * A typical live source will timestamp the buffers it creates with the
87  * current running time of the pipeline. This is one reason why a live source
88  * can only produce data in the PLAYING state, when the clock is actually
89  * distributed and running.
90  * 
91  * Live sources that synchronize and block on the clock (an audio source, for
92  * example) can use gst_base_src_wait_playing() when the
93  * #GstBaseSrcClass.create() function was interrupted by a state change to
94  * PAUSED.
95  * 
96  * The #GstBaseSrcClass.get_times() method can be used to implement pseudo-live
97  * sources. It only makes sense to implement the #GstBaseSrcClass.get_times()
98  * function if the source is a live source. The #GstBaseSrcClass.get_times()
99  * function should return timestamps starting from 0, as if it were a non-live
100  * source. The base class will make sure that the timestamps are transformed
101  * into the current running_time. The base source will then wait for the
102  * calculated running_time before pushing out the buffer.
103  * 
104  * For live sources, the base class will by default report a latency of 0.
105  * For pseudo live sources, the base class will by default measure the difference
106  * between the first buffer timestamp and the start time of get_times and will
107  * report this value as the latency.
108  * Subclasses should override the query function when this behaviour is not
109  * acceptable.
110  * 
111  * There is only support in #GstBaseSrc for exactly one source pad, which
112  * should be named "src". A source implementation (subclass of #GstBaseSrc)
113  * should install a pad template in its class_init function, like so:
114  * |[<!-- language="C" -->
115  * static void
116  * my_element_class_init (GstMyElementClass *klass)
117  * {
118  * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
119  * // srctemplate should be a #GstStaticPadTemplate with direction
120  * // %GST_PAD_SRC and name "src"
121  * gst_element_class_add_static_pad_template (gstelement_class, &amp;srctemplate);
122  * 
123  * gst_element_class_set_static_metadata (gstelement_class,
124  * "Source name",
125  * "Source",
126  * "My Source element",
127  * "The author <my.sink@my.email>");
128  * }
129  * ]|
130  * 
131  * ## Controlled shutdown of live sources in applications
132  * 
133  * Applications that record from a live source may want to stop recording
134  * in a controlled way, so that the recording is stopped, but the data
135  * already in the pipeline is processed to the end (remember that many live
136  * sources would go on recording forever otherwise). For that to happen the
137  * application needs to make the source stop recording and send an EOS
138  * event down the pipeline. The application would then wait for an
139  * EOS message posted on the pipeline's bus to know when all data has
140  * been processed and the pipeline can safely be stopped.
141  * 
142  * An application may send an EOS event to a source element to make it
143  * perform the EOS logic (send EOS event downstream or post a
144  * %GST_MESSAGE_SEGMENT_DONE on the bus). This can typically be done
145  * with the gst_element_send_event() function on the element or its parent bin.
146  * 
147  * After the EOS has been sent to the element, the application should wait for
148  * an EOS message to be posted on the pipeline's bus. Once this EOS message is
149  * received, it may safely shut down the entire pipeline.
150  */
151 public class BaseSrc : Element
152 {
153 	/** the main Gtk struct */
154 	protected GstBaseSrc* gstBaseSrc;
155 
156 	/** Get the main Gtk struct */
157 	public GstBaseSrc* getBaseSrcStruct(bool transferOwnership = false)
158 	{
159 		if (transferOwnership)
160 			ownedRef = false;
161 		return gstBaseSrc;
162 	}
163 
164 	/** the main Gtk struct as a void* */
165 	protected override void* getStruct()
166 	{
167 		return cast(void*)gstBaseSrc;
168 	}
169 
170 	protected override void setStruct(GObject* obj)
171 	{
172 		gstBaseSrc = cast(GstBaseSrc*)obj;
173 		super.setStruct(obj);
174 	}
175 
176 	/**
177 	 * Sets our main struct and passes it to the parent class.
178 	 */
179 	public this (GstBaseSrc* gstBaseSrc, bool ownedRef = false)
180 	{
181 		this.gstBaseSrc = gstBaseSrc;
182 		super(cast(GstElement*)gstBaseSrc, ownedRef);
183 	}
184 
185 
186 	/** */
187 	public static GType getType()
188 	{
189 		return gst_base_src_get_type();
190 	}
191 
192 	/**
193 	 * Lets #GstBaseSrc sub-classes to know the memory @allocator
194 	 * used by the base class and its @params.
195 	 *
196 	 * Unref the @allocator after usage.
197 	 *
198 	 * Params:
199 	 *     allocator = the #GstAllocator
200 	 *         used
201 	 *     params = the
202 	 *         #GstAllocationParams of @allocator
203 	 */
204 	public void getAllocator(out Allocator allocator, out AllocationParams params)
205 	{
206 		GstAllocator* outallocator = null;
207 		GstAllocationParams* outparams = gMalloc!GstAllocationParams();
208 
209 		gst_base_src_get_allocator(gstBaseSrc, &outallocator, outparams);
210 
211 		allocator = ObjectG.getDObject!(Allocator)(outallocator);
212 		params = ObjectG.getDObject!(AllocationParams)(outparams, true);
213 	}
214 
215 	/**
216 	 * Get the number of bytes that @src will push out with each buffer.
217 	 *
218 	 * Returns: the number of bytes pushed with each buffer.
219 	 */
220 	public uint getBlocksize()
221 	{
222 		return gst_base_src_get_blocksize(gstBaseSrc);
223 	}
224 
225 	/**
226 	 * Returns: the instance of the #GstBufferPool used
227 	 *     by the src; unref it after usage.
228 	 */
229 	public BufferPool getBufferPool()
230 	{
231 		auto p = gst_base_src_get_buffer_pool(gstBaseSrc);
232 
233 		if(p is null)
234 		{
235 			return null;
236 		}
237 
238 		return ObjectG.getDObject!(BufferPool)(cast(GstBufferPool*) p, true);
239 	}
240 
241 	/**
242 	 * Query if @src timestamps outgoing buffers based on the current running_time.
243 	 *
244 	 * Returns: %TRUE if the base class will automatically timestamp outgoing buffers.
245 	 */
246 	public bool getDoTimestamp()
247 	{
248 		return gst_base_src_get_do_timestamp(gstBaseSrc) != 0;
249 	}
250 
251 	/**
252 	 * Get the current async behaviour of @src. See also gst_base_src_set_async().
253 	 *
254 	 * Returns: %TRUE if @src is operating in async mode.
255 	 */
256 	public bool isAsync()
257 	{
258 		return gst_base_src_is_async(gstBaseSrc) != 0;
259 	}
260 
261 	/**
262 	 * Check if an element is in live mode.
263 	 *
264 	 * Returns: %TRUE if element is in live mode.
265 	 */
266 	public bool isLive()
267 	{
268 		return gst_base_src_is_live(gstBaseSrc) != 0;
269 	}
270 
271 	/**
272 	 * Prepare a new seamless segment for emission downstream. This function must
273 	 * only be called by derived sub-classes, and only from the create() function,
274 	 * as the stream-lock needs to be held.
275 	 *
276 	 * The format for the new segment will be the current format of the source, as
277 	 * configured with gst_base_src_set_format()
278 	 *
279 	 * Params:
280 	 *     start = The new start value for the segment
281 	 *     stop = Stop value for the new segment
282 	 *     time = The new time value for the start of the new segment
283 	 *
284 	 * Returns: %TRUE if preparation of the seamless segment succeeded.
285 	 */
286 	public bool newSeamlessSegment(long start, long stop, long time)
287 	{
288 		return gst_base_src_new_seamless_segment(gstBaseSrc, start, stop, time) != 0;
289 	}
290 
291 	/**
292 	 * Query the source for the latency parameters. @live will be %TRUE when @src is
293 	 * configured as a live source. @min_latency and @max_latency will be set
294 	 * to the difference between the running time and the timestamp of the first
295 	 * buffer.
296 	 *
297 	 * This function is mostly used by subclasses.
298 	 *
299 	 * Params:
300 	 *     live = if the source is live
301 	 *     minLatency = the min latency of the source
302 	 *     maxLatency = the max latency of the source
303 	 *
304 	 * Returns: %TRUE if the query succeeded.
305 	 */
306 	public bool queryLatency(out bool live, out GstClockTime minLatency, out GstClockTime maxLatency)
307 	{
308 		int outlive;
309 
310 		auto p = gst_base_src_query_latency(gstBaseSrc, &outlive, &minLatency, &maxLatency) != 0;
311 
312 		live = (outlive == 1);
313 
314 		return p;
315 	}
316 
317 	/**
318 	 * Configure async behaviour in @src, no state change will block. The open,
319 	 * close, start, stop, play and pause virtual methods will be executed in a
320 	 * different thread and are thus allowed to perform blocking operations. Any
321 	 * blocking operation should be unblocked with the unlock vmethod.
322 	 *
323 	 * Params:
324 	 *     async = new async mode
325 	 */
326 	public void setAsync(bool async)
327 	{
328 		gst_base_src_set_async(gstBaseSrc, async);
329 	}
330 
331 	/**
332 	 * If @automatic_eos is %TRUE, @src will automatically go EOS if a buffer
333 	 * after the total size is returned. By default this is %TRUE but sources
334 	 * that can't return an authoritative size and only know that they're EOS
335 	 * when trying to read more should set this to %FALSE.
336 	 *
337 	 * Params:
338 	 *     automaticEos = automatic eos
339 	 *
340 	 * Since: 1.4
341 	 */
342 	public void setAutomaticEos(bool automaticEos)
343 	{
344 		gst_base_src_set_automatic_eos(gstBaseSrc, automaticEos);
345 	}
346 
347 	/**
348 	 * Set the number of bytes that @src will push out with each buffer. When
349 	 * @blocksize is set to -1, a default length will be used.
350 	 *
351 	 * Params:
352 	 *     blocksize = the new blocksize in bytes
353 	 */
354 	public void setBlocksize(uint blocksize)
355 	{
356 		gst_base_src_set_blocksize(gstBaseSrc, blocksize);
357 	}
358 
359 	/**
360 	 * Set new caps on the basesrc source pad.
361 	 *
362 	 * Params:
363 	 *     caps = a #GstCaps
364 	 *
365 	 * Returns: %TRUE if the caps could be set
366 	 */
367 	public bool setCaps(Caps caps)
368 	{
369 		return gst_base_src_set_caps(gstBaseSrc, (caps is null) ? null : caps.getCapsStruct()) != 0;
370 	}
371 
372 	/**
373 	 * Configure @src to automatically timestamp outgoing buffers based on the
374 	 * current running_time of the pipeline. This property is mostly useful for live
375 	 * sources.
376 	 *
377 	 * Params:
378 	 *     timestamp = enable or disable timestamping
379 	 */
380 	public void setDoTimestamp(bool timestamp)
381 	{
382 		gst_base_src_set_do_timestamp(gstBaseSrc, timestamp);
383 	}
384 
385 	/**
386 	 * If not @dynamic, size is only updated when needed, such as when trying to
387 	 * read past current tracked size.  Otherwise, size is checked for upon each
388 	 * read.
389 	 *
390 	 * Params:
391 	 *     dynamic = new dynamic size mode
392 	 */
393 	public void setDynamicSize(bool dynamic)
394 	{
395 		gst_base_src_set_dynamic_size(gstBaseSrc, dynamic);
396 	}
397 
398 	/**
399 	 * Sets the default format of the source. This will be the format used
400 	 * for sending SEGMENT events and for performing seeks.
401 	 *
402 	 * If a format of GST_FORMAT_BYTES is set, the element will be able to
403 	 * operate in pull mode if the #GstBaseSrcClass.is_seekable() returns %TRUE.
404 	 *
405 	 * This function must only be called in states < %GST_STATE_PAUSED.
406 	 *
407 	 * Params:
408 	 *     format = the format to use
409 	 */
410 	public void setFormat(GstFormat format)
411 	{
412 		gst_base_src_set_format(gstBaseSrc, format);
413 	}
414 
415 	/**
416 	 * If the element listens to a live source, @live should
417 	 * be set to %TRUE.
418 	 *
419 	 * A live source will not produce data in the PAUSED state and
420 	 * will therefore not be able to participate in the PREROLL phase
421 	 * of a pipeline. To signal this fact to the application and the
422 	 * pipeline, the state change return value of the live source will
423 	 * be GST_STATE_CHANGE_NO_PREROLL.
424 	 *
425 	 * Params:
426 	 *     live = new live-mode
427 	 */
428 	public void setLive(bool live)
429 	{
430 		gst_base_src_set_live(gstBaseSrc, live);
431 	}
432 
433 	/**
434 	 * Complete an asynchronous start operation. When the subclass overrides the
435 	 * start method, it should call gst_base_src_start_complete() when the start
436 	 * operation completes either from the same thread or from an asynchronous
437 	 * helper thread.
438 	 *
439 	 * Params:
440 	 *     ret = a #GstFlowReturn
441 	 */
442 	public void startComplete(GstFlowReturn ret)
443 	{
444 		gst_base_src_start_complete(gstBaseSrc, ret);
445 	}
446 
447 	/**
448 	 * Wait until the start operation completes.
449 	 *
450 	 * Returns: a #GstFlowReturn.
451 	 */
452 	public GstFlowReturn startWait()
453 	{
454 		return gst_base_src_start_wait(gstBaseSrc);
455 	}
456 
457 	/**
458 	 * If the #GstBaseSrcClass.create() method performs its own synchronisation
459 	 * against the clock it must unblock when going from PLAYING to the PAUSED state
460 	 * and call this method before continuing to produce the remaining data.
461 	 *
462 	 * This function will block until a state change to PLAYING happens (in which
463 	 * case this function returns %GST_FLOW_OK) or the processing must be stopped due
464 	 * to a state change to READY or a FLUSH event (in which case this function
465 	 * returns %GST_FLOW_FLUSHING).
466 	 *
467 	 * Returns: %GST_FLOW_OK if @src is PLAYING and processing can
468 	 *     continue. Any other return value should be returned from the create vmethod.
469 	 */
470 	public GstFlowReturn waitPlaying()
471 	{
472 		return gst_base_src_wait_playing(gstBaseSrc);
473 	}
474 }