emotion: minor cleanup.
[profile/ivi/emotion.git] / src / modules / gstreamer / emotion_gstreamer.h
1 #ifndef __EMOTION_GSTREAMER_H__
2 #define __EMOTION_GSTREAMER_H__
3
4 #ifdef HAVE_CONFIG_H
5 # include "config.h"
6 #endif
7
8 #include <Evas.h>
9 #include <Ecore.h>
10
11 #ifdef HAVE_ECORE_X
12 # include <Ecore_X.h>
13 # include <Ecore_Evas.h>
14 # ifdef HAVE_XOVERLAY_H
15 #  include <gst/interfaces/xoverlay.h>
16 # endif
17 #endif
18
19 #define HTTP_STREAM 0
20 #define RTSP_STREAM 1
21 #include <glib.h>
22 #include <gst/gst.h>
23 #include <glib-object.h>
24 #include <gst/video/gstvideosink.h>
25 #include <gst/video/video.h>
26
27 #include "emotion_private.h"
28
29 typedef void (*Evas_Video_Convert_Cb)(unsigned char *evas_data,
30                                       const unsigned char *gst_data,
31                                       unsigned int w,
32                                       unsigned int h,
33                                       unsigned int output_height);
34
35 typedef struct _EvasVideoSinkPrivate EvasVideoSinkPrivate;
36 typedef struct _EvasVideoSink        EvasVideoSink;
37 typedef struct _EvasVideoSinkClass   EvasVideoSinkClass;
38 typedef struct _Emotion_Gstreamer_Video Emotion_Gstreamer_Video;
39 typedef struct _Emotion_Audio_Stream Emotion_Audio_Stream;
40 typedef struct _Emotion_Gstreamer_Metadata Emotion_Gstreamer_Metadata;
41 typedef struct _Emotion_Gstreamer_Buffer Emotion_Gstreamer_Buffer;
42 typedef struct _Emotion_Gstreamer_Message Emotion_Gstreamer_Message;
43 typedef struct _Emotion_Video_Stream Emotion_Video_Stream;
44
45 struct _Emotion_Video_Stream
46 {
47    gdouble     length_time;
48    gint        width;
49    gint        height;
50    gint        fps_num;
51    gint        fps_den;
52    guint32     fourcc;
53    int         index;
54 };
55
56 struct _Emotion_Audio_Stream
57 {
58    gdouble     length_time;
59    gint        channels;
60    gint        samplerate;
61 };
62
63 struct _Emotion_Gstreamer_Metadata
64 {
65    char *title;
66    char *album;
67    char *artist;
68    char *genre;
69    char *comment;
70    char *year;
71    char *count;
72    char *disc_id;
73 };
74
75 struct _Emotion_Gstreamer_Video
76 {
77    /* Gstreamer elements */
78    GstElement       *pipeline;
79    GstElement       *sink;
80    GstElement       *esink;
81    GstElement       *xvsink;
82    GstElement       *tee;
83    GstPad           *teepad;
84    GstPad           *xvpad;
85    Eina_List        *threads;
86
87    /* eos */
88    GstBus           *eos_bus;
89
90    /* Strams */
91    Eina_List        *video_streams;
92    Eina_List        *audio_streams;
93
94    int               video_stream_nbr;
95    int               audio_stream_nbr;
96
97     /* We need to keep a copy of the last inserted buffer as evas doesn't copy YUV data around */
98    GstBuffer        *last_buffer;
99
100    /* Evas object */
101    Evas_Object      *obj;
102
103    /* Characteristics of stream */
104    double            position;
105    double            ratio;
106    double            volume;
107
108    volatile int      seek_to;
109    volatile int      get_poslen;
110
111    Emotion_Gstreamer_Metadata *metadata;
112
113 #ifdef HAVE_ECORE_X
114    Ecore_X_Window    win;
115 #endif
116
117    const char       *uri;
118
119    Emotion_Gstreamer_Buffer *send;
120
121    EvasVideoSinkPrivate *sink_data;
122
123    Emotion_Vis       vis;
124
125    int               in;
126    int               out;
127
128    int frames;
129    int flapse;
130    double rtime;
131    double rlapse;
132
133    struct
134    {
135       double         width;
136       double         height;
137    } fill;
138
139    Eina_Bool         play         : 1;
140    Eina_Bool         play_started : 1;
141    Eina_Bool         video_mute   : 1;
142    Eina_Bool         audio_mute   : 1;
143    Eina_Bool         pipeline_parsed : 1;
144    Eina_Bool         delete_me    : 1;
145    Eina_Bool         samsung      : 1;
146    Eina_Bool         kill_buffer  : 1;
147    Eina_Bool         stream       : 1;
148    Eina_Bool         priority     : 1;
149 };
150
151 struct _EvasVideoSink {
152     /*< private >*/
153     GstVideoSink parent;
154     EvasVideoSinkPrivate *priv;
155 };
156
157 struct _EvasVideoSinkClass {
158     /*< private >*/
159     GstVideoSinkClass parent_class;
160 };
161
162 struct _EvasVideoSinkPrivate {
163    EINA_REFCOUNT;
164
165    Evas_Object *o;
166
167    Emotion_Gstreamer_Video *ev;
168
169    Evas_Video_Convert_Cb func;
170
171    unsigned int width;
172    unsigned int height;
173    unsigned int source_height;
174    Evas_Colorspace eformat;
175
176    Eina_Lock m;
177    Eina_Condition c;
178
179    // If this is TRUE all processing should finish ASAP
180    // This is necessary because there could be a race between
181    // unlock() and render(), where unlock() wins, signals the
182    // GCond, then render() tries to render a frame although
183    // everything else isn't running anymore. This will lead
184    // to deadlocks because render() holds the stream lock.
185    //
186    // Protected by the buffer mutex
187    Eina_Bool unlocked : 1;
188    Eina_Bool samsung : 1; /** ST12 will only define a Samsung specific GstBuffer */
189 };
190
191 struct _Emotion_Gstreamer_Buffer
192 {
193    Emotion_Gstreamer_Video *ev;
194    EvasVideoSinkPrivate *sink;
195
196    GstBuffer *frame;
197
198    Eina_Bool preroll : 1;
199    Eina_Bool force : 1;
200 };
201
202 struct _Emotion_Gstreamer_Message
203 {
204    Emotion_Gstreamer_Video *ev;
205
206    GstMessage *msg;
207 };
208
209 extern Eina_Bool window_manager_video;
210 extern Eina_Bool debug_fps;
211 extern int _emotion_gstreamer_log_domain;
212 #define DBG(...) EINA_LOG_DOM_DBG(_emotion_gstreamer_log_domain, __VA_ARGS__)
213 #define INF(...) EINA_LOG_DOM_INFO(_emotion_gstreamer_log_domain, __VA_ARGS__)
214 #define WRN(...) EINA_LOG_DOM_WARN(_emotion_gstreamer_log_domain, __VA_ARGS__)
215 #define ERR(...) EINA_LOG_DOM_ERR(_emotion_gstreamer_log_domain, __VA_ARGS__)
216 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_emotion_gstreamer_log_domain, __VA_ARGS__)
217
218 #define EVAS_TYPE_VIDEO_SINK evas_video_sink_get_type()
219
220 GType fakeeos_bin_get_type(void);
221
222 #define EVAS_VIDEO_SINK(obj) \
223     (G_TYPE_CHECK_INSTANCE_CAST((obj), \
224     EVAS_TYPE_VIDEO_SINK, EvasVideoSink))
225
226 #define EVAS_VIDEO_SINK_CLASS(klass) \
227     (G_TYPE_CHECK_CLASS_CAST((klass), \
228     EVAS_TYPE_VIDEO_SINK, EvasVideoSinkClass))
229
230 #define EVAS_IS_VIDEO_SINK(obj) \
231     (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
232     EVAS_TYPE_VIDEO_SINK))
233
234 #define EVAS_IS_VIDEO_SINK_CLASS(klass) \
235     (G_TYPE_CHECK_CLASS_TYPE((klass), \
236     EVAS_TYPE_VIDEO_SINK))
237
238 #define EVAS_VIDEO_SINK_GET_CLASS(obj) \
239     (G_TYPE_INSTANCE_GET_CLASS((obj), \
240     EVAS_TYPE_VIDEO_SINK, EvasVideoSinkClass))
241
242 #define GST_TYPE_FAKEEOS_BIN fakeeos_bin_get_type()
243
244 GstElement *gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
245                                      Evas_Object *obj,
246                                      const char *uri);
247
248 gboolean    gstreamer_plugin_init(GstPlugin *plugin);
249
250 Emotion_Gstreamer_Buffer *emotion_gstreamer_buffer_alloc(EvasVideoSinkPrivate *sink,
251                                                          GstBuffer *buffer,
252                                                          Eina_Bool preroll);
253 void emotion_gstreamer_buffer_free(Emotion_Gstreamer_Buffer *send);
254
255 Emotion_Gstreamer_Message *emotion_gstreamer_message_alloc(Emotion_Gstreamer_Video *ev,
256                                                            GstMessage *msg);
257 void emotion_gstreamer_message_free(Emotion_Gstreamer_Message *send);
258 Eina_Bool _emotion_gstreamer_video_pipeline_parse(Emotion_Gstreamer_Video *ev,
259                                                   Eina_Bool force);
260
261 int em_shutdown(void *video);
262
263 typedef struct _ColorSpace_FourCC_Convertion ColorSpace_FourCC_Convertion;
264 typedef struct _ColorSpace_Format_Convertion ColorSpace_Format_Convertion;
265
266 struct _ColorSpace_FourCC_Convertion
267 {
268    const char *name;
269    guint32 fourcc;
270    Evas_Colorspace eformat;
271    Evas_Video_Convert_Cb func;
272    Eina_Bool force_height;
273 };
274
275 struct _ColorSpace_Format_Convertion
276 {
277    const char *name;
278    GstVideoFormat format;
279    Evas_Colorspace eformat;
280    Evas_Video_Convert_Cb func;
281 };
282
283 extern const ColorSpace_FourCC_Convertion colorspace_fourcc_convertion[];
284 extern const ColorSpace_Format_Convertion colorspace_format_convertion[];
285
286 /** Samsung specific infrastructure - do not touch, do not modify */
287 #define MPLANE_IMGB_MAX_COUNT 4
288 #define SCMN_IMGB_MAX_PLANE 4
289
290 typedef struct _GstMultiPlaneImageBuffer GstMultiPlaneImageBuffer;
291 typedef struct _SCMN_IMGB SCMN_IMGB;
292
293 struct _GstMultiPlaneImageBuffer
294 {
295    GstBuffer buffer;
296
297    /* width of each image plane */
298    gint      width[MPLANE_IMGB_MAX_COUNT];
299    /* height of each image plane */
300    gint      height[MPLANE_IMGB_MAX_COUNT];
301    /* stride of each image plane */
302    gint      stride[MPLANE_IMGB_MAX_COUNT];
303    /* elevation of each image plane */
304    gint      elevation[MPLANE_IMGB_MAX_COUNT];
305    /* user space address of each image plane */
306    gpointer uaddr[MPLANE_IMGB_MAX_COUNT];
307    /* Index of real address of each image plane, if needs */
308    gpointer index[MPLANE_IMGB_MAX_COUNT];
309    /* left postion, if needs */
310    gint      x;
311    /* top position, if needs */
312    gint      y;
313    /* to align memory */
314    gint      __dummy2;
315    /* arbitrary data */
316    gint      data[16];
317 };
318
319 struct _SCMN_IMGB
320 {
321    /* width of each image plane */
322    int      width[SCMN_IMGB_MAX_PLANE];
323    /* height of each image plane */
324    int      height[SCMN_IMGB_MAX_PLANE];
325    /* stride of each image plane */
326    int      stride[SCMN_IMGB_MAX_PLANE];
327    /* elevation of each image plane */
328    int      elevation[SCMN_IMGB_MAX_PLANE];
329    /* user space address of each image plane */
330    void   * uaddr[SCMN_IMGB_MAX_PLANE];
331    /* physical address of each image plane, if needs */
332    void   * p[SCMN_IMGB_MAX_PLANE];
333    /* color space type of image */
334    int      cs;
335    /* left postion, if needs */
336    int      x;
337    /* top position, if needs */
338    int      y;
339    /* to align memory */
340    int      __dummy2;
341    /* arbitrary data */
342    int      data[16];
343 };
344
345 void _evas_video_st12_multiplane(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__);
346 void _evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w __UNUSED__, unsigned int h, unsigned int output_height __UNUSED__);
347
348 #endif /* __EMOTION_GSTREAMER_H__ */