emotion: properly handle some race condition.
[profile/ivi/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      goto exit_point;
401
402    ev = evas_object_data_get(priv->o, "_emotion_gstreamer_video");
403    if (!ev) goto exit_point;
404
405    evas_data = (unsigned char *)evas_object_image_data_get(priv->o, 1);
406
407    // Evas's BGRA has pre-multiplied alpha while GStreamer's doesn't.
408    // Here we convert to Evas's BGRA.
409    if (priv->format == GST_VIDEO_FORMAT_BGR) {
410       unsigned char *evas_tmp;
411       int x;
412       int y;
413
414       evas_tmp = evas_data;
415       /* FIXME: could this be optimized ? */
416       for (x = 0; x < priv->height; x++) {
417          for (y = 0; y < priv->width; y++) {
418             evas_tmp[0] = gst_data[0];
419             evas_tmp[1] = gst_data[1];
420             evas_tmp[2] = gst_data[2];
421             evas_tmp[3] = 255;
422             gst_data += 3;
423             evas_tmp += 4;
424          }
425       }
426    }
427
428    // Evas's BGRA has pre-multiplied alpha while GStreamer's doesn't.
429    // Here we convert to Evas's BGRA.
430    if (priv->format == GST_VIDEO_FORMAT_BGRx) {
431       unsigned char *evas_tmp;
432       int x;
433       int y;
434
435       evas_tmp = evas_data;
436       /* FIXME: could this be optimized ? */
437       for (x = 0; x < priv->height; x++) {
438          for (y = 0; y < priv->width; y++) {
439             evas_tmp[0] = gst_data[0];
440             evas_tmp[1] = gst_data[1];
441             evas_tmp[2] = gst_data[2];
442             evas_tmp[3] = 255;
443             gst_data += 4;
444             evas_tmp += 4;
445          }
446       }
447    }
448
449    // Evas's BGRA has pre-multiplied alpha while GStreamer's doesn't.
450    // Here we convert to Evas's BGRA.
451    if (priv->format == GST_VIDEO_FORMAT_BGRA) {
452       unsigned char *evas_tmp;
453       int x;
454       int y;
455       unsigned char alpha;
456
457       evas_tmp = evas_data;
458       /* FIXME: could this be optimized ? */
459       for (x = 0; x < priv->height; x++) {
460          for (y = 0; y < priv->width; y++) {
461             alpha = gst_data[3];
462             evas_tmp[0] = (gst_data[0] * alpha) / 255;
463             evas_tmp[1] = (gst_data[1] * alpha) / 255;
464             evas_tmp[2] = (gst_data[2] * alpha) / 255;
465             evas_tmp[3] = alpha;
466             gst_data += 4;
467             evas_tmp += 4;
468          }
469       }
470    }
471
472    if (priv->format == GST_VIDEO_FORMAT_I420) {
473       int i;
474       unsigned char **rows;
475
476       evas_object_image_pixels_dirty_set(priv->o, 1);
477       rows = (unsigned char **)evas_data;
478
479       for (i = 0; i < priv->height; i++)
480         rows[i] = &gst_data[i * priv->width];
481
482       rows += priv->height;
483       for (i = 0; i < (priv->height / 2); i++)
484         rows[i] = &gst_data[priv->height * priv->width + i * (priv->width / 2)];
485
486       rows += priv->height / 2;
487       for (i = 0; i < (priv->height / 2); i++)
488         rows[i] = &gst_data[priv->height * priv->width + priv->height * (priv->width /4) + i * (priv->width / 2)];
489    }
490
491    if (priv->format == GST_VIDEO_FORMAT_YV12) {
492       int i;
493       unsigned char **rows;
494
495       evas_object_image_pixels_dirty_set(priv->o, 1);
496
497       rows = (unsigned char **)evas_data;
498
499       for (i = 0; i < priv->height; i++)
500         rows[i] = &gst_data[i * priv->width];
501
502       rows += priv->height;
503       for (i = 0; i < (priv->height / 2); i++)
504         rows[i] = &gst_data[priv->height * priv->width + priv->height * (priv->width /4) + i * (priv->width / 2)];
505
506       rows += priv->height / 2;
507       for (i = 0; i < (priv->height / 2); i++)
508         rows[i] = &gst_data[priv->height * priv->width + i * (priv->width / 2)];
509    }
510
511    evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
512    evas_object_image_data_set(priv->o, evas_data);
513    evas_object_image_pixels_dirty_set(priv->o, 0);
514
515    _emotion_frame_new(ev->obj);
516
517    vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
518
519    gst_element_query_position(ev->pipeline, &fmt, &pos);
520    ev->position = (double)pos / (double)GST_SECOND;
521
522    vstream->width = priv->width;
523    vstream->height = priv->height;
524    ev->ratio = (double) priv->width / (double) priv->height;
525
526    _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
527    _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
528
529  exit_point:
530    if (priv->last_buffer) gst_buffer_unref(priv->last_buffer);
531    priv->last_buffer = buffer;
532
533    if (priv->preroll) return ;
534
535    g_mutex_lock(priv->buffer_mutex);
536
537    if (priv->unlocked) {
538       g_mutex_unlock(priv->buffer_mutex);
539       return;
540    }
541
542    g_cond_signal(priv->data_cond);
543    g_mutex_unlock(priv->buffer_mutex);
544 }
545
546 static void
547 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
548 {
549    g_mutex_lock(priv->buffer_mutex);
550
551    priv->unlocked = EINA_TRUE;
552    g_cond_signal(priv->data_cond);
553    g_mutex_unlock(priv->buffer_mutex);
554 }
555
556 static void
557 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
558                          guint n_param_values, const GValue * param_values,
559                          gpointer invocation_hint __UNUSED__, gpointer marshal_data)
560 {
561    typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
562    marshalfunc_VOID__MINIOBJECT callback;
563    GCClosure *cc;
564    gpointer data1, data2;
565
566    cc = (GCClosure *) closure;
567
568    g_return_if_fail(n_param_values == 2);
569
570    if (G_CCLOSURE_SWAP_DATA(closure)) {
571       data1 = closure->data;
572       data2 = g_value_peek_pointer(param_values + 0);
573    } else {
574       data1 = g_value_peek_pointer(param_values + 0);
575       data2 = closure->data;
576    }
577    callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
578
579    callback(data1, gst_value_get_mini_object(param_values + 1), data2);
580 }
581
582 static void
583 evas_video_sink_class_init(EvasVideoSinkClass* klass)
584 {
585    GObjectClass* gobject_class;
586    GstBaseSinkClass* gstbase_sink_class;
587
588    gobject_class = G_OBJECT_CLASS(klass);
589    gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
590
591    g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
592
593    gobject_class->set_property = evas_video_sink_set_property;
594    gobject_class->get_property = evas_video_sink_get_property;
595
596    g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
597                                     g_param_spec_pointer ("evas-object", "Evas Object",
598                                                           "The Evas object where the display of the video will be done",
599                                                           G_PARAM_READWRITE));
600
601    g_object_class_install_property (gobject_class, PROP_WIDTH,
602                                     g_param_spec_int ("width", "Width",
603                                                       "The width of the video",
604                                                       0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
605
606    g_object_class_install_property (gobject_class, PROP_HEIGHT,
607                                     g_param_spec_int ("height", "Height",
608                                                       "The height of the video",
609                                                       0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
610
611    gobject_class->dispose = evas_video_sink_dispose;
612
613    gstbase_sink_class->set_caps = evas_video_sink_set_caps;
614    gstbase_sink_class->stop = evas_video_sink_stop;
615    gstbase_sink_class->start = evas_video_sink_start;
616    gstbase_sink_class->unlock = evas_video_sink_unlock;
617    gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
618    gstbase_sink_class->render = evas_video_sink_render;
619    gstbase_sink_class->preroll = evas_video_sink_preroll;
620
621    evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
622                                                              G_TYPE_FROM_CLASS(klass),
623                                                              (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
624                                                              0,
625                                                              0,
626                                                              0,
627                                                              marshal_VOID__MINIOBJECT,
628                                                              G_TYPE_NONE, 1, GST_TYPE_BUFFER);
629 }
630
631 gboolean
632 gstreamer_plugin_init (GstPlugin * plugin)
633 {
634    return gst_element_register (plugin,
635                                 "emotion-sink",
636                                 GST_RANK_NONE,
637                                 EVAS_TYPE_VIDEO_SINK);
638 }
639
640 GstElement *
641 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
642                          Evas_Object *o,
643                          const char *uri)
644 {
645    GstElement *playbin;
646    GstElement *sink;
647    Evas_Object *obj;
648    GstStateChangeReturn res;
649
650    obj = _emotion_image_get(o);
651    if (!obj)
652      {
653         ERR("Not Evas_Object specified");
654         return NULL;
655      }
656
657    playbin = gst_element_factory_make("playbin2", "playbin");
658    if (!playbin)
659      {
660         ERR("Unable to create 'playbin' GstElement.");
661         return NULL;
662      }
663
664    sink = gst_element_factory_make("emotion-sink", "sink");
665    if (!sink)
666      {
667         ERR("Unable to create 'emotion-sink' GstElement.");
668         goto unref_pipeline;
669      }
670
671    g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL);
672    g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
673    g_object_set(G_OBJECT(sink), "evas-object", obj, NULL);
674
675    res = gst_element_set_state(playbin, GST_STATE_PAUSED);
676    if (res == GST_STATE_CHANGE_FAILURE)
677      {
678         ERR("Unable to set GST_STATE_PAUSED.");
679         goto unref_pipeline;
680      }
681
682    res = gst_element_get_state(playbin, NULL, NULL, GST_CLOCK_TIME_NONE);
683    if (res != GST_STATE_CHANGE_SUCCESS)
684      {
685         ERR("Unable to get GST_CLOCK_TIME_NONE.");
686         goto unref_pipeline;
687      }
688
689    evas_object_data_set(obj, "_emotion_gstreamer_video", ev);
690
691    /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
692    /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
693    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"));
694
695    return playbin;
696
697  unref_pipeline:
698    gst_object_unref(playbin);
699    return NULL;
700 }