1 /* GStreamer
2 * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef __GST_XVCONTEXT_H__
21 #define __GST_XVCONTEXT_H__
22
23 #ifdef HAVE_XSHM
24 #include <sys/types.h>
25 #include <sys/ipc.h>
26 #include <sys/shm.h>
27 #endif /* HAVE_XSHM */
28
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31
32 #ifdef HAVE_XSHM
33 #include <X11/extensions/XShm.h>
34 #endif /* HAVE_XSHM */
35
36 #include <X11/extensions/Xv.h>
37 #include <X11/extensions/Xvlib.h>
38
39 #include <string.h>
40 #include <math.h>
41 #include <stdlib.h>
42
43 #include <gst/video/video.h>
44
45 G_BEGIN_DECLS
46
47 typedef struct _GstXvContextConfig GstXvContextConfig;
48 typedef struct _GstXvImageFormat GstXvImageFormat;
49 typedef struct _GstXvContext GstXvContext;
50
51 /**
52 * GstXvContextConfig:
53 *
54 * current configuration of the context
55 */
56 struct _GstXvContextConfig
57 {
58 gchar *display_name;
59 guint adaptor_nr;
60
61 /* port attributes */
62 gboolean autopaint_colorkey;
63 gint colorkey;
64
65 gboolean double_buffer;
66
67 gint brightness;
68 gint contrast;
69 gint hue;
70 gint saturation;
71 gboolean cb_changed;
72 };
73
74 /**
75 * GstXvImageFormat:
76 * @format: the image format
77 * @caps: generated #GstCaps for this image format
78 *
79 * Structure storing image format to #GstCaps association.
80 */
81 struct _GstXvImageFormat
82 {
83 gint format;
84 GstVideoFormat vformat;
85 GstCaps *caps;
86 };
87
88 #define GST_TYPE_XVCONTEXT (gst_xvcontext_get_type())
89 #define GST_IS_XVCONTEXT(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_XVCONTEXT))
90 #define GST_XVCONTEXT_CAST(obj) ((GstXvContext *)obj)
91 #define GST_XVCONTEXT(obj) (GST_XVCONTEXT_CAST(obj))
92
93 /*
94 * GstXvContext:
95 * @disp: the X11 Display of this context
96 * @screen: the default Screen of Display @disp
97 * @screen_num: the Screen number of @screen
98 * @visual: the default Visual of Screen @screen
99 * @root: the root Window of Display @disp
100 * @white: the value of a white pixel on Screen @screen
101 * @black: the value of a black pixel on Screen @screen
102 * @depth: the color depth of Display @disp
103 * @bpp: the number of bits per pixel on Display @disp
104 * @endianness: the endianness of image bytes on Display @disp
105 * @width: the width in pixels of Display @disp
106 * @height: the height in pixels of Display @disp
107 * @widthmm: the width in millimeters of Display @disp
108 * @heightmm: the height in millimeters of Display @disp
109 * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
110 * @heightmm ratio
111 * @use_xshm: used to known wether of not XShm extension is usable or not even
112 * if the Extension is present
113 * @xv_port_id: the XVideo port ID
114 * @im_format: used to store at least a valid format for XShm calls checks
115 * @formats_list: list of supported image formats on @xv_port_id
116 * @channels_list: list of #GstColorBalanceChannels
117 * @caps: the #GstCaps that Display @disp can accept
118 *
119 * Structure used to store various informations collected/calculated for a
120 * Display.
121 */
122 struct _GstXvContext
123 {
124 GstMiniObject parent;
125
126 GMutex lock;
127
128 Display *disp;
129
130 Screen *screen;
131 gint screen_num;
132
133 Visual *visual;
134
135 Window root;
136
137 gulong white, black;
138
139 gint depth;
140 gint bpp;
141 gint endianness;
142
143 gint width, height;
144 gint widthmm, heightmm;
145 GValue *par; /* calculated pixel aspect ratio */
146
147 gboolean use_xshm;
148
149 XvPortID xv_port_id;
150 guint nb_adaptors;
151 gchar **adaptors;
152 guint adaptor_nr;
153 gint im_format;
154
155 /* port features */
156 gboolean have_autopaint_colorkey;
157 gboolean have_colorkey;
158 gboolean have_double_buffer;
159 gboolean have_iturbt709;
160
161 GList *formats_list;
162
163 GList *channels_list;
164
165 GstCaps *caps;
166
167 /* Optimisation storage for buffer_alloc return */
168 GstCaps *last_caps;
169 gint last_format;
170 gint last_width;
171 gint last_height;
172 };
173
174 GType gst_xvcontext_get_type (void);
175
176 void gst_xvcontext_config_clear (GstXvContextConfig *config);
177
178 GstXvContext * gst_xvcontext_new (GstXvContextConfig *config, GError **error);
179
180 /* refcounting */
181 static inline GstXvContext *
gst_xvcontext_ref(GstXvContext * xvcontext)182 gst_xvcontext_ref (GstXvContext * xvcontext)
183 {
184 return GST_XVCONTEXT_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
185 xvcontext)));
186 }
187
188 static inline void
gst_xvcontext_unref(GstXvContext * xvcontext)189 gst_xvcontext_unref (GstXvContext * xvcontext)
190 {
191 gst_mini_object_unref (GST_MINI_OBJECT_CAST (xvcontext));
192 }
193
194 gint gst_xvcontext_get_format_from_info (GstXvContext * xvcontext,
195 GstVideoInfo * info);
196
197
198 void gst_xvcontext_set_synchronous (GstXvContext * xvcontext,
199 gboolean synchronous);
200 void gst_xvcontext_update_colorbalance (GstXvContext * xvcontext,
201 GstXvContextConfig * config);
202 void gst_xvcontext_set_colorimetry (GstXvContext * xvcontext,
203 GstVideoColorimetry *colorimetry);
204
205
206 typedef struct _GstXWindow GstXWindow;
207
208 /*
209 * GstXWindow:
210 * @win: the Window ID of this X11 window
211 * @width: the width in pixels of Window @win
212 * @height: the height in pixels of Window @win
213 * @internal: used to remember if Window @win was created internally or passed
214 * through the #GstVideoOverlay interface
215 * @gc: the Graphical Context of Window @win
216 *
217 * Structure used to store informations about a Window.
218 */
219 struct _GstXWindow
220 {
221 GstXvContext *context;
222
223 Window win;
224 gint width, height;
225 gboolean have_render_rect;
226 GstVideoRectangle render_rect;
227 gboolean internal;
228 GC gc;
229 };
230
231 G_END_DECLS
232
233 GstXWindow * gst_xvcontext_create_xwindow (GstXvContext * context,
234 gint width, gint height);
235 GstXWindow * gst_xvcontext_create_xwindow_from_xid (GstXvContext * context, XID xid);
236
237 void gst_xwindow_destroy (GstXWindow * window);
238
239 void gst_xwindow_set_event_handling (GstXWindow * window, gboolean handle_events);
240 void gst_xwindow_set_title (GstXWindow * window, const gchar * title);
241
242 void gst_xwindow_update_geometry (GstXWindow * window);
243 void gst_xwindow_clear (GstXWindow * window);
244
245 void gst_xwindow_set_render_rectangle (GstXWindow * window,
246 gint x, gint y, gint width, gint height);
247
248
249
250 #endif /* __GST_XVCONTEXT_H__ */
251