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