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()
73 	{
74 		return gstContext;
75 	}
76 
77 	/** the main Gtk struct as a void* */
78 	protected void* getStruct()
79 	{
80 		return cast(void*)gstContext;
81 	}
82 
83 	/**
84 	 * Sets our main struct and passes it to the parent class.
85 	 */
86 	public this (GstContext* gstContext, bool ownedRef = false)
87 	{
88 		this.gstContext = gstContext;
89 		this.ownedRef = ownedRef;
90 	}
91 
92 
93 	/** */
94 	public static GType getType()
95 	{
96 		return gst_context_get_type();
97 	}
98 
99 	/**
100 	 * Create a new context.
101 	 *
102 	 * Params:
103 	 *     contextType = Context type
104 	 *     persistent = Persistent context
105 	 *
106 	 * Return: The new context.
107 	 *
108 	 * Since: 1.2
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this(string contextType, bool persistent)
113 	{
114 		auto p = gst_context_new(Str.toStringz(contextType), persistent);
115 		
116 		if(p is null)
117 		{
118 			throw new ConstructionException("null returned by new");
119 		}
120 		
121 		this(cast(GstContext*) p);
122 	}
123 
124 	/**
125 	 * Get the type of @context.
126 	 *
127 	 * Return: The type of the context.
128 	 *
129 	 * Since: 1.2
130 	 */
131 	public string getContextType()
132 	{
133 		return Str.toString(gst_context_get_context_type(gstContext));
134 	}
135 
136 	/**
137 	 * Access the structure of the context.
138 	 *
139 	 * Return: The structure of the context. The structure is
140 	 *     still owned by the context, which means that you should not modify it,
141 	 *     free it and that the pointer becomes invalid when you free the context.
142 	 *
143 	 * Since: 1.2
144 	 */
145 	public Structure getStructure()
146 	{
147 		auto p = gst_context_get_structure(gstContext);
148 		
149 		if(p is null)
150 		{
151 			return null;
152 		}
153 		
154 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
155 	}
156 
157 	/**
158 	 * Checks if @context has @context_type.
159 	 *
160 	 * Params:
161 	 *     contextType = Context type to check.
162 	 *
163 	 * Return: %TRUE if @context has @context_type.
164 	 *
165 	 * Since: 1.2
166 	 */
167 	public bool hasContextType(string contextType)
168 	{
169 		return gst_context_has_context_type(gstContext, Str.toStringz(contextType)) != 0;
170 	}
171 
172 	/**
173 	 * Check if @context is persistent.
174 	 *
175 	 * Return: %TRUE if the context is persistent.
176 	 *
177 	 * Since: 1.2
178 	 */
179 	public bool isPersistent()
180 	{
181 		return gst_context_is_persistent(gstContext) != 0;
182 	}
183 
184 	/**
185 	 * Get a writable version of the structure.
186 	 *
187 	 * Return: The structure of the context. The structure is still
188 	 *     owned by the context, which means that you should not free it and
189 	 *     that the pointer becomes invalid when you free the context.
190 	 *     This function checks if @context is writable.
191 	 *
192 	 * Since: 1.2
193 	 */
194 	public Structure writableStructure()
195 	{
196 		auto p = gst_context_writable_structure(gstContext);
197 		
198 		if(p is null)
199 		{
200 			return null;
201 		}
202 		
203 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p, true);
204 	}
205 }