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 	/**
171 	 * Sets our main struct and passes it to the parent class.
172 	 */
173 	public this (GstBaseSrc* gstBaseSrc, bool ownedRef = false)
174 	{
175 		this.gstBaseSrc = gstBaseSrc;
176 		super(cast(GstElement*)gstBaseSrc, ownedRef);
177 	}
178 
179 
180 	/** */
181 	public static GType getType()
182 	{
183 		return gst_base_src_get_type();
184 	}
185 
186 	/**
187 	 * Lets #GstBaseSrc sub-classes to know the memory @allocator
188 	 * used by the base class and its @params.
189 	 *
190 	 * Unref the @allocator after usage.
191 	 *
192 	 * Params:
193 	 *     allocator = the #GstAllocator
194 	 *         used
195 	 *     params = the
196 	 *         #GstAllocationParams of @allocator
197 	 */
198 	public void getAllocator(out Allocator allocator, out AllocationParams params)
199 	{
200 		GstAllocator* outallocator = null;
201 		GstAllocationParams* outparams = gMalloc!GstAllocationParams();
202 
203 		gst_base_src_get_allocator(gstBaseSrc, &outallocator, outparams);
204 
205 		allocator = ObjectG.getDObject!(Allocator)(outallocator);
206 		params = ObjectG.getDObject!(AllocationParams)(outparams, true);
207 	}
208 
209 	/**
210 	 * Get the number of bytes that @src will push out with each buffer.
211 	 *
212 	 * Returns: the number of bytes pushed with each buffer.
213 	 */
214 	public uint getBlocksize()
215 	{
216 		return gst_base_src_get_blocksize(gstBaseSrc);
217 	}
218 
219 	/**
220 	 * Returns: the instance of the #GstBufferPool used
221 	 *     by the src; unref it after usage.
222 	 */
223 	public BufferPool getBufferPool()
224 	{
225 		auto p = gst_base_src_get_buffer_pool(gstBaseSrc);
226 
227 		if(p is null)
228 		{
229 			return null;
230 		}
231 
232 		return ObjectG.getDObject!(BufferPool)(cast(GstBufferPool*) p, true);
233 	}
234 
235 	/**
236 	 * Query if @src timestamps outgoing buffers based on the current running_time.
237 	 *
238 	 * Returns: %TRUE if the base class will automatically timestamp outgoing buffers.
239 	 */
240 	public bool getDoTimestamp()
241 	{
242 		return gst_base_src_get_do_timestamp(gstBaseSrc) != 0;
243 	}
244 
245 	/**
246 	 * Get the current async behaviour of @src. See also gst_base_src_set_async().
247 	 *
248 	 * Returns: %TRUE if @src is operating in async mode.
249 	 */
250 	public bool isAsync()
251 	{
252 		return gst_base_src_is_async(gstBaseSrc) != 0;
253 	}
254 
255 	/**
256 	 * Check if an element is in live mode.
257 	 *
258 	 * Returns: %TRUE if element is in live mode.
259 	 */
260 	public bool isLive()
261 	{
262 		return gst_base_src_is_live(gstBaseSrc) != 0;
263 	}
264 
265 	/**
266 	 * Prepare a new seamless segment for emission downstream. This function must
267 	 * only be called by derived sub-classes, and only from the create() function,
268 	 * as the stream-lock needs to be held.
269 	 *
270 	 * The format for the new segment will be the current format of the source, as
271 	 * configured with gst_base_src_set_format()
272 	 *
273 	 * Params:
274 	 *     start = The new start value for the segment
275 	 *     stop = Stop value for the new segment
276 	 *     time = The new time value for the start of the new segment
277 	 *
278 	 * Returns: %TRUE if preparation of the seamless segment succeeded.
279 	 */
280 	public bool newSeamlessSegment(long start, long stop, long time)
281 	{
282 		return gst_base_src_new_seamless_segment(gstBaseSrc, start, stop, time) != 0;
283 	}
284 
285 	/**
286 	 * Query the source for the latency parameters. @live will be %TRUE when @src is
287 	 * configured as a live source. @min_latency and @max_latency will be set
288 	 * to the difference between the running time and the timestamp of the first
289 	 * buffer.
290 	 *
291 	 * This function is mostly used by subclasses.
292 	 *
293 	 * Params:
294 	 *     live = if the source is live
295 	 *     minLatency = the min latency of the source
296 	 *     maxLatency = the max latency of the source
297 	 *
298 	 * Returns: %TRUE if the query succeeded.
299 	 */
300 	public bool queryLatency(out bool live, out GstClockTime minLatency, out GstClockTime maxLatency)
301 	{
302 		int outlive;
303 
304 		auto p = gst_base_src_query_latency(gstBaseSrc, &outlive, &minLatency, &maxLatency) != 0;
305 
306 		live = (outlive == 1);
307 
308 		return p;
309 	}
310 
311 	/**
312 	 * Configure async behaviour in @src, no state change will block. The open,
313 	 * close, start, stop, play and pause virtual methods will be executed in a
314 	 * different thread and are thus allowed to perform blocking operations. Any
315 	 * blocking operation should be unblocked with the unlock vmethod.
316 	 *
317 	 * Params:
318 	 *     async = new async mode
319 	 */
320 	public void setAsync(bool async)
321 	{
322 		gst_base_src_set_async(gstBaseSrc, async);
323 	}
324 
325 	/**
326 	 * If @automatic_eos is %TRUE, @src will automatically go EOS if a buffer
327 	 * after the total size is returned. By default this is %TRUE but sources
328 	 * that can't return an authoritative size and only know that they're EOS
329 	 * when trying to read more should set this to %FALSE.
330 	 *
331 	 * Params:
332 	 *     automaticEos = automatic eos
333 	 *
334 	 * Since: 1.4
335 	 */
336 	public void setAutomaticEos(bool automaticEos)
337 	{
338 		gst_base_src_set_automatic_eos(gstBaseSrc, automaticEos);
339 	}
340 
341 	/**
342 	 * Set the number of bytes that @src will push out with each buffer. When
343 	 * @blocksize is set to -1, a default length will be used.
344 	 *
345 	 * Params:
346 	 *     blocksize = the new blocksize in bytes
347 	 */
348 	public void setBlocksize(uint blocksize)
349 	{
350 		gst_base_src_set_blocksize(gstBaseSrc, blocksize);
351 	}
352 
353 	/**
354 	 * Set new caps on the basesrc source pad.
355 	 *
356 	 * Params:
357 	 *     caps = a #GstCaps
358 	 *
359 	 * Returns: %TRUE if the caps could be set
360 	 */
361 	public bool setCaps(Caps caps)
362 	{
363 		return gst_base_src_set_caps(gstBaseSrc, (caps is null) ? null : caps.getCapsStruct()) != 0;
364 	}
365 
366 	/**
367 	 * Configure @src to automatically timestamp outgoing buffers based on the
368 	 * current running_time of the pipeline. This property is mostly useful for live
369 	 * sources.
370 	 *
371 	 * Params:
372 	 *     timestamp = enable or disable timestamping
373 	 */
374 	public void setDoTimestamp(bool timestamp)
375 	{
376 		gst_base_src_set_do_timestamp(gstBaseSrc, timestamp);
377 	}
378 
379 	/**
380 	 * If not @dynamic, size is only updated when needed, such as when trying to
381 	 * read past current tracked size.  Otherwise, size is checked for upon each
382 	 * read.
383 	 *
384 	 * Params:
385 	 *     dynamic = new dynamic size mode
386 	 */
387 	public void setDynamicSize(bool dynamic)
388 	{
389 		gst_base_src_set_dynamic_size(gstBaseSrc, dynamic);
390 	}
391 
392 	/**
393 	 * Sets the default format of the source. This will be the format used
394 	 * for sending SEGMENT events and for performing seeks.
395 	 *
396 	 * If a format of GST_FORMAT_BYTES is set, the element will be able to
397 	 * operate in pull mode if the #GstBaseSrcClass.is_seekable() returns %TRUE.
398 	 *
399 	 * This function must only be called in states < %GST_STATE_PAUSED.
400 	 *
401 	 * Params:
402 	 *     format = the format to use
403 	 */
404 	public void setFormat(GstFormat format)
405 	{
406 		gst_base_src_set_format(gstBaseSrc, format);
407 	}
408 
409 	/**
410 	 * If the element listens to a live source, @live should
411 	 * be set to %TRUE.
412 	 *
413 	 * A live source will not produce data in the PAUSED state and
414 	 * will therefore not be able to participate in the PREROLL phase
415 	 * of a pipeline. To signal this fact to the application and the
416 	 * pipeline, the state change return value of the live source will
417 	 * be GST_STATE_CHANGE_NO_PREROLL.
418 	 *
419 	 * Params:
420 	 *     live = new live-mode
421 	 */
422 	public void setLive(bool live)
423 	{
424 		gst_base_src_set_live(gstBaseSrc, live);
425 	}
426 
427 	/**
428 	 * Complete an asynchronous start operation. When the subclass overrides the
429 	 * start method, it should call gst_base_src_start_complete() when the start
430 	 * operation completes either from the same thread or from an asynchronous
431 	 * helper thread.
432 	 *
433 	 * Params:
434 	 *     ret = a #GstFlowReturn
435 	 */
436 	public void startComplete(GstFlowReturn ret)
437 	{
438 		gst_base_src_start_complete(gstBaseSrc, ret);
439 	}
440 
441 	/**
442 	 * Wait until the start operation completes.
443 	 *
444 	 * Returns: a #GstFlowReturn.
445 	 */
446 	public GstFlowReturn startWait()
447 	{
448 		return gst_base_src_start_wait(gstBaseSrc);
449 	}
450 
451 	/**
452 	 * If the #GstBaseSrcClass.create() method performs its own synchronisation
453 	 * against the clock it must unblock when going from PLAYING to the PAUSED state
454 	 * and call this method before continuing to produce the remaining data.
455 	 *
456 	 * This function will block until a state change to PLAYING happens (in which
457 	 * case this function returns %GST_FLOW_OK) or the processing must be stopped due
458 	 * to a state change to READY or a FLUSH event (in which case this function
459 	 * returns %GST_FLOW_FLUSHING).
460 	 *
461 	 * Returns: %GST_FLOW_OK if @src is PLAYING and processing can
462 	 *     continue. Any other return value should be returned from the create vmethod.
463 	 */
464 	public GstFlowReturn waitPlaying()
465 	{
466 		return gst_base_src_wait_playing(gstBaseSrc);
467 	}
468 }