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.app.AppSrc;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gst.app.c.functions;
30 public  import gst.app.c.types;
31 private import gst.base.BaseSrc;
32 private import gstreamer.Buffer;
33 private import gstreamer.BufferList;
34 private import gstreamer.Caps;
35 private import gstreamer.Sample;
36 private import gstreamer.URIHandlerIF;
37 private import gstreamer.URIHandlerT;
38 private import std.algorithm;
39 
40 
41 /**
42  * The appsrc element can be used by applications to insert data into a
43  * GStreamer pipeline. Unlike most GStreamer elements, appsrc provides
44  * external API functions.
45  * 
46  * appsrc can be used by linking with the libgstapp library to access the
47  * methods directly or by using the appsrc action signals.
48  * 
49  * Before operating appsrc, the caps property must be set to fixed caps
50  * describing the format of the data that will be pushed with appsrc. An
51  * exception to this is when pushing buffers with unknown caps, in which case no
52  * caps should be set. This is typically true of file-like sources that push raw
53  * byte buffers. If you don't want to explicitly set the caps, you can use
54  * gst_app_src_push_sample. This method gets the caps associated with the
55  * sample and sets them on the appsrc replacing any previously set caps (if
56  * different from sample's caps).
57  * 
58  * The main way of handing data to the appsrc element is by calling the
59  * gst_app_src_push_buffer() method or by emitting the push-buffer action signal.
60  * This will put the buffer onto a queue from which appsrc will read from in its
61  * streaming thread. It is important to note that data transport will not happen
62  * from the thread that performed the push-buffer call.
63  * 
64  * The "max-bytes" property controls how much data can be queued in appsrc
65  * before appsrc considers the queue full. A filled internal queue will always
66  * signal the "enough-data" signal, which signals the application that it should
67  * stop pushing data into appsrc. The "block" property will cause appsrc to
68  * block the push-buffer method until free data becomes available again.
69  * 
70  * When the internal queue is running out of data, the "need-data" signal is
71  * emitted, which signals the application that it should start pushing more data
72  * into appsrc.
73  * 
74  * In addition to the "need-data" and "enough-data" signals, appsrc can emit the
75  * "seek-data" signal when the "stream-mode" property is set to "seekable" or
76  * "random-access". The signal argument will contain the new desired position in
77  * the stream expressed in the unit set with the "format" property. After
78  * receiving the seek-data signal, the application should push-buffers from the
79  * new position.
80  * 
81  * These signals allow the application to operate the appsrc in two different
82  * ways:
83  * 
84  * The push mode, in which the application repeatedly calls the push-buffer/push-sample
85  * method with a new buffer/sample. Optionally, the queue size in the appsrc
86  * can be controlled with the enough-data and need-data signals by respectively
87  * stopping/starting the push-buffer/push-sample calls. This is a typical
88  * mode of operation for the stream-type "stream" and "seekable". Use this
89  * mode when implementing various network protocols or hardware devices.
90  * 
91  * The pull mode, in which the need-data signal triggers the next push-buffer call.
92  * This mode is typically used in the "random-access" stream-type. Use this
93  * mode for file access or other randomly accessable sources. In this mode, a
94  * buffer of exactly the amount of bytes given by the need-data signal should be
95  * pushed into appsrc.
96  * 
97  * In all modes, the size property on appsrc should contain the total stream
98  * size in bytes. Setting this property is mandatory in the random-access mode.
99  * For the stream and seekable modes, setting this property is optional but
100  * recommended.
101  * 
102  * When the application has finished pushing data into appsrc, it should call
103  * gst_app_src_end_of_stream() or emit the end-of-stream action signal. After
104  * this call, no more buffers can be pushed into appsrc until a flushing seek
105  * occurs or the state of the appsrc has gone through READY.
106  */
107 public class AppSrc : BaseSrc, URIHandlerIF
108 {
109 	/** the main Gtk struct */
110 	protected GstAppSrc* gstAppSrc;
111 
112 	/** Get the main Gtk struct */
113 	public GstAppSrc* getAppSrcStruct(bool transferOwnership = false)
114 	{
115 		if (transferOwnership)
116 			ownedRef = false;
117 		return gstAppSrc;
118 	}
119 
120 	/** the main Gtk struct as a void* */
121 	protected override void* getStruct()
122 	{
123 		return cast(void*)gstAppSrc;
124 	}
125 
126 	/**
127 	 * Sets our main struct and passes it to the parent class.
128 	 */
129 	public this (GstAppSrc* gstAppSrc, bool ownedRef = false)
130 	{
131 		this.gstAppSrc = gstAppSrc;
132 		super(cast(GstBaseSrc*)gstAppSrc, ownedRef);
133 	}
134 
135 	// add the URIHandler capabilities
136 	mixin URIHandlerT!(GstAppSrc);
137 
138 
139 	/** */
140 	public static GType getType()
141 	{
142 		return gst_app_src_get_type();
143 	}
144 
145 	/**
146 	 * Indicates to the appsrc element that the last buffer queued in the
147 	 * element is the last buffer of the stream.
148 	 *
149 	 * Returns: #GST_FLOW_OK when the EOS was successfuly queued.
150 	 *     #GST_FLOW_FLUSHING when @appsrc is not PAUSED or PLAYING.
151 	 */
152 	public GstFlowReturn endOfStream()
153 	{
154 		return gst_app_src_end_of_stream(gstAppSrc);
155 	}
156 
157 	/**
158 	 * Get the configured caps on @appsrc.
159 	 *
160 	 * Returns: the #GstCaps produced by the source. gst_caps_unref() after usage.
161 	 */
162 	public Caps getCaps()
163 	{
164 		auto p = gst_app_src_get_caps(gstAppSrc);
165 
166 		if(p is null)
167 		{
168 			return null;
169 		}
170 
171 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p, true);
172 	}
173 
174 	/**
175 	 * Get the number of currently queued bytes inside @appsrc.
176 	 *
177 	 * Returns: The number of currently queued bytes.
178 	 *
179 	 * Since: 1.2
180 	 */
181 	public ulong getCurrentLevelBytes()
182 	{
183 		return gst_app_src_get_current_level_bytes(gstAppSrc);
184 	}
185 
186 	/**
187 	 * Get the duration of the stream in nanoseconds. A value of GST_CLOCK_TIME_NONE means that the duration is
188 	 * not known.
189 	 *
190 	 * Returns: the duration of the stream previously set with gst_app_src_set_duration();
191 	 *
192 	 * Since: 1.10
193 	 */
194 	public GstClockTime getDuration()
195 	{
196 		return gst_app_src_get_duration(gstAppSrc);
197 	}
198 
199 	/**
200 	 * Check if appsrc will emit the "new-preroll" and "new-buffer" signals.
201 	 *
202 	 * Returns: %TRUE if @appsrc is emitting the "new-preroll" and "new-buffer"
203 	 *     signals.
204 	 */
205 	public bool getEmitSignals()
206 	{
207 		return gst_app_src_get_emit_signals(gstAppSrc) != 0;
208 	}
209 
210 	/**
211 	 * Retrieve the min and max latencies in @min and @max respectively.
212 	 *
213 	 * Params:
214 	 *     min = the min latency
215 	 *     max = the max latency
216 	 */
217 	public void getLatency(out ulong min, out ulong max)
218 	{
219 		gst_app_src_get_latency(gstAppSrc, &min, &max);
220 	}
221 
222 	/**
223 	 * Get the maximum amount of bytes that can be queued in @appsrc.
224 	 *
225 	 * Returns: The maximum amount of bytes that can be queued.
226 	 */
227 	public ulong getMaxBytes()
228 	{
229 		return gst_app_src_get_max_bytes(gstAppSrc);
230 	}
231 
232 	/**
233 	 * Get the size of the stream in bytes. A value of -1 means that the size is
234 	 * not known.
235 	 *
236 	 * Returns: the size of the stream previously set with gst_app_src_set_size();
237 	 */
238 	public long getSize()
239 	{
240 		return gst_app_src_get_size(gstAppSrc);
241 	}
242 
243 	/**
244 	 * Get the stream type. Control the stream type of @appsrc
245 	 * with gst_app_src_set_stream_type().
246 	 *
247 	 * Returns: the stream type.
248 	 */
249 	public GstAppStreamType getStreamType()
250 	{
251 		return gst_app_src_get_stream_type(gstAppSrc);
252 	}
253 
254 	/**
255 	 * Adds a buffer to the queue of buffers that the appsrc element will
256 	 * push to its source pad.  This function takes ownership of the buffer.
257 	 *
258 	 * When the block property is TRUE, this function can block until free
259 	 * space becomes available in the queue.
260 	 *
261 	 * Params:
262 	 *     buffer = a #GstBuffer to push
263 	 *
264 	 * Returns: #GST_FLOW_OK when the buffer was successfuly queued.
265 	 *     #GST_FLOW_FLUSHING when @appsrc is not PAUSED or PLAYING.
266 	 *     #GST_FLOW_EOS when EOS occured.
267 	 */
268 	public GstFlowReturn pushBuffer(Buffer buffer)
269 	{
270 		return gst_app_src_push_buffer(gstAppSrc, (buffer is null) ? null : buffer.getBufferStruct());
271 	}
272 
273 	/**
274 	 * Adds a buffer list to the queue of buffers and buffer lists that the
275 	 * appsrc element will push to its source pad.  This function takes ownership
276 	 * of @buffer_list.
277 	 *
278 	 * When the block property is TRUE, this function can block until free
279 	 * space becomes available in the queue.
280 	 *
281 	 * Params:
282 	 *     bufferList = a #GstBufferList to push
283 	 *
284 	 * Returns: #GST_FLOW_OK when the buffer list was successfuly queued.
285 	 *     #GST_FLOW_FLUSHING when @appsrc is not PAUSED or PLAYING.
286 	 *     #GST_FLOW_EOS when EOS occured.
287 	 *
288 	 * Since: 1.14
289 	 */
290 	public GstFlowReturn pushBufferList(BufferList bufferList)
291 	{
292 		return gst_app_src_push_buffer_list(gstAppSrc, (bufferList is null) ? null : bufferList.getBufferListStruct());
293 	}
294 
295 	/**
296 	 * Extract a buffer from the provided sample and adds it to the queue of
297 	 * buffers that the appsrc element will push to its source pad. Any
298 	 * previous caps that were set on appsrc will be replaced by the caps
299 	 * associated with the sample if not equal.
300 	 *
301 	 * This function does not take ownership of the
302 	 * sample so the sample needs to be unreffed after calling this function.
303 	 *
304 	 * When the block property is TRUE, this function can block until free
305 	 * space becomes available in the queue.
306 	 *
307 	 * Params:
308 	 *     sample = a #GstSample from which buffer and caps may be
309 	 *         extracted
310 	 *
311 	 * Returns: #GST_FLOW_OK when the buffer was successfuly queued.
312 	 *     #GST_FLOW_FLUSHING when @appsrc is not PAUSED or PLAYING.
313 	 *     #GST_FLOW_EOS when EOS occured.
314 	 *
315 	 * Since: 1.6
316 	 */
317 	public GstFlowReturn pushSample(Sample sample)
318 	{
319 		return gst_app_src_push_sample(gstAppSrc, (sample is null) ? null : sample.getSampleStruct());
320 	}
321 
322 	/**
323 	 * Set callbacks which will be executed when data is needed, enough data has
324 	 * been collected or when a seek should be performed.
325 	 * This is an alternative to using the signals, it has lower overhead and is thus
326 	 * less expensive, but also less flexible.
327 	 *
328 	 * If callbacks are installed, no signals will be emitted for performance
329 	 * reasons.
330 	 *
331 	 * Params:
332 	 *     callbacks = the callbacks
333 	 *     userData = a user_data argument for the callbacks
334 	 *     notify = a destroy notify function
335 	 */
336 	public void setCallbacks(GstAppSrcCallbacks* callbacks, void* userData, GDestroyNotify notify)
337 	{
338 		gst_app_src_set_callbacks(gstAppSrc, callbacks, userData, notify);
339 	}
340 
341 	/**
342 	 * Set the duration of the stream in nanoseconds. A value of GST_CLOCK_TIME_NONE means that the duration is
343 	 * not known.
344 	 *
345 	 * Params:
346 	 *     duration = the duration to set
347 	 *
348 	 * Since: 1.10
349 	 */
350 	public void setDuration(GstClockTime duration)
351 	{
352 		gst_app_src_set_duration(gstAppSrc, duration);
353 	}
354 
355 	/**
356 	 * Make appsrc emit the "new-preroll" and "new-buffer" signals. This option is
357 	 * by default disabled because signal emission is expensive and unneeded when
358 	 * the application prefers to operate in pull mode.
359 	 *
360 	 * Params:
361 	 *     emit = the new state
362 	 */
363 	public void setEmitSignals(bool emit)
364 	{
365 		gst_app_src_set_emit_signals(gstAppSrc, emit);
366 	}
367 
368 	/**
369 	 * Configure the @min and @max latency in @src. If @min is set to -1, the
370 	 * default latency calculations for pseudo-live sources will be used.
371 	 *
372 	 * Params:
373 	 *     min = the min latency
374 	 *     max = the max latency
375 	 */
376 	public void setLatency(ulong min, ulong max)
377 	{
378 		gst_app_src_set_latency(gstAppSrc, min, max);
379 	}
380 
381 	/**
382 	 * Set the maximum amount of bytes that can be queued in @appsrc.
383 	 * After the maximum amount of bytes are queued, @appsrc will emit the
384 	 * "enough-data" signal.
385 	 *
386 	 * Params:
387 	 *     max = the maximum number of bytes to queue
388 	 */
389 	public void setMaxBytes(ulong max)
390 	{
391 		gst_app_src_set_max_bytes(gstAppSrc, max);
392 	}
393 
394 	/**
395 	 * Set the size of the stream in bytes. A value of -1 means that the size is
396 	 * not known.
397 	 *
398 	 * Params:
399 	 *     size = the size to set
400 	 */
401 	public void setSize(long size)
402 	{
403 		gst_app_src_set_size(gstAppSrc, size);
404 	}
405 
406 	/**
407 	 * Set the stream type on @appsrc. For seekable streams, the "seek" signal must
408 	 * be connected to.
409 	 *
410 	 * A stream_type stream
411 	 *
412 	 * Params:
413 	 *     type = the new state
414 	 */
415 	public void setStreamType(GstAppStreamType type)
416 	{
417 		gst_app_src_set_stream_type(gstAppSrc, type);
418 	}
419 
420 	/**
421 	 * Notify @appsrc that no more buffer are available.
422 	 */
423 	gulong addOnEndOfStream(GstFlowReturn delegate(AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
424 	{
425 		return Signals.connect(this, "end-of-stream", dlg, connectFlags ^ ConnectFlags.SWAPPED);
426 	}
427 
428 	/**
429 	 * Signal that the source has enough data. It is recommended that the
430 	 * application stops calling push-buffer until the need-data signal is
431 	 * emitted again to avoid excessive buffer queueing.
432 	 */
433 	gulong addOnEnoughData(void delegate(AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
434 	{
435 		return Signals.connect(this, "enough-data", dlg, connectFlags ^ ConnectFlags.SWAPPED);
436 	}
437 
438 	/**
439 	 * Signal that the source needs more data. In the callback or from another
440 	 * thread you should call push-buffer or end-of-stream.
441 	 *
442 	 * @length is just a hint and when it is set to -1, any number of bytes can be
443 	 * pushed into @appsrc.
444 	 *
445 	 * You can call push-buffer multiple times until the enough-data signal is
446 	 * fired.
447 	 *
448 	 * Params:
449 	 *     length = the amount of bytes needed.
450 	 */
451 	gulong addOnNeedData(void delegate(uint, AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
452 	{
453 		return Signals.connect(this, "need-data", dlg, connectFlags ^ ConnectFlags.SWAPPED);
454 	}
455 
456 	/**
457 	 * Adds a buffer to the queue of buffers that the appsrc element will
458 	 * push to its source pad. This function does not take ownership of the
459 	 * buffer so the buffer needs to be unreffed after calling this function.
460 	 *
461 	 * When the block property is TRUE, this function can block until free space
462 	 * becomes available in the queue.
463 	 *
464 	 * Params:
465 	 *     buffer = a buffer to push
466 	 */
467 	gulong addOnPushBuffer(GstFlowReturn delegate(Buffer, AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
468 	{
469 		return Signals.connect(this, "push-buffer", dlg, connectFlags ^ ConnectFlags.SWAPPED);
470 	}
471 
472 	/**
473 	 * Adds a buffer list to the queue of buffers and buffer lists that the
474 	 * appsrc element will push to its source pad. This function does not take
475 	 * ownership of the buffer list so the buffer list needs to be unreffed
476 	 * after calling this function.
477 	 *
478 	 * When the block property is TRUE, this function can block until free space
479 	 * becomes available in the queue.
480 	 *
481 	 * Params:
482 	 *     bufferList = a buffer list to push
483 	 *
484 	 * Since: 1.14
485 	 */
486 	gulong addOnPushBufferList(GstFlowReturn delegate(BufferList, AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
487 	{
488 		return Signals.connect(this, "push-buffer-list", dlg, connectFlags ^ ConnectFlags.SWAPPED);
489 	}
490 
491 	/**
492 	 * Extract a buffer from the provided sample and adds the extracted buffer
493 	 * to the queue of buffers that the appsrc element will
494 	 * push to its source pad. This function set the appsrc caps based on the caps
495 	 * in the sample and reset the caps if they change.
496 	 * Only the caps and the buffer of the provided sample are used and not
497 	 * for example the segment in the sample.
498 	 * This function does not take ownership of the
499 	 * sample so the sample needs to be unreffed after calling this function.
500 	 *
501 	 * When the block property is TRUE, this function can block until free space
502 	 * becomes available in the queue.
503 	 *
504 	 * Params:
505 	 *     sample = a sample from which extract buffer to push
506 	 *
507 	 * Since: 1.6
508 	 */
509 	gulong addOnPushSample(GstFlowReturn delegate(Sample, AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
510 	{
511 		return Signals.connect(this, "push-sample", dlg, connectFlags ^ ConnectFlags.SWAPPED);
512 	}
513 
514 	/**
515 	 * Seek to the given offset. The next push-buffer should produce buffers from
516 	 * the new @offset.
517 	 * This callback is only called for seekable stream types.
518 	 *
519 	 * Params:
520 	 *     offset = the offset to seek to
521 	 *
522 	 * Returns: %TRUE if the seek succeeded.
523 	 */
524 	gulong addOnSeekData(bool delegate(ulong, AppSrc) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
525 	{
526 		return Signals.connect(this, "seek-data", dlg, connectFlags ^ ConnectFlags.SWAPPED);
527 	}
528 
529 	/**
530 	 * Set the capabilities on the appsrc element.  This function takes
531 	 * a copy of the caps structure. After calling this method, the source will
532 	 * only produce caps that match @caps. @caps must be fixed and the caps on the
533 	 * buffers must match the caps or left NULL.
534 	 *
535 	 * Params:
536 	 *     caps = caps to set
537 	 */
538 	public void appSrcSetCaps(Caps caps)
539 	{
540 		gst_app_src_set_caps(gstAppSrc, (caps is null) ? null : caps.getCapsStruct());
541 	}
542 }