xvimagesink: port to new GLib thread API
[platform/upstream/gstreamer.git] / sys / xvimage / xvimagesink.h
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GST_XVIMAGESINK_H__
21 #define __GST_XVIMAGESINK_H__
22
23 #include <gst/video/gstvideosink.h>
24
25 #ifdef HAVE_XSHM
26 #include <sys/types.h>
27 #include <sys/ipc.h>
28 #include <sys/shm.h>
29 #endif /* HAVE_XSHM */
30
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33
34 #ifdef HAVE_XSHM
35 #include <X11/extensions/XShm.h>
36 #endif /* HAVE_XSHM */
37
38 #include <X11/extensions/Xv.h>
39 #include <X11/extensions/Xvlib.h>
40
41 #include <string.h>
42 #include <math.h>
43 #include <stdlib.h>
44
45 /* Helper functions */
46 #include <gst/video/video.h>
47
48 G_BEGIN_DECLS
49 #define GST_TYPE_XVIMAGESINK \
50   (gst_xvimagesink_get_type())
51 #define GST_XVIMAGESINK(obj) \
52   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XVIMAGESINK, GstXvImageSink))
53 #define GST_XVIMAGESINK_CLASS(klass) \
54   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XVIMAGESINK, GstXvImageSinkClass))
55 #define GST_IS_XVIMAGESINK(obj) \
56   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
57 #define GST_IS_XVIMAGESINK_CLASS(klass) \
58   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
59 typedef struct _GstXContext GstXContext;
60 typedef struct _GstXWindow GstXWindow;
61 typedef struct _GstXvImageFormat GstXvImageFormat;
62
63 typedef struct _GstXvImageSink GstXvImageSink;
64 typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
65
66 #include "xvimagepool.h"
67
68 /*
69  * GstXContext:
70  * @disp: the X11 Display of this context
71  * @screen: the default Screen of Display @disp
72  * @screen_num: the Screen number of @screen
73  * @visual: the default Visual of Screen @screen
74  * @root: the root Window of Display @disp
75  * @white: the value of a white pixel on Screen @screen
76  * @black: the value of a black pixel on Screen @screen
77  * @depth: the color depth of Display @disp
78  * @bpp: the number of bits per pixel on Display @disp
79  * @endianness: the endianness of image bytes on Display @disp
80  * @width: the width in pixels of Display @disp
81  * @height: the height in pixels of Display @disp
82  * @widthmm: the width in millimeters of Display @disp
83  * @heightmm: the height in millimeters of Display @disp
84  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
85  * @heightmm ratio
86  * @use_xshm: used to known wether of not XShm extension is usable or not even
87  * if the Extension is present
88  * @xv_port_id: the XVideo port ID
89  * @im_format: used to store at least a valid format for XShm calls checks
90  * @formats_list: list of supported image formats on @xv_port_id
91  * @channels_list: list of #GstColorBalanceChannels
92  * @caps: the #GstCaps that Display @disp can accept
93  *
94  * Structure used to store various informations collected/calculated for a
95  * Display.
96  */
97 struct _GstXContext
98 {
99   Display *disp;
100
101   Screen *screen;
102   gint screen_num;
103
104   Visual *visual;
105
106   Window root;
107
108   gulong white, black;
109
110   gint depth;
111   gint bpp;
112   gint endianness;
113
114   gint width, height;
115   gint widthmm, heightmm;
116   GValue *par;                  /* calculated pixel aspect ratio */
117
118   gboolean use_xshm;
119
120   XvPortID xv_port_id;
121   guint nb_adaptors;
122   gchar **adaptors;
123   gint im_format;
124
125   GList *formats_list;
126   GList *channels_list;
127
128   GstCaps *caps;
129
130   /* Optimisation storage for buffer_alloc return */
131   GstCaps *last_caps;
132   gint last_format;
133   gint last_width;
134   gint last_height;
135 };
136
137 /*
138  * GstXWindow:
139  * @win: the Window ID of this X11 window
140  * @width: the width in pixels of Window @win
141  * @height: the height in pixels of Window @win
142  * @internal: used to remember if Window @win was created internally or passed
143  * through the #GstXOverlay interface
144  * @gc: the Graphical Context of Window @win
145  *
146  * Structure used to store informations about a Window.
147  */
148 struct _GstXWindow
149 {
150   Window win;
151   gint width, height;
152   gboolean internal;
153   GC gc;
154 };
155
156 /**
157  * GstXvImageFormat:
158  * @format: the image format
159  * @caps: generated #GstCaps for this image format
160  *
161  * Structure storing image format to #GstCaps association.
162  */
163 struct _GstXvImageFormat
164 {
165   gint format;
166   GstVideoFormat vformat;
167   GstCaps *caps;
168 };
169
170
171 /**
172  * GstXvImageSink:
173  * @display_name: the name of the Display we want to render to
174  * @xcontext: our instance's #GstXContext
175  * @xwindow: the #GstXWindow we are rendering to
176  * @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
177  * is used when Expose events are received to redraw the latest video frame
178  * @event_thread: a thread listening for events on @xwindow and handling them
179  * @running: used to inform @event_thread if it should run/shutdown
180  * @fps_n: the framerate fraction numerator
181  * @fps_d: the framerate fraction denominator
182  * @x_lock: used to protect X calls as we are not using the XLib in threaded
183  * mode
184  * @flow_lock: used to protect data flow routines from external calls such as
185  * events from @event_thread or methods from the #GstXOverlay interface
186  * @par: used to override calculated pixel aspect ratio from @xcontext
187  * @pool_lock: used to protect the buffer pool
188  * @image_pool: a list of #GstXvImageBuffer that could be reused at next buffer
189  * allocation call
190  * @synchronous: used to store if XSynchronous should be used or not (for
191  * debugging purpose only)
192  * @keep_aspect: used to remember if reverse negotiation scaling should respect
193  * aspect ratio
194  * @handle_events: used to know if we should handle select XEvents or not
195  * @brightness: used to store the user settings for color balance brightness
196  * @contrast: used to store the user settings for color balance contrast
197  * @hue: used to store the user settings for color balance hue
198  * @saturation: used to store the user settings for color balance saturation
199  * @cb_changed: used to store if the color balance settings where changed
200  * @video_width: the width of incoming video frames in pixels
201  * @video_height: the height of incoming video frames in pixels
202  *
203  * The #GstXvImageSink data structure.
204  */
205 struct _GstXvImageSink
206 {
207   /* Our element stuff */
208   GstVideoSink videosink;
209
210   char *display_name;
211   guint adaptor_no;
212
213   GstXContext *xcontext;
214   GstXWindow *xwindow;
215   GstBuffer *cur_image;
216
217   GThread *event_thread;
218   gboolean running;
219
220   GstVideoInfo info;
221
222   /* Framerate numerator and denominator */
223   gint fps_n;
224   gint fps_d;
225
226   GMutex x_lock;
227   GMutex flow_lock;
228
229   /* object-set pixel aspect ratio */
230   GValue *par;
231
232   /* the buffer pool */
233   GstBufferPool *pool;
234
235   gboolean synchronous;
236   gboolean double_buffer;
237   gboolean keep_aspect;
238   gboolean redraw_border;
239   gboolean handle_events;
240   gboolean handle_expose;
241
242   gint brightness;
243   gint contrast;
244   gint hue;
245   gint saturation;
246   gboolean cb_changed;
247
248   /* size of incoming video, used as the size for XvImage */
249   guint video_width, video_height;
250
251   /* port attributes */
252   gboolean autopaint_colorkey;
253   gint colorkey;
254
255   gboolean draw_borders;
256
257   /* port features */
258   gboolean have_autopaint_colorkey;
259   gboolean have_colorkey;
260   gboolean have_double_buffer;
261
262   /* stream metadata */
263   gchar *media_title;
264
265   /* target video rectangle */
266   GstVideoRectangle render_rect;
267   gboolean have_render_rect;
268 };
269
270 struct _GstXvImageSinkClass
271 {
272   GstVideoSinkClass parent_class;
273 };
274
275 GType gst_xvimagesink_get_type (void);
276
277 G_END_DECLS
278 #endif /* __GST_XVIMAGESINK_H__ */