2 * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
3 * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd.
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.
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.
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.
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
26 #ifndef __GST_XVIMAGESINK_H__
27 #define __GST_XVIMAGESINK_H__
29 #include <gst/video/gstvideosink.h>
32 #include <sys/types.h>
35 #endif /* HAVE_XSHM */
38 #include <X11/Xutil.h>
41 #include <X11/extensions/XShm.h>
42 #endif /* HAVE_XSHM */
44 #include <X11/extensions/Xv.h>
45 #include <X11/extensions/Xvlib.h>
46 #ifdef GST_EXT_XV_ENHANCEMENT
47 #include <X11/Xatom.h>
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))
68 #ifdef GST_EXT_XV_ENHANCEMENT
69 #define XV_SCREEN_SIZE_WIDTH 4096
70 #define XV_SCREEN_SIZE_HEIGHT 4096
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 */
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;
83 typedef struct _GstXvImageSink GstXvImageSink;
84 typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
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,
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
112 * Structure used to store various informations collected/calculated for a
115 struct _GstXContext {
132 gint widthmm, heightmm;
133 GValue *par; /* calculated pixel aspect ratio */
143 GList *channels_list;
147 /* Optimisation storage for buffer_alloc return */
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
163 * Structure used to store informations about a Window.
167 #ifdef GST_EXT_XV_ENHANCEMENT
175 #ifdef GST_EXT_XV_ENHANCEMENT
186 * @format: the image format
187 * @caps: generated #GstCaps for this image format
189 * Structure storing image format to #GstCaps association.
191 struct _GstXvImageFormat {
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
205 * Subclass of #GstBuffer containing additional information about an XvImage.
207 struct _GstXvImageBuffer {
210 /* Reference to the xvimagesink we belong to */
211 GstXvImageSink *xvimagesink;
216 XShmSegmentInfo SHMInfo;
217 #endif /* HAVE_XSHM */
219 gint width, height, im_format;
223 #ifdef GST_EXT_XV_ENHANCEMENT
224 #define MAX_PLANE_NUM 4
225 #endif /* GST_EXT_XV_ENHANCEMENT */
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
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
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
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
261 * The #GstXvImageSink data structure.
263 struct _GstXvImageSink {
264 /* Our element stuff */
265 GstVideoSink videosink;
270 GstXContext *xcontext;
272 GstXvImageBuffer *xvimage;
273 GstXvImageBuffer *cur_image;
275 GThread *event_thread;
284 /* object-set pixel aspect ratio */
288 gboolean pool_invalid;
291 gboolean synchronous;
292 gboolean double_buffer;
293 gboolean keep_aspect;
294 gboolean redraw_border;
295 gboolean handle_events;
296 gboolean handle_expose;
304 /* size of incoming video, used as the size for XvImage */
305 guint video_width, video_height;
307 /* display sizes, used for clipping the image */
309 gint disp_width, disp_height;
311 /* port attributes */
312 gboolean autopaint_colorkey;
315 gboolean draw_borders;
318 gboolean have_autopaint_colorkey;
319 gboolean have_colorkey;
320 gboolean have_double_buffer;
322 /* stream metadata */
325 /* target video rectangle */
326 GstVideoRectangle render_rect;
327 gboolean have_render_rect;
329 #ifdef GST_EXT_XV_ENHANCEMENT
331 gboolean xid_updated;
333 guint display_geometry_method;
336 gboolean rotate_changed;
341 GstVideoRectangle dst_roi;
342 XImage* xim_transparenter;
346 /* needed if fourcc is one if S series */
348 guint aligned_height;
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 */
359 #ifdef GST_EXT_XV_ENHANCEMENT
360 /* max plane count *********************************************************/
361 #define MPLANE_IMGB_MAX_COUNT (4)
363 /* image buffer definition ***************************************************
365 +------------------------------------------+ ---
367 | uaddr[], index[] | |
368 | +---------------------------+ --- | |
370 | |<-------- width[] -------->| | | |
373 | | |height[]|elevation[]
378 | +---------------------------+ --- | |
380 +------------------------------------------+ ---
382 |<----------------- stride[] ------------------>|
384 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
385 struct _GstMultiPlaneImageBuffer
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 */
403 /* top position, if needs */
405 /* to align memory */
410 #endif /* GST_EXT_XV_ENHANCEMENT */
412 struct _GstXvImageSinkClass {
413 GstVideoSinkClass parent_class;
416 GType gst_xvimagesink_get_type(void);
420 #endif /* __GST_XVIMAGESINK_H__ */