emotion: fix race condition and never call fill_set in the backend.
[framework/uifw/emotion.git] / src / modules / gstreamer / emotion_sink.c
1 #include <glib.h>
2 #include <gst/gst.h>
3 #include <gst/video/video.h>
4 #include <gst/video/gstvideosink.h>
5
6 #include <Ecore.h>
7
8 #include "emotion_gstreamer.h"
9
10 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE("sink",
11                                                                    GST_PAD_SINK, GST_PAD_ALWAYS,
12                                                                    GST_STATIC_CAPS(GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_BGR ";" GST_VIDEO_CAPS_BGRA ";" GST_VIDEO_CAPS_YUV("{I420,YV12}")));
13
14
15 GST_DEBUG_CATEGORY_STATIC(evas_video_sink_debug);
16 #define GST_CAT_DEFAULT evas_video_sink_debug
17
18 enum {
19   REPAINT_REQUESTED,
20   LAST_SIGNAL
21 };
22
23 enum {
24   PROP_0,
25   PROP_EVAS_OBJECT,
26   PROP_WIDTH,
27   PROP_HEIGHT,
28   PROP_LAST,
29 };
30
31 static guint evas_video_sink_signals[LAST_SIGNAL] = { 0, };
32
33 struct _EvasVideoSinkPrivate {
34    Evas_Object *o;
35    Ecore_Pipe *p;
36
37    int width;
38    int height;
39    GstVideoFormat format;
40
41    GMutex* buffer_mutex;
42    GCond* data_cond;
43
44    GstBuffer *last_buffer; /* We need to keep a copy of the last inserted buffer as evas doesn't copy YUV data around */
45
46    // If this is TRUE all processing should finish ASAP
47    // This is necessary because there could be a race between
48    // unlock() and render(), where unlock() wins, signals the
49    // GCond, then render() tries to render a frame although
50    // everything else isn't running anymore. This will lead
51    // to deadlocks because render() holds the stream lock.
52    //
53    // Protected by the buffer mutex
54    Eina_Bool unlocked : 1;
55    Eina_Bool preroll : 1;
56    Eina_Bool update_size : 1;
57 };
58
59 #define _do_init(bla)                                   \
60   GST_DEBUG_CATEGORY_INIT(evas_video_sink_debug,        \
61                           "emotion-sink",               \
62                           0,                            \
63                           "emotion video sink")
64
65 GST_BOILERPLATE_FULL(EvasVideoSink,
66                      evas_video_sink,
67                      GstVideoSink,
68                      GST_TYPE_VIDEO_SINK,
69                      _do_init);
70
71
72 static void unlock_buffer_mutex(EvasVideoSinkPrivate* priv);
73
74 static void evas_video_sink_render_handler(void *data, void *buf, unsigned int len);
75
76 static void
77 evas_video_sink_base_init(gpointer g_class)
78 {
79    GstElementClass* element_class;
80
81    element_class = GST_ELEMENT_CLASS(g_class);
82    gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&sinktemplate));
83    gst_element_class_set_details_simple(element_class, "Evas video sink",
84                                         "Sink/Video", "Sends video data from a GStreamer pipeline to an Evas object",
85                                         "Vincent Torri <vtorri@univ-evry.fr>");
86 }
87
88 static void
89 evas_video_sink_init(EvasVideoSink* sink, EvasVideoSinkClass* klass __UNUSED__)
90 {
91    EvasVideoSinkPrivate* priv;
92
93    sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(sink, EVAS_TYPE_VIDEO_SINK, EvasVideoSinkPrivate);
94    priv->o = NULL;
95    priv->p = ecore_pipe_add(evas_video_sink_render_handler, sink);
96    priv->last_buffer = NULL;
97    priv->width = 0;
98    priv->height = 0;
99    priv->format = GST_VIDEO_FORMAT_UNKNOWN;
100    priv->data_cond = g_cond_new();
101    priv->buffer_mutex = g_mutex_new();
102    priv->preroll = EINA_FALSE;
103    priv->unlocked = EINA_FALSE;
104    priv->update_size = EINA_TRUE;
105 }
106
107
108 /**** Object methods ****/
109
110 static void
111 evas_video_sink_set_property(GObject * object, guint prop_id,
112                              const GValue * value, GParamSpec * pspec)
113 {
114    EvasVideoSink* sink;
115    EvasVideoSinkPrivate* priv;
116
117    sink = EVAS_VIDEO_SINK (object);
118    priv = sink->priv;
119
120    switch (prop_id) {
121     case PROP_EVAS_OBJECT:
122        g_mutex_lock(priv->buffer_mutex);
123        priv->o = g_value_get_pointer (value);
124        g_mutex_unlock(priv->buffer_mutex);
125        break;
126     default:
127        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128        break;
129    }
130 }
131
132 static void
133 evas_video_sink_get_property(GObject * object, guint prop_id,
134                              GValue * value, GParamSpec * pspec)
135 {
136    EvasVideoSink* sink;
137    EvasVideoSinkPrivate* priv;
138
139    sink = EVAS_VIDEO_SINK (object);
140    priv = sink->priv;
141
142    switch (prop_id) {
143     case PROP_EVAS_OBJECT:
144        g_mutex_lock(priv->buffer_mutex);
145        g_value_set_pointer (value, priv->o);
146        g_mutex_unlock(priv->buffer_mutex);
147        break;
148     case PROP_WIDTH:
149        g_mutex_lock(priv->buffer_mutex);
150        g_value_set_int(value, priv->width);
151        g_mutex_unlock(priv->buffer_mutex);
152        break;
153     case PROP_HEIGHT:
154        g_mutex_lock(priv->buffer_mutex);
155        g_value_set_int (value, priv->height);
156        g_mutex_unlock(priv->buffer_mutex);
157        break;
158     default:
159        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
160        break;
161    }
162 }
163
164 static void
165 evas_video_sink_dispose(GObject* object)
166 {
167    EvasVideoSink* sink;
168    EvasVideoSinkPrivate* priv;
169
170    sink = EVAS_VIDEO_SINK(object);
171    priv = sink->priv;
172
173    if (priv->buffer_mutex) {
174       g_mutex_free(priv->buffer_mutex);
175       priv->buffer_mutex = 0;
176    }
177
178    if (priv->data_cond) {
179       g_cond_free(priv->data_cond);
180       priv->data_cond = 0;
181    }
182
183    if (priv->p) {
184       ecore_pipe_del(priv->p);
185       priv->p = NULL;
186    }
187
188    if (priv->last_buffer) {
189       gst_buffer_unref(priv->last_buffer);
190       priv->last_buffer = NULL;
191    }
192
193    G_OBJECT_CLASS(parent_class)->dispose(object);
194 }
195
196
197 /**** BaseSink methods ****/
198
199 gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps)
200 {
201    EvasVideoSink* sink;
202    EvasVideoSinkPrivate* priv;
203    int width;
204    int height;
205
206    sink = EVAS_VIDEO_SINK(bsink);
207    priv = sink->priv;
208
209    if (G_UNLIKELY(!gst_video_format_parse_caps(caps, &priv->format, &width, &height))) {
210       return FALSE;
211    }
212
213    if ((width != priv->width) || (height != priv->height))
214      {
215         priv->width = width;
216         priv->height = height;
217         priv->update_size = EINA_TRUE;
218      }
219
220    printf("format :");
221    switch (priv->format)
222      {
223       case GST_VIDEO_FORMAT_I420:
224          evas_object_image_size_set(priv->o, priv->width, priv->height);
225          evas_object_image_colorspace_set(priv->o, EVAS_COLORSPACE_YCBCR422P601_PL);
226          evas_object_image_alpha_set(priv->o, 0);
227          printf ("I420\n");
228          break;
229       case GST_VIDEO_FORMAT_YV12:
230          evas_object_image_size_set(priv->o, priv->width, priv->height);
231          evas_object_image_colorspace_set(priv->o, EVAS_COLORSPACE_YCBCR422P601_PL);
232          evas_object_image_alpha_set(priv->o, 0);
233          printf ("YV12\n");
234          break;
235       case GST_VIDEO_FORMAT_BGR:
236          printf ("BGR\n");
237          break;
238       case GST_VIDEO_FORMAT_BGRx:
239          printf ("BGRx\n");
240          break;
241       case GST_VIDEO_FORMAT_BGRA:
242          printf ("BGRA\n");
243          break;
244       default:
245          printf ("unsupported : %d\n", priv->format);
246          return FALSE;
247      }
248
249    return TRUE;
250 }
251
252 static gboolean
253 evas_video_sink_start(GstBaseSink* base_sink)
254 {
255    EvasVideoSinkPrivate* priv;
256    gboolean res = TRUE;
257
258    priv = EVAS_VIDEO_SINK(base_sink)->priv;
259    g_mutex_lock(priv->buffer_mutex);
260    if (!priv->o)
261      res = FALSE;
262    else
263      {
264         if (!priv->p)
265           res = FALSE;
266         else
267           {
268              priv->unlocked = EINA_FALSE;
269           }
270      }
271    g_mutex_unlock(priv->buffer_mutex);
272    return res;
273 }
274
275 static gboolean
276 evas_video_sink_stop(GstBaseSink* base_sink)
277 {
278    EvasVideoSinkPrivate* priv = EVAS_VIDEO_SINK(base_sink)->priv;
279
280    unlock_buffer_mutex(priv);
281    return TRUE;
282 }
283
284 static gboolean
285 evas_video_sink_unlock(GstBaseSink* object)
286 {
287    EvasVideoSink* sink;
288
289    sink = EVAS_VIDEO_SINK(object);
290
291    unlock_buffer_mutex(sink->priv);
292
293    return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock,
294                                        (object), TRUE);
295 }
296
297 static gboolean
298 evas_video_sink_unlock_stop(GstBaseSink* object)
299 {
300    EvasVideoSink* sink;
301    EvasVideoSinkPrivate* priv;
302
303    sink = EVAS_VIDEO_SINK(object);
304    priv = sink->priv;
305
306    g_mutex_lock(priv->buffer_mutex);
307    priv->unlocked = FALSE;
308    g_mutex_unlock(priv->buffer_mutex);
309
310    return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock_stop,
311                                        (object), TRUE);
312 }
313
314 static GstFlowReturn
315 evas_video_sink_preroll(GstBaseSink* bsink, GstBuffer* buffer)
316 {
317    GstBuffer *send;
318    EvasVideoSink* sink;
319    EvasVideoSinkPrivate* priv;
320
321    sink = EVAS_VIDEO_SINK(bsink);
322    priv = sink->priv;
323
324    send = gst_buffer_ref(buffer);
325
326    priv->preroll = EINA_TRUE;
327
328    ecore_pipe_write(priv->p, &send, sizeof(buffer));
329    return GST_FLOW_OK;
330 }
331
332 static GstFlowReturn
333 evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer)
334 {
335    GstBuffer *send;
336    EvasVideoSink* sink;
337    EvasVideoSinkPrivate* priv;
338    Eina_Bool ret;
339
340    sink = EVAS_VIDEO_SINK(bsink);
341    priv = sink->priv;
342
343    g_mutex_lock(priv->buffer_mutex);
344
345    if (priv->unlocked) {
346       g_mutex_unlock(priv->buffer_mutex);
347       return GST_FLOW_OK;
348    }
349
350    priv->preroll = EINA_FALSE;
351
352    send = gst_buffer_ref(buffer);
353    ret = ecore_pipe_write(priv->p, &send, sizeof(buffer));
354    if (!ret)
355      return GST_FLOW_ERROR;
356
357    g_cond_wait(priv->data_cond, priv->buffer_mutex);
358    g_mutex_unlock(priv->buffer_mutex);
359
360    return GST_FLOW_OK;
361 }
362
363 static void evas_video_sink_render_handler(void *data,
364                                            void *buf,
365                                            unsigned int len)
366 {
367    Emotion_Gstreamer_Video *ev;
368    Emotion_Video_Stream *vstream;
369    EvasVideoSink* sink;
370    EvasVideoSinkPrivate* priv;
371    GstBuffer* buffer;
372    unsigned char *evas_data;
373    const guint8 *gst_data;
374    GstQuery *query;
375    GstFormat fmt = GST_FORMAT_TIME;
376    Evas_Coord w, h;
377    gint64 pos;
378
379    sink = (EvasVideoSink *)data;
380    priv = sink->priv;
381
382    buffer = *((GstBuffer **)buf);
383
384    if (priv->unlocked)
385      goto exit_point;
386
387    gst_data = GST_BUFFER_DATA(buffer);
388    if (!gst_data) goto exit_point;
389    if (priv->update_size)
390      {
391         evas_object_image_size_set(priv->o, priv->width, priv->height);
392         if (!priv->preroll) priv->update_size = FALSE;
393      }
394
395    // This prevent a race condition when data are still in the pipe
396    // but the buffer size as changed because of a request from
397    // emotion smart (like on a file set).
398    evas_object_image_size_get(priv->o, &w, &h);
399    if (w != priv->width || h != priv->height)
400      return ;
401
402    evas_data = (unsigned char *)evas_object_image_data_get(priv->o, 1);
403
404    // Evas's BGRA has pre-multiplied alpha while GStreamer's doesn't.
405    // Here we convert to Evas's BGRA.
406    if (priv->format == GST_VIDEO_FORMAT_BGR) {
407       unsigned char *evas_tmp;
408       int x;
409       int y;
410
411       evas_tmp = evas_data;
412       /* FIXME: could this be optimized ? */
413       for (x = 0; x < priv->height; x++) {
414          for (y = 0; y < priv->width; y++) {
415             evas_tmp[0] = gst_data[0];
416             evas_tmp[1] = gst_data[1];
417             evas_tmp[2] = gst_data[2];
418             evas_tmp[3] = 255;
419             gst_data += 3;
420             evas_tmp += 4;
421          }
422       }
423    }
424
425    // Evas's BGRA has pre-multiplied alpha while GStreamer's doesn't.
426    // Here we convert to Evas's BGRA.
427    if (priv->format == GST_VIDEO_FORMAT_BGRx) {
428       unsigned char *evas_tmp;
429       int x;
430       int y;
431
432       evas_tmp = evas_data;
433       /* FIXME: could this be optimized ? */
434       for (x = 0; x < priv->height; x++) {
435          for (y = 0; y < priv->width; y++) {
436             evas_tmp[0] = gst_data[0];
437             evas_tmp[1] = gst_data[1];
438             evas_tmp[2] = gst_data[2];
439             evas_tmp[3] = 255;
440             gst_data += 4;
441             evas_tmp += 4;
442          }
443       }
444    }
445
446    // Evas's BGRA has pre-multiplied alpha while GStreamer's doesn't.
447    // Here we convert to Evas's BGRA.
448    if (priv->format == GST_VIDEO_FORMAT_BGRA) {
449       unsigned char *evas_tmp;
450       int x;
451       int y;
452       unsigned char alpha;
453
454       evas_tmp = evas_data;
455       /* FIXME: could this be optimized ? */
456       for (x = 0; x < priv->height; x++) {
457          for (y = 0; y < priv->width; y++) {
458             alpha = gst_data[3];
459             evas_tmp[0] = (gst_data[0] * alpha) / 255;
460             evas_tmp[1] = (gst_data[1] * alpha) / 255;
461             evas_tmp[2] = (gst_data[2] * alpha) / 255;
462             evas_tmp[3] = alpha;
463             gst_data += 4;
464             evas_tmp += 4;
465          }
466       }
467    }
468
469    if (priv->format == GST_VIDEO_FORMAT_I420) {
470       int i;
471       unsigned char **rows;
472
473       evas_object_image_pixels_dirty_set(priv->o, 1);
474       rows = (unsigned char **)evas_data;
475
476       for (i = 0; i < priv->height; i++)
477         rows[i] = &gst_data[i * priv->width];
478
479       rows += priv->height;
480       for (i = 0; i < (priv->height / 2); i++)
481         rows[i] = &gst_data[priv->height * priv->width + i * (priv->width / 2)];
482
483       rows += priv->height / 2;
484       for (i = 0; i < (priv->height / 2); i++)
485         rows[i] = &gst_data[priv->height * priv->width + priv->height * (priv->width /4) + i * (priv->width / 2)];
486    }
487
488    if (priv->format == GST_VIDEO_FORMAT_YV12) {
489       int i;
490       unsigned char **rows;
491
492       evas_object_image_pixels_dirty_set(priv->o, 1);
493
494       rows = (unsigned char **)evas_data;
495
496       for (i = 0; i < priv->height; i++)
497         rows[i] = &gst_data[i * priv->width];
498
499       rows += priv->height;
500       for (i = 0; i < (priv->height / 2); i++)
501         rows[i] = &gst_data[priv->height * priv->width + priv->height * (priv->width /4) + i * (priv->width / 2)];
502
503       rows += priv->height / 2;
504       for (i = 0; i < (priv->height / 2); i++)
505         rows[i] = &gst_data[priv->height * priv->width + i * (priv->width / 2)];
506    }
507
508    evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
509    evas_object_image_data_set(priv->o, evas_data);
510    evas_object_image_pixels_dirty_set(priv->o, 0);
511
512    ev = evas_object_data_get(priv->o, "_emotion_gstreamer_video");
513    _emotion_frame_new(ev->obj);
514
515    vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
516
517    gst_element_query_position(ev->pipeline, &fmt, &pos);
518    ev->position = (double)pos / (double)GST_SECOND;
519
520    vstream->width = priv->width;
521    vstream->height = priv->height;
522    ev->ratio = (double) priv->width / (double) priv->height;
523
524    _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
525    _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
526
527  exit_point:
528    if (priv->last_buffer) gst_buffer_unref(priv->last_buffer);
529    priv->last_buffer = buffer;
530
531    if (priv->preroll) return ;
532
533    g_mutex_lock(priv->buffer_mutex);
534
535    if (priv->unlocked) {
536       g_mutex_unlock(priv->buffer_mutex);
537       return;
538    }
539
540    g_cond_signal(priv->data_cond);
541    g_mutex_unlock(priv->buffer_mutex);
542 }
543
544 static void
545 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
546 {
547    g_mutex_lock(priv->buffer_mutex);
548
549    priv->unlocked = EINA_TRUE;
550    g_cond_signal(priv->data_cond);
551    g_mutex_unlock(priv->buffer_mutex);
552 }
553
554 static void
555 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
556                          guint n_param_values, const GValue * param_values,
557                          gpointer invocation_hint __UNUSED__, gpointer marshal_data)
558 {
559    typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
560    marshalfunc_VOID__MINIOBJECT callback;
561    GCClosure *cc;
562    gpointer data1, data2;
563
564    cc = (GCClosure *) closure;
565
566    g_return_if_fail(n_param_values == 2);
567
568    if (G_CCLOSURE_SWAP_DATA(closure)) {
569       data1 = closure->data;
570       data2 = g_value_peek_pointer(param_values + 0);
571    } else {
572       data1 = g_value_peek_pointer(param_values + 0);
573       data2 = closure->data;
574    }
575    callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
576
577    callback(data1, gst_value_get_mini_object(param_values + 1), data2);
578 }
579
580 static void
581 evas_video_sink_class_init(EvasVideoSinkClass* klass)
582 {
583    GObjectClass* gobject_class;
584    GstBaseSinkClass* gstbase_sink_class;
585
586    gobject_class = G_OBJECT_CLASS(klass);
587    gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
588
589    g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
590
591    gobject_class->set_property = evas_video_sink_set_property;
592    gobject_class->get_property = evas_video_sink_get_property;
593
594    g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
595                                     g_param_spec_pointer ("evas-object", "Evas Object",
596                                                           "The Evas object where the display of the video will be done",
597                                                           G_PARAM_READWRITE));
598
599    g_object_class_install_property (gobject_class, PROP_WIDTH,
600                                     g_param_spec_int ("width", "Width",
601                                                       "The width of the video",
602                                                       0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
603
604    g_object_class_install_property (gobject_class, PROP_HEIGHT,
605                                     g_param_spec_int ("height", "Height",
606                                                       "The height of the video",
607                                                       0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
608
609    gobject_class->dispose = evas_video_sink_dispose;
610
611    gstbase_sink_class->set_caps = evas_video_sink_set_caps;
612    gstbase_sink_class->stop = evas_video_sink_stop;
613    gstbase_sink_class->start = evas_video_sink_start;
614    gstbase_sink_class->unlock = evas_video_sink_unlock;
615    gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
616    gstbase_sink_class->render = evas_video_sink_render;
617    gstbase_sink_class->preroll = evas_video_sink_preroll;
618
619    evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
620                                                              G_TYPE_FROM_CLASS(klass),
621                                                              (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
622                                                              0,
623                                                              0,
624                                                              0,
625                                                              marshal_VOID__MINIOBJECT,
626                                                              G_TYPE_NONE, 1, GST_TYPE_BUFFER);
627 }
628
629 gboolean
630 gstreamer_plugin_init (GstPlugin * plugin)
631 {
632    return gst_element_register (plugin,
633                                 "emotion-sink",
634                                 GST_RANK_NONE,
635                                 EVAS_TYPE_VIDEO_SINK);
636 }
637
638 GstElement *
639 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
640                          Evas_Object *o,
641                          const char *uri)
642 {
643    GstElement *playbin;
644    GstElement *sink;
645    Evas_Object *obj;
646    GstStateChangeReturn res;
647
648    obj = _emotion_image_get(o);
649    if (!obj)
650      {
651         ERR("Not Evas_Object specified");
652         return NULL;
653      }
654
655    playbin = gst_element_factory_make("playbin2", "playbin");
656    if (!playbin)
657      {
658         ERR("Unable to create 'playbin' GstElement.");
659         return NULL;
660      }
661
662    sink = gst_element_factory_make("emotion-sink", "sink");
663    if (!sink)
664      {
665         ERR("Unable to create 'emotion-sink' GstElement.");
666         goto unref_pipeline;
667      }
668
669    g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL);
670    g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
671    g_object_set(G_OBJECT(sink), "evas-object", obj, NULL);
672
673    res = gst_element_set_state(playbin, GST_STATE_PAUSED);
674    if (res == GST_STATE_CHANGE_FAILURE)
675      {
676         ERR("Unable to set GST_STATE_PAUSED.");
677         goto unref_pipeline;
678      }
679
680    res = gst_element_get_state(playbin, NULL, NULL, GST_CLOCK_TIME_NONE);
681    if (res != GST_STATE_CHANGE_SUCCESS)
682      {
683         ERR("Unable to get GST_CLOCK_TIME_NONE.");
684         goto unref_pipeline;
685      }
686
687    evas_object_data_set(obj, "_emotion_gstreamer_video", ev);
688
689    /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
690    /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
691    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"));
692
693    return playbin;
694
695  unref_pipeline:
696    gst_object_unref(playbin);
697    return NULL;
698 }