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 gstreamer.StreamCollection;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.ParamSpec;
31 private import gobject.Signals;
32 private import gstreamer.ObjectGst;
33 private import gstreamer.Stream;
34 private import gstreamer.c.functions;
35 public  import gstreamer.c.types;
36 public  import gstreamerc.gstreamertypes;
37 private import std.algorithm;
38 
39 
40 /**
41  * A collection of #GstStream that are available.
42  * 
43  * A #GstStreamCollection will be provided by elements that can make those
44  * streams available. Applications can use the collection to show the user
45  * what streams are available by using %gst_stream_collection_get_stream()
46  * 
47  * Once posted, a #GstStreamCollection is immutable. Updates are made by sending
48  * a new #GstStreamCollection message, which may or may not share some of
49  * the #GstStream objects from the collection it replaces. The receiver can check
50  * the sender of a stream collection message to know which collection is
51  * obsoleted.
52  * 
53  * Several elements in a pipeline can provide #GstStreamCollection.
54  * 
55  * Applications can activate streams from a collection by using the
56  * #GST_EVENT_SELECT_STREAMS event on a pipeline, bin or element.
57  *
58  * Since: 1.10
59  */
60 public class StreamCollection : ObjectGst
61 {
62 	/** the main Gtk struct */
63 	protected GstStreamCollection* gstStreamCollection;
64 
65 	/** Get the main Gtk struct */
66 	public GstStreamCollection* getStreamCollectionStruct(bool transferOwnership = false)
67 	{
68 		if (transferOwnership)
69 			ownedRef = false;
70 		return gstStreamCollection;
71 	}
72 
73 	/** the main Gtk struct as a void* */
74 	protected override void* getStruct()
75 	{
76 		return cast(void*)gstStreamCollection;
77 	}
78 
79 	protected override void setStruct(GObject* obj)
80 	{
81 		gstStreamCollection = cast(GstStreamCollection*)obj;
82 		super.setStruct(obj);
83 	}
84 
85 	/**
86 	 * Sets our main struct and passes it to the parent class.
87 	 */
88 	public this (GstStreamCollection* gstStreamCollection, bool ownedRef = false)
89 	{
90 		this.gstStreamCollection = gstStreamCollection;
91 		super(cast(GstObject*)gstStreamCollection, ownedRef);
92 	}
93 
94 
95 	/** */
96 	public static GType getType()
97 	{
98 		return gst_stream_collection_get_type();
99 	}
100 
101 	/**
102 	 * Create a new #GstStreamCollection.
103 	 *
104 	 * Params:
105 	 *     upstreamId = The stream id of the parent stream
106 	 *
107 	 * Returns: The new #GstStreamCollection.
108 	 *
109 	 * Since: 1.10
110 	 *
111 	 * Throws: ConstructionException GTK+ fails to create the object.
112 	 */
113 	public this(string upstreamId)
114 	{
115 		auto p = gst_stream_collection_new(Str.toStringz(upstreamId));
116 
117 		if(p is null)
118 		{
119 			throw new ConstructionException("null returned by new");
120 		}
121 
122 		this(cast(GstStreamCollection*) p);
123 	}
124 
125 	/**
126 	 * Add the given @stream to the @collection.
127 	 *
128 	 * Params:
129 	 *     stream = the #GstStream to add
130 	 *
131 	 * Returns: %TRUE if the @stream was properly added, else %FALSE
132 	 *
133 	 * Since: 1.10
134 	 */
135 	public bool addStream(Stream stream)
136 	{
137 		return gst_stream_collection_add_stream(gstStreamCollection, (stream is null) ? null : stream.getStreamStruct()) != 0;
138 	}
139 
140 	/**
141 	 * Get the number of streams this collection contains
142 	 *
143 	 * Returns: The number of streams that @collection contains
144 	 *
145 	 * Since: 1.10
146 	 */
147 	public uint getSize()
148 	{
149 		return gst_stream_collection_get_size(gstStreamCollection);
150 	}
151 
152 	/**
153 	 * Retrieve the #GstStream with index @index from the collection.
154 	 *
155 	 * The caller should not modify the returned #GstStream
156 	 *
157 	 * Params:
158 	 *     index = Index of the stream to retrieve
159 	 *
160 	 * Returns: A #GstStream
161 	 *
162 	 * Since: 1.10
163 	 */
164 	public Stream getStream(uint index)
165 	{
166 		auto p = gst_stream_collection_get_stream(gstStreamCollection, index);
167 
168 		if(p is null)
169 		{
170 			return null;
171 		}
172 
173 		return ObjectG.getDObject!(Stream)(cast(GstStream*) p);
174 	}
175 
176 	/**
177 	 * Returns the upstream id of the @collection.
178 	 *
179 	 * Returns: The upstream id
180 	 *
181 	 * Since: 1.10
182 	 */
183 	public string getUpstreamId()
184 	{
185 		return Str.toString(gst_stream_collection_get_upstream_id(gstStreamCollection));
186 	}
187 
188 	protected class OnStreamNotifyDelegateWrapper
189 	{
190 		void delegate(Stream, ParamSpec, StreamCollection) dlg;
191 		gulong handlerId;
192 
193 		this(void delegate(Stream, ParamSpec, StreamCollection) dlg)
194 		{
195 			this.dlg = dlg;
196 			onStreamNotifyListeners ~= this;
197 		}
198 
199 		void remove(OnStreamNotifyDelegateWrapper source)
200 		{
201 			foreach(index, wrapper; onStreamNotifyListeners)
202 			{
203 				if (wrapper.handlerId == source.handlerId)
204 				{
205 					onStreamNotifyListeners[index] = null;
206 					onStreamNotifyListeners = std.algorithm.remove(onStreamNotifyListeners, index);
207 					break;
208 				}
209 			}
210 		}
211 	}
212 	OnStreamNotifyDelegateWrapper[] onStreamNotifyListeners;
213 
214 	/** */
215 	gulong addOnStreamNotify(void delegate(Stream, ParamSpec, StreamCollection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
216 	{
217 		auto wrapper = new OnStreamNotifyDelegateWrapper(dlg);
218 		wrapper.handlerId = Signals.connectData(
219 			this,
220 			"stream-notify",
221 			cast(GCallback)&callBackStreamNotify,
222 			cast(void*)wrapper,
223 			cast(GClosureNotify)&callBackStreamNotifyDestroy,
224 			connectFlags);
225 		return wrapper.handlerId;
226 	}
227 
228 	extern(C) static void callBackStreamNotify(GstStreamCollection* streamcollectionStruct, GstStream* object, GParamSpec* p0, OnStreamNotifyDelegateWrapper wrapper)
229 	{
230 		wrapper.dlg(ObjectG.getDObject!(Stream)(object), ObjectG.getDObject!(ParamSpec)(p0), wrapper.outer);
231 	}
232 
233 	extern(C) static void callBackStreamNotifyDestroy(OnStreamNotifyDelegateWrapper wrapper, GClosure* closure)
234 	{
235 		wrapper.remove(wrapper);
236 	}
237 }