3 #include "emotion_gstreamer.h"
5 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE("sink",
6 GST_PAD_SINK, GST_PAD_ALWAYS,
7 GST_STATIC_CAPS(GST_VIDEO_CAPS_YUV("{ I420, YV12, YUY2, NV12, ST12, TM12 }") ";"
8 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_BGR ";" GST_VIDEO_CAPS_BGRA));
10 GST_DEBUG_CATEGORY_STATIC(evas_video_sink_debug);
11 #define GST_CAT_DEFAULT evas_video_sink_debug
27 static guint evas_video_sink_signals[LAST_SIGNAL] = { 0, };
29 #define _do_init(bla) \
30 GST_DEBUG_CATEGORY_INIT(evas_video_sink_debug, \
35 GST_BOILERPLATE_FULL(EvasVideoSink,
42 static void unlock_buffer_mutex(EvasVideoSinkPrivate* priv);
43 static void evas_video_sink_main_render(void *data);
44 static void evas_video_sink_samsung_main_render(void *data);
47 _evas_video_bgrx_step(unsigned char *evas_data, const unsigned char *gst_data,
48 unsigned int w, unsigned int h, unsigned int step)
53 for (y = 0; y < h; ++y)
55 for (x = 0; x < w; x++)
57 evas_data[0] = gst_data[0];
58 evas_data[1] = gst_data[1];
59 evas_data[2] = gst_data[2];
68 _evas_video_bgr(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
70 _evas_video_bgrx_step(evas_data, gst_data, w, h, 3);
74 _evas_video_bgrx(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
76 _evas_video_bgrx_step(evas_data, gst_data, w, h, 4);
80 _evas_video_bgra(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
85 for (y = 0; y < h; ++y)
89 for (x = 0; x < w; ++x)
92 evas_data[0] = (gst_data[0] * alpha) / 255;
93 evas_data[1] = (gst_data[1] * alpha) / 255;
94 evas_data[2] = (gst_data[2] * alpha) / 255;
103 _evas_video_i420(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
105 const unsigned char **rows;
108 rows = (const unsigned char **)evas_data;
110 for (i = 0; i < h; i++)
111 rows[i] = &gst_data[i * w];
114 for (i = 0; i < (h / 2); i++)
115 rows[i] = &gst_data[h * w + i * (w / 2)];
118 for (i = 0; i < (h / 2); i++)
119 rows[i] = &gst_data[h * w + h * (w /4) + i * (w / 2)];
123 _evas_video_yv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
125 const unsigned char **rows;
128 rows = (const unsigned char **)evas_data;
130 for (i = 0; i < h; i++)
131 rows[i] = &gst_data[i * w];
134 for (i = 0; i < (h / 2); i++)
135 rows[i] = &gst_data[h * w + h * (w /4) + i * (w / 2)];
138 for (i = 0; i < (h / 2); i++)
139 rows[i] = &gst_data[h * w + i * (w / 2)];
143 _evas_video_yuy2(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
145 const unsigned char **rows;
148 rows = (const unsigned char **)evas_data;
150 for (i = 0; i < h; i++)
151 rows[i] = &gst_data[i * w * 2];
155 _evas_video_nv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
157 const unsigned char **rows;
160 rows = (const unsigned char **)evas_data;
162 for (i = 0; i < h; i++)
163 rows[i] = &gst_data[i * w];
166 for (j = 0; j < (h / 2); j++, i++)
167 rows[i] = &gst_data[h * w + j * w];
171 _evas_video_mt12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
173 const unsigned char **rows;
177 rows = (const unsigned char **)evas_data;
179 for (i = 0; i < (h / 32) / 2; i++)
180 rows[i] = &gst_data[i * w * 2 * 32];
184 rows[i] = &gst_data[i * w * 2 * 32];
189 for (j = 0; j < ((h / 2) / 32) / 2; ++j, ++i)
190 rows[i] = &gst_data[h * w + j * (w / 2) * 2 * 16];
194 _evas_video_st12_multiplane(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
196 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) gst_data;
197 const unsigned char **rows;
201 rows = (const unsigned char **)evas_data;
203 for (i = 0; i < (h / 32) / 2; i++)
204 rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
207 rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
211 for (j = 0; j < ((h / 2) / 16) / 2; j++, i++)
212 rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16;
213 if (((h / 2) / 16) % 2)
214 rows[i] = mp_buf->uaddr[0] + j * w * 2 * 16;
218 _evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h)
220 const SCMN_IMGB *imgb = (const SCMN_IMGB *) gst_data;
221 const unsigned char **rows;
224 rows = (const unsigned char **)evas_data;
226 for (i = 0; i < (h / 32) / 2; i++)
227 rows[i] = imgb->uaddr[0] + i * w * 2 * 32;
230 rows[i] = imgb->uaddr[0] + i * w * 2 * 32;
234 for (j = 0; j < ((h / 2) / 16) / 2; j++, i++)
235 rows[i] = imgb->uaddr[1] + j * w * 2 * 16;
236 if (((h / 2) / 16) % 2)
237 rows[i] = imgb->uaddr[1] + j * w * 2 * 16;
240 static const struct {
242 Evas_Colorspace eformat;
243 Evas_Video_Convert_Cb func;
244 } colorspace_fourcc_convertion[] = {
245 { GST_MAKE_FOURCC('I', '4', '2', '0'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420 },
246 { GST_MAKE_FOURCC('Y', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12 },
247 { GST_MAKE_FOURCC('Y', 'U', 'Y', '2'), EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2 },
248 { GST_MAKE_FOURCC('N', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12 },
249 { GST_MAKE_FOURCC('T', 'M', '1', '2'), EVAS_COLORSPACE_YCBCR420TM12601_PL, _evas_video_mt12 }
252 static const struct {
253 GstVideoFormat format;
254 Evas_Colorspace eformat;
255 Evas_Video_Convert_Cb func;
256 } colorspace_format_convertion[] = {
257 { GST_VIDEO_FORMAT_BGR, EVAS_COLORSPACE_ARGB8888, _evas_video_bgr },
258 { GST_VIDEO_FORMAT_BGRx, EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx },
259 { GST_VIDEO_FORMAT_BGRA, EVAS_COLORSPACE_ARGB8888, _evas_video_bgra }
263 evas_video_sink_base_init(gpointer g_class)
265 GstElementClass* element_class;
267 element_class = GST_ELEMENT_CLASS(g_class);
268 gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&sinktemplate));
269 gst_element_class_set_details_simple(element_class, "Evas video sink",
270 "Sink/Video", "Sends video data from a GStreamer pipeline to an Evas object",
271 "Vincent Torri <vtorri@univ-evry.fr>");
275 evas_video_sink_init(EvasVideoSink* sink, EvasVideoSinkClass* klass __UNUSED__)
277 EvasVideoSinkPrivate* priv;
280 sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(sink, EVAS_TYPE_VIDEO_SINK, EvasVideoSinkPrivate);
282 priv->last_buffer = NULL;
286 priv->eformat = EVAS_COLORSPACE_ARGB8888;
287 priv->samsung = EINA_FALSE;
288 eina_lock_new(&priv->m);
289 eina_condition_new(&priv->c, &priv->m);
290 priv->unlocked = EINA_FALSE;
294 /**** Object methods ****/
296 _cleanup_priv(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
298 EvasVideoSinkPrivate* priv;
302 eina_lock_take(&priv->m);
305 eina_lock_release(&priv->m);
309 evas_video_sink_set_property(GObject * object, guint prop_id,
310 const GValue * value, GParamSpec * pspec)
313 EvasVideoSinkPrivate* priv;
315 sink = EVAS_VIDEO_SINK (object);
319 case PROP_EVAS_OBJECT:
320 eina_lock_take(&priv->m);
321 evas_object_event_callback_del(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv);
322 priv->o = g_value_get_pointer (value);
323 INF("sink set Evas_Object %p.", priv->o);
324 evas_object_event_callback_add(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv, priv);
325 eina_lock_release(&priv->m);
329 eina_lock_take(&priv->m);
330 priv->ev = g_value_get_pointer (value);
331 eina_lock_release(&priv->m);
334 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
335 ERR("invalid property");
341 evas_video_sink_get_property(GObject * object, guint prop_id,
342 GValue * value, GParamSpec * pspec)
345 EvasVideoSinkPrivate* priv;
347 sink = EVAS_VIDEO_SINK (object);
351 case PROP_EVAS_OBJECT:
352 INF("sink get property.");
353 eina_lock_take(&priv->m);
354 g_value_set_pointer(value, priv->o);
355 eina_lock_release(&priv->m);
358 INF("sink get width.");
359 eina_lock_take(&priv->m);
360 g_value_set_int(value, priv->width);
361 eina_lock_release(&priv->m);
364 INF("sink get height.");
365 eina_lock_take(&priv->m);
366 g_value_set_int (value, priv->height);
367 eina_lock_release(&priv->m);
371 eina_lock_take(&priv->m);
372 g_value_set_pointer (value, priv->ev);
373 eina_lock_release(&priv->m);
376 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
377 ERR("invalide property");
383 evas_video_sink_dispose(GObject* object)
386 EvasVideoSinkPrivate* priv;
390 sink = EVAS_VIDEO_SINK(object);
393 eina_lock_free(&priv->m);
394 eina_condition_free(&priv->c);
396 if (priv->last_buffer) {
397 gst_buffer_unref(priv->last_buffer);
398 priv->last_buffer = NULL;
401 G_OBJECT_CLASS(parent_class)->dispose(object);
405 /**** BaseSink methods ****/
407 gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps)
410 EvasVideoSinkPrivate* priv;
411 GstStructure *structure;
412 GstVideoFormat format;
416 sink = EVAS_VIDEO_SINK(bsink);
419 structure = gst_caps_get_structure(caps, 0);
421 if (gst_structure_get_int(structure, "width", &priv->width)
422 && gst_structure_get_int(structure, "height", &priv->height)
423 && gst_structure_get_fourcc(structure, "format", &fourcc))
425 for (i = 0; i < sizeof (colorspace_fourcc_convertion) / sizeof (colorspace_fourcc_convertion[0]); ++i)
426 if (fourcc == colorspace_fourcc_convertion[i].fourcc)
428 priv->eformat = colorspace_fourcc_convertion[i].eformat;
429 priv->func = colorspace_fourcc_convertion[i].func;
433 if (fourcc == GST_MAKE_FOURCC('S', 'T', '1', '2'))
435 priv->eformat = EVAS_COLORSPACE_YCBCR420TM12601_PL;
436 priv->samsung = EINA_TRUE;
441 INF("fallback code !");
442 if (!gst_video_format_parse_caps(caps, &format, &priv->width, &priv->height))
444 ERR("Unable to parse caps.");
448 for (i = 0; i < sizeof (colorspace_format_convertion) / sizeof (colorspace_format_convertion[0]); ++i)
449 if (format == colorspace_format_convertion[i].format)
451 priv->eformat = colorspace_format_convertion[i].eformat;
452 priv->func = colorspace_format_convertion[i].func;
456 ERR("unsupported : %d\n", format);
461 evas_video_sink_start(GstBaseSink* base_sink)
463 EvasVideoSinkPrivate* priv;
468 priv = EVAS_VIDEO_SINK(base_sink)->priv;
469 eina_lock_take(&priv->m);
473 priv->unlocked = EINA_FALSE;
474 eina_lock_release(&priv->m);
479 evas_video_sink_stop(GstBaseSink* base_sink)
481 EvasVideoSinkPrivate* priv = EVAS_VIDEO_SINK(base_sink)->priv;
485 unlock_buffer_mutex(priv);
490 evas_video_sink_unlock(GstBaseSink* object)
496 sink = EVAS_VIDEO_SINK(object);
498 unlock_buffer_mutex(sink->priv);
500 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock,
505 evas_video_sink_unlock_stop(GstBaseSink* object)
508 EvasVideoSinkPrivate* priv;
510 sink = EVAS_VIDEO_SINK(object);
513 INF("sink unlock stop");
515 eina_lock_take(&priv->m);
516 priv->unlocked = FALSE;
517 eina_lock_release(&priv->m);
519 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock_stop,
524 evas_video_sink_preroll(GstBaseSink* bsink, GstBuffer* buffer)
526 Emotion_Gstreamer_Buffer *send;
527 EvasVideoSinkPrivate *priv;
530 INF("sink preroll %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
532 sink = EVAS_VIDEO_SINK(bsink);
535 if (GST_BUFFER_SIZE(buffer) <= 0 && !priv->samsung)
541 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_TRUE);
549 GstStructure *structure;
551 gboolean is_multiplane = FALSE;
553 caps = GST_BUFFER_CAPS(buffer);
554 structure = gst_caps_get_structure (caps, 0);
555 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
558 priv->func = _evas_video_st12_multiplane;
560 priv->func = _evas_video_st12;
563 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
566 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
573 evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer)
575 Emotion_Gstreamer_Buffer *send;
576 EvasVideoSinkPrivate *priv;
579 INF("sink render %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
581 sink = EVAS_VIDEO_SINK(bsink);
584 eina_lock_take(&priv->m);
586 if (priv->unlocked) {
588 eina_lock_release(&priv->m);
592 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_FALSE);
594 eina_lock_release(&priv->m);
595 return GST_FLOW_ERROR;
602 GstStructure *structure;
604 gboolean is_multiplane = FALSE;
606 caps = GST_BUFFER_CAPS(buffer);
607 structure = gst_caps_get_structure (caps, 0);
608 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
611 priv->func = _evas_video_st12_multiplane;
613 priv->func = _evas_video_st12;
616 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
619 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
621 eina_condition_wait(&priv->c);
622 eina_lock_release(&priv->m);
628 evas_video_sink_samsung_main_render(void *data)
630 Emotion_Gstreamer_Buffer *send;
631 Emotion_Video_Stream *vstream;
632 EvasVideoSinkPrivate* priv;
634 unsigned char *evas_data;
635 const guint8 *gst_data;
636 GstFormat fmt = GST_FORMAT_TIME;
639 int stride, elevation;
644 if (!send) goto exit_point;
647 buffer = send->frame;
648 preroll = send->preroll;
650 if (!priv || !priv->o || priv->unlocked || !send->ev)
653 _emotion_gstreamer_video_pipeline_parse(send->ev, EINA_TRUE);
655 /* Getting stride to compute the right size and then fill the object properly */
656 /* Y => [0] and UV in [1] */
657 if (priv->func == _evas_video_st12_multiplane)
659 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) buffer;
661 stride = mp_buf->stride[0];
662 elevation = mp_buf->elevation[0];
663 priv->width = mp_buf->width[0];
664 priv->height = mp_buf->height[0];
666 gst_data = (const guint8 *) mp_buf;
670 const SCMN_IMGB *imgb = (const SCMN_IMGB *) GST_BUFFER_MALLOCDATA(buffer);
672 stride = imgb->stride[0];
673 elevation = imgb->elevation[0];
674 priv->width = imgb->width[0];
675 priv->height = imgb->height[0];
677 gst_data = (const guint8 *) imgb;
680 INF("sink main render [%i, %i] - [%i, %i]", priv->width, priv->height, stride, elevation);
682 evas_object_image_alpha_set(priv->o, 0);
683 evas_object_image_colorspace_set(priv->o, priv->eformat);
684 evas_object_image_size_set(priv->o, stride, elevation);
685 evas_object_geometry_get(priv->o, NULL, NULL, &w, &h);
686 evas_object_image_fill_set(priv->o, 0, 0, stride * w / priv->width, elevation * h / priv->height);
688 evas_data = evas_object_image_data_get(priv->o, 1);
691 priv->func(evas_data, gst_data, stride, elevation);
693 WRN("No way to decode %x colorspace !", priv->eformat);
695 evas_object_image_data_set(priv->o, evas_data);
696 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
697 evas_object_image_pixels_dirty_set(priv->o, 0);
699 _emotion_frame_new(send->ev->obj);
701 vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1);
703 gst_element_query_position(send->ev->pipeline, &fmt, &pos);
704 send->ev->position = (double)pos / (double)GST_SECOND;
706 vstream->width = priv->width;
707 vstream->height = priv->height;
708 send->ev->ratio = (double) priv->width / (double) priv->height;
710 _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time);
711 _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio);
713 if (priv->last_buffer) gst_buffer_unref(priv->last_buffer);
714 priv->last_buffer = gst_buffer_ref(buffer);
717 emotion_gstreamer_buffer_free(send);
719 if (preroll || !priv->o || !send->ev) return ;
721 eina_lock_take(&priv->m);
723 eina_condition_signal(&priv->c);
725 eina_lock_release(&priv->m);
729 evas_video_sink_main_render(void *data)
731 Emotion_Gstreamer_Buffer *send;
732 Emotion_Gstreamer_Video *ev = NULL;
733 Emotion_Video_Stream *vstream;
734 EvasVideoSinkPrivate* priv;
736 unsigned char *evas_data;
737 GstFormat fmt = GST_FORMAT_TIME;
743 if (!send) goto exit_point;
746 buffer = send->frame;
747 preroll = send->preroll;
750 if (!priv || !priv->o || priv->unlocked || !ev)
753 _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE);
755 INF("sink main render [%i, %i]", priv->width, priv->height);
757 evas_object_image_alpha_set(priv->o, 0);
758 evas_object_image_colorspace_set(priv->o, priv->eformat);
759 evas_object_image_size_set(priv->o, priv->width, priv->height);
761 evas_data = evas_object_image_data_get(priv->o, 1);
764 priv->func(evas_data, GST_BUFFER_DATA(buffer), priv->width, priv->height);
766 WRN("No way to decode %x colorspace !", priv->eformat);
768 evas_object_image_data_set(priv->o, evas_data);
769 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
770 evas_object_image_pixels_dirty_set(priv->o, 0);
772 _emotion_frame_new(ev->obj);
774 vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
776 gst_element_query_position(ev->pipeline, &fmt, &pos);
777 ev->position = (double)pos / (double)GST_SECOND;
779 vstream->width = priv->width;
780 vstream->height = priv->height;
781 ev->ratio = (double) priv->width / (double) priv->height;
783 _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
784 _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
786 if (priv->last_buffer) gst_buffer_unref(priv->last_buffer);
787 priv->last_buffer = gst_buffer_ref(buffer);
790 emotion_gstreamer_buffer_free(send);
792 if (preroll || !priv->o || !ev) return ;
794 eina_lock_take(&priv->m);
796 eina_condition_signal(&priv->c);
798 eina_lock_release(&priv->m);
802 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
804 eina_lock_take(&priv->m);
805 priv->unlocked = EINA_TRUE;
807 eina_condition_signal(&priv->c);
808 eina_lock_release(&priv->m);
812 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
813 guint n_param_values, const GValue * param_values,
814 gpointer invocation_hint __UNUSED__, gpointer marshal_data)
816 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
817 marshalfunc_VOID__MINIOBJECT callback;
819 gpointer data1, data2;
821 cc = (GCClosure *) closure;
823 g_return_if_fail(n_param_values == 2);
825 if (G_CCLOSURE_SWAP_DATA(closure)) {
826 data1 = closure->data;
827 data2 = g_value_peek_pointer(param_values + 0);
829 data1 = g_value_peek_pointer(param_values + 0);
830 data2 = closure->data;
832 callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
834 callback(data1, gst_value_get_mini_object(param_values + 1), data2);
838 evas_video_sink_class_init(EvasVideoSinkClass* klass)
840 GObjectClass* gobject_class;
841 GstBaseSinkClass* gstbase_sink_class;
843 gobject_class = G_OBJECT_CLASS(klass);
844 gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
846 g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
848 gobject_class->set_property = evas_video_sink_set_property;
849 gobject_class->get_property = evas_video_sink_get_property;
851 g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
852 g_param_spec_pointer ("evas-object", "Evas Object",
853 "The Evas object where the display of the video will be done",
856 g_object_class_install_property (gobject_class, PROP_WIDTH,
857 g_param_spec_int ("width", "Width",
858 "The width of the video",
859 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
861 g_object_class_install_property (gobject_class, PROP_HEIGHT,
862 g_param_spec_int ("height", "Height",
863 "The height of the video",
864 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
865 g_object_class_install_property (gobject_class, PROP_EV,
866 g_param_spec_pointer ("ev", "Emotion_Gstreamer_Video",
867 "THe internal data of the emotion object",
870 gobject_class->dispose = evas_video_sink_dispose;
872 gstbase_sink_class->set_caps = evas_video_sink_set_caps;
873 gstbase_sink_class->stop = evas_video_sink_stop;
874 gstbase_sink_class->start = evas_video_sink_start;
875 gstbase_sink_class->unlock = evas_video_sink_unlock;
876 gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
877 gstbase_sink_class->render = evas_video_sink_render;
878 gstbase_sink_class->preroll = evas_video_sink_preroll;
880 evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
881 G_TYPE_FROM_CLASS(klass),
882 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
886 marshal_VOID__MINIOBJECT,
887 G_TYPE_NONE, 1, GST_TYPE_BUFFER);
891 gstreamer_plugin_init (GstPlugin * plugin)
893 return gst_element_register (plugin,
896 EVAS_TYPE_VIDEO_SINK);
900 _emotion_gstreamer_pause(void *data, Ecore_Thread *thread)
902 Emotion_Gstreamer_Video *ev = data;
904 if (ecore_thread_check(thread) || !ev->pipeline) return ;
906 gst_element_set_state(ev->pipeline, GST_STATE_PAUSED);
910 _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread)
912 Emotion_Gstreamer_Video *ev = data;
914 ev->threads = eina_list_remove(ev->threads, thread);
916 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"));
918 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
923 _emotion_gstreamer_end(void *data, Ecore_Thread *thread)
925 Emotion_Gstreamer_Video *ev = data;
927 ev->threads = eina_list_remove(ev->threads, thread);
931 gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
932 ev->play_started = 1;
935 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"));
937 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
940 _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE);
944 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
953 obj = emotion_object_image_get(o);
956 ERR("Not Evas_Object specified");
960 playbin = gst_element_factory_make("playbin2", "playbin");
963 ERR("Unable to create 'playbin' GstElement.");
967 sink = gst_element_factory_make("emotion-sink", "sink");
970 ERR("Unable to create 'emotion-sink' GstElement.");
974 #define GST_PLAY_FLAG_NATIVE_VIDEO (1 << 6)
975 #define GST_PLAY_FLAG_DOWNLOAD (1 << 7)
976 #define GST_PLAY_FLAG_BUFFERING (1 << 8)
978 g_object_set(G_OBJECT(sink), "evas-object", obj, NULL);
979 g_object_set(G_OBJECT(sink), "ev", ev, NULL);
981 g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
982 g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD | GST_PLAY_FLAG_BUFFERING, NULL);
983 g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL);
984 g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
986 ev->pipeline = playbin;
988 ev->threads = eina_list_append(ev->threads,
989 ecore_thread_run(_emotion_gstreamer_pause,
990 _emotion_gstreamer_end,
991 _emotion_gstreamer_cancel,
994 /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
995 /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
996 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"));
1001 gst_object_unref(playbin);