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