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>
51 #include <utilX_ext.h>
60 #define GST_TYPE_XVIMAGESINK \
61 (gst_xvimagesink_get_type())
62 #define GST_XVIMAGESINK(obj) \
63 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XVIMAGESINK, GstXvImageSink))
64 #define GST_XVIMAGESINK_CLASS(klass) \
65 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XVIMAGESINK, GstXvImageSinkClass))
66 #define GST_IS_XVIMAGESINK(obj) \
67 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
68 #define GST_IS_XVIMAGESINK_CLASS(klass) \
69 (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
71 #ifdef GST_EXT_XV_ENHANCEMENT
72 #define XV_SCREEN_SIZE_WIDTH 4096
73 #define XV_SCREEN_SIZE_HEIGHT 4096
74 #define DISPLAYING_BUFFERS_MAX_NUM 10
76 #define MAX_PIXMAP_NUM 10
77 typedef uint (*get_pixmap_callback)(void *user_data);
78 typedef struct _GstXPixmap GstXPixmap;
79 typedef struct _GstXvImageDisplayingBuffer GstXvImageDisplayingBuffer;
80 typedef struct _GstXvImageFlushBuffer GstXvImageFlushBuffer;
81 #endif /* GST_EXT_XV_ENHANCEMENT */
83 typedef struct _GstXContext GstXContext;
84 typedef struct _GstXWindow GstXWindow;
85 typedef struct _GstXvImageFormat GstXvImageFormat;
86 typedef struct _GstXvImageBuffer GstXvImageBuffer;
87 typedef struct _GstXvImageBufferClass GstXvImageBufferClass;
89 typedef struct _GstXvImageSink GstXvImageSink;
90 typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
94 * @disp: the X11 Display of this context
95 * @screen: the default Screen of Display @disp
96 * @screen_num: the Screen number of @screen
97 * @visual: the default Visual of Screen @screen
98 * @root: the root Window of Display @disp
99 * @white: the value of a white pixel on Screen @screen
100 * @black: the value of a black pixel on Screen @screen
101 * @depth: the color depth of Display @disp
102 * @bpp: the number of bits per pixel on Display @disp
103 * @endianness: the endianness of image bytes on Display @disp
104 * @width: the width in pixels of Display @disp
105 * @height: the height in pixels of Display @disp
106 * @widthmm: the width in millimeters of Display @disp
107 * @heightmm: the height in millimeters of Display @disp
108 * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
110 * @use_xshm: used to known wether of not XShm extension is usable or not even
111 * if the Extension is present
112 * @xv_port_id: the XVideo port ID
113 * @im_format: used to store at least a valid format for XShm calls checks
114 * @formats_list: list of supported image formats on @xv_port_id
115 * @channels_list: list of #GstColorBalanceChannels
116 * @caps: the #GstCaps that Display @disp can accept
118 * Structure used to store various informations collected/calculated for a
121 struct _GstXContext {
138 gint widthmm, heightmm;
139 GValue *par; /* calculated pixel aspect ratio */
149 GList *channels_list;
153 /* Optimisation storage for buffer_alloc return */
162 * @win: the Window ID of this X11 window
163 * @width: the width in pixels of Window @win
164 * @height: the height in pixels of Window @win
165 * @internal: used to remember if Window @win was created internally or passed
166 * through the #GstXOverlay interface
167 * @gc: the Graphical Context of Window @win
169 * Structure used to store informations about a Window.
173 #ifdef GST_EXT_XV_ENHANCEMENT
181 #ifdef GST_EXT_XV_ENHANCEMENT
189 struct _GstXvImageDisplayingBuffer {
191 unsigned int dmabuf_fd[XV_BUF_PLANE_NUM];
192 unsigned int gem_name[XV_BUF_PLANE_NUM];
193 unsigned int gem_handle[XV_BUF_PLANE_NUM];
194 void *bo[XV_BUF_PLANE_NUM];
195 unsigned int ref_count;
198 struct _GstXvImageFlushBuffer {
199 unsigned int gem_name[XV_BUF_PLANE_NUM];
200 void *bo[XV_BUF_PLANE_NUM];
206 * @format: the image format
207 * @caps: generated #GstCaps for this image format
209 * Structure storing image format to #GstCaps association.
211 struct _GstXvImageFormat {
218 * @xvimagesink: a reference to our #GstXvImageSink
219 * @xvimage: the XvImage of this buffer
220 * @width: the width in pixels of XvImage @xvimage
221 * @height: the height in pixels of XvImage @xvimage
222 * @im_format: the image format of XvImage @xvimage
223 * @size: the size in bytes of XvImage @xvimage
225 * Subclass of #GstBuffer containing additional information about an XvImage.
227 struct _GstXvImageBuffer {
230 /* Reference to the xvimagesink we belong to */
231 GstXvImageSink *xvimagesink;
236 XShmSegmentInfo SHMInfo;
237 #endif /* HAVE_XSHM */
239 gint width, height, im_format;
241 #ifdef GST_EXT_XV_ENHANCEMENT
242 GstBuffer *current_buffer;
243 #endif /* GST_EXT_XV_ENHANCEMENT */
246 #ifdef GST_EXT_XV_ENHANCEMENT
247 #define MAX_PLANE_NUM 4
248 #endif /* GST_EXT_XV_ENHANCEMENT */
252 * @display_name: the name of the Display we want to render to
253 * @xcontext: our instance's #GstXContext
254 * @xwindow: the #GstXWindow we are rendering to
255 * @xvimage: internal #GstXvImage used to store incoming buffers and render when
256 * not using the buffer_alloc optimization mechanism
257 * @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
258 * is used when Expose events are received to redraw the latest video frame
259 * @event_thread: a thread listening for events on @xwindow and handling them
260 * @running: used to inform @event_thread if it should run/shutdown
261 * @fps_n: the framerate fraction numerator
262 * @fps_d: the framerate fraction denominator
263 * @x_lock: used to protect X calls as we are not using the XLib in threaded
265 * @flow_lock: used to protect data flow routines from external calls such as
266 * events from @event_thread or methods from the #GstXOverlay interface
267 * @par: used to override calculated pixel aspect ratio from @xcontext
268 * @pool_lock: used to protect the buffer pool
269 * @image_pool: a list of #GstXvImageBuffer that could be reused at next buffer
271 * @synchronous: used to store if XSynchronous should be used or not (for
272 * debugging purpose only)
273 * @keep_aspect: used to remember if reverse negotiation scaling should respect
275 * @handle_events: used to know if we should handle select XEvents or not
276 * @brightness: used to store the user settings for color balance brightness
277 * @contrast: used to store the user settings for color balance contrast
278 * @hue: used to store the user settings for color balance hue
279 * @saturation: used to store the user settings for color balance saturation
280 * @cb_changed: used to store if the color balance settings where changed
281 * @video_width: the width of incoming video frames in pixels
282 * @video_height: the height of incoming video frames in pixels
284 * The #GstXvImageSink data structure.
286 struct _GstXvImageSink {
287 /* Our element stuff */
288 GstVideoSink videosink;
293 GstXContext *xcontext;
295 GstXvImageBuffer *xvimage;
296 GstXvImageBuffer *cur_image;
297 #ifdef GST_EXT_XV_ENHANCEMENT
298 GstXvImageBuffer *last_image;
299 unsigned int last_image_vaddr[4];
302 GThread *event_thread;
311 /* object-set pixel aspect ratio */
315 gboolean pool_invalid;
318 gboolean synchronous;
319 gboolean double_buffer;
320 gboolean keep_aspect;
321 gboolean redraw_border;
322 gboolean handle_events;
323 gboolean handle_expose;
331 /* size of incoming video, used as the size for XvImage */
332 guint video_width, video_height;
334 /* display sizes, used for clipping the image */
336 gint disp_width, disp_height;
338 /* port attributes */
339 gboolean autopaint_colorkey;
342 gboolean draw_borders;
345 gboolean have_autopaint_colorkey;
346 gboolean have_colorkey;
347 gboolean have_double_buffer;
349 /* stream metadata */
352 /* target video rectangle */
353 GstVideoRectangle render_rect;
354 gboolean have_render_rect;
356 #ifdef GST_EXT_XV_ENHANCEMENT
359 gboolean xid_updated;
362 guint display_geometry_method;
373 GstVideoRectangle dst_roi;
374 XImage* xim_transparenter;
378 gboolean is_quick_panel_on;
379 gboolean is_multi_window;
380 gboolean is_during_seek;
381 GstVideoRectangle src_crop;
383 /* needed if fourcc is one if S series */
385 guint aligned_height;
389 /* for using multiple pixmaps */
390 GstXPixmap *xpixmap[MAX_PIXMAP_NUM];
391 gint current_pixmap_idx;
392 get_pixmap_callback get_pixmap_cb;
393 void* get_pixmap_cb_user_data;
395 /* for sync displaying buffers */
396 GstXvImageDisplayingBuffer displaying_buffers[DISPLAYING_BUFFERS_MAX_NUM];
397 GMutex *display_buffer_lock;
399 /* buffer count check */
400 guint displayed_buffer_count;
401 guint displaying_buffer_count;
403 /* zero copy format */
404 gboolean is_zero_copy_format;
406 /* secure contents path */
412 #ifdef GST_EXT_ENABLE_HEVC
413 /* if needed combine planes data */
414 gint need_combine_data;
417 /* display request time */
418 struct timeval request_time[DISPLAYING_BUFFERS_MAX_NUM];
420 /* last added buffer index */
421 gint last_added_buffer_index;
424 GstXvImageFlushBuffer *flush_buffer;
425 gboolean enable_flush_buffer;
427 /* subtitle format */
428 Pixmap pixmap_for_subpicture;
429 gboolean is_subpicture_format;
430 gboolean set_overlay_for_subpicture_just_once;
432 gboolean is_hided_subpicture;
433 gboolean is_quick_panel_on_subpicture;
434 gboolean is_multi_window_subpicture;
436 /* external display */
438 gint external_height;
439 gboolean skip_frame_due_to_external_dev;
440 gboolean keep_external_fullscreen_post;
441 gboolean keep_external_fullscreen_prev;
443 gboolean eos_received;
445 #endif /* GST_EXT_XV_ENHANCEMENT */
448 #ifdef GST_EXT_XV_ENHANCEMENT
449 /* max plane count *********************************************************/
450 #define MPLANE_IMGB_MAX_COUNT (4)
452 /* image buffer definition ***************************************************
454 +------------------------------------------+ ---
456 | uaddr[], index[] | |
457 | +---------------------------+ --- | |
459 | |<-------- width[] -------->| | | |
462 | | |height[]|elevation[]
467 | +---------------------------+ --- | |
469 +------------------------------------------+ ---
471 |<----------------- stride[] ------------------>|
473 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
474 struct _GstMultiPlaneImageBuffer
478 /* width of each image plane */
479 gint width[MPLANE_IMGB_MAX_COUNT];
480 /* height of each image plane */
481 gint height[MPLANE_IMGB_MAX_COUNT];
482 /* stride of each image plane */
483 gint stride[MPLANE_IMGB_MAX_COUNT];
484 /* elevation of each image plane */
485 gint elevation[MPLANE_IMGB_MAX_COUNT];
486 /* user space address of each image plane */
487 gpointer uaddr[MPLANE_IMGB_MAX_COUNT];
488 /* Index of real address of each image plane, if needs */
489 gpointer index[MPLANE_IMGB_MAX_COUNT];
490 /* left postion, if needs */
492 /* top position, if needs */
494 /* to align memory */
499 #endif /* GST_EXT_XV_ENHANCEMENT */
501 struct _GstXvImageSinkClass {
502 GstVideoSinkClass parent_class;
505 GType gst_xvimagesink_get_type(void);
509 #endif /* __GST_XVIMAGESINK_H__ */