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