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