Initialize Tizen 2.3
[framework/multimedia/gst-plugins-ext0.10.git] / mobile / 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 <tbm_bufmgr.h>
55
56 #include <string.h>
57 #include <math.h>
58 #include <stdlib.h>
59
60 #define MAX_PLANE_NUM           3
61 #define MAX_BUFFER_NUM          20
62 #define MAX_GEM_BUFFER_NUM      (MAX_PLANE_NUM * MAX_BUFFER_NUM)
63 typedef struct _gem_info_t {
64         int dmabuf_fd;
65         unsigned int gem_handle;
66         unsigned int gem_name;
67         tbm_bo bo;
68         Pixmap ref_pixmap;
69 } gem_info_t;
70
71 typedef enum {
72         BUF_SHARE_METHOD_NONE = -1,
73         BUF_SHARE_METHOD_PADDR = 0,
74         BUF_SHARE_METHOD_FD,
75         BUF_SHARE_METHOD_TIZEN_BUFFER
76 } buf_share_method_t;
77
78 G_BEGIN_DECLS
79
80 #define GST_TYPE_EVASPIXMAPSINK \
81   (gst_evaspixmapsink_get_type())
82 #define GST_EVASPIXMAPSINK(obj) \
83   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_EVASPIXMAPSINK, GstEvasPixmapSink))
84 #define GST_EVASPIXMAPSINK_CLASS(klass) \
85   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_EVASPIXMAPSINK, GstEvasPixmapSinkClass))
86 #define GST_IS_EVASPIXMAPSINK(obj) \
87   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_EVASPIXMAPSINK))
88 #define GST_IS_EVASPIXMAPSINK_CLASS(klass) \
89   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_EVASPIXMAPSINK))
90
91 #define XV_SCREEN_SIZE_WIDTH  4096
92 #define XV_SCREEN_SIZE_HEIGHT 4096
93
94 #define MARGIN_OF_ERROR       0.005
95 #define NUM_OF_PIXMAP         3
96
97 typedef struct _GstXContext GstXContext;
98 typedef struct _GstXPixmap GstXPixmap;
99 typedef struct _GstEvasPixmapFormat GstEvasPixmapFormat;
100 typedef struct _GstEvasPixmapBuffer GstEvasPixmapBuffer;
101 typedef struct _GstEvasPixmapBufferClass GstEvasPixmapBufferClass;
102 typedef struct _GstEvasPixmapSink GstEvasPixmapSink;
103 typedef struct _GstEvasPixmapSinkClass GstEvasPixmapSinkClass;
104
105 /*
106  * GstXContext:
107  * @disp: the X11 Display of this context
108  * @screen: the default Screen of Display @disp
109  * @screen_num: the Screen number of @screen
110  * @visual: the default Visual of Screen @screen
111  * @root: the root Window of Display @disp
112  * @white: the value of a white pixel on Screen @screen
113  * @black: the value of a black pixel on Screen @screen
114  * @depth: the color depth of Display @disp
115  * @bpp: the number of bits per pixel on Display @disp
116  * @endianness: the endianness of image bytes on Display @disp
117  * @width: the width in pixels of Display @disp
118  * @height: the height in pixels of Display @disp
119  * @widthmm: the width in millimeters of Display @disp
120  * @heightmm: the height in millimeters of Display @disp
121  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
122  * @heightmm ratio
123  * @use_xshm: used to known wether of not XShm extension is usable or not even
124  * if the Extension is present
125  * @xv_port_id: the XVideo port ID
126  * @im_format: used to store at least a valid format for XShm calls checks
127  * @formats_list: list of supported image formats on @xv_port_id
128  * @channels_list: list of #GstColorBalanceChannels
129  * @caps: the #GstCaps that Display @disp can accept
130  *
131  * Structure used to store various informations collected/calculated for a
132  * Display.
133  */
134 struct _GstXContext {
135         Display *disp;
136
137         Screen *screen;
138         gint screen_num;
139
140         Visual *visual;
141
142         Window root;
143
144         gulong white, black;
145
146         gint depth;
147         gint bpp;
148         gint endianness;
149
150         gint width, height;
151         gint widthmm, heightmm;
152         GValue *par;                  /* calculated pixel aspect ratio */
153
154         gboolean use_xshm;
155
156         XvPortID xv_port_id;
157         guint nb_adaptors;
158         gchar ** adaptors;
159         gint im_format;
160
161         GList *formats_list;
162         GList *channels_list;
163
164         GstCaps *caps;
165 };
166
167 /*
168  * GstXPixmap:
169  * @pixmap: the pixmap ID of this X11 pixmap
170  * @width: the width in pixels of Pixmap @pixmap
171  * @height: the height in pixels of Pixmap @pixmap
172  * @gc: the Graphical Context of Pixmap @pixmap
173  *
174  * Structure used to store informations about a Pixmap.
175  */
176 struct _GstXPixmap {
177         Pixmap pixmap;
178         gint x, y;
179         gint width, height;
180         GC gc;
181         guint ref;
182         gint damaged_time;
183         Pixmap prev_pixmap;
184         GC prev_gc;
185 };
186
187 /**
188  * GstEvasPixmapFormat:
189  * @format: the image format
190  * @caps: generated #GstCaps for this image format
191  *
192  * Structure storing image format to #GstCaps association.
193  */
194 struct _GstEvasPixmapFormat {
195         gint format;
196         GstCaps *caps;
197 };
198
199 /**
200  * GstEvasPixmapBuffer:
201  * @evaspixmapsink: a reference to our #GstEvasPixmapSink
202  * @xvimage: the XvImage of this buffer
203  * @width: the width in pixels of XvImage @xvimage
204  * @height: the height in pixels of XvImage @xvimage
205  * @im_format: the image format of XvImage @xvimage
206  * @size: the size in bytes of XvImage @xvimage
207  *
208  * Subclass of #GstBuffer containing additional information about an XvImage.
209  */
210 struct _GstEvasPixmapBuffer {
211         GstBuffer buffer;
212
213         /* Reference to the evaspixmapsink we belong to */
214         GstEvasPixmapSink *evaspixmapsink;
215         XvImage *xvimage;
216
217 #ifdef HAVE_XSHM
218         XShmSegmentInfo SHMInfo;
219 #endif /* HAVE_XSHM */
220
221         gint width, height;
222         gint im_format;
223         size_t size;
224 };
225
226 /**
227  * GstEvasPixmapSink:
228  * @display_name: the name of the Display we want to render to
229  * @xcontext: our instance's #GstXContext
230  * @xpixmap: the #GstXPixmap we are rendering to
231  * @fps_n: the framerate fraction numerator
232  * @fps_d: the framerate fraction denominator
233  * @x_lock: used to protect X calls as we are not using the XLib in threaded
234  * mode
235  * @flow_lock: used to protect data flow routines from external calls such as
236  * methods from the #GstXOverlay interface
237  * @par: used to override calculated pixel aspect ratio from @xcontext
238  * @synchronous: used to store if XSynchronous should be used or not (for
239  * debugging purpose only)
240  * @keep_aspect: used to remember if reverse negotiation scaling should respect
241  * aspect ratio
242  * @brightness: used to store the user settings for color balance brightness
243  * @contrast: used to store the user settings for color balance contrast
244  * @hue: used to store the user settings for color balance hue
245  * @saturation: used to store the user settings for color balance saturation
246  * @cb_changed: used to store if the color balance settings where changed
247  * @video_width: the width of incoming video frames in pixels
248  * @video_height: the height of incoming video frames in pixels
249  *
250  * The #GstEvasPixmapSink data structure.
251  */
252 struct _GstEvasPixmapSink {
253         /* Our element stuff */
254         GstVideoSink videosink;
255
256         char *display_name;
257         guint adaptor_no;
258
259         GstXContext *xcontext;
260         GstXPixmap *xpixmap[NUM_OF_PIXMAP];
261         GstEvasPixmapBuffer *evas_pixmap_buf;
262
263         GThread *event_thread;
264         gboolean running;
265
266         gint fps_n;
267         gint fps_d;
268
269         GMutex *x_lock;
270         GMutex *flow_lock;
271         GMutex *pixmap_ref_lock;
272
273         /* object-set pixel aspect ratio */
274         GValue *par;
275
276         gboolean synchronous;
277         gboolean double_buffer;
278
279         gint brightness;
280         gint contrast;
281         gint hue;
282         gint saturation;
283         gboolean cb_changed;
284
285         /* size of incoming video, used as the size for XvImage */
286         guint video_width, video_height;
287
288         /* display sizes, used for clipping the image */
289         gint disp_x, disp_y;
290         gint disp_width, disp_height;
291
292         /* port attributes */
293         gboolean autopaint_colorkey;
294         gint colorkey;
295
296         /* port features */
297         gboolean have_autopaint_colorkey;
298         gboolean have_colorkey;
299         gboolean have_double_buffer;
300
301         /* target video rectagle */
302         GstVideoRectangle render_rect;
303         gboolean have_render_rect;
304
305         /* display */
306         guint flip;
307         guint rotate_angle;
308         guint display_geometry_method;
309         GstVideoRectangle dst_roi;
310         guint scr_w, scr_h;
311         /* needed if fourcc is one if S series */
312         guint aligned_width;
313         guint aligned_height;
314
315         gboolean stop_video;
316         buf_share_method_t buf_shared_type;
317
318         /* ecore & evas object */
319         Ecore_Pipe *epipe;
320         Evas_Object *eo;
321         Evas_Coord w;
322         Evas_Coord h;
323         gboolean visible;
324         gint last_updated_idx;
325         gchar update_visibility;
326         guint epipe_request_count;
327
328         /* pixmap */
329         gboolean do_link;
330         gboolean use_origin_size;
331         gboolean previous_origin_size;
332         gint sizediff_width;
333         gint sizediff_height;
334         guint num_of_pixmaps;
335
336         /* damage event */
337         Damage damage[NUM_OF_PIXMAP];
338         Damage prev_damage[NUM_OF_PIXMAP];
339         int damage_case;
340
341         gint drm_fd;
342         gem_info_t gem_info[MAX_GEM_BUFFER_NUM];
343 };
344
345 /* max plane count *********************************************************/
346 #define MPLANE_IMGB_MAX_COUNT         (4)
347
348 /* image buffer definition ***************************************************
349
350     +------------------------------------------+ ---
351     |                                          |  ^
352     |     uaddr[], index[]                     |  |
353     |     +---------------------------+ ---    |  |
354     |     |                           |  ^     |  |
355     |     |<-------- width[] -------->|  |     |  |
356     |     |                           |  |     |  |
357     |     |                           |        |
358     |     |                           |height[]|elevation[]
359     |     |                           |        |
360     |     |                           |  |     |  |
361     |     |                           |  |     |  |
362     |     |                           |  v     |  |
363     |     +---------------------------+ ---    |  |
364     |                                          |  v
365     +------------------------------------------+ ---
366
367     |<----------------- stride[] ------------------>|
368 */
369 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
370 struct _GstMultiPlaneImageBuffer
371 {
372     GstBuffer buffer;
373
374     /* width of each image plane */
375     gint      width[MPLANE_IMGB_MAX_COUNT];
376     /* height of each image plane */
377     gint      height[MPLANE_IMGB_MAX_COUNT];
378     /* stride of each image plane */
379     gint      stride[MPLANE_IMGB_MAX_COUNT];
380     /* elevation of each image plane */
381     gint      elevation[MPLANE_IMGB_MAX_COUNT];
382     /* user space address of each image plane */
383     gpointer uaddr[MPLANE_IMGB_MAX_COUNT];
384     /* Index of real address of each image plane, if needs */
385     gpointer index[MPLANE_IMGB_MAX_COUNT];
386     /* left postion, if needs */
387     gint      x;
388     /* top position, if needs */
389     gint      y;
390     /* to align memory */
391     gint      __dummy2;
392     /* arbitrary data */
393     gint      data[16];
394 };
395
396 struct _GstEvasPixmapSinkClass {
397   GstVideoSinkClass parent_class;
398 };
399
400 GType gst_evaspixmapsink_get_type(void);
401
402 G_END_DECLS
403
404 #endif /* __GST_EVASPIXMAPSINK_H__ */