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 gstreamerc.gstreamer;
35 public  import gstreamerc.gstreamertypes;
36 public  import gtkc.gdktypes;
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()
67 	{
68 		return gstStreamCollection;
69 	}
70 
71 	/** the main Gtk struct as a void* */
72 	protected override void* getStruct()
73 	{
74 		return cast(void*)gstStreamCollection;
75 	}
76 
77 	protected override void setStruct(GObject* obj)
78 	{
79 		gstStreamCollection = cast(GstStreamCollection*)obj;
80 		super.setStruct(obj);
81 	}
82 
83 	/**
84 	 * Sets our main struct and passes it to the parent class.
85 	 */
86 	public this (GstStreamCollection* gstStreamCollection, bool ownedRef = false)
87 	{
88 		this.gstStreamCollection = gstStreamCollection;
89 		super(cast(GstObject*)gstStreamCollection, ownedRef);
90 	}
91 
92 
93 	/** */
94 	public static GType getType()
95 	{
96 		return gst_stream_collection_get_type();
97 	}
98 
99 	/**
100 	 * Create a new #GstStreamCollection.
101 	 *
102 	 * Params:
103 	 *     upstreamId = The stream id of the parent stream
104 	 *
105 	 * Return: The new #GstStreamCollection.
106 	 *
107 	 * Since: 1.10
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(string upstreamId)
112 	{
113 		auto p = gst_stream_collection_new(Str.toStringz(upstreamId));
114 		
115 		if(p is null)
116 		{
117 			throw new ConstructionException("null returned by new");
118 		}
119 		
120 		this(cast(GstStreamCollection*) p);
121 	}
122 
123 	/**
124 	 * Add the given @stream to the @collection.
125 	 *
126 	 * Params:
127 	 *     stream = the #GstStream to add
128 	 *
129 	 * Return: %TRUE if the @stream was properly added, else %FALSE
130 	 *
131 	 * Since: 1.10
132 	 */
133 	public bool addStream(Stream stream)
134 	{
135 		return gst_stream_collection_add_stream(gstStreamCollection, (stream is null) ? null : stream.getStreamStruct()) != 0;
136 	}
137 
138 	/**
139 	 * Get the number of streams this collection contains
140 	 *
141 	 * Return: The number of streams that @collection contains
142 	 *
143 	 * Since: 1.10
144 	 */
145 	public uint getSize()
146 	{
147 		return gst_stream_collection_get_size(gstStreamCollection);
148 	}
149 
150 	/**
151 	 * Retrieve the #GstStream with index @index from the collection.
152 	 *
153 	 * The caller should not modify the returned #GstStream
154 	 *
155 	 * Params:
156 	 *     index = Index of the stream to retrieve
157 	 *
158 	 * Return: A #GstStream
159 	 *
160 	 * Since: 1.10
161 	 */
162 	public Stream getStream(uint index)
163 	{
164 		auto p = gst_stream_collection_get_stream(gstStreamCollection, index);
165 		
166 		if(p is null)
167 		{
168 			return null;
169 		}
170 		
171 		return ObjectG.getDObject!(Stream)(cast(GstStream*) p);
172 	}
173 
174 	/**
175 	 * Returns the upstream id of the @collection.
176 	 *
177 	 * Return: The upstream id
178 	 *
179 	 * Since: 1.10
180 	 */
181 	public string getUpstreamId()
182 	{
183 		return Str.toString(gst_stream_collection_get_upstream_id(gstStreamCollection));
184 	}
185 
186 	protected class OnStreamNotifyDelegateWrapper
187 	{
188 		void delegate(Stream, ParamSpec, StreamCollection) dlg;
189 		gulong handlerId;
190 		ConnectFlags flags;
191 		this(void delegate(Stream, ParamSpec, StreamCollection) dlg, gulong handlerId, ConnectFlags flags)
192 		{
193 			this.dlg = dlg;
194 			this.handlerId = handlerId;
195 			this.flags = flags;
196 		}
197 	}
198 	protected OnStreamNotifyDelegateWrapper[] onStreamNotifyListeners;
199 
200 	/** */
201 	gulong addOnStreamNotify(void delegate(Stream, ParamSpec, StreamCollection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
202 	{
203 		onStreamNotifyListeners ~= new OnStreamNotifyDelegateWrapper(dlg, 0, connectFlags);
204 		onStreamNotifyListeners[onStreamNotifyListeners.length - 1].handlerId = Signals.connectData(
205 			this,
206 			"stream-notify",
207 			cast(GCallback)&callBackStreamNotify,
208 			cast(void*)onStreamNotifyListeners[onStreamNotifyListeners.length - 1],
209 			cast(GClosureNotify)&callBackStreamNotifyDestroy,
210 			connectFlags);
211 		return onStreamNotifyListeners[onStreamNotifyListeners.length - 1].handlerId;
212 	}
213 	
214 	extern(C) static void callBackStreamNotify(GstStreamCollection* streamcollectionStruct, GstStream* object, GParamSpec* p0,OnStreamNotifyDelegateWrapper wrapper)
215 	{
216 		wrapper.dlg(ObjectG.getDObject!(Stream)(object), ObjectG.getDObject!(ParamSpec)(p0), wrapper.outer);
217 	}
218 	
219 	extern(C) static void callBackStreamNotifyDestroy(OnStreamNotifyDelegateWrapper wrapper, GClosure* closure)
220 	{
221 		wrapper.outer.internalRemoveOnStreamNotify(wrapper);
222 	}
223 
224 	protected void internalRemoveOnStreamNotify(OnStreamNotifyDelegateWrapper source)
225 	{
226 		foreach(index, wrapper; onStreamNotifyListeners)
227 		{
228 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
229 			{
230 				onStreamNotifyListeners[index] = null;
231 				onStreamNotifyListeners = std.algorithm.remove(onStreamNotifyListeners, index);
232 				break;
233 			}
234 		}
235 	}
236 	
237 }