cc0fe49fbef3ed5324d523469ee73c20dc39343d
[profile/ivi/emotion.git] / src / modules / gstreamer / emotion_sink.c
1 #include "emotion_gstreamer.h"
2
3 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE("sink",
4                                                                    GST_PAD_SINK, GST_PAD_ALWAYS,
5                                                                    GST_STATIC_CAPS(GST_VIDEO_CAPS_YUV("{ I420, YV12, YUY2, NV12, ST12, TM12 }") ";"
6                                                                                    GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_BGR ";" GST_VIDEO_CAPS_BGRA));
7
8 GST_DEBUG_CATEGORY_STATIC(evas_video_sink_debug);
9 #define GST_CAT_DEFAULT evas_video_sink_debug
10
11 enum {
12   REPAINT_REQUESTED,
13   LAST_SIGNAL
14 };
15
16 enum {
17   PROP_0,
18   PROP_EVAS_OBJECT,
19   PROP_WIDTH,
20   PROP_HEIGHT,
21   PROP_EV,
22   PROP_LAST
23 };
24
25 static guint evas_video_sink_signals[LAST_SIGNAL] = { 0, };
26
27 #define _do_init(bla)                                   \
28   GST_DEBUG_CATEGORY_INIT(evas_video_sink_debug,        \
29                           "emotion-sink",               \
30                           0,                            \
31                           "emotion video sink")
32
33 GST_BOILERPLATE_FULL(EvasVideoSink,
34                      evas_video_sink,
35                      GstVideoSink,
36                      GST_TYPE_VIDEO_SINK,
37                      _do_init);
38
39
40 static void unlock_buffer_mutex(EvasVideoSinkPrivate* priv);
41 static void evas_video_sink_main_render(void *data);
42 static void evas_video_sink_samsung_main_render(void *data);
43
44 static void
45 _evas_video_bgrx_step(unsigned char *evas_data, const unsigned char *gst_data,
46                       unsigned int w, unsigned int h __UNUSED__, unsigned int output_height, unsigned int step)
47 {
48    unsigned int x;
49    unsigned int y;
50
51    for (y = 0; y < output_height; ++y)
52      {
53         for (x = 0; x < w; x++)
54           {
55              evas_data[0] = gst_data[0];
56              evas_data[1] = gst_data[1];
57              evas_data[2] = gst_data[2];
58              evas_data[3] = 255;
59              gst_data += step;
60              evas_data += 4;
61           }
62      }
63 }
64
65 static void
66 _evas_video_bgr(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
67 {
68    _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 3);
69 }
70
71 static void
72 _evas_video_bgrx(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
73 {
74    _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 4);
75 }
76
77 static void
78 _evas_video_bgra(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
79 {
80    unsigned int x;
81    unsigned int y;
82
83    for (y = 0; y < output_height; ++y)
84      {
85         unsigned char alpha;
86
87         for (x = 0; x < w; ++x)
88           {
89              alpha = gst_data[3];
90              evas_data[0] = (gst_data[0] * alpha) / 255;
91              evas_data[1] = (gst_data[1] * alpha) / 255;
92              evas_data[2] = (gst_data[2] * alpha) / 255;
93              evas_data[3] = alpha;
94              gst_data += 4;
95              evas_data += 4;
96           }
97      }
98 }
99
100 static void
101 _evas_video_i420(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
102 {
103    const unsigned char **rows;
104    unsigned int i, j;
105    unsigned int rh;
106
107    rh = output_height;
108
109    rows = (const unsigned char **)evas_data;
110
111    for (i = 0; i < rh; i++)
112      rows[i] = &gst_data[i * w];
113
114    for (j = 0; j < (rh / 2); j++, i++)
115      rows[i] = &gst_data[h * w + j * (w / 2)];
116
117    for (j = 0; j < (rh / 2); j++, i++)
118      rows[i] = &gst_data[h * w + rh * (w / 4) + j * (w / 2)];
119 }
120
121 static void
122 _evas_video_yv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
123 {
124    const unsigned char **rows;
125    unsigned int i, j;
126    unsigned int rh;
127
128    rh = output_height;
129
130    rows = (const unsigned char **)evas_data;
131
132    for (i = 0; i < rh; i++)
133      rows[i] = &gst_data[i * w];
134
135    for (j = 0; j < (rh / 2); j++, i++)
136      rows[i] = &gst_data[h * w + rh * (w / 4) + j * (w / 2)];
137
138    for (j = 0; j < (rh / 2); j++, i++)
139      rows[i] = &gst_data[h * w + j * (w / 2)];
140 }
141
142 static void
143 _evas_video_yuy2(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
144 {
145    const unsigned char **rows;
146    unsigned int i;
147
148    rows = (const unsigned char **)evas_data;
149
150    for (i = 0; i < output_height; i++)
151      rows[i] = &gst_data[i * w * 2];
152 }
153
154 static void
155 _evas_video_nv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
156 {
157    const unsigned char **rows;
158    unsigned int i, j;
159    unsigned int rh;
160
161    rh = output_height;
162
163    rows = (const unsigned char **)evas_data;
164
165    for (i = 0; i < rh; i++)
166      rows[i] = &gst_data[i * w];
167
168    for (j = 0; j < (rh / 2); j++, i++)
169      rows[i] = &gst_data[rh * w + j * w];
170 }
171
172 static void
173 _evas_video_mt12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
174 {
175    const unsigned char **rows;
176    unsigned int i;
177    unsigned int j;
178
179    rows = (const unsigned char **)evas_data;
180
181    for (i = 0; i < (h / 32) / 2; i++)
182      rows[i] = &gst_data[i * w * 2 * 32];
183
184    if ((h / 32) % 2)
185      {
186         rows[i] = &gst_data[i * w * 2 * 32];
187         i++;
188      }
189
190    for (j = 0; j < ((h / 2) / 32) / 2; ++j, ++i)
191      rows[i] = &gst_data[h * w + j * (w / 2) * 2 * 16];
192 }
193
194 static void
195 _evas_video_st12_multiplane(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
196 {
197    const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) gst_data;
198    const unsigned char **rows;
199    unsigned int i;
200    unsigned int j;
201
202    rows = (const unsigned char **)evas_data;
203
204    for (i = 0; i < (h / 32) / 2; i++)
205      rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
206    if ((h / 32) % 2)
207      {
208         rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
209         i++;
210      }
211
212    for (j = 0; j < ((h / 2) / 16) / 2; j++, i++)
213      {
214        rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2;
215      }
216    if (((h / 2) / 16) % 2)
217      rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2;
218 }
219
220 static void
221 _evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w __UNUSED__, unsigned int h, unsigned int output_height __UNUSED__)
222 {
223    const SCMN_IMGB *imgb = (const SCMN_IMGB *) gst_data;
224    const unsigned char **rows;
225    unsigned int i, j;
226
227    rows = (const unsigned char **)evas_data;
228
229    for (i = 0; i < (h / 32) / 2; i++)
230      rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32;
231    if ((h / 32) % 2)
232      {
233         rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32;
234         i++;
235      }
236
237    for (j = 0; j < (unsigned int) imgb->elevation[1] / 32 / 2; j++, i++)
238      rows[i] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2;
239    if ((imgb->elevation[1] / 32) % 2)
240      rows[i++] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2;
241 }
242
243 static const struct {
244    const char *name;
245    guint32 fourcc;
246    Evas_Colorspace eformat;
247    Evas_Video_Convert_Cb func;
248    Eina_Bool force_height;
249 } colorspace_fourcc_convertion[] = {
250   { "I420", GST_MAKE_FOURCC('I', '4', '2', '0'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420, EINA_TRUE },
251   { "YV12", GST_MAKE_FOURCC('Y', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12, EINA_TRUE },
252   { "YUY2", GST_MAKE_FOURCC('Y', 'U', 'Y', '2'), EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2, EINA_FALSE },
253   { "NV12", GST_MAKE_FOURCC('N', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE },
254   { "TM12", GST_MAKE_FOURCC('T', 'M', '1', '2'), EVAS_COLORSPACE_YCBCR420TM12601_PL, _evas_video_mt12, EINA_TRUE }
255 };
256
257 static const struct {
258    const char *name;
259    GstVideoFormat format;
260    Evas_Colorspace eformat;
261    Evas_Video_Convert_Cb func;
262 } colorspace_format_convertion[] = {
263   { "BGR", GST_VIDEO_FORMAT_BGR, EVAS_COLORSPACE_ARGB8888, _evas_video_bgr },
264   { "BGRx", GST_VIDEO_FORMAT_BGRx, EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx },
265   { "BGRA", GST_VIDEO_FORMAT_BGRA, EVAS_COLORSPACE_ARGB8888, _evas_video_bgra }
266 };
267
268 static void
269 evas_video_sink_base_init(gpointer g_class)
270 {
271    GstElementClass* element_class;
272
273    element_class = GST_ELEMENT_CLASS(g_class);
274    gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&sinktemplate));
275    gst_element_class_set_details_simple(element_class, "Evas video sink",
276                                         "Sink/Video", "Sends video data from a GStreamer pipeline to an Evas object",
277                                         "Vincent Torri <vtorri@univ-evry.fr>");
278 }
279
280 static void
281 evas_video_sink_init(EvasVideoSink* sink, EvasVideoSinkClass* klass __UNUSED__)
282 {
283    EvasVideoSinkPrivate* priv;
284
285    INF("sink init");
286    sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(sink, EVAS_TYPE_VIDEO_SINK, EvasVideoSinkPrivate);
287    priv->o = NULL;
288    priv->width = 0;
289    priv->height = 0;
290    priv->func = NULL;
291    priv->eformat = EVAS_COLORSPACE_ARGB8888;
292    priv->samsung = EINA_FALSE;
293    eina_lock_new(&priv->m);
294    eina_condition_new(&priv->c, &priv->m);
295    priv->unlocked = EINA_FALSE;
296 }
297
298 /**** Object methods ****/
299 static void
300 _cleanup_priv(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
301 {
302    EvasVideoSinkPrivate* priv;
303
304    priv = data;
305
306    eina_lock_take(&priv->m);
307    if (priv->o == obj)
308      priv->o = NULL;
309    eina_lock_release(&priv->m);
310 }
311
312 static void
313 evas_video_sink_set_property(GObject * object, guint prop_id,
314                              const GValue * value, GParamSpec * pspec)
315 {
316    EvasVideoSink* sink;
317    EvasVideoSinkPrivate* priv;
318
319    sink = EVAS_VIDEO_SINK (object);
320    priv = sink->priv;
321
322    switch (prop_id) {
323     case PROP_EVAS_OBJECT:
324        eina_lock_take(&priv->m);
325        evas_object_event_callback_del(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv);
326        priv->o = g_value_get_pointer (value);
327        INF("sink set Evas_Object %p.", priv->o);
328        evas_object_event_callback_add(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv, priv);
329        eina_lock_release(&priv->m);
330        break;
331     case PROP_EV:
332        INF("sink set ev.");
333        eina_lock_take(&priv->m);
334        priv->ev = g_value_get_pointer (value);
335        if (priv->ev)
336          priv->ev->samsung = EINA_TRUE;
337        eina_lock_release(&priv->m);
338        break;
339     default:
340        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
341        ERR("invalid property");
342        break;
343    }
344 }
345
346 static void
347 evas_video_sink_get_property(GObject * object, guint prop_id,
348                              GValue * value, GParamSpec * pspec)
349 {
350    EvasVideoSink* sink;
351    EvasVideoSinkPrivate* priv;
352
353    sink = EVAS_VIDEO_SINK (object);
354    priv = sink->priv;
355
356    switch (prop_id) {
357     case PROP_EVAS_OBJECT:
358        INF("sink get property.");
359        eina_lock_take(&priv->m);
360        g_value_set_pointer(value, priv->o);
361        eina_lock_release(&priv->m);
362        break;
363     case PROP_WIDTH:
364        INF("sink get width.");
365        eina_lock_take(&priv->m);
366        g_value_set_int(value, priv->width);
367        eina_lock_release(&priv->m);
368        break;
369     case PROP_HEIGHT:
370        INF("sink get height.");
371        eina_lock_take(&priv->m);
372        g_value_set_int (value, priv->height);
373        eina_lock_release(&priv->m);
374        break;
375     case PROP_EV:
376        INF("sink get ev.");
377        eina_lock_take(&priv->m);
378        g_value_set_pointer (value, priv->ev);
379        eina_lock_release(&priv->m);
380        break;
381     default:
382        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
383        ERR("invalide property");
384        break;
385    }
386 }
387
388 static void
389 evas_video_sink_dispose(GObject* object)
390 {
391    EvasVideoSink* sink;
392    EvasVideoSinkPrivate* priv;
393
394    INF("dispose.");
395
396    sink = EVAS_VIDEO_SINK(object);
397    priv = sink->priv;
398
399    eina_lock_free(&priv->m);
400    eina_condition_free(&priv->c);
401
402    G_OBJECT_CLASS(parent_class)->dispose(object);
403 }
404
405
406 /**** BaseSink methods ****/
407
408 gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps)
409 {
410    EvasVideoSink* sink;
411    EvasVideoSinkPrivate* priv;
412    GstStructure *structure;
413    GstVideoFormat format;
414    guint32 fourcc;
415    unsigned int i;
416
417    sink = EVAS_VIDEO_SINK(bsink);
418    priv = sink->priv;
419
420    structure = gst_caps_get_structure(caps, 0);
421
422    if (gst_structure_get_int(structure, "width", (int*) &priv->width)
423        && gst_structure_get_int(structure, "height", (int*) &priv->height)
424        && gst_structure_get_fourcc(structure, "format", &fourcc))
425      {
426         priv->source_height = priv->height;
427
428         for (i = 0; i < sizeof (colorspace_fourcc_convertion) / sizeof (colorspace_fourcc_convertion[0]); ++i)
429           if (fourcc == colorspace_fourcc_convertion[i].fourcc)
430             {
431                fprintf(stderr, "Found '%s'\n", colorspace_fourcc_convertion[i].name);
432                priv->eformat = colorspace_fourcc_convertion[i].eformat;
433                priv->func = colorspace_fourcc_convertion[i].func;
434                if (colorspace_fourcc_convertion[i].force_height)
435                  {
436                     priv->height = (priv->height >> 1) << 1;
437                  }
438                if (priv->ev)
439                  priv->ev->kill_buffer = EINA_TRUE;
440                return TRUE;
441             }
442
443         if (fourcc == GST_MAKE_FOURCC('S', 'T', '1', '2'))
444           {
445              fprintf(stderr, "Found '%s'\n", "ST12");
446              priv->eformat = EVAS_COLORSPACE_YCBCR420TM12601_PL;
447              priv->samsung = EINA_TRUE;
448              priv->func = NULL;
449              if (priv->ev)
450                {
451                   priv->ev->samsung = EINA_TRUE;
452                   priv->ev->kill_buffer = EINA_TRUE;
453                }
454              return TRUE;
455           }
456      }
457
458    INF("fallback code !");
459    if (!gst_video_format_parse_caps(caps, &format, (int*) &priv->width, (int*) &priv->height))
460      {
461         ERR("Unable to parse caps.");
462         return FALSE;
463      }
464
465    priv->source_height = priv->height;
466
467    for (i = 0; i < sizeof (colorspace_format_convertion) / sizeof (colorspace_format_convertion[0]); ++i)
468      if (format == colorspace_format_convertion[i].format)
469        {
470           fprintf(stderr, "Found '%s'\n", colorspace_format_convertion[i].name);
471           priv->eformat = colorspace_format_convertion[i].eformat;
472           priv->func = colorspace_format_convertion[i].func;
473           if (priv->ev)
474             priv->ev->kill_buffer = EINA_FALSE;
475           return TRUE;
476        }
477
478    ERR("unsupported : %d\n", format);
479    return FALSE;
480 }
481
482 static gboolean
483 evas_video_sink_start(GstBaseSink* base_sink)
484 {
485    EvasVideoSinkPrivate* priv;
486    gboolean res = TRUE;
487
488    INF("sink start");
489
490    priv = EVAS_VIDEO_SINK(base_sink)->priv;
491    eina_lock_take(&priv->m);
492    if (!priv->o)
493      res = FALSE;
494    else
495      priv->unlocked = EINA_FALSE;
496    eina_lock_release(&priv->m);
497    return res;
498 }
499
500 static gboolean
501 evas_video_sink_stop(GstBaseSink* base_sink)
502 {
503    EvasVideoSinkPrivate* priv = EVAS_VIDEO_SINK(base_sink)->priv;
504
505    INF("sink stop");
506
507    unlock_buffer_mutex(priv);
508    return TRUE;
509 }
510
511 static gboolean
512 evas_video_sink_unlock(GstBaseSink* object)
513 {
514    EvasVideoSink* sink;
515
516    INF("sink unlock");
517
518    sink = EVAS_VIDEO_SINK(object);
519
520    unlock_buffer_mutex(sink->priv);
521
522    return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock,
523                                        (object), TRUE);
524 }
525
526 static gboolean
527 evas_video_sink_unlock_stop(GstBaseSink* object)
528 {
529    EvasVideoSink* sink;
530    EvasVideoSinkPrivate* priv;
531
532    sink = EVAS_VIDEO_SINK(object);
533    priv = sink->priv;
534
535    INF("sink unlock stop");
536
537    eina_lock_take(&priv->m);
538    priv->unlocked = FALSE;
539    eina_lock_release(&priv->m);
540
541    return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock_stop,
542                                        (object), TRUE);
543 }
544
545 static GstFlowReturn
546 evas_video_sink_preroll(GstBaseSink* bsink, GstBuffer* buffer)
547 {
548    Emotion_Gstreamer_Buffer *send;
549    EvasVideoSinkPrivate *priv;
550    EvasVideoSink *sink;
551
552    INF("sink preroll %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
553
554    sink = EVAS_VIDEO_SINK(bsink);
555    priv = sink->priv;
556
557    if (GST_BUFFER_SIZE(buffer) <= 0 && !priv->samsung)
558      {
559         WRN("empty buffer");
560         return GST_FLOW_OK;
561      }
562
563    send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_TRUE);
564
565    if (send)
566      {
567         if (priv->samsung)
568           {
569              if (!priv->func)
570                {
571                   GstStructure *structure;
572                   GstCaps *caps;
573                   gboolean is_multiplane = FALSE;
574
575                   caps = GST_BUFFER_CAPS(buffer);
576                   structure = gst_caps_get_structure (caps, 0);
577                   gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
578                   gst_caps_unref(caps);
579
580                   if (is_multiplane)
581                     priv->func = _evas_video_st12_multiplane;
582                   else
583                     priv->func = _evas_video_st12;
584                }
585
586              ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
587           }
588         else
589           ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
590      }
591
592    return GST_FLOW_OK;
593 }
594
595 static GstFlowReturn
596 evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer)
597 {
598    Emotion_Gstreamer_Buffer *send;
599    EvasVideoSinkPrivate *priv;
600    EvasVideoSink *sink;
601
602    INF("sink render %p", buffer);
603
604    sink = EVAS_VIDEO_SINK(bsink);
605    priv = sink->priv;
606
607    eina_lock_take(&priv->m);
608
609    if (priv->unlocked) {
610       ERR("LOCKED");
611       eina_lock_release(&priv->m);
612       return GST_FLOW_OK;
613    }
614
615    send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_FALSE);
616    if (!send) {
617       eina_lock_release(&priv->m);
618       return GST_FLOW_ERROR;
619    }
620
621    if (priv->samsung)
622      {
623         if (!priv->func)
624           {
625              GstStructure *structure;
626              GstCaps *caps;
627              gboolean is_multiplane = FALSE;
628
629              caps = GST_BUFFER_CAPS(buffer);
630              structure = gst_caps_get_structure (caps, 0);
631              gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
632              gst_caps_unref(caps);
633
634              if (is_multiplane)
635                priv->func = _evas_video_st12_multiplane;
636              else
637                priv->func = _evas_video_st12;
638           }
639
640         ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
641      }
642    else
643      ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
644
645    eina_condition_wait(&priv->c);
646    eina_lock_release(&priv->m);
647
648    return GST_FLOW_OK;
649 }
650
651 static void
652 _update_emotion_fps(Emotion_Gstreamer_Video *ev)
653 {
654    double tim;
655
656    if (!debug_fps) return ;
657
658    tim = ecore_time_get();
659    ev->frames++;
660
661    if (ev->rlapse == 0.0)
662      {
663         ev->rlapse = tim;
664         ev->flapse = ev->frames;
665      }
666    else if ((tim - ev->rlapse) >= 0.5)
667      {
668         printf("FRAME: %i, FPS: %3.1f\n",
669                ev->frames,
670                (ev->frames - ev->flapse) / (tim - ev->rlapse));
671         ev->rlapse = tim;
672         ev->flapse = ev->frames;
673      }
674 }
675
676 static void
677 evas_video_sink_samsung_main_render(void *data)
678 {
679    Emotion_Gstreamer_Buffer *send;
680    Emotion_Video_Stream *vstream;
681    EvasVideoSinkPrivate* priv;
682    GstBuffer* buffer;
683    unsigned char *evas_data;
684    const guint8 *gst_data;
685    GstFormat fmt = GST_FORMAT_TIME;
686    gint64 pos;
687    Eina_Bool preroll;
688    int stride, elevation;
689    Evas_Coord w, h;
690
691    send = data;
692
693    if (!send) goto exit_point;
694
695    priv = send->sink;
696    buffer = send->frame;
697    preroll = send->preroll;
698
699    if (!priv || !priv->o || priv->unlocked)
700      goto exit_point;
701
702    if (!send->ev->stream && !send->force)
703      {
704         if (send->ev->send)
705           emotion_gstreamer_buffer_free(send->ev->send);
706         send->ev->send = send;
707         goto exit_stream;
708      }
709
710    _emotion_gstreamer_video_pipeline_parse(send->ev, EINA_TRUE);
711
712    /* Getting stride to compute the right size and then fill the object properly */
713    /* Y => [0] and UV in [1] */
714    if (priv->func == _evas_video_st12_multiplane)
715      {
716         const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) buffer;
717
718         stride = mp_buf->stride[0];
719         elevation = mp_buf->elevation[0];
720         priv->width = mp_buf->width[0];
721         priv->height = mp_buf->height[0];
722
723         gst_data = (const guint8 *) mp_buf;
724      }
725    else
726      {
727         const SCMN_IMGB *imgb = (const SCMN_IMGB *) GST_BUFFER_MALLOCDATA(buffer);
728
729         stride = imgb->stride[0];
730         elevation = imgb->elevation[0];
731         priv->width = imgb->width[0];
732         priv->height = imgb->height[0];
733
734         gst_data = (const guint8 *) imgb;
735      }
736
737    evas_object_geometry_get(priv->o, NULL, NULL, &w, &h);
738
739    send->ev->fill.width = stride * w / priv->width;
740    send->ev->fill.height = elevation * h / priv->height;
741
742    evas_object_image_alpha_set(priv->o, 0);
743    evas_object_image_colorspace_set(priv->o, priv->eformat);
744    evas_object_image_size_set(priv->o, stride, elevation);
745    evas_object_image_fill_set(priv->o, 0, 0, send->ev->fill.width, send->ev->fill.height);
746
747    _update_emotion_fps(send->ev);
748
749    evas_data = evas_object_image_data_get(priv->o, 1);
750
751    if (priv->func)
752      priv->func(evas_data, gst_data, stride, elevation, elevation);
753    else
754      WRN("No way to decode %x colorspace !", priv->eformat);
755
756    evas_object_image_data_set(priv->o, evas_data);
757    evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
758    evas_object_image_pixels_dirty_set(priv->o, 0);
759
760    if (!preroll && send->ev->play_started)
761      {
762         _emotion_playback_started(send->ev->obj);
763         send->ev->play_started = 0;
764      }
765
766    _emotion_frame_new(send->ev->obj);
767
768    vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1);
769
770    gst_element_query_position(send->ev->pipeline, &fmt, &pos);
771    send->ev->position = (double)pos / (double)GST_SECOND;
772
773    if (vstream)
774      {
775         vstream->width = priv->width;
776         vstream->height = priv->height;
777
778         _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time);
779      }
780
781    send->ev->ratio = (double) priv->width / (double) priv->height;
782    _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio);
783
784    /* FIXME: why is last buffer not protected ? */
785
786  exit_point:
787    emotion_gstreamer_buffer_free(send);
788
789  exit_stream:
790    if (preroll || !priv->o) return ;
791
792    if (!priv->unlocked)
793      eina_condition_signal(&priv->c);
794 }
795
796 static void
797 evas_video_sink_main_render(void *data)
798 {
799    Emotion_Gstreamer_Buffer *send;
800    Emotion_Gstreamer_Video *ev = NULL;
801    Emotion_Video_Stream *vstream;
802    EvasVideoSinkPrivate* priv;
803    GstBuffer* buffer;
804    unsigned char *evas_data;
805    GstFormat fmt = GST_FORMAT_TIME;
806    gint64 pos;
807    Eina_Bool preroll;
808
809    send = data;
810
811    if (!send) goto exit_point;
812
813    priv = send->sink;
814    buffer = send->frame;
815    preroll = send->preroll;
816    ev = send->ev;
817
818    if (!priv || !priv->o || priv->unlocked)
819      goto exit_point;
820
821    if (!ev->stream && !send->force)
822      {
823         if (ev->send)
824           emotion_gstreamer_buffer_free(ev->send);
825         ev->send = send;
826         evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
827         goto exit_stream;
828      }
829
830    _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE);
831
832    INF("sink main render [%i, %i] (source height: %i)", priv->width, priv->height, priv->source_height);
833
834    evas_object_image_alpha_set(priv->o, 0);
835    evas_object_image_colorspace_set(priv->o, priv->eformat);
836    evas_object_image_size_set(priv->o, priv->width, priv->height);
837
838    evas_data = evas_object_image_data_get(priv->o, 1);
839
840    if (priv->func)
841      priv->func(evas_data, GST_BUFFER_DATA(buffer), priv->width, priv->source_height, priv->height);
842    else
843      WRN("No way to decode %x colorspace !", priv->eformat);
844
845    evas_object_image_data_set(priv->o, evas_data);
846    evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
847    evas_object_image_pixels_dirty_set(priv->o, 0);
848
849    if (!preroll && ev->play_started)
850      {
851         _emotion_playback_started(ev->obj);
852         ev->play_started = 0;
853      }
854
855    _emotion_frame_new(ev->obj);
856
857    gst_element_query_position(ev->pipeline, &fmt, &pos);
858    ev->position = (double)pos / (double)GST_SECOND;
859
860    vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
861
862    if (vstream)
863      {
864        vstream->width = priv->width;
865        vstream->height = priv->height;
866        _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
867      }
868
869    ev->ratio = (double) priv->width / (double) priv->height;
870
871    _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
872
873    buffer = gst_buffer_ref(buffer);
874    if (ev->last_buffer) gst_buffer_unref(ev->last_buffer);
875    ev->last_buffer = buffer;
876
877  exit_point:
878    emotion_gstreamer_buffer_free(send);
879
880  exit_stream:
881    if (preroll || !priv->o) return ;
882
883    if (!priv->unlocked)
884      eina_condition_signal(&priv->c);
885 }
886
887 static void
888 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
889 {
890    priv->unlocked = EINA_TRUE;
891
892    eina_condition_signal(&priv->c);
893 }
894
895 static void
896 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
897                          guint n_param_values, const GValue * param_values,
898                          gpointer invocation_hint __UNUSED__, gpointer marshal_data)
899 {
900    typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
901    marshalfunc_VOID__MINIOBJECT callback;
902    GCClosure *cc;
903    gpointer data1, data2;
904
905    cc = (GCClosure *) closure;
906
907    g_return_if_fail(n_param_values == 2);
908
909    if (G_CCLOSURE_SWAP_DATA(closure)) {
910       data1 = closure->data;
911       data2 = g_value_peek_pointer(param_values + 0);
912    } else {
913       data1 = g_value_peek_pointer(param_values + 0);
914       data2 = closure->data;
915    }
916    callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
917
918    callback(data1, gst_value_get_mini_object(param_values + 1), data2);
919 }
920
921 static void
922 evas_video_sink_class_init(EvasVideoSinkClass* klass)
923 {
924    GObjectClass* gobject_class;
925    GstBaseSinkClass* gstbase_sink_class;
926
927    gobject_class = G_OBJECT_CLASS(klass);
928    gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
929
930    g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
931
932    gobject_class->set_property = evas_video_sink_set_property;
933    gobject_class->get_property = evas_video_sink_get_property;
934
935    g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
936                                     g_param_spec_pointer ("evas-object", "Evas Object",
937                                                           "The Evas object where the display of the video will be done",
938                                                           G_PARAM_READWRITE));
939
940    g_object_class_install_property (gobject_class, PROP_WIDTH,
941                                     g_param_spec_int ("width", "Width",
942                                                       "The width of the video",
943                                                       0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
944
945    g_object_class_install_property (gobject_class, PROP_HEIGHT,
946                                     g_param_spec_int ("height", "Height",
947                                                       "The height of the video",
948                                                       0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
949    g_object_class_install_property (gobject_class, PROP_EV,
950                                     g_param_spec_pointer ("ev", "Emotion_Gstreamer_Video",
951                                                           "THe internal data of the emotion object",
952                                                           G_PARAM_READWRITE));
953
954    gobject_class->dispose = evas_video_sink_dispose;
955
956    gstbase_sink_class->set_caps = evas_video_sink_set_caps;
957    gstbase_sink_class->stop = evas_video_sink_stop;
958    gstbase_sink_class->start = evas_video_sink_start;
959    gstbase_sink_class->unlock = evas_video_sink_unlock;
960    gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
961    gstbase_sink_class->render = evas_video_sink_render;
962    gstbase_sink_class->preroll = evas_video_sink_preroll;
963
964    evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
965                                                              G_TYPE_FROM_CLASS(klass),
966                                                              (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
967                                                              0,
968                                                              0,
969                                                              0,
970                                                              marshal_VOID__MINIOBJECT,
971                                                              G_TYPE_NONE, 1, GST_TYPE_BUFFER);
972 }
973
974 gboolean
975 gstreamer_plugin_init (GstPlugin * plugin)
976 {
977    return gst_element_register (plugin,
978                                 "emotion-sink",
979                                 GST_RANK_NONE,
980                                 EVAS_TYPE_VIDEO_SINK);
981 }
982
983 static void
984 _emotion_gstreamer_pause(void *data, Ecore_Thread *thread)
985 {
986    Emotion_Gstreamer_Video *ev = data;
987    gboolean res;
988
989    if (ecore_thread_check(thread) || !ev->pipeline) return ;
990
991    gst_element_set_state(ev->pipeline, GST_STATE_PAUSED);
992    res = gst_element_get_state(ev->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
993    if (res == GST_STATE_CHANGE_NO_PREROLL)
994      {
995         gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
996         gst_element_get_state(ev->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
997      }
998 }
999
1000 static void
1001 _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread)
1002 {
1003    Emotion_Gstreamer_Video *ev = data;
1004
1005    ev->threads = eina_list_remove(ev->threads, thread);
1006
1007    if (getenv("EMOTION_GSTREAMER_DOT")) GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(ev->pipeline), GST_DEBUG_GRAPH_SHOW_ALL, getenv("EMOTION_GSTREAMER_DOT"));
1008
1009    if (ev->in == ev->out && ev->delete_me)
1010      em_shutdown(ev);
1011 }
1012
1013 static void
1014 _emotion_gstreamer_end(void *data, Ecore_Thread *thread)
1015 {
1016    Emotion_Gstreamer_Video *ev = data;
1017
1018    ev->threads = eina_list_remove(ev->threads, thread);
1019
1020    if (ev->play)
1021      {
1022         gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
1023         ev->play_started = 1;
1024      }
1025
1026    if (getenv("EMOTION_GSTREAMER_DOT")) GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(ev->pipeline), GST_DEBUG_GRAPH_SHOW_ALL, getenv("EMOTION_GSTREAMER_DOT"));
1027
1028    if (ev->in == ev->out && ev->delete_me)
1029      em_shutdown(ev);
1030    else
1031      _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE);
1032 }
1033
1034 static void
1035 _on_resize_fill(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1036 {
1037    Emotion_Gstreamer_Video *ev = data;
1038
1039    if (ev->samsung)
1040      evas_object_image_fill_set(obj, 0, 0, ev->fill.width, ev->fill.height);
1041 }
1042
1043 static void
1044 _video_resize(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__,
1045               Evas_Coord w, Evas_Coord h)
1046 {
1047    Emotion_Gstreamer_Video *ev = data;
1048
1049    ecore_x_window_resize(ev->win, w, h);
1050    fprintf(stderr, "resize: %i, %i\n", w, h);
1051 }
1052
1053 static void
1054 _video_move(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__,
1055             Evas_Coord x, Evas_Coord y)
1056 {
1057    Emotion_Gstreamer_Video *ev = data;
1058
1059    fprintf(stderr, "move: %i, %i\n", x, y);
1060    ecore_x_window_move(ev->win, x, y);
1061 }
1062
1063 #if 0
1064 /* Much better idea to always feed the XvImageSink and let him handle optimizing the rendering as we do */
1065 static void
1066 _block_pad_unlink_cb(GstPad *pad, gboolean blocked, gpointer user_data)
1067 {
1068    if (blocked)
1069      {
1070         Emotion_Gstreamer_Video *ev = user_data;
1071         GstEvent *gev;
1072
1073         gst_pad_unlink(ev->teepad, ev->xvpad);
1074         gev = gst_event_new_eos();
1075         gst_pad_send_event(ev->xvpad, gev);
1076         gst_pad_set_blocked_async(pad, FALSE, _block_pad_unlink_cb, NULL);
1077      }
1078 }
1079
1080 static void
1081 _block_pad_link_cb(GstPad *pad, gboolean blocked, gpointer user_data)
1082 {
1083    if (blocked)
1084      {
1085         Emotion_Gstreamer_Video *ev = user_data;
1086
1087         gst_pad_link(ev->teepad, ev->xvpad);
1088         if (ev->play)
1089           gst_element_set_state(ev->xvsink, GST_STATE_PLAYING);
1090         else
1091           gst_element_set_state(ev->xvsink, GST_STATE_PAUSED);
1092         gst_pad_set_blocked_async(pad, FALSE, _block_pad_link_cb, NULL);
1093      }
1094 }
1095 #endif
1096
1097 static void
1098 _video_show(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__)
1099 {
1100    Emotion_Gstreamer_Video *ev = data;
1101
1102    ecore_x_window_show(ev->win);
1103    /* gst_pad_set_blocked_async(ev->teepad, TRUE, _block_pad_link_cb, ev); */
1104 }
1105
1106 static void
1107 _video_hide(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__)
1108 {
1109    Emotion_Gstreamer_Video *ev = data;
1110
1111    ecore_x_window_hide(ev->win);
1112    /* gst_pad_set_blocked_async(ev->teepad, TRUE, _block_pad_unlink_cb, ev); */
1113 }
1114
1115 static void
1116 _video_update_pixels(void *data, Evas_Object *obj, const Evas_Video_Surface *surface __UNUSED__)
1117 {
1118    Emotion_Gstreamer_Video *ev = data;
1119
1120    if (!ev->send) return ;
1121
1122    ev->send->force = EINA_TRUE;
1123    evas_video_sink_main_render(ev->send);
1124    ev->send = NULL;
1125 }
1126
1127 GstElement *
1128 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
1129                          Evas_Object *o,
1130                          const char *uri)
1131 {
1132    GstElement *playbin;
1133    GstElement *bin = NULL;
1134    GstElement *esink = NULL;
1135    GstElement *xvsink = NULL;
1136    GstElement *tee = NULL;
1137    GstElement *queue = NULL;
1138    Evas_Object *obj;
1139    GstPad *pad;
1140    GstPad *teepad;
1141    int flags;
1142 #if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H
1143    const char *engine;
1144    Eina_List *engines;
1145 #endif
1146
1147    obj = emotion_object_image_get(o);
1148    if (!obj)
1149      {
1150         ERR("Not Evas_Object specified");
1151         return NULL;
1152      }
1153
1154    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev);
1155
1156    if (!uri)
1157      return NULL;
1158
1159    playbin = gst_element_factory_make("playbin2", "playbin");
1160    if (!playbin)
1161      {
1162         ERR("Unable to create 'playbin' GstElement.");
1163         return NULL;
1164      }
1165
1166    bin = gst_bin_new(NULL);
1167    if (!bin)
1168      {
1169        ERR("Unable to create GstBin !");
1170        goto unref_pipeline;
1171      }
1172
1173    tee = gst_element_factory_make("tee", NULL);
1174    if (!tee)
1175      {
1176        ERR("Unable to create 'tee' GstElement.");
1177        goto unref_pipeline;
1178      }
1179
1180 #if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H
1181    engines = evas_render_method_list();
1182
1183    engine = eina_list_nth(engines, evas_output_method_get(evas_object_evas_get(obj)) - 1);
1184
1185    if (ev->priority && engine && strstr(engine, "_x11") != NULL)
1186      {
1187         Ecore_Evas *ee;
1188         Evas_Coord x, y, w, h;
1189         Ecore_X_Window win;
1190         Ecore_X_Window parent;
1191
1192         evas_object_geometry_get(obj, &x, &y, &w, &h);
1193
1194         ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
1195
1196         if (w < 4) w = 4;
1197         if (h < 2) h = 2;
1198
1199         /* Here we really need to have the help of the window manager, this code will change when we update E17. */
1200         parent = (Ecore_X_Window) ecore_evas_window_get(ee);
1201         fprintf(stderr, "parent: %x\n", parent);
1202
1203         win = ecore_x_window_override_new(0, x, y, w, h);
1204         fprintf(stderr, "creating window: %x [%i, %i, %i, %i]\n", win, x, y, w, h);
1205         if (win)
1206           {
1207              ecore_x_window_show(win);
1208              xvsink = gst_element_factory_make("xvimagesink", NULL);
1209              if (xvsink)
1210                {
1211                   Ecore_X_Atom atom;
1212
1213                   gst_x_overlay_set_window_handle(GST_X_OVERLAY(xvsink), win);
1214                   ev->win = win;
1215
1216                   atom = ecore_x_atom_get("enlightenment.video");
1217                   if (atom)
1218                     {
1219                        ecore_x_window_prop_card32_set(win, atom, &parent, 1);
1220                     }
1221                }
1222              else
1223                {
1224                   fprintf(stderr, "destroying win: %x\n", win);
1225                   ecore_x_window_free(win);
1226                }
1227           }
1228      }
1229    evas_render_method_list_free(engines);
1230 #else
1231 # warning "no ecore_x or xoverlay"
1232 #endif
1233
1234    esink = gst_element_factory_make("emotion-sink", "sink");
1235    if (!esink)
1236      {
1237         ERR("Unable to create 'emotion-sink' GstElement.");
1238         goto unref_pipeline;
1239      }
1240
1241    g_object_set(G_OBJECT(esink), "evas-object", obj, NULL);
1242    g_object_set(G_OBJECT(esink), "ev", ev, NULL);
1243
1244    evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1245
1246    /* We need queue to force each video sink to be in its own thread */
1247    queue = gst_element_factory_make("queue", NULL);
1248    if (!queue)
1249      {
1250         ERR("Unable to create 'queue' GstElement.");
1251         goto unref_pipeline;
1252      }
1253
1254    gst_bin_add_many(GST_BIN(bin), tee, queue, esink, NULL);
1255    gst_element_link_many(queue, esink, NULL);
1256
1257    /* link both sink to GstTee */
1258    pad = gst_element_get_pad(queue, "sink");
1259    teepad = gst_element_get_request_pad(tee, "src%d");
1260    gst_pad_link(teepad, pad);
1261    gst_object_unref(pad);
1262    gst_object_unref(teepad);
1263
1264    if (xvsink)
1265      {
1266         GstElement *fakeeos;
1267
1268         queue = gst_element_factory_make("queue", NULL);
1269         fakeeos = GST_ELEMENT(GST_BIN(g_object_new(GST_TYPE_FAKEEOS_BIN, "name", "eosbin", NULL)));
1270         if (queue && fakeeos)
1271           {
1272              GstPad *queue_pad;
1273
1274              gst_bin_add_many(GST_BIN(bin), fakeeos, NULL);
1275
1276              gst_bin_add_many(GST_BIN(fakeeos), queue, xvsink, NULL);
1277              gst_element_link_many(queue, xvsink, NULL);
1278              queue_pad = gst_element_get_pad(queue, "sink");
1279              gst_element_add_pad(fakeeos, gst_ghost_pad_new("sink", queue_pad));
1280
1281              pad = gst_element_get_pad(fakeeos, "sink");
1282              teepad = gst_element_get_request_pad(tee, "src%d");
1283              gst_pad_link(teepad, pad);
1284
1285              xvsink = fakeeos;
1286
1287              ev->teepad = teepad;
1288              ev->xvpad = pad;
1289           }
1290         else
1291           {
1292              if (fakeeos) gst_object_unref(fakeeos);
1293              if (queue) gst_object_unref(queue);
1294              gst_object_unref(xvsink);
1295              xvsink = NULL;
1296           }
1297      }
1298
1299    teepad = gst_element_get_pad(tee, "sink");
1300    gst_element_add_pad(bin, gst_ghost_pad_new("sink", teepad));
1301    gst_object_unref(teepad);
1302
1303 #define GST_PLAY_FLAG_NATIVE_VIDEO  (1 << 6)
1304 #define GST_PLAY_FLAG_DOWNLOAD      (1 << 7)
1305 #define GST_PLAY_FLAG_AUDIO         (1 << 1)
1306 #define GST_PLAY_FLAG_NATIVE_AUDIO  (1 << 5)
1307
1308    g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
1309    g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD | GST_PLAY_FLAG_NATIVE_AUDIO, NULL);
1310    g_object_set(G_OBJECT(playbin), "video-sink", bin, NULL);
1311    g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
1312
1313    evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1314    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev);
1315
1316    ev->stream = EINA_TRUE;
1317
1318    if (xvsink)
1319      {
1320         Evas_Video_Surface video;
1321
1322         video.version = EVAS_VIDEO_SURFACE_VERSION;
1323         video.data = ev;
1324         video.parent = NULL;
1325         video.move = _video_move;
1326         video.resize = _video_resize;
1327         video.show = _video_show;
1328         video.hide = _video_hide;
1329         video.update_pixels = _video_update_pixels;
1330
1331         evas_object_image_video_surface_set(obj, &video);
1332         ev->stream = EINA_FALSE;
1333      }
1334
1335    eina_stringshare_replace(&ev->uri, uri);
1336    ev->pipeline = playbin;
1337    ev->sink = bin;
1338    ev->esink = esink;
1339    ev->xvsink = xvsink;
1340    ev->tee = tee;
1341    ev->threads = eina_list_append(ev->threads,
1342                                   ecore_thread_run(_emotion_gstreamer_pause,
1343                                                    _emotion_gstreamer_end,
1344                                                    _emotion_gstreamer_cancel,
1345                                                    ev));
1346
1347    /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
1348    /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
1349    if (getenv("EMOTION_GSTREAMER_DOT")) GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(playbin), GST_DEBUG_GRAPH_SHOW_ALL, getenv("EMOTION_GSTREAMER_DOT"));
1350
1351    return playbin;
1352
1353  unref_pipeline:
1354    gst_object_unref(xvsink);
1355    gst_object_unref(esink);
1356    gst_object_unref(tee);
1357    gst_object_unref(bin);
1358    gst_object_unref(playbin);
1359    return NULL;
1360 }