Initialize Tizen 2.3
[framework/multimedia/gst-plugins-ext0.10.git] / mobile / evasimagesink / src / gstevasimagesink.c
1 /*
2  * evasimagesink
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Sangchul Lee <sc11.lee@samsung.com>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at your option)
11  * any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc., 51
20  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23
24 /**
25  * SECTION:element-evasimagesink
26  * Gstreamer Evas Video Sink - draw video on the given Evas Image Object
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32
33 #include <sys/types.h>
34 #include <gst/gst.h>
35 #include <gst/video/video.h>
36 #include <gst/video/gstvideosink.h>
37 #include <Evas.h>
38 #include <Ecore.h>
39 #include <Ecore_X.h>
40
41 #include "gstevasimagesink.h"
42
43 #define CAP_WIDTH "width"
44 #define CAP_HEIGHT "height"
45
46 GST_DEBUG_CATEGORY_STATIC (gst_evas_image_sink_debug);
47 #define GST_CAT_DEFAULT gst_evas_image_sink_debug
48
49 /* Enumerations */
50 enum
51 {
52         LAST_SIGNAL
53 };
54
55 enum
56 {
57         PROP_0,
58         PROP_EVAS_OBJECT,
59         PROP_EVAS_OBJECT_SHOW
60 };
61
62 enum
63 {
64         UPDATE_FALSE,
65         UPDATE_TRUE
66 };
67
68 #define COLOR_DEPTH 4
69 #define GL_X11_ENGINE "gl_x11"
70 #define DO_RENDER_FROM_FIMC 1
71 #define SIZE_FOR_UPDATE_VISIBILITY sizeof(gchar)
72
73 #define EVASIMAGESINK_SET_EVAS_OBJECT_EVENT_CALLBACK( x_evas_image_object, x_usr_data ) \
74 do \
75 { \
76         if (x_evas_image_object) { \
77                 evas_object_event_callback_add (x_evas_image_object, EVAS_CALLBACK_DEL, evas_callback_del_event, x_usr_data); \
78                 evas_object_event_callback_add (x_evas_image_object, EVAS_CALLBACK_RESIZE, evas_callback_resize_event, x_usr_data); \
79         } \
80 }while(0)
81
82 #define EVASIMAGESINK_UNSET_EVAS_OBJECT_EVENT_CALLBACK( x_evas_image_object ) \
83 do \
84 { \
85         if (x_evas_image_object) { \
86                 evas_object_event_callback_del (x_evas_image_object, EVAS_CALLBACK_DEL, evas_callback_del_event); \
87                 evas_object_event_callback_del (x_evas_image_object, EVAS_CALLBACK_RESIZE, evas_callback_resize_event); \
88         } \
89 }while(0)
90
91 GMutex *instance_lock;
92 guint instance_lock_count;
93
94 static inline gboolean
95 is_evas_image_object (Evas_Object *obj)
96 {
97         const char *type;
98         if (!obj) {
99                 return FALSE;
100         }
101         type = evas_object_type_get (obj);
102         if (!type) {
103                 return FALSE;
104         }
105         if (strcmp (type, "image") == 0) {
106                 return TRUE;
107         }
108         return FALSE;
109 }
110
111 /* the capabilities of the inputs.
112  *
113  * BGRx format
114  */
115 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
116                 GST_PAD_SINK,
117                 GST_PAD_ALWAYS,
118                 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx));
119
120 GST_BOILERPLATE (GstEvasImageSink, gst_evas_image_sink, GstVideoSink, GST_TYPE_VIDEO_SINK);
121
122 static void gst_evas_image_sink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
123 static void gst_evas_image_sink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
124 static gboolean gst_evas_image_sink_set_caps (GstBaseSink *base_sink, GstCaps *caps);
125 static GstFlowReturn gst_evas_image_sink_show_frame (GstVideoSink *video_sink, GstBuffer *buf);
126 static gboolean gst_evas_image_sink_event (GstBaseSink *sink, GstEvent *event);
127 static GstStateChangeReturn gst_evas_image_sink_change_state (GstElement *element, GstStateChange transition);
128 static void evas_callback_del_event (void *data, Evas *e, Evas_Object *obj, void *event_info);
129 static void evas_callback_resize_event (void *data, Evas *e, Evas_Object *obj, void *event_info);
130
131 static void
132 gst_evas_image_sink_base_init (gpointer gclass)
133 {
134         GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
135
136         gst_element_class_set_details_simple (element_class,
137                 "EvasImageSink",
138                 "VideoSink",
139                 "Video sink element for evas image object",
140                 "Samsung Electronics <www.samsung.com>");
141
142         gst_element_class_add_pad_template (element_class,
143         gst_static_pad_template_get (&sink_factory));
144 }
145
146 static void
147 gst_evas_image_sink_class_init (GstEvasImageSinkClass *klass)
148 {
149         GObjectClass *gobject_class;
150         GstBaseSinkClass *gstbasesink_class;
151         GstVideoSinkClass *gstvideosink_class;
152         GstElementClass *gstelement_class;
153
154         gobject_class = (GObjectClass *) klass;
155         gstbasesink_class = GST_BASE_SINK_CLASS (klass);
156         gstvideosink_class = GST_VIDEO_SINK_CLASS (klass);
157         gstelement_class = (GstElementClass *) klass;
158
159         gobject_class->set_property = gst_evas_image_sink_set_property;
160         gobject_class->get_property = gst_evas_image_sink_get_property;
161
162         g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
163                 g_param_spec_pointer ("evas-object", "Destination Evas Object", "Destination evas image object", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164         g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT_SHOW,
165                 g_param_spec_boolean ("visible", "Show Evas Object", "When disabled, evas object does not show", TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
166
167         gstvideosink_class->show_frame = GST_DEBUG_FUNCPTR (gst_evas_image_sink_show_frame);
168         gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_evas_image_sink_set_caps);
169         gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_evas_image_sink_event);
170         gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_evas_image_sink_change_state);
171 }
172
173 static void
174 gst_evas_image_sink_fini (gpointer data, GObject *obj)
175 {
176         GST_DEBUG ("[ENTER]");
177
178         GstEvasImageSink *esink = GST_EVASIMAGESINK (obj);
179         if (!esink) {
180                 return;
181         }
182         if (esink->oldbuf) {
183                 gst_buffer_unref (esink->oldbuf);
184         }
185
186         if (esink->eo) {
187                 evas_object_image_data_set(esink->eo, NULL);
188         }
189
190         g_mutex_lock (instance_lock);
191         instance_lock_count--;
192         g_mutex_unlock (instance_lock);
193         if (instance_lock_count == 0) {
194                 g_mutex_free (instance_lock);
195                 instance_lock = NULL;
196         }
197
198         GST_DEBUG ("[LEAVE]");
199 }
200
201 static void
202 evas_image_sink_cb_pipe (void *data, void *buffer, unsigned int nbyte)
203 {
204         GstBuffer *buf;
205         GstEvasImageSink *esink = data;
206         void *img_data;
207
208         GST_DEBUG ("[ENTER]");
209
210         if (!esink || !esink->eo) {
211                 return;
212         }
213         if (nbyte == SIZE_FOR_UPDATE_VISIBILITY) {
214                 if(!esink->object_show) {
215                         evas_object_hide(esink->eo);
216                         GST_INFO ("object hide..");
217                 } else {
218                         evas_object_show(esink->eo);
219                         GST_INFO ("object show..");
220                 }
221                 GST_DEBUG ("[LEAVE]");
222                 return;
223         }
224         if (!buffer || nbyte != sizeof (GstBuffer *)) {
225                 return;
226         }
227
228         memcpy (&buf, buffer, sizeof (GstBuffer *));
229         if (!buf) {
230                 GST_ERROR ("There is no buffer");
231                 return;
232         }
233         if (esink->present_data_addr == -1) {
234                 /* if present_data_addr is -1, we don't use this member variable */
235         } else if (esink->present_data_addr != DO_RENDER_FROM_FIMC) {
236                 GST_WARNING ("skip rendering this buffer, present_data_addr:%d, DO_RENDER_FROM_FIMC:%d", esink->present_data_addr, DO_RENDER_FROM_FIMC);
237                 return;
238         }
239
240         MMTA_ACUM_ITEM_BEGIN("eavsimagesink _cb_pipe total", FALSE);
241
242         if ( !esink->is_evas_object_size_set && esink->w > 0 && esink->h > 0) {
243                         evas_object_image_size_set (esink->eo, esink->w, esink->h);
244                         GST_DEBUG("evas_object_image_size_set(), width(%d),height(%d)",esink->w,esink->h);
245                         esink->is_evas_object_size_set = TRUE;
246         }
247         if (esink->gl_zerocopy) {
248                 img_data = evas_object_image_data_get (esink->eo, EINA_TRUE);
249                 if (!img_data || !GST_BUFFER_DATA(buf)) {
250                         GST_WARNING ("Cannot get image data from evas object or cannot get gstbuffer data");
251                         evas_object_image_data_set(esink->eo, img_data);
252                 } else {
253                         GST_DEBUG ("img_data(%x), GST_BUFFER_DATA(buf):%x, esink->w(%d),esink->h(%d), esink->eo(%x)",img_data,GST_BUFFER_DATA(buf),esink->w,esink->h,esink->eo);
254                         __ta__("evasimagesink memcpy in _cb_pipe", memcpy (img_data, GST_BUFFER_DATA (buf), esink->w * esink->h * COLOR_DEPTH););
255                         evas_object_image_pixels_dirty_set (esink->eo, 1);
256                         evas_object_image_data_set(esink->eo, img_data);
257                 }
258                 gst_buffer_unref (buf);
259         } else {
260                 GST_DEBUG ("GST_BUFFER_DATA(buf):%x, esink->eo(%x)",GST_BUFFER_DATA(buf),esink->eo);
261                 evas_object_image_data_set (esink->eo, GST_BUFFER_DATA (buf));
262                 evas_object_image_pixels_dirty_set (esink->eo, 1);
263                 if (esink->oldbuf) {
264                         gst_buffer_unref(esink->oldbuf);
265                 }
266                 esink->oldbuf = buf;
267         }
268
269         MMTA_ACUM_ITEM_END("eavsimagesink _cb_pipe total", FALSE);
270
271         GST_DEBUG ("[LEAVE]");
272 }
273
274 static void
275 gst_evas_image_sink_init (GstEvasImageSink *esink, GstEvasImageSinkClass *gclass)
276 {
277         GST_DEBUG ("[ENTER]");
278
279         esink->eo = NULL;
280         esink->epipe = NULL;
281         esink->object_show = FALSE;
282         esink->update_visibility = UPDATE_FALSE;
283         esink->gl_zerocopy = FALSE;
284         esink->is_evas_object_size_set = FALSE;
285         esink->present_data_addr = -1;
286
287         if(!instance_lock) {
288                 instance_lock = g_mutex_new();
289         }
290         g_mutex_lock (instance_lock);
291         instance_lock_count++;
292         g_mutex_unlock (instance_lock);
293
294         g_object_weak_ref (G_OBJECT (esink), gst_evas_image_sink_fini, NULL);
295
296         GST_DEBUG ("[LEAVE]");
297 }
298
299 static void
300 evas_callback_del_event (void *data, Evas *e, Evas_Object *obj, void *event_info)
301 {
302         GST_DEBUG ("[ENTER]");
303
304         GstEvasImageSink *esink = data;
305         if (!esink) {
306                 return;
307         }
308
309         EVASIMAGESINK_UNSET_EVAS_OBJECT_EVENT_CALLBACK (esink->eo);
310         if (esink->oldbuf) {
311                 gst_buffer_unref (esink->oldbuf);
312                 esink->oldbuf = NULL;
313         }
314
315         if (esink->eo) {
316                 evas_object_image_data_set(esink->eo, NULL);
317                 esink->eo = NULL;
318         }
319
320         GST_DEBUG ("[LEAVE]");
321 }
322
323 static void
324 evas_callback_resize_event (void *data, Evas *e, Evas_Object *obj, void *event_info)
325 {
326         int w = 0;
327         int h = 0;
328
329         GST_DEBUG ("[ENTER]");
330
331         GstEvasImageSink *esink = data;
332         if (!esink) {
333                 return;
334         }
335
336         evas_object_geometry_get(esink->eo, NULL, NULL, &w, &h);
337         if (!w || !h) {
338                 GST_WARNING ("evas object size (w:%d,h:%d) was not set",w,h);
339         } else {
340                 evas_object_image_fill_set(esink->eo, 0, 0, w, h);
341                 GST_DEBUG ("evas object fill set (w:%d,h:%d)",w,h);
342         }
343
344         GST_DEBUG ("[LEAVE]");
345 }
346
347 static int
348 evas_image_sink_get_size_from_caps (GstCaps *caps, int *w, int *h)
349 {
350         gboolean r;
351         int width, height;
352         GstStructure *s;
353
354         if (!caps || !w || !h) {
355                 return -1;
356         }
357         s = gst_caps_get_structure (caps, 0);
358         if (!s) {
359                 return -1;
360         }
361
362         r = gst_structure_get_int (s, CAP_WIDTH, &width);
363         if (r == FALSE) {
364                 return -1;
365         }
366
367         r = gst_structure_get_int (s, CAP_HEIGHT, &height);
368         if (r == FALSE) {
369                 return -1;
370         }
371
372         *w = width;
373         *h = height;
374         return 0;
375 }
376
377 static gboolean
378 is_zerocopy_supported (Evas *e)
379 {
380         Eina_List *engines, *l;
381         int cur_id;
382         int id;
383         char *name;
384
385         if (!e) {
386                 return FALSE;
387         }
388
389         engines = evas_render_method_list ();
390         if (!engines) {
391                 return FALSE;
392         }
393
394         cur_id = evas_output_method_get (e);
395
396         EINA_LIST_FOREACH (engines, l, name) {
397                 id = evas_render_method_lookup (name);
398                 if (name && id == cur_id) {
399                         if (!strcmp (name, GL_X11_ENGINE)) {
400                                 return TRUE;
401                         }
402                         break;
403                 }
404         }
405         return FALSE;
406 }
407
408 static int
409 evas_image_sink_event_parse_data (GstEvasImageSink *esink, GstEvent *event)
410 {
411         const GstStructure *st;
412         guint st_data_addr = 0;
413         gint st_data_width = 0;
414         gint st_data_height = 0;
415
416         g_return_val_if_fail (event != NULL, FALSE);
417         g_return_val_if_fail (esink != NULL, FALSE);
418
419         if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM_OOB) {
420                 GST_WARNING ("it's not a custom downstream oob event");
421                 return -1;
422         }
423         st = gst_event_get_structure (event);
424         if (st == NULL || !gst_structure_has_name (st, "GstStructureForCustomEvent")) {
425                 GST_WARNING ("structure in a given event is not proper");
426                 return -1;
427         }
428         if (!gst_structure_get_uint (st, "data-addr", &st_data_addr)) {
429                 GST_WARNING ("parsing data-addr failed");
430                 return -1;
431         }
432         esink->present_data_addr = st_data_addr;
433
434         return 0;
435 }
436
437 static gboolean
438 gst_evas_image_sink_event (GstBaseSink *sink, GstEvent *event)
439 {
440         GstEvasImageSink *esink = GST_EVASIMAGESINK (sink);
441         GstMessage *msg;
442         gchar *str;
443
444         switch (GST_EVENT_TYPE (event)) {
445                 case GST_EVENT_FLUSH_START:
446                         GST_DEBUG ("GST_EVENT_FLUSH_START");
447                         break;
448                 case GST_EVENT_FLUSH_STOP:
449                         GST_DEBUG ("GST_EVENT_FLUSH_STOP");
450                         break;
451                 case GST_EVENT_EOS:
452                         GST_DEBUG ("GST_EVENT_EOS");
453                         break;
454                 case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
455                         if(!evas_image_sink_event_parse_data(esink, event)) {
456                                 GST_DEBUG ("GST_EVENT_CUSTOM_DOWNSTREAM_OOB, present_data_addr:%x",esink->present_data_addr);
457                         } else {
458                                 GST_ERROR ("evas_image_sink_event_parse_data() failed");
459                         }
460                         break;
461                 default:
462                         break;
463         }
464         if (GST_BASE_SINK_CLASS (parent_class)->event) {
465                 return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
466         } else {
467                 return TRUE;
468         }
469 }
470
471 static GstStateChangeReturn
472 gst_evas_image_sink_change_state (GstElement *element, GstStateChange transition)
473 {
474         GstStateChangeReturn ret_state = GST_STATE_CHANGE_SUCCESS;
475         GstEvasImageSink *esink = NULL;
476         esink = GST_EVASIMAGESINK(element);
477         int ret = 0;
478
479         if(!esink) {
480                 GST_ERROR("can not get evasimagesink from element");
481                 return GST_STATE_CHANGE_FAILURE;
482         }
483
484         switch (transition) {
485                 case GST_STATE_CHANGE_NULL_TO_READY:
486                         GST_INFO ("*** STATE_CHANGE_NULL_TO_READY ***");
487                         break;
488                 case GST_STATE_CHANGE_READY_TO_PAUSED:
489                         GST_INFO ("*** STATE_CHANGE_READY_TO_PAUSED ***");
490                         break;
491                 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
492                         GST_INFO ("*** STATE_CHANGE_PAUSED_TO_PLAYING ***");
493                         break;
494                 default:
495                         break;
496         }
497
498         ret_state = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
499
500         switch (transition) {
501                 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
502                         GST_INFO ("*** STATE_CHANGE_PLAYING_TO_PAUSED ***");
503                         break;
504                 case GST_STATE_CHANGE_PAUSED_TO_READY:
505                         GST_INFO ("*** STATE_CHANGE_PAUSED_TO_READY ***");
506                         break;
507                 case GST_STATE_CHANGE_READY_TO_NULL:
508                         GST_INFO ("*** STATE_CHANGE_READY_TO_NULL ***");
509                         EVASIMAGESINK_UNSET_EVAS_OBJECT_EVENT_CALLBACK (esink->eo);
510                         if (esink->epipe) {
511                                 ecore_pipe_del (esink->epipe);
512                                 esink->epipe = NULL;
513                         }
514                         break;
515                 default:
516                         break;
517         }
518
519         return ret_state;
520 }
521
522 static void
523 gst_evas_image_sink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
524 {
525         GstEvasImageSink *esink = GST_EVASIMAGESINK (object);
526         Evas_Object *eo;
527
528         g_mutex_lock (instance_lock);
529
530         switch (prop_id) {
531         case PROP_EVAS_OBJECT:
532                 eo = g_value_get_pointer (value);
533                 if (is_evas_image_object (eo)) {
534                         if (eo != esink->eo) {
535                                 Eina_Bool r;
536
537                                 /* delete evas object callbacks registrated on a previous evas image object */
538                                 EVASIMAGESINK_UNSET_EVAS_OBJECT_EVENT_CALLBACK (esink->eo);
539                                 esink->eo = eo;
540                                 /* add evas object callbacks on a new evas image object */
541                                 EVASIMAGESINK_SET_EVAS_OBJECT_EVENT_CALLBACK (esink->eo, esink);
542
543                                 esink->gl_zerocopy = is_zerocopy_supported (evas_object_evas_get (eo));
544                                 if (esink->gl_zerocopy) {
545                                         evas_object_image_content_hint_set (esink->eo, EVAS_IMAGE_CONTENT_HINT_DYNAMIC);
546                                         GST_DEBUG("Enable gl zerocopy");
547                                 }
548                                 GST_DEBUG("Evas Image Object(%x) is set",esink->eo);
549                                 esink->is_evas_object_size_set = FALSE;
550                                 if (!esink->epipe) {
551                                         esink->epipe = ecore_pipe_add (evas_image_sink_cb_pipe, esink);
552                                         if (!esink->epipe) {
553                                                 GST_ERROR ("ecore-pipe create failed");
554                                                 break;
555                                         }
556                                 }
557                         }
558                 } else {
559                         GST_ERROR ("Cannot set evas-object property: value is not an evas image object");
560                 }
561                 break;
562
563         case PROP_EVAS_OBJECT_SHOW:
564         {
565                 Eina_Bool r;
566                 esink->object_show = g_value_get_boolean (value);
567                 if( !is_evas_image_object(esink->eo) ) {
568                         GST_WARNING ("Cannot apply visible(show-object) property: cannot get an evas object\n");
569                         break;
570                 }
571                 esink->update_visibility = UPDATE_TRUE;
572                 if (!esink->epipe) {
573                         esink->epipe = ecore_pipe_add (evas_image_sink_cb_pipe, esink);
574                         if (!esink->epipe) {
575                                 GST_ERROR ("ecore-pipe create failed");
576                                 break;
577                         }
578                 }
579                 r = ecore_pipe_write (esink->epipe, &esink->update_visibility, SIZE_FOR_UPDATE_VISIBILITY);
580                 if (r == EINA_FALSE)  {
581                         GST_WARNING ("Failed to ecore_pipe_write() for updating visibility)\n");
582                 }
583                 break;
584         }
585         default:
586                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
587                 break;
588         }
589
590         g_mutex_unlock (instance_lock);
591 }
592
593 static void
594 gst_evas_image_sink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
595 {
596         GstEvasImageSink *esink = GST_EVASIMAGESINK (object);
597
598         switch (prop_id) {
599         case PROP_EVAS_OBJECT:
600                 g_value_set_pointer (value, esink->eo);
601                 break;
602         case PROP_EVAS_OBJECT_SHOW:
603                 g_value_set_boolean (value, esink->object_show);
604                 break;
605         default:
606                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
607                 break;
608         }
609 }
610
611 static gboolean
612 gst_evas_image_sink_set_caps (GstBaseSink *base_sink, GstCaps *caps)
613 {
614         int r;
615         int w, h;
616         GstEvasImageSink *esink = GST_EVASIMAGESINK (base_sink);
617
618         esink->is_evas_object_size_set = FALSE;
619         r = evas_image_sink_get_size_from_caps (caps, &w, &h);
620         if (!r) {
621                 esink->w = w;
622                 esink->h = h;
623                 GST_DEBUG ("set size w(%d), h(%d)", w, h);
624         }
625         return TRUE;
626 }
627
628 static GstFlowReturn
629 gst_evas_image_sink_show_frame (GstVideoSink *video_sink, GstBuffer *buf)
630 {
631         GstEvasImageSink *esink = GST_EVASIMAGESINK (video_sink);
632         Eina_Bool r;
633
634         g_mutex_lock (instance_lock);
635         if (esink->present_data_addr == -1) {
636                 /* if present_data_addr is -1, we don't use this member variable */
637         } else if (esink->present_data_addr != DO_RENDER_FROM_FIMC) {
638                 GST_WARNING ("skip rendering this buffer, present_data_addr:%d, DO_RENDER_FROM_FIMC:%d", esink->present_data_addr, DO_RENDER_FROM_FIMC);
639                 g_mutex_unlock (instance_lock);
640                 return GST_FLOW_OK;
641         }
642         if (!esink->epipe) {
643                 esink->epipe = ecore_pipe_add (evas_image_sink_cb_pipe, esink);
644                 if (!esink->epipe) {
645                         GST_ERROR ("ecore-pipe create failed");
646                         g_mutex_unlock (instance_lock);
647                         return GST_FLOW_ERROR;
648                 }
649         }
650
651         gst_buffer_ref (buf);
652         __ta__("evasimagesink ecore_pipe_write", r = ecore_pipe_write (esink->epipe, &buf, sizeof (GstBuffer *)););
653         if (r == EINA_FALSE)  {
654                 gst_buffer_unref (buf);
655         }
656         GST_DEBUG ("ecore_pipe_write() was called with GST_BUFFER_DATA(buf):%x", GST_BUFFER_DATA(buf));
657
658         g_mutex_unlock (instance_lock);
659         return GST_FLOW_OK;
660 }
661
662 static gboolean
663 evas_image_sink_init (GstPlugin *evasimagesink)
664 {
665         GST_DEBUG_CATEGORY_INIT (gst_evas_image_sink_debug, "evasimagesink", 0, "Evas image object based videosink");
666
667         return gst_element_register (evasimagesink, "evasimagesink", GST_RANK_NONE, GST_TYPE_EVASIMAGESINK);
668 }
669
670 #ifndef PACKAGE
671 #define PACKAGE "gstevasimagesink-plugin-package"
672 #endif
673
674 GST_PLUGIN_DEFINE (
675         GST_VERSION_MAJOR,
676         GST_VERSION_MINOR,
677         "evasimagesink",
678         "Evas image object based videosink",
679         evas_image_sink_init,
680         VERSION,
681         "LGPL",
682         "Samsung Electronics Co",
683         "http://www.samsung.com/"
684 )