[evaspixmapsink] 1.Removed PROP_FORCE_ASPECT_RATIO property, added to call XSync...
[framework/multimedia/gst-plugins-ext0.10.git] / evaspixmapsink / evaspixmapsink.h
1 /*
2  * EvasPixmapSink
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Sangchul Lee <sc11.lee@samsung.com>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at your option)
11  * any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc., 51
20  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23
24 #ifndef __GST_EVASPIXMAPSINK_H__
25 #define __GST_EVASPIXMAPSINK_H__
26
27 #include <gst/video/gstvideosink.h>
28 #include <mm_ta.h>
29
30 #ifdef HAVE_XSHM
31 #include <sys/types.h>
32 #include <sys/ipc.h>
33 #include <sys/shm.h>
34 #endif /* HAVE_XSHM */
35
36 #include <X11/Xlib.h>
37 #include <X11/Xutil.h>
38
39 #ifdef HAVE_XSHM
40 #include <X11/extensions/XShm.h>
41 #endif /* HAVE_XSHM */
42
43 #include <X11/extensions/Xv.h>
44 #include <X11/extensions/Xvlib.h>
45 #include <X11/extensions/Xdamage.h>
46 #include <X11/extensions/damagewire.h>
47 #include <X11/Xatom.h>
48 #include <stdio.h>
49
50 #include <Evas.h>
51 #include <Ecore.h>
52 #include <Ecore_X.h>
53
54 #include <string.h>
55 #include <math.h>
56 #include <stdlib.h>
57
58 #define MAX_PLANE_NUM           3
59 #define MAX_BUFFER_NUM          20
60 #define MAX_GEM_BUFFER_NUM      (MAX_PLANE_NUM * MAX_BUFFER_NUM)
61 typedef struct _gem_info_t {
62         int dmabuf_fd;
63         unsigned int gem_handle;
64         unsigned int gem_name;
65 } gem_info_t;
66
67
68 G_BEGIN_DECLS
69
70 #define GST_TYPE_EVASPIXMAPSINK \
71   (gst_evaspixmapsink_get_type())
72 #define GST_EVASPIXMAPSINK(obj) \
73   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_EVASPIXMAPSINK, GstEvasPixmapSink))
74 #define GST_EVASPIXMAPSINK_CLASS(klass) \
75   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_EVASPIXMAPSINK, GstEvasPixmapSinkClass))
76 #define GST_IS_EVASPIXMAPSINK(obj) \
77   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_EVASPIXMAPSINK))
78 #define GST_IS_EVASPIXMAPSINK_CLASS(klass) \
79   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_EVASPIXMAPSINK))
80
81 #define XV_SCREEN_SIZE_WIDTH 4096
82 #define XV_SCREEN_SIZE_HEIGHT 4096
83
84 #define MARGIN_OF_ERROR 0.005
85
86 typedef struct _GstXContext GstXContext;
87 typedef struct _GstXPixmap GstXPixmap;
88 typedef struct _GstEvasPixmapFormat GstEvasPixmapFormat;
89 typedef struct _GstEvasPixmapBuffer GstEvasPixmapBuffer;
90 typedef struct _GstEvasPixmapBufferClass GstEvasPixmapBufferClass;
91 typedef struct _GstEvasPixmapSink GstEvasPixmapSink;
92 typedef struct _GstEvasPixmapSinkClass GstEvasPixmapSinkClass;
93
94 /*
95  * GstXContext:
96  * @disp: the X11 Display of this context
97  * @screen: the default Screen of Display @disp
98  * @screen_num: the Screen number of @screen
99  * @visual: the default Visual of Screen @screen
100  * @root: the root Window of Display @disp
101  * @white: the value of a white pixel on Screen @screen
102  * @black: the value of a black pixel on Screen @screen
103  * @depth: the color depth of Display @disp
104  * @bpp: the number of bits per pixel on Display @disp
105  * @endianness: the endianness of image bytes on Display @disp
106  * @width: the width in pixels of Display @disp
107  * @height: the height in pixels of Display @disp
108  * @widthmm: the width in millimeters of Display @disp
109  * @heightmm: the height in millimeters of Display @disp
110  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
111  * @heightmm ratio
112  * @use_xshm: used to known wether of not XShm extension is usable or not even
113  * if the Extension is present
114  * @xv_port_id: the XVideo port ID
115  * @im_format: used to store at least a valid format for XShm calls checks
116  * @formats_list: list of supported image formats on @xv_port_id
117  * @channels_list: list of #GstColorBalanceChannels
118  * @caps: the #GstCaps that Display @disp can accept
119  *
120  * Structure used to store various informations collected/calculated for a
121  * Display.
122  */
123 struct _GstXContext {
124         Display *disp;
125
126         Screen *screen;
127         gint screen_num;
128
129         Visual *visual;
130
131         Window root;
132
133         gulong white, black;
134
135         gint depth;
136         gint bpp;
137         gint endianness;
138
139         gint width, height;
140         gint widthmm, heightmm;
141         GValue *par;                  /* calculated pixel aspect ratio */
142
143         gboolean use_xshm;
144
145         XvPortID xv_port_id;
146         guint nb_adaptors;
147         gchar ** adaptors;
148         gint im_format;
149
150         GList *formats_list;
151         GList *channels_list;
152
153         GstCaps *caps;
154 };
155
156 /*
157  * GstXPixmap:
158  * @pixmap: the pixmap ID of this X11 pixmap
159  * @width: the width in pixels of Pixmap @pixmap
160  * @height: the height in pixels of Pixmap @pixmap
161  * @gc: the Graphical Context of Pixmap @pixmap
162  *
163  * Structure used to store informations about a Pixmap.
164  */
165 struct _GstXPixmap {
166         Pixmap pixmap;
167         gint x, y;
168         gint width, height;
169         GC gc;
170 };
171
172 /**
173  * GstEvasPixmapFormat:
174  * @format: the image format
175  * @caps: generated #GstCaps for this image format
176  *
177  * Structure storing image format to #GstCaps association.
178  */
179 struct _GstEvasPixmapFormat {
180         gint format;
181         GstCaps *caps;
182 };
183
184 /**
185  * GstEvasPixmapBuffer:
186  * @evaspixmapsink: a reference to our #GstEvasPixmapSink
187  * @xvimage: the XvImage of this buffer
188  * @width: the width in pixels of XvImage @xvimage
189  * @height: the height in pixels of XvImage @xvimage
190  * @im_format: the image format of XvImage @xvimage
191  * @size: the size in bytes of XvImage @xvimage
192  *
193  * Subclass of #GstBuffer containing additional information about an XvImage.
194  */
195 struct _GstEvasPixmapBuffer {
196         GstBuffer buffer;
197
198         /* Reference to the evaspixmapsink we belong to */
199         GstEvasPixmapSink *evaspixmapsink;
200         XvImage *xvimage;
201
202 #ifdef HAVE_XSHM
203         XShmSegmentInfo SHMInfo;
204 #endif /* HAVE_XSHM */
205
206         gint width, height;
207         gint im_format;
208         size_t size;
209 };
210
211 /**
212  * GstEvasPixmapSink:
213  * @display_name: the name of the Display we want to render to
214  * @xcontext: our instance's #GstXContext
215  * @xpixmap: the #GstXPixmap we are rendering to
216  * @fps_n: the framerate fraction numerator
217  * @fps_d: the framerate fraction denominator
218  * @x_lock: used to protect X calls as we are not using the XLib in threaded
219  * mode
220  * @flow_lock: used to protect data flow routines from external calls such as
221  * methods from the #GstXOverlay interface
222  * @par: used to override calculated pixel aspect ratio from @xcontext
223  * @synchronous: used to store if XSynchronous should be used or not (for
224  * debugging purpose only)
225  * @keep_aspect: used to remember if reverse negotiation scaling should respect
226  * aspect ratio
227  * @brightness: used to store the user settings for color balance brightness
228  * @contrast: used to store the user settings for color balance contrast
229  * @hue: used to store the user settings for color balance hue
230  * @saturation: used to store the user settings for color balance saturation
231  * @cb_changed: used to store if the color balance settings where changed
232  * @video_width: the width of incoming video frames in pixels
233  * @video_height: the height of incoming video frames in pixels
234  *
235  * The #GstEvasPixmapSink data structure.
236  */
237 struct _GstEvasPixmapSink {
238         /* Our element stuff */
239         GstVideoSink videosink;
240
241         char *display_name;
242         guint adaptor_no;
243
244         GstXContext *xcontext;
245         GstXPixmap *xpixmap;
246         GstEvasPixmapBuffer *evas_pixmap_buf;
247
248         GThread *event_thread;
249         gboolean running;
250
251         gint fps_n;
252         gint fps_d;
253
254         GMutex *x_lock;
255         GMutex *flow_lock;
256
257         /* object-set pixel aspect ratio */
258         GValue *par;
259
260         gboolean synchronous;
261         gboolean double_buffer;
262
263         gint brightness;
264         gint contrast;
265         gint hue;
266         gint saturation;
267         gboolean cb_changed;
268
269         /* size of incoming video, used as the size for XvImage */
270         guint video_width, video_height;
271
272         /* display sizes, used for clipping the image */
273         gint disp_x, disp_y;
274         gint disp_width, disp_height;
275
276         /* port attributes */
277         gboolean autopaint_colorkey;
278         gint colorkey;
279
280         /* port features */
281         gboolean have_autopaint_colorkey;
282         gboolean have_colorkey;
283         gboolean have_double_buffer;
284
285         /* target video rectagle */
286         GstVideoRectangle render_rect;
287         gboolean have_render_rect;
288
289         /* display */
290         guint flip;
291         guint rotate_angle;
292         guint display_geometry_method;
293         GstVideoRectangle dst_roi;
294         guint scr_w, scr_h;
295         /* needed if fourcc is one if S series */
296         guint aligned_width;
297         guint aligned_height;
298
299         gboolean stop_video;
300
301         /* evas object */
302         Evas_Object *eo;
303         Evas_Coord w;
304         Evas_Coord h;
305         gboolean visible;
306
307         /* pixmap */
308         gboolean do_link;
309         gboolean use_origin_size;
310         gboolean previous_origin_size;
311
312         /* damage event */
313         Damage damage;
314         int damage_case;
315         Ecore_Event_Handler *handler;
316         Ecore_Pipe *epipe;
317
318         gint drm_fd;
319         gem_info_t gem_info[MAX_GEM_BUFFER_NUM];
320 };
321
322 /* max plane count *********************************************************/
323 #define MPLANE_IMGB_MAX_COUNT         (4)
324
325 /* image buffer definition ***************************************************
326
327     +------------------------------------------+ ---
328     |                                          |  ^
329     |     uaddr[], index[]                     |  |
330     |     +---------------------------+ ---    |  |
331     |     |                           |  ^     |  |
332     |     |<-------- width[] -------->|  |     |  |
333     |     |                           |  |     |  |
334     |     |                           |        |
335     |     |                           |height[]|elevation[]
336     |     |                           |        |
337     |     |                           |  |     |  |
338     |     |                           |  |     |  |
339     |     |                           |  v     |  |
340     |     +---------------------------+ ---    |  |
341     |                                          |  v
342     +------------------------------------------+ ---
343
344     |<----------------- stride[] ------------------>|
345 */
346 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
347 struct _GstMultiPlaneImageBuffer
348 {
349     GstBuffer buffer;
350
351     /* width of each image plane */
352     gint      width[MPLANE_IMGB_MAX_COUNT];
353     /* height of each image plane */
354     gint      height[MPLANE_IMGB_MAX_COUNT];
355     /* stride of each image plane */
356     gint      stride[MPLANE_IMGB_MAX_COUNT];
357     /* elevation of each image plane */
358     gint      elevation[MPLANE_IMGB_MAX_COUNT];
359     /* user space address of each image plane */
360     gpointer uaddr[MPLANE_IMGB_MAX_COUNT];
361     /* Index of real address of each image plane, if needs */
362     gpointer index[MPLANE_IMGB_MAX_COUNT];
363     /* left postion, if needs */
364     gint      x;
365     /* top position, if needs */
366     gint      y;
367     /* to align memory */
368     gint      __dummy2;
369     /* arbitrary data */
370     gint      data[16];
371 };
372
373 struct _GstEvasPixmapSinkClass {
374   GstVideoSinkClass parent_class;
375 };
376
377 GType gst_evaspixmapsink_get_type(void);
378
379 G_END_DECLS
380
381 #endif /* __GST_EVASPIXMAPSINK_H__ */