• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 whether of not XShm extension is usable or not even
112  * if the Extension is present
113  * @use_xkb: used to known wether of not Xkb extension is usable or not even
114  * if the Extension is present
115  * @xv_port_id: the XVideo port ID
116  * @im_format: used to store at least a valid format for XShm calls checks
117  * @formats_list: list of supported image formats on @xv_port_id
118  * @channels_list: list of #GstColorBalanceChannels
119  * @caps: the #GstCaps that Display @disp can accept
120  *
121  * Structure used to store various information collected/calculated for a
122  * Display.
123  */
124 struct _GstXvContext
125 {
126   GstMiniObject parent;
127 
128   GMutex lock;
129 
130   Display *disp;
131 
132   Screen *screen;
133   gint screen_num;
134 
135   Visual *visual;
136 
137   Window root;
138 
139   gulong white, black;
140 
141   gint depth;
142   gint bpp;
143   gint endianness;
144 
145   gint width, height;
146   gint widthmm, heightmm;
147   GValue *par;                  /* calculated pixel aspect ratio */
148 
149   gboolean use_xshm;
150   gboolean use_xkb;
151 
152   XvPortID xv_port_id;
153   guint nb_adaptors;
154   gchar **adaptors;
155   guint adaptor_nr;
156   gint im_format;
157 
158   /* port features */
159   gboolean have_autopaint_colorkey;
160   gboolean have_colorkey;
161   gboolean have_double_buffer;
162   gboolean have_iturbt709;
163   gboolean have_xvcolorspace;
164 
165   GList *formats_list;
166 
167   GList *channels_list;
168 
169   GstCaps *caps;
170 
171   /* Optimisation storage for buffer_alloc return */
172   GstCaps *last_caps;
173   gint last_format;
174   gint last_width;
175   gint last_height;
176 };
177 
178 GType gst_xvcontext_get_type (void);
179 
180 void            gst_xvcontext_config_clear (GstXvContextConfig *config);
181 
182 GstXvContext *  gst_xvcontext_new          (GstXvContextConfig *config, GError **error);
183 
184 /* refcounting */
185 static inline GstXvContext *
gst_xvcontext_ref(GstXvContext * xvcontext)186 gst_xvcontext_ref (GstXvContext * xvcontext)
187 {
188   return GST_XVCONTEXT_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
189       xvcontext)));
190 }
191 
192 static inline void
gst_xvcontext_unref(GstXvContext * xvcontext)193 gst_xvcontext_unref (GstXvContext * xvcontext)
194 {
195   gst_mini_object_unref (GST_MINI_OBJECT_CAST (xvcontext));
196 }
197 
198 gint            gst_xvcontext_get_format_from_info      (GstXvContext * xvcontext,
199                                                          const GstVideoInfo * info);
200 
201 
202 void            gst_xvcontext_set_synchronous           (GstXvContext * xvcontext,
203                                                          gboolean synchronous);
204 void            gst_xvcontext_update_colorbalance       (GstXvContext * xvcontext,
205                                                          GstXvContextConfig * config);
206 void            gst_xvcontext_set_colorimetry           (GstXvContext * xvcontext,
207                                                          GstVideoColorimetry *colorimetry);
208 
209 
210 typedef struct _GstXWindow GstXWindow;
211 
212 /*
213  * GstXWindow:
214  * @win: the Window ID of this X11 window
215  * @width: the width in pixels of Window @win
216  * @height: the height in pixels of Window @win
217  * @internal: used to remember if Window @win was created internally or passed
218  * through the #GstVideoOverlay interface
219  * @gc: the Graphical Context of Window @win
220  *
221  * Structure used to store information about a Window.
222  */
223 struct _GstXWindow
224 {
225   GstXvContext *context;
226 
227   Window win;
228   gint width, height;
229   gboolean have_render_rect;
230   GstVideoRectangle render_rect;
231   gboolean internal;
232   GC gc;
233 };
234 
235 G_END_DECLS
236 
237 GstXWindow *   gst_xvcontext_create_xwindow     (GstXvContext * context,
238                                                  gint width, gint height);
239 GstXWindow *   gst_xvcontext_create_xwindow_from_xid (GstXvContext * context, XID xid);
240 
241 void           gst_xwindow_destroy              (GstXWindow * window);
242 
243 void           gst_xwindow_set_event_handling   (GstXWindow * window, gboolean handle_events);
244 void           gst_xwindow_set_title            (GstXWindow * window, const gchar * title);
245 
246 void           gst_xwindow_update_geometry      (GstXWindow * window);
247 void           gst_xwindow_clear                (GstXWindow * window);
248 
249 void           gst_xwindow_set_render_rectangle (GstXWindow * window,
250                                                  gint x, gint y, gint width, gint height);
251 
252 
253 
254 #endif /* __GST_XVCONTEXT_H__ */
255