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