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.Context;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gstreamer.Structure;
31 private import gstreamer.c.functions;
32 public  import gstreamer.c.types;
33 public  import gstreamerc.gstreamertypes;
34 
35 
36 /**
37  * #GstContext is a container object used to store contexts like a device
38  * context, a display server connection and similar concepts that should
39  * be shared between multiple elements.
40  * 
41  * Applications can set a context on a complete pipeline by using
42  * gst_element_set_context(), which will then be propagated to all
43  * child elements. Elements can handle these in #GstElementClass.set_context()
44  * and merge them with the context information they already have.
45  * 
46  * When an element needs a context it will do the following actions in this
47  * order until one step succeeds:
48  * 1. Check if the element already has a context
49  * 2. Query downstream with GST_QUERY_CONTEXT for the context
50  * 3. Query upstream with GST_QUERY_CONTEXT for the context
51  * 4. Post a GST_MESSAGE_NEED_CONTEXT message on the bus with the required
52  * context types and afterwards check if a usable context was set now
53  * 5. Create a context by itself and post a GST_MESSAGE_HAVE_CONTEXT message
54  * on the bus.
55  * 
56  * Bins will catch GST_MESSAGE_NEED_CONTEXT messages and will set any previously
57  * known context on the element that asks for it if possible. Otherwise the
58  * application should provide one if it can.
59  * 
60  * #GstContext<!-- -->s can be persistent.
61  * A persistent #GstContext is kept in elements when they reach
62  * %GST_STATE_NULL, non-persistent ones will be removed.
63  * Also, a non-persistent context won't override a previous persistent
64  * context set to an element.
65  *
66  * Since: 1.2
67  */
68 public class Context
69 {
70 	/** the main Gtk struct */
71 	protected GstContext* gstContext;
72 	protected bool ownedRef;
73 
74 	/** Get the main Gtk struct */
75 	public GstContext* getContextStruct(bool transferOwnership = false)
76 	{
77 		if (transferOwnership)
78 			ownedRef = false;
79 		return gstContext;
80 	}
81 
82 	/** the main Gtk struct as a void* */
83 	protected void* getStruct()
84 	{
85 		return cast(void*)gstContext;
86 	}
87 
88 	/**
89 	 * Sets our main struct and passes it to the parent class.
90 	 */
91 	public this (GstContext* gstContext, bool ownedRef = false)
92 	{
93 		this.gstContext = gstContext;
94 		this.ownedRef = ownedRef;
95 	}
96 
97 
98 	/** */
99 	public static GType getType()
100 	{
101 		return gst_context_get_type();
102 	}
103 
104 	/**
105 	 * Create a new context.
106 	 *
107 	 * Params:
108 	 *     contextType = Context type
109 	 *     persistent = Persistent context
110 	 *
111 	 * Returns: The new context.
112 	 *
113 	 * Since: 1.2
114 	 *
115 	 * Throws: ConstructionException GTK+ fails to create the object.
116 	 */
117 	public this(string contextType, bool persistent)
118 	{
119 		auto p = gst_context_new(Str.toStringz(contextType), persistent);
120 
121 		if(p is null)
122 		{
123 			throw new ConstructionException("null returned by new");
124 		}
125 
126 		this(cast(GstContext*) p);
127 	}
128 
129 	/**
130 	 * Get the type of @context.
131 	 *
132 	 * Returns: The type of the context.
133 	 *
134 	 * Since: 1.2
135 	 */
136 	public string getContextType()
137 	{
138 		return Str.toString(gst_context_get_context_type(gstContext));
139 	}
140 
141 	/**
142 	 * Access the structure of the context.
143 	 *
144 	 * Returns: The structure of the context. The structure is
145 	 *     still owned by the context, which means that you should not modify it,
146 	 *     free it and that the pointer becomes invalid when you free the context.
147 	 *
148 	 * Since: 1.2
149 	 */
150 	public Structure getStructure()
151 	{
152 		auto p = gst_context_get_structure(gstContext);
153 
154 		if(p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
160 	}
161 
162 	/**
163 	 * Checks if @context has @context_type.
164 	 *
165 	 * Params:
166 	 *     contextType = Context type to check.
167 	 *
168 	 * Returns: %TRUE if @context has @context_type.
169 	 *
170 	 * Since: 1.2
171 	 */
172 	public bool hasContextType(string contextType)
173 	{
174 		return gst_context_has_context_type(gstContext, Str.toStringz(contextType)) != 0;
175 	}
176 
177 	/**
178 	 * Check if @context is persistent.
179 	 *
180 	 * Returns: %TRUE if the context is persistent.
181 	 *
182 	 * Since: 1.2
183 	 */
184 	public bool isPersistent()
185 	{
186 		return gst_context_is_persistent(gstContext) != 0;
187 	}
188 
189 	/**
190 	 * Get a writable version of the structure.
191 	 *
192 	 * Returns: The structure of the context. The structure is still
193 	 *     owned by the context, which means that you should not free it and
194 	 *     that the pointer becomes invalid when you free the context.
195 	 *     This function checks if @context is writable.
196 	 *
197 	 * Since: 1.2
198 	 */
199 	public Structure writableStructure()
200 	{
201 		auto p = gst_context_writable_structure(gstContext);
202 
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 
208 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p, true);
209 	}
210 }