Revert "[xvimagesink] Fixed ifdef statement in gst_xvimagesink_xwindow_clear()"
[framework/multimedia/gst-plugins-base0.10.git] / sys / xvimage / xvimagesink.h
1 /* GStreamer
2  * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
3  * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * * Modifications by Samsung Electronics Co., Ltd.
21  * 1. Add display related properties
22  * 2. Support samsung extension format to improve performance
23  * 3. Support video texture overlay of OSP layer
24  */
25
26 #ifndef __GST_XVIMAGESINK_H__
27 #define __GST_XVIMAGESINK_H__
28
29 #include <gst/video/gstvideosink.h>
30
31 #ifdef HAVE_XSHM
32 #include <sys/types.h>
33 #include <sys/ipc.h>
34 #include <sys/shm.h>
35 #endif /* HAVE_XSHM */
36
37 #include <X11/Xlib.h>
38 #include <X11/Xutil.h>
39
40 #ifdef HAVE_XSHM
41 #include <X11/extensions/XShm.h>
42 #endif /* HAVE_XSHM */
43
44 #include <X11/extensions/Xv.h>
45 #include <X11/extensions/Xvlib.h>
46 #ifdef GST_EXT_XV_ENHANCEMENT
47 #include <X11/Xatom.h>
48 #include <stdio.h>
49 #endif
50
51 #include <string.h>
52 #include <math.h>
53 #include <stdlib.h>
54
55 G_BEGIN_DECLS
56
57 #define GST_TYPE_XVIMAGESINK \
58   (gst_xvimagesink_get_type())
59 #define GST_XVIMAGESINK(obj) \
60   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XVIMAGESINK, GstXvImageSink))
61 #define GST_XVIMAGESINK_CLASS(klass) \
62   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XVIMAGESINK, GstXvImageSinkClass))
63 #define GST_IS_XVIMAGESINK(obj) \
64   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
65 #define GST_IS_XVIMAGESINK_CLASS(klass) \
66   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
67
68 #ifdef GST_EXT_XV_ENHANCEMENT
69 #define XV_SCREEN_SIZE_WIDTH 4096
70 #define XV_SCREEN_SIZE_HEIGHT 4096
71
72 #define MAX_PIXMAP_NUM 10
73 typedef uint (*get_pixmap_callback)(void *user_data);
74 typedef struct _GstXPixmap GstXPixmap;
75 #endif /* GST_EXT_XV_ENHANCEMENT */
76
77 typedef struct _GstXContext GstXContext;
78 typedef struct _GstXWindow GstXWindow;
79 typedef struct _GstXvImageFormat GstXvImageFormat;
80 typedef struct _GstXvImageBuffer GstXvImageBuffer;
81 typedef struct _GstXvImageBufferClass GstXvImageBufferClass;
82
83 typedef struct _GstXvImageSink GstXvImageSink;
84 typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
85
86 /*
87  * GstXContext:
88  * @disp: the X11 Display of this context
89  * @screen: the default Screen of Display @disp
90  * @screen_num: the Screen number of @screen
91  * @visual: the default Visual of Screen @screen
92  * @root: the root Window of Display @disp
93  * @white: the value of a white pixel on Screen @screen
94  * @black: the value of a black pixel on Screen @screen
95  * @depth: the color depth of Display @disp
96  * @bpp: the number of bits per pixel on Display @disp
97  * @endianness: the endianness of image bytes on Display @disp
98  * @width: the width in pixels of Display @disp
99  * @height: the height in pixels of Display @disp
100  * @widthmm: the width in millimeters of Display @disp
101  * @heightmm: the height in millimeters of Display @disp
102  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
103  * @heightmm ratio
104  * @use_xshm: used to known wether of not XShm extension is usable or not even
105  * if the Extension is present
106  * @xv_port_id: the XVideo port ID
107  * @im_format: used to store at least a valid format for XShm calls checks
108  * @formats_list: list of supported image formats on @xv_port_id
109  * @channels_list: list of #GstColorBalanceChannels
110  * @caps: the #GstCaps that Display @disp can accept
111  *
112  * Structure used to store various informations collected/calculated for a
113  * Display.
114  */
115 struct _GstXContext {
116   Display *disp;
117
118   Screen *screen;
119   gint screen_num;
120
121   Visual *visual;
122
123   Window root;
124
125   gulong white, black;
126
127   gint depth;
128   gint bpp;
129   gint endianness;
130
131   gint width, height;
132   gint widthmm, heightmm;
133   GValue *par;                  /* calculated pixel aspect ratio */
134
135   gboolean use_xshm;
136
137   XvPortID xv_port_id;
138   guint nb_adaptors;
139   gchar ** adaptors;
140   gint im_format;
141
142   GList *formats_list;
143   GList *channels_list;
144
145   GstCaps *caps;
146
147   /* Optimisation storage for buffer_alloc return */
148   GstCaps *last_caps;
149   gint last_format;
150   gint last_width;
151   gint last_height;
152 };
153
154 /*
155  * GstXWindow:
156  * @win: the Window ID of this X11 window
157  * @width: the width in pixels of Window @win
158  * @height: the height in pixels of Window @win
159  * @internal: used to remember if Window @win was created internally or passed
160  * through the #GstXOverlay interface
161  * @gc: the Graphical Context of Window @win
162  *
163  * Structure used to store informations about a Window.
164  */
165 struct _GstXWindow {
166   Window win;
167 #ifdef GST_EXT_XV_ENHANCEMENT
168   gint x, y;
169 #endif
170   gint width, height;
171   gboolean internal;
172   GC gc;
173 };
174
175 #ifdef GST_EXT_XV_ENHANCEMENT
176 struct _GstXPixmap {
177         Window pixmap;
178         gint x, y;
179         gint width, height;
180         GC gc;
181 };
182 #endif
183
184 /**
185  * GstXvImageFormat:
186  * @format: the image format
187  * @caps: generated #GstCaps for this image format
188  *
189  * Structure storing image format to #GstCaps association.
190  */
191 struct _GstXvImageFormat {
192   gint format;
193   GstCaps *caps;
194 };
195
196 /**
197  * GstXImageBuffer:
198  * @xvimagesink: a reference to our #GstXvImageSink
199  * @xvimage: the XvImage of this buffer
200  * @width: the width in pixels of XvImage @xvimage
201  * @height: the height in pixels of XvImage @xvimage
202  * @im_format: the image format of XvImage @xvimage
203  * @size: the size in bytes of XvImage @xvimage
204  *
205  * Subclass of #GstBuffer containing additional information about an XvImage.
206  */
207 struct _GstXvImageBuffer {
208   GstBuffer   buffer;
209
210   /* Reference to the xvimagesink we belong to */
211   GstXvImageSink *xvimagesink;
212
213   XvImage *xvimage;
214
215 #ifdef HAVE_XSHM
216   XShmSegmentInfo SHMInfo;
217 #endif /* HAVE_XSHM */
218
219   gint width, height, im_format;
220   size_t size;
221 };
222
223 #ifdef GST_EXT_XV_ENHANCEMENT
224 #define MAX_PLANE_NUM          4
225 #endif /* GST_EXT_XV_ENHANCEMENT */
226
227 /**
228  * GstXvImageSink:
229  * @display_name: the name of the Display we want to render to
230  * @xcontext: our instance's #GstXContext
231  * @xwindow: the #GstXWindow we are rendering to
232  * @xvimage: internal #GstXvImage used to store incoming buffers and render when
233  * not using the buffer_alloc optimization mechanism
234  * @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
235  * is used when Expose events are received to redraw the latest video frame
236  * @event_thread: a thread listening for events on @xwindow and handling them
237  * @running: used to inform @event_thread if it should run/shutdown
238  * @fps_n: the framerate fraction numerator
239  * @fps_d: the framerate fraction denominator
240  * @x_lock: used to protect X calls as we are not using the XLib in threaded
241  * mode
242  * @flow_lock: used to protect data flow routines from external calls such as
243  * events from @event_thread or methods from the #GstXOverlay interface
244  * @par: used to override calculated pixel aspect ratio from @xcontext
245  * @pool_lock: used to protect the buffer pool
246  * @image_pool: a list of #GstXvImageBuffer that could be reused at next buffer
247  * allocation call
248  * @synchronous: used to store if XSynchronous should be used or not (for
249  * debugging purpose only)
250  * @keep_aspect: used to remember if reverse negotiation scaling should respect
251  * aspect ratio
252  * @handle_events: used to know if we should handle select XEvents or not
253  * @brightness: used to store the user settings for color balance brightness
254  * @contrast: used to store the user settings for color balance contrast
255  * @hue: used to store the user settings for color balance hue
256  * @saturation: used to store the user settings for color balance saturation
257  * @cb_changed: used to store if the color balance settings where changed
258  * @video_width: the width of incoming video frames in pixels
259  * @video_height: the height of incoming video frames in pixels
260  *
261  * The #GstXvImageSink data structure.
262  */
263 struct _GstXvImageSink {
264   /* Our element stuff */
265   GstVideoSink videosink;
266
267   char *display_name;
268   guint adaptor_no;
269
270   GstXContext *xcontext;
271   GstXWindow *xwindow;
272   GstXvImageBuffer *xvimage;
273   GstXvImageBuffer *cur_image;
274
275   GThread *event_thread;
276   gboolean running;
277
278   gint fps_n;
279   gint fps_d;
280
281   GMutex *x_lock;
282   GMutex *flow_lock;
283
284   /* object-set pixel aspect ratio */
285   GValue *par;
286
287   GMutex *pool_lock;
288   gboolean pool_invalid;
289   GSList *image_pool;
290
291   gboolean synchronous;
292   gboolean double_buffer;
293   gboolean keep_aspect;
294   gboolean redraw_border;
295   gboolean handle_events;
296   gboolean handle_expose;
297
298   gint brightness;
299   gint contrast;
300   gint hue;
301   gint saturation;
302   gboolean cb_changed;
303
304   /* size of incoming video, used as the size for XvImage */
305   guint video_width, video_height;
306
307   /* display sizes, used for clipping the image */
308   gint disp_x, disp_y;
309   gint disp_width, disp_height;
310
311   /* port attributes */
312   gboolean autopaint_colorkey;
313   gint colorkey;
314   
315   gboolean draw_borders;
316   
317   /* port features */
318   gboolean have_autopaint_colorkey;
319   gboolean have_colorkey;
320   gboolean have_double_buffer;
321   
322   /* stream metadata */
323   gchar *media_title;
324
325   /* target video rectangle */
326   GstVideoRectangle render_rect;
327   gboolean have_render_rect;
328
329 #ifdef GST_EXT_XV_ENHANCEMENT
330   /* display mode */
331   gboolean xid_updated;
332   guint display_mode;
333   guint display_geometry_method;
334   guint flip;
335   guint rotate_angle;
336   gboolean rotate_changed;
337   gboolean visible;
338   guint zoom;
339   guint rotation;
340   guint rotate_cnt;
341   GstVideoRectangle dst_roi;
342   XImage* xim_transparenter;
343   guint scr_w, scr_h;
344   gboolean stop_video;
345   gboolean is_hided;
346   /* needed if fourcc is one if S series */
347   guint aligned_width;
348   guint aligned_height;
349   gint drm_fd;
350   unsigned int gem_handle[MAX_PLANE_NUM];
351   /* for using multiple pixmaps */
352   GstXPixmap *xpixmap[MAX_PIXMAP_NUM];
353   gint current_pixmap_idx;
354   get_pixmap_callback get_pixmap_cb;
355   void* get_pixmap_cb_user_data;
356 #endif /* GST_EXT_XV_ENHANCEMENT */
357 };
358
359 #ifdef GST_EXT_XV_ENHANCEMENT
360 /* max plane count *********************************************************/
361 #define MPLANE_IMGB_MAX_COUNT         (4)
362
363 /* image buffer definition ***************************************************
364
365     +------------------------------------------+ ---
366     |                                          |  ^
367     |     uaddr[], index[]                     |  |
368     |     +---------------------------+ ---    |  |
369     |     |                           |  ^     |  |
370     |     |<-------- width[] -------->|  |     |  |
371     |     |                           |  |     |  |
372     |     |                           |        |
373     |     |                           |height[]|elevation[]
374     |     |                           |        |
375     |     |                           |  |     |  |
376     |     |                           |  |     |  |
377     |     |                           |  v     |  |
378     |     +---------------------------+ ---    |  |
379     |                                          |  v
380     +------------------------------------------+ ---
381
382     |<----------------- stride[] ------------------>|
383 */
384 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
385 struct _GstMultiPlaneImageBuffer
386 {
387     GstBuffer buffer;
388
389     /* width of each image plane */
390     gint      width[MPLANE_IMGB_MAX_COUNT];
391     /* height of each image plane */
392     gint      height[MPLANE_IMGB_MAX_COUNT];
393     /* stride of each image plane */
394     gint      stride[MPLANE_IMGB_MAX_COUNT];
395     /* elevation of each image plane */
396     gint      elevation[MPLANE_IMGB_MAX_COUNT];
397     /* user space address of each image plane */
398     gpointer uaddr[MPLANE_IMGB_MAX_COUNT];
399     /* Index of real address of each image plane, if needs */
400     gpointer index[MPLANE_IMGB_MAX_COUNT];
401     /* left postion, if needs */
402     gint      x;
403     /* top position, if needs */
404     gint      y;
405     /* to align memory */
406     gint      __dummy2;
407     /* arbitrary data */
408     gint      data[16];
409 };
410 #endif /* GST_EXT_XV_ENHANCEMENT */
411
412 struct _GstXvImageSinkClass {
413   GstVideoSinkClass parent_class;
414 };
415
416 GType gst_xvimagesink_get_type(void);
417
418 G_END_DECLS
419
420 #endif /* __GST_XVIMAGESINK_H__ */