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>
58 #define GST_TYPE_XVIMAGESINK \
59 (gst_xvimagesink_get_type())
60 #define GST_XVIMAGESINK(obj) \
61 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XVIMAGESINK, GstXvImageSink))
62 #define GST_XVIMAGESINK_CLASS(klass) \
63 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XVIMAGESINK, GstXvImageSinkClass))
64 #define GST_IS_XVIMAGESINK(obj) \
65 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
66 #define GST_IS_XVIMAGESINK_CLASS(klass) \
67 (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
69 #ifdef GST_EXT_XV_ENHANCEMENT
70 #define XV_SCREEN_SIZE_WIDTH 4096
71 #define XV_SCREEN_SIZE_HEIGHT 4096
72 #define DISPLAYING_BUFFERS_MAX_NUM 10
74 #define MAX_PIXMAP_NUM 10
75 typedef uint (*get_pixmap_callback)(void *user_data);
76 typedef struct _GstXPixmap GstXPixmap;
77 typedef struct _GstXvImageDisplayingBuffer GstXvImageDisplayingBuffer;
78 typedef struct _GstXvImageFlushBuffer GstXvImageFlushBuffer;
79 #endif /* GST_EXT_XV_ENHANCEMENT */
81 typedef struct _GstXContext GstXContext;
82 typedef struct _GstXWindow GstXWindow;
83 typedef struct _GstXvImageFormat GstXvImageFormat;
84 typedef struct _GstXvImageBuffer GstXvImageBuffer;
85 typedef struct _GstXvImageBufferClass GstXvImageBufferClass;
87 typedef struct _GstXvImageSink GstXvImageSink;
88 typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
92 * @disp: the X11 Display of this context
93 * @screen: the default Screen of Display @disp
94 * @screen_num: the Screen number of @screen
95 * @visual: the default Visual of Screen @screen
96 * @root: the root Window of Display @disp
97 * @white: the value of a white pixel on Screen @screen
98 * @black: the value of a black pixel on Screen @screen
99 * @depth: the color depth of Display @disp
100 * @bpp: the number of bits per pixel on Display @disp
101 * @endianness: the endianness of image bytes on Display @disp
102 * @width: the width in pixels of Display @disp
103 * @height: the height in pixels of Display @disp
104 * @widthmm: the width in millimeters of Display @disp
105 * @heightmm: the height in millimeters of Display @disp
106 * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
108 * @use_xshm: used to known wether of not XShm extension is usable or not even
109 * if the Extension is present
110 * @xv_port_id: the XVideo port ID
111 * @im_format: used to store at least a valid format for XShm calls checks
112 * @formats_list: list of supported image formats on @xv_port_id
113 * @channels_list: list of #GstColorBalanceChannels
114 * @caps: the #GstCaps that Display @disp can accept
116 * Structure used to store various informations collected/calculated for a
119 struct _GstXContext {
136 gint widthmm, heightmm;
137 GValue *par; /* calculated pixel aspect ratio */
147 GList *channels_list;
151 /* Optimisation storage for buffer_alloc return */
160 * @win: the Window ID of this X11 window
161 * @width: the width in pixels of Window @win
162 * @height: the height in pixels of Window @win
163 * @internal: used to remember if Window @win was created internally or passed
164 * through the #GstXOverlay interface
165 * @gc: the Graphical Context of Window @win
167 * Structure used to store informations about a Window.
171 #ifdef GST_EXT_XV_ENHANCEMENT
179 #ifdef GST_EXT_XV_ENHANCEMENT
187 struct _GstXvImageDisplayingBuffer {
189 unsigned int dmabuf_fd[XV_BUF_PLANE_NUM];
190 unsigned int gem_name[XV_BUF_PLANE_NUM];
191 unsigned int gem_handle[XV_BUF_PLANE_NUM];
192 void *bo[XV_BUF_PLANE_NUM];
193 void *vaddr[XV_BUF_PLANE_NUM];
194 unsigned int ref_count;
197 struct _GstXvImageFlushBuffer {
198 unsigned int gem_name[XV_BUF_PLANE_NUM];
199 void *bo[XV_BUF_PLANE_NUM];
205 * @format: the image format
206 * @caps: generated #GstCaps for this image format
208 * Structure storing image format to #GstCaps association.
210 struct _GstXvImageFormat {
217 * @xvimagesink: a reference to our #GstXvImageSink
218 * @xvimage: the XvImage of this buffer
219 * @width: the width in pixels of XvImage @xvimage
220 * @height: the height in pixels of XvImage @xvimage
221 * @im_format: the image format of XvImage @xvimage
222 * @size: the size in bytes of XvImage @xvimage
224 * Subclass of #GstBuffer containing additional information about an XvImage.
226 struct _GstXvImageBuffer {
229 /* Reference to the xvimagesink we belong to */
230 GstXvImageSink *xvimagesink;
235 XShmSegmentInfo SHMInfo;
236 #endif /* HAVE_XSHM */
238 gint width, height, im_format;
240 #ifdef GST_EXT_XV_ENHANCEMENT
241 GstBuffer *current_buffer;
242 #endif /* GST_EXT_XV_ENHANCEMENT */
245 #ifdef GST_EXT_XV_ENHANCEMENT
246 #define MAX_PLANE_NUM 4
247 #endif /* GST_EXT_XV_ENHANCEMENT */
251 * @display_name: the name of the Display we want to render to
252 * @xcontext: our instance's #GstXContext
253 * @xwindow: the #GstXWindow we are rendering to
254 * @xvimage: internal #GstXvImage used to store incoming buffers and render when
255 * not using the buffer_alloc optimization mechanism
256 * @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
257 * is used when Expose events are received to redraw the latest video frame
258 * @event_thread: a thread listening for events on @xwindow and handling them
259 * @running: used to inform @event_thread if it should run/shutdown
260 * @fps_n: the framerate fraction numerator
261 * @fps_d: the framerate fraction denominator
262 * @x_lock: used to protect X calls as we are not using the XLib in threaded
264 * @flow_lock: used to protect data flow routines from external calls such as
265 * events from @event_thread or methods from the #GstXOverlay interface
266 * @par: used to override calculated pixel aspect ratio from @xcontext
267 * @pool_lock: used to protect the buffer pool
268 * @image_pool: a list of #GstXvImageBuffer that could be reused at next buffer
270 * @synchronous: used to store if XSynchronous should be used or not (for
271 * debugging purpose only)
272 * @keep_aspect: used to remember if reverse negotiation scaling should respect
274 * @handle_events: used to know if we should handle select XEvents or not
275 * @brightness: used to store the user settings for color balance brightness
276 * @contrast: used to store the user settings for color balance contrast
277 * @hue: used to store the user settings for color balance hue
278 * @saturation: used to store the user settings for color balance saturation
279 * @cb_changed: used to store if the color balance settings where changed
280 * @video_width: the width of incoming video frames in pixels
281 * @video_height: the height of incoming video frames in pixels
283 * The #GstXvImageSink data structure.
285 struct _GstXvImageSink {
286 /* Our element stuff */
287 GstVideoSink videosink;
292 GstXContext *xcontext;
294 GstXvImageBuffer *xvimage;
295 GstXvImageBuffer *cur_image;
296 #ifdef GST_EXT_XV_ENHANCEMENT
297 GstXvImageBuffer *last_image;
298 unsigned int last_image_vaddr[4];
301 GThread *event_thread;
310 /* object-set pixel aspect ratio */
314 gboolean pool_invalid;
317 gboolean synchronous;
318 gboolean double_buffer;
319 gboolean keep_aspect;
320 gboolean redraw_border;
321 gboolean handle_events;
322 gboolean handle_expose;
330 /* size of incoming video, used as the size for XvImage */
331 guint video_width, video_height;
333 /* display sizes, used for clipping the image */
335 gint disp_width, disp_height;
337 /* port attributes */
338 gboolean autopaint_colorkey;
341 gboolean draw_borders;
344 gboolean have_autopaint_colorkey;
345 gboolean have_colorkey;
346 gboolean have_double_buffer;
348 /* stream metadata */
351 /* target video rectangle */
352 GstVideoRectangle render_rect;
353 gboolean have_render_rect;
355 #ifdef GST_EXT_XV_ENHANCEMENT
358 gboolean xid_updated;
361 guint display_geometry_method;
371 guint dst_roi_orientation;
372 GstVideoRectangle dst_roi;
373 XImage* xim_transparenter;
377 GstVideoRectangle src_crop;
379 /* needed if fourcc is one if S series */
381 guint aligned_height;
385 /* for using multiple pixmaps */
386 GstXPixmap *xpixmap[MAX_PIXMAP_NUM];
387 gint current_pixmap_idx;
388 get_pixmap_callback get_pixmap_cb;
389 void* get_pixmap_cb_user_data;
391 /* for sync displaying buffers */
392 GstXvImageDisplayingBuffer displaying_buffers[DISPLAYING_BUFFERS_MAX_NUM];
393 GMutex *display_buffer_lock;
395 /* buffer count check */
396 guint displayed_buffer_count;
397 guint displaying_buffer_count;
399 /* zero copy format */
400 gboolean is_zero_copy_format;
402 /* secure contents path */
408 /* if needed combine planes data */
409 gint need_combine_data;
411 /* display request time */
412 struct timeval request_time[DISPLAYING_BUFFERS_MAX_NUM];
414 /* last added buffer index */
415 gint last_added_buffer_index;
418 GstXvImageFlushBuffer *flush_buffer;
419 gboolean enable_flush_buffer;
421 #endif /* GST_EXT_XV_ENHANCEMENT */
424 #ifdef GST_EXT_XV_ENHANCEMENT
425 /* max plane count *********************************************************/
426 #define MPLANE_IMGB_MAX_COUNT (4)
428 /* image buffer definition ***************************************************
430 +------------------------------------------+ ---
432 | uaddr[], index[] | |
433 | +---------------------------+ --- | |
435 | |<-------- width[] -------->| | | |
438 | | |height[]|elevation[]
443 | +---------------------------+ --- | |
445 +------------------------------------------+ ---
447 |<----------------- stride[] ------------------>|
449 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
450 struct _GstMultiPlaneImageBuffer
454 /* width of each image plane */
455 gint width[MPLANE_IMGB_MAX_COUNT];
456 /* height of each image plane */
457 gint height[MPLANE_IMGB_MAX_COUNT];
458 /* stride of each image plane */
459 gint stride[MPLANE_IMGB_MAX_COUNT];
460 /* elevation of each image plane */
461 gint elevation[MPLANE_IMGB_MAX_COUNT];
462 /* user space address of each image plane */
463 gpointer uaddr[MPLANE_IMGB_MAX_COUNT];
464 /* Index of real address of each image plane, if needs */
465 gpointer index[MPLANE_IMGB_MAX_COUNT];
466 /* left postion, if needs */
468 /* top position, if needs */
470 /* to align memory */
475 #endif /* GST_EXT_XV_ENHANCEMENT */
477 struct _GstXvImageSinkClass {
478 GstVideoSinkClass parent_class;
481 GType gst_xvimagesink_get_type(void);
485 #endif /* __GST_XVIMAGESINK_H__ */