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 __UNUSED__, unsigned int output_height, unsigned int step)
53 for (y = 0; y < output_height; ++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, unsigned int output_height)
70 _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 3);
74 _evas_video_bgrx(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
76 _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 4);
80 _evas_video_bgra(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
85 for (y = 0; y < output_height; ++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, unsigned int output_height)
105 const unsigned char **rows;
111 rows = (const unsigned char **)evas_data;
113 for (i = 0; i < rh; i++)
114 rows[i] = &gst_data[i * w];
116 for (j = 0; j < (rh / 2); j++, i++)
117 rows[i] = &gst_data[h * w + j * (w / 2)];
119 for (j = 0; j < (rh / 2); j++, i++)
120 rows[i] = &gst_data[h * w + h * (w / 4) + j * (w / 2)];
124 _evas_video_yv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
126 const unsigned char **rows;
132 rows = (const unsigned char **)evas_data;
134 for (i = 0; i < rh; i++)
135 rows[i] = &gst_data[i * w];
137 for (j = 0; j < (rh / 2); j++, i++)
138 rows[i] = &gst_data[h * w + h * (w / 4) + j * (w / 2)];
140 for (j = 0; j < (rh / 2); j++, i++)
141 rows[i] = &gst_data[h * w + j * (w / 2)];
145 _evas_video_yuy2(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
147 const unsigned char **rows;
150 rows = (const unsigned char **)evas_data;
152 for (i = 0; i < output_height; i++)
153 rows[i] = &gst_data[i * w * 2];
157 _evas_video_nv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
159 const unsigned char **rows;
165 rows = (const unsigned char **)evas_data;
167 for (i = 0; i < rh; i++)
168 rows[i] = &gst_data[i * w];
170 for (j = 0; j < (rh / 2); j++, i++)
171 rows[i] = &gst_data[h * w + j * w];
175 _evas_video_mt12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
177 const unsigned char **rows;
181 rows = (const unsigned char **)evas_data;
183 for (i = 0; i < (h / 32) / 2; i++)
184 rows[i] = &gst_data[i * w * 2 * 32];
188 rows[i] = &gst_data[i * w * 2 * 32];
192 for (j = 0; j < ((h / 2) / 32) / 2; ++j, ++i)
193 rows[i] = &gst_data[h * w + j * (w / 2) * 2 * 16];
197 _evas_video_st12_multiplane(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
199 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) gst_data;
200 const unsigned char **rows;
204 rows = (const unsigned char **)evas_data;
206 for (i = 0; i < (h / 32) / 2; i++)
207 rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
210 rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
214 for (j = 0; j < ((h / 2) / 16) / 2; j++, i++)
215 rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16;
216 if (((h / 2) / 16) % 2)
217 rows[i] = mp_buf->uaddr[0] + j * w * 2 * 16;
221 _evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
223 const SCMN_IMGB *imgb = (const SCMN_IMGB *) gst_data;
224 const unsigned char **rows;
227 rows = (const unsigned char **)evas_data;
229 for (i = 0; i < (h / 32) / 2; i++)
230 rows[i] = imgb->uaddr[0] + i * w * 2 * 32;
233 rows[i] = imgb->uaddr[0] + i * w * 2 * 32;
237 for (j = 0; j < ((h / 2) / 16) / 2; j++, i++)
238 rows[i] = imgb->uaddr[1] + j * w * 2 * 16;
239 if (((h / 2) / 16) % 2)
240 rows[i] = imgb->uaddr[1] + j * w * 2 * 16;
243 static const struct {
245 Evas_Colorspace eformat;
246 Evas_Video_Convert_Cb func;
247 Eina_Bool force_height;
248 } colorspace_fourcc_convertion[] = {
249 { GST_MAKE_FOURCC('I', '4', '2', '0'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420, EINA_TRUE },
250 { GST_MAKE_FOURCC('Y', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12, EINA_TRUE },
251 { GST_MAKE_FOURCC('Y', 'U', 'Y', '2'), EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2, EINA_FALSE },
252 { GST_MAKE_FOURCC('N', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE },
253 { GST_MAKE_FOURCC('T', 'M', '1', '2'), EVAS_COLORSPACE_YCBCR420TM12601_PL, _evas_video_mt12, EINA_TRUE }
256 static const struct {
257 GstVideoFormat format;
258 Evas_Colorspace eformat;
259 Evas_Video_Convert_Cb func;
260 } colorspace_format_convertion[] = {
261 { GST_VIDEO_FORMAT_BGR, EVAS_COLORSPACE_ARGB8888, _evas_video_bgr },
262 { GST_VIDEO_FORMAT_BGRx, EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx },
263 { GST_VIDEO_FORMAT_BGRA, EVAS_COLORSPACE_ARGB8888, _evas_video_bgra }
267 evas_video_sink_base_init(gpointer g_class)
269 GstElementClass* element_class;
271 element_class = GST_ELEMENT_CLASS(g_class);
272 gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&sinktemplate));
273 gst_element_class_set_details_simple(element_class, "Evas video sink",
274 "Sink/Video", "Sends video data from a GStreamer pipeline to an Evas object",
275 "Vincent Torri <vtorri@univ-evry.fr>");
279 evas_video_sink_init(EvasVideoSink* sink, EvasVideoSinkClass* klass __UNUSED__)
281 EvasVideoSinkPrivate* priv;
284 sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(sink, EVAS_TYPE_VIDEO_SINK, EvasVideoSinkPrivate);
286 priv->last_buffer = NULL;
290 priv->eformat = EVAS_COLORSPACE_ARGB8888;
291 priv->samsung = EINA_FALSE;
292 eina_lock_new(&priv->m);
293 eina_condition_new(&priv->c, &priv->m);
294 priv->unlocked = EINA_FALSE;
297 /**** Object methods ****/
299 _cleanup_priv(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
301 EvasVideoSinkPrivate* priv;
305 eina_lock_take(&priv->m);
308 eina_lock_release(&priv->m);
312 evas_video_sink_set_property(GObject * object, guint prop_id,
313 const GValue * value, GParamSpec * pspec)
316 EvasVideoSinkPrivate* priv;
318 sink = EVAS_VIDEO_SINK (object);
322 case PROP_EVAS_OBJECT:
323 eina_lock_take(&priv->m);
324 evas_object_event_callback_del(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv);
325 priv->o = g_value_get_pointer (value);
326 INF("sink set Evas_Object %p.", priv->o);
327 evas_object_event_callback_add(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv, priv);
328 eina_lock_release(&priv->m);
332 eina_lock_take(&priv->m);
333 priv->ev = g_value_get_pointer (value);
334 eina_lock_release(&priv->m);
337 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338 ERR("invalid property");
344 evas_video_sink_get_property(GObject * object, guint prop_id,
345 GValue * value, GParamSpec * pspec)
348 EvasVideoSinkPrivate* priv;
350 sink = EVAS_VIDEO_SINK (object);
354 case PROP_EVAS_OBJECT:
355 INF("sink get property.");
356 eina_lock_take(&priv->m);
357 g_value_set_pointer(value, priv->o);
358 eina_lock_release(&priv->m);
361 INF("sink get width.");
362 eina_lock_take(&priv->m);
363 g_value_set_int(value, priv->width);
364 eina_lock_release(&priv->m);
367 INF("sink get height.");
368 eina_lock_take(&priv->m);
369 g_value_set_int (value, priv->height);
370 eina_lock_release(&priv->m);
374 eina_lock_take(&priv->m);
375 g_value_set_pointer (value, priv->ev);
376 eina_lock_release(&priv->m);
379 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
380 ERR("invalide property");
386 evas_video_sink_dispose(GObject* object)
389 EvasVideoSinkPrivate* priv;
393 sink = EVAS_VIDEO_SINK(object);
396 eina_lock_free(&priv->m);
397 eina_condition_free(&priv->c);
399 if (priv->last_buffer) {
400 gst_buffer_unref(priv->last_buffer);
401 priv->last_buffer = NULL;
404 G_OBJECT_CLASS(parent_class)->dispose(object);
408 /**** BaseSink methods ****/
410 gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps)
413 EvasVideoSinkPrivate* priv;
414 GstStructure *structure;
415 GstVideoFormat format;
419 sink = EVAS_VIDEO_SINK(bsink);
422 structure = gst_caps_get_structure(caps, 0);
424 if (gst_structure_get_int(structure, "width", (int*) &priv->width)
425 && gst_structure_get_int(structure, "height", (int*) &priv->height)
426 && gst_structure_get_fourcc(structure, "format", &fourcc))
428 priv->source_height = priv->height;
430 for (i = 0; i < sizeof (colorspace_fourcc_convertion) / sizeof (colorspace_fourcc_convertion[0]); ++i)
431 if (fourcc == colorspace_fourcc_convertion[i].fourcc)
433 priv->eformat = colorspace_fourcc_convertion[i].eformat;
434 priv->func = colorspace_fourcc_convertion[i].func;
435 if (colorspace_fourcc_convertion[i].force_height)
437 priv->height = (priv->height >> 1) << 1;
442 if (fourcc == GST_MAKE_FOURCC('S', 'T', '1', '2'))
444 priv->eformat = EVAS_COLORSPACE_YCBCR420TM12601_PL;
445 priv->samsung = EINA_TRUE;
451 INF("fallback code !");
452 if (!gst_video_format_parse_caps(caps, &format, (int*) &priv->width, (int*) &priv->height))
454 ERR("Unable to parse caps.");
458 priv->source_height = priv->height;
460 for (i = 0; i < sizeof (colorspace_format_convertion) / sizeof (colorspace_format_convertion[0]); ++i)
461 if (format == colorspace_format_convertion[i].format)
463 priv->eformat = colorspace_format_convertion[i].eformat;
464 priv->func = colorspace_format_convertion[i].func;
468 ERR("unsupported : %d\n", format);
473 evas_video_sink_start(GstBaseSink* base_sink)
475 EvasVideoSinkPrivate* priv;
480 priv = EVAS_VIDEO_SINK(base_sink)->priv;
481 eina_lock_take(&priv->m);
485 priv->unlocked = EINA_FALSE;
486 eina_lock_release(&priv->m);
491 evas_video_sink_stop(GstBaseSink* base_sink)
493 EvasVideoSinkPrivate* priv = EVAS_VIDEO_SINK(base_sink)->priv;
497 unlock_buffer_mutex(priv);
502 evas_video_sink_unlock(GstBaseSink* object)
508 sink = EVAS_VIDEO_SINK(object);
510 unlock_buffer_mutex(sink->priv);
512 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock,
517 evas_video_sink_unlock_stop(GstBaseSink* object)
520 EvasVideoSinkPrivate* priv;
522 sink = EVAS_VIDEO_SINK(object);
525 INF("sink unlock stop");
527 eina_lock_take(&priv->m);
528 priv->unlocked = FALSE;
529 eina_lock_release(&priv->m);
531 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock_stop,
536 evas_video_sink_preroll(GstBaseSink* bsink, GstBuffer* buffer)
538 Emotion_Gstreamer_Buffer *send;
539 EvasVideoSinkPrivate *priv;
542 INF("sink preroll %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
544 sink = EVAS_VIDEO_SINK(bsink);
547 if (GST_BUFFER_SIZE(buffer) <= 0 && !priv->samsung)
553 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_TRUE);
561 GstStructure *structure;
563 gboolean is_multiplane = FALSE;
565 caps = GST_BUFFER_CAPS(buffer);
566 structure = gst_caps_get_structure (caps, 0);
567 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
570 priv->func = _evas_video_st12_multiplane;
572 priv->func = _evas_video_st12;
575 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
578 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
585 evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer)
587 Emotion_Gstreamer_Buffer *send;
588 EvasVideoSinkPrivate *priv;
591 INF("sink render %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
593 sink = EVAS_VIDEO_SINK(bsink);
596 eina_lock_take(&priv->m);
598 if (priv->unlocked) {
600 eina_lock_release(&priv->m);
604 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_FALSE);
606 eina_lock_release(&priv->m);
607 return GST_FLOW_ERROR;
614 GstStructure *structure;
616 gboolean is_multiplane = FALSE;
618 caps = GST_BUFFER_CAPS(buffer);
619 structure = gst_caps_get_structure (caps, 0);
620 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
623 priv->func = _evas_video_st12_multiplane;
625 priv->func = _evas_video_st12;
628 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
631 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
633 eina_condition_wait(&priv->c);
634 eina_lock_release(&priv->m);
640 evas_video_sink_samsung_main_render(void *data)
642 Emotion_Gstreamer_Buffer *send;
643 Emotion_Video_Stream *vstream;
644 EvasVideoSinkPrivate* priv;
646 unsigned char *evas_data;
647 const guint8 *gst_data;
648 GstFormat fmt = GST_FORMAT_TIME;
651 int stride, elevation;
656 if (!send) goto exit_point;
659 buffer = send->frame;
660 preroll = send->preroll;
662 if (!priv || !priv->o || priv->unlocked || !send->ev)
665 _emotion_gstreamer_video_pipeline_parse(send->ev, EINA_TRUE);
667 /* Getting stride to compute the right size and then fill the object properly */
668 /* Y => [0] and UV in [1] */
669 if (priv->func == _evas_video_st12_multiplane)
671 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) buffer;
673 stride = mp_buf->stride[0];
674 elevation = mp_buf->elevation[0];
675 priv->width = mp_buf->width[0];
676 priv->height = mp_buf->height[0];
678 gst_data = (const guint8 *) mp_buf;
682 const SCMN_IMGB *imgb = (const SCMN_IMGB *) GST_BUFFER_MALLOCDATA(buffer);
684 stride = imgb->stride[0];
685 elevation = imgb->elevation[0];
686 priv->width = imgb->width[0];
687 priv->height = imgb->height[0];
689 gst_data = (const guint8 *) imgb;
692 INF("sink main render [%i, %i] - [%i, %i]", priv->width, priv->height, stride, elevation);
694 evas_object_image_alpha_set(priv->o, 0);
695 evas_object_image_colorspace_set(priv->o, priv->eformat);
696 evas_object_image_size_set(priv->o, stride, elevation);
697 evas_object_geometry_get(priv->o, NULL, NULL, &w, &h);
698 evas_object_image_fill_set(priv->o, 0, 0, stride * w / priv->width, elevation * h / priv->height);
700 evas_data = evas_object_image_data_get(priv->o, 1);
703 priv->func(evas_data, gst_data, stride, elevation, elevation);
705 WRN("No way to decode %x colorspace !", priv->eformat);
707 evas_object_image_data_set(priv->o, evas_data);
708 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
709 evas_object_image_pixels_dirty_set(priv->o, 0);
711 _emotion_frame_new(send->ev->obj);
713 vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1);
715 gst_element_query_position(send->ev->pipeline, &fmt, &pos);
716 send->ev->position = (double)pos / (double)GST_SECOND;
718 vstream->width = priv->width;
719 vstream->height = priv->height;
720 send->ev->ratio = (double) priv->width / (double) priv->height;
722 _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time);
723 _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio);
725 if (priv->last_buffer) gst_buffer_unref(priv->last_buffer);
726 priv->last_buffer = gst_buffer_ref(buffer);
729 emotion_gstreamer_buffer_free(send);
731 if (preroll || !priv->o || !send->ev) return ;
733 eina_lock_take(&priv->m);
735 eina_condition_signal(&priv->c);
737 eina_lock_release(&priv->m);
741 evas_video_sink_main_render(void *data)
743 Emotion_Gstreamer_Buffer *send;
744 Emotion_Gstreamer_Video *ev = NULL;
745 Emotion_Video_Stream *vstream;
746 EvasVideoSinkPrivate* priv;
748 unsigned char *evas_data;
749 GstFormat fmt = GST_FORMAT_TIME;
755 if (!send) goto exit_point;
758 buffer = send->frame;
759 preroll = send->preroll;
762 if (!priv || !priv->o || priv->unlocked || !ev)
765 _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE);
767 INF("sink main render [%i, %i] (source height: %i)", priv->width, priv->height, priv->source_height);
769 evas_object_image_alpha_set(priv->o, 0);
770 evas_object_image_colorspace_set(priv->o, priv->eformat);
771 evas_object_image_size_set(priv->o, priv->width, priv->height);
773 evas_data = evas_object_image_data_get(priv->o, 1);
776 priv->func(evas_data, GST_BUFFER_DATA(buffer), priv->width, priv->source_height, priv->height);
778 WRN("No way to decode %x colorspace !", priv->eformat);
780 evas_object_image_data_set(priv->o, evas_data);
781 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
782 evas_object_image_pixels_dirty_set(priv->o, 0);
784 _emotion_frame_new(ev->obj);
786 vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
788 gst_element_query_position(ev->pipeline, &fmt, &pos);
789 ev->position = (double)pos / (double)GST_SECOND;
791 vstream->width = priv->width;
792 vstream->height = priv->height;
793 ev->ratio = (double) priv->width / (double) priv->height;
795 _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
796 _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
798 if (priv->last_buffer) gst_buffer_unref(priv->last_buffer);
799 priv->last_buffer = gst_buffer_ref(buffer);
802 emotion_gstreamer_buffer_free(send);
804 if (preroll || !priv->o || !ev) return ;
806 eina_lock_take(&priv->m);
808 eina_condition_signal(&priv->c);
810 eina_lock_release(&priv->m);
814 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
816 eina_lock_take(&priv->m);
817 priv->unlocked = EINA_TRUE;
819 eina_condition_signal(&priv->c);
820 eina_lock_release(&priv->m);
824 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
825 guint n_param_values, const GValue * param_values,
826 gpointer invocation_hint __UNUSED__, gpointer marshal_data)
828 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
829 marshalfunc_VOID__MINIOBJECT callback;
831 gpointer data1, data2;
833 cc = (GCClosure *) closure;
835 g_return_if_fail(n_param_values == 2);
837 if (G_CCLOSURE_SWAP_DATA(closure)) {
838 data1 = closure->data;
839 data2 = g_value_peek_pointer(param_values + 0);
841 data1 = g_value_peek_pointer(param_values + 0);
842 data2 = closure->data;
844 callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
846 callback(data1, gst_value_get_mini_object(param_values + 1), data2);
850 evas_video_sink_class_init(EvasVideoSinkClass* klass)
852 GObjectClass* gobject_class;
853 GstBaseSinkClass* gstbase_sink_class;
855 gobject_class = G_OBJECT_CLASS(klass);
856 gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
858 g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
860 gobject_class->set_property = evas_video_sink_set_property;
861 gobject_class->get_property = evas_video_sink_get_property;
863 g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
864 g_param_spec_pointer ("evas-object", "Evas Object",
865 "The Evas object where the display of the video will be done",
868 g_object_class_install_property (gobject_class, PROP_WIDTH,
869 g_param_spec_int ("width", "Width",
870 "The width of the video",
871 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
873 g_object_class_install_property (gobject_class, PROP_HEIGHT,
874 g_param_spec_int ("height", "Height",
875 "The height of the video",
876 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
877 g_object_class_install_property (gobject_class, PROP_EV,
878 g_param_spec_pointer ("ev", "Emotion_Gstreamer_Video",
879 "THe internal data of the emotion object",
882 gobject_class->dispose = evas_video_sink_dispose;
884 gstbase_sink_class->set_caps = evas_video_sink_set_caps;
885 gstbase_sink_class->stop = evas_video_sink_stop;
886 gstbase_sink_class->start = evas_video_sink_start;
887 gstbase_sink_class->unlock = evas_video_sink_unlock;
888 gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
889 gstbase_sink_class->render = evas_video_sink_render;
890 gstbase_sink_class->preroll = evas_video_sink_preroll;
892 evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
893 G_TYPE_FROM_CLASS(klass),
894 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
898 marshal_VOID__MINIOBJECT,
899 G_TYPE_NONE, 1, GST_TYPE_BUFFER);
903 gstreamer_plugin_init (GstPlugin * plugin)
905 return gst_element_register (plugin,
908 EVAS_TYPE_VIDEO_SINK);
912 _emotion_gstreamer_pause(void *data, Ecore_Thread *thread)
914 Emotion_Gstreamer_Video *ev = data;
916 if (ecore_thread_check(thread) || !ev->pipeline) return ;
918 gst_element_set_state(ev->pipeline, GST_STATE_PAUSED);
922 _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread)
924 Emotion_Gstreamer_Video *ev = data;
926 ev->threads = eina_list_remove(ev->threads, thread);
928 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"));
930 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
935 _emotion_gstreamer_end(void *data, Ecore_Thread *thread)
937 Emotion_Gstreamer_Video *ev = data;
939 ev->threads = eina_list_remove(ev->threads, thread);
943 gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
944 ev->play_started = 1;
947 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"));
949 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
952 _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE);
956 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
965 obj = emotion_object_image_get(o);
968 ERR("Not Evas_Object specified");
972 playbin = gst_element_factory_make("playbin2", "playbin");
975 ERR("Unable to create 'playbin' GstElement.");
979 sink = gst_element_factory_make("emotion-sink", "sink");
982 ERR("Unable to create 'emotion-sink' GstElement.");
986 #define GST_PLAY_FLAG_NATIVE_VIDEO (1 << 6)
987 #define GST_PLAY_FLAG_DOWNLOAD (1 << 7)
988 #define GST_PLAY_FLAG_BUFFERING (1 << 8)
990 g_object_set(G_OBJECT(sink), "evas-object", obj, NULL);
991 g_object_set(G_OBJECT(sink), "ev", ev, NULL);
993 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
995 g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
996 g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD | GST_PLAY_FLAG_BUFFERING, NULL);
997 g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL);
998 g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
1000 ev->pipeline = playbin;
1002 ev->threads = eina_list_append(ev->threads,
1003 ecore_thread_run(_emotion_gstreamer_pause,
1004 _emotion_gstreamer_end,
1005 _emotion_gstreamer_cancel,
1008 /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
1009 /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
1010 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"));
1015 gst_object_unref(playbin);