tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.git] / sys / ximage / ximagesink.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_XIMAGESINK_H__
21 #define __GST_XIMAGESINK_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 <string.h>
39 #include <math.h>
40
41 G_BEGIN_DECLS
42 #define GST_TYPE_XIMAGESINK \
43   (gst_ximagesink_get_type())
44 #define GST_XIMAGESINK(obj) \
45   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XIMAGESINK, GstXImageSink))
46 #define GST_XIMAGESINK_CLASS(klass) \
47   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XIMAGESINK, GstXImageSinkClass))
48 #define GST_IS_XIMAGESINK(obj) \
49   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XIMAGESINK))
50 #define GST_IS_XIMAGESINK_CLASS(klass) \
51   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XIMAGESINK))
52 typedef struct _GstXContext GstXContext;
53 typedef struct _GstXWindow GstXWindow;
54
55 typedef struct _GstXImageBuffer GstXImageBuffer;
56 typedef struct _GstXImageBufferClass GstXImageBufferClass;
57
58 typedef struct _GstXImageSink GstXImageSink;
59 typedef struct _GstXImageSinkClass GstXImageSinkClass;
60
61 /*
62  * GstXContext:
63  * @disp: the X11 Display of this context
64  * @screen: the default Screen of Display @disp
65  * @screen_num: the Screen number of @screen
66  * @visual: the default Visual of Screen @screen
67  * @root: the root Window of Display @disp
68  * @white: the value of a white pixel on Screen @screen
69  * @black: the value of a black pixel on Screen @screen
70  * @depth: the color depth of Display @disp
71  * @bpp: the number of bits per pixel on Display @disp
72  * @endianness: the endianness of image bytes on Display @disp
73  * @width: the width in pixels of Display @disp
74  * @height: the height in pixels of Display @disp
75  * @widthmm: the width in millimeters of Display @disp
76  * @heightmm: the height in millimeters of Display @disp
77  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height, 
78  * @heightmm ratio
79  * @use_xshm: used to known wether of not XShm extension is usable or not even
80  * if the Extension is present
81  * @caps: the #GstCaps that Display @disp can accept
82  *
83  * Structure used to store various informations collected/calculated for a
84  * Display.
85  */
86 struct _GstXContext
87 {
88   Display *disp;
89
90   Screen *screen;
91   gint screen_num;
92
93   Visual *visual;
94
95   Window root;
96
97   gulong white, black;
98
99   gint depth;
100   gint bpp;
101   gint endianness;
102
103   gint width, height;
104   gint widthmm, heightmm;
105   GValue *par;                  /* calculated pixel aspect ratio */
106
107   gboolean use_xshm;
108
109   GstCaps *caps;
110   GstCaps *last_caps;
111 };
112
113 /*
114  * GstXWindow:
115  * @win: the Window ID of this X11 window
116  * @width: the width in pixels of Window @win
117  * @height: the height in pixels of Window @win
118  * @internal: used to remember if Window @win was created internally or passed
119  * through the #GstXOverlay interface
120  * @gc: the Graphical Context of Window @win
121  *
122  * Structure used to store informations about a Window.
123  */
124 struct _GstXWindow
125 {
126   Window win;
127   gint width, height;
128   gboolean internal;
129   GC gc;
130 };
131
132 /**
133  * GstXImageBuffer:
134  * @ximagesink: a reference to our #GstXImageSink
135  * @ximage: the XImage of this buffer
136  * @width: the width in pixels of XImage @ximage
137  * @height: the height in pixels of XImage @ximage
138  * @size: the size in bytes of XImage @ximage
139  *
140  * Subclass of #GstBuffer containing additional information about an XImage.
141  */
142 struct _GstXImageBuffer
143 {
144   GstBuffer buffer;
145
146   /* Reference to the ximagesink we belong to */
147   GstXImageSink *ximagesink;
148
149   XImage *ximage;
150
151 #ifdef HAVE_XSHM
152   XShmSegmentInfo SHMInfo;
153 #endif                          /* HAVE_XSHM */
154
155   gint width, height;
156   size_t size;
157 };
158
159 /**
160  * GstXImageSink:
161  * @display_name: the name of the Display we want to render to
162  * @xcontext: our instance's #GstXContext
163  * @xwindow: the #GstXWindow we are rendering to
164  * @ximage: internal #GstXImage used to store incoming buffers and render when
165  * not using the buffer_alloc optimization mechanism
166  * @cur_image: a reference to the last #GstXImage that was put to @xwindow. It
167  * is used when Expose events are received to redraw the latest video frame
168  * @event_thread: a thread listening for events on @xwindow and handling them
169  * @running: used to inform @event_thread if it should run/shutdown
170  * @fps_n: the framerate fraction numerator
171  * @fps_d: the framerate fraction denominator
172  * @x_lock: used to protect X calls as we are not using the XLib in threaded
173  * mode
174  * @flow_lock: used to protect data flow routines from external calls such as
175  * events from @event_thread or methods from the #GstXOverlay interface
176  * @par: used to override calculated pixel aspect ratio from @xcontext
177  * @pool_lock: used to protect the buffer pool
178  * @buffer_pool: a list of #GstXImageBuffer that could be reused at next buffer
179  * allocation call
180  * @synchronous: used to store if XSynchronous should be used or not (for 
181  * debugging purpose only)
182  * @keep_aspect: used to remember if reverse negotiation scaling should respect
183  * aspect ratio
184  * @handle_events: used to know if we should handle select XEvents or not
185  *
186  * The #GstXImageSink data structure.
187  */
188 struct _GstXImageSink
189 {
190   /* Our element stuff */
191   GstVideoSink videosink;
192
193   char *display_name;
194
195   GstXContext *xcontext;
196   GstXWindow *xwindow;
197   GstXImageBuffer *ximage;
198   GstXImageBuffer *cur_image;
199
200   GThread *event_thread;
201   gboolean running;
202
203   /* Framerate numerator and denominator */
204   gint fps_n;
205   gint fps_d;
206
207   GMutex *x_lock;
208   GMutex *flow_lock;
209
210   /* object-set pixel aspect ratio */
211   GValue *par;
212
213   GMutex *pool_lock;
214   GSList *buffer_pool;
215
216   gboolean synchronous;
217   gboolean keep_aspect;
218   gboolean handle_events;
219   gboolean handle_expose;
220   gboolean draw_border;
221
222   /* stream metadata */
223   gchar *media_title;
224 };
225
226 struct _GstXImageSinkClass
227 {
228   GstVideoSinkClass parent_class;
229 };
230
231 GType gst_ximagesink_get_type (void);
232
233 G_END_DECLS
234 #endif /* __GST_XIMAGESINK_H__ */