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