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