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 __UNUSED__, 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 + rh * (w / 4) + j * (w / 2)];
124 _evas_video_yv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, 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 + rh * (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 __UNUSED__, 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[rh * 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++)
216 rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2;
218 if (((h / 2) / 16) % 2)
219 rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2;
223 _evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w __UNUSED__, unsigned int h, unsigned int output_height __UNUSED__)
225 const SCMN_IMGB *imgb = (const SCMN_IMGB *) gst_data;
226 const unsigned char **rows;
229 rows = (const unsigned char **)evas_data;
231 for (i = 0; i < (h / 32) / 2; i++)
232 rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32;
235 rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32;
239 for (j = 0; j < (unsigned int) imgb->elevation[1] / 32 / 2; j++, i++)
240 rows[i] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2;
241 if ((imgb->elevation[1] / 32) % 2)
242 rows[i++] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2;
245 static const struct {
248 Evas_Colorspace eformat;
249 Evas_Video_Convert_Cb func;
250 Eina_Bool force_height;
251 } colorspace_fourcc_convertion[] = {
252 { "I420", GST_MAKE_FOURCC('I', '4', '2', '0'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420, EINA_TRUE },
253 { "YV12", GST_MAKE_FOURCC('Y', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12, EINA_TRUE },
254 { "YUY2", GST_MAKE_FOURCC('Y', 'U', 'Y', '2'), EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2, EINA_FALSE },
255 { "NV12", GST_MAKE_FOURCC('N', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE },
256 { "TM12", GST_MAKE_FOURCC('T', 'M', '1', '2'), EVAS_COLORSPACE_YCBCR420TM12601_PL, _evas_video_mt12, EINA_TRUE }
259 static const struct {
261 GstVideoFormat format;
262 Evas_Colorspace eformat;
263 Evas_Video_Convert_Cb func;
264 } colorspace_format_convertion[] = {
265 { "BGR", GST_VIDEO_FORMAT_BGR, EVAS_COLORSPACE_ARGB8888, _evas_video_bgr },
266 { "BGRx", GST_VIDEO_FORMAT_BGRx, EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx },
267 { "BGRA", GST_VIDEO_FORMAT_BGRA, EVAS_COLORSPACE_ARGB8888, _evas_video_bgra }
271 evas_video_sink_base_init(gpointer g_class)
273 GstElementClass* element_class;
275 element_class = GST_ELEMENT_CLASS(g_class);
276 gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&sinktemplate));
277 gst_element_class_set_details_simple(element_class, "Evas video sink",
278 "Sink/Video", "Sends video data from a GStreamer pipeline to an Evas object",
279 "Vincent Torri <vtorri@univ-evry.fr>");
283 evas_video_sink_init(EvasVideoSink* sink, EvasVideoSinkClass* klass __UNUSED__)
285 EvasVideoSinkPrivate* priv;
288 sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(sink, EVAS_TYPE_VIDEO_SINK, EvasVideoSinkPrivate);
293 priv->eformat = EVAS_COLORSPACE_ARGB8888;
294 priv->samsung = EINA_FALSE;
295 eina_lock_new(&priv->m);
296 eina_condition_new(&priv->c, &priv->m);
297 priv->unlocked = EINA_FALSE;
300 /**** Object methods ****/
302 _cleanup_priv(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
304 EvasVideoSinkPrivate* priv;
308 eina_lock_take(&priv->m);
311 eina_lock_release(&priv->m);
315 evas_video_sink_set_property(GObject * object, guint prop_id,
316 const GValue * value, GParamSpec * pspec)
319 EvasVideoSinkPrivate* priv;
321 sink = EVAS_VIDEO_SINK (object);
325 case PROP_EVAS_OBJECT:
326 eina_lock_take(&priv->m);
327 evas_object_event_callback_del(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv);
328 priv->o = g_value_get_pointer (value);
329 INF("sink set Evas_Object %p.", priv->o);
330 evas_object_event_callback_add(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv, priv);
331 eina_lock_release(&priv->m);
335 eina_lock_take(&priv->m);
336 priv->ev = g_value_get_pointer (value);
338 priv->ev->samsung = EINA_TRUE;
339 eina_lock_release(&priv->m);
342 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
343 ERR("invalid property");
349 evas_video_sink_get_property(GObject * object, guint prop_id,
350 GValue * value, GParamSpec * pspec)
353 EvasVideoSinkPrivate* priv;
355 sink = EVAS_VIDEO_SINK (object);
359 case PROP_EVAS_OBJECT:
360 INF("sink get property.");
361 eina_lock_take(&priv->m);
362 g_value_set_pointer(value, priv->o);
363 eina_lock_release(&priv->m);
366 INF("sink get width.");
367 eina_lock_take(&priv->m);
368 g_value_set_int(value, priv->width);
369 eina_lock_release(&priv->m);
372 INF("sink get height.");
373 eina_lock_take(&priv->m);
374 g_value_set_int (value, priv->height);
375 eina_lock_release(&priv->m);
379 eina_lock_take(&priv->m);
380 g_value_set_pointer (value, priv->ev);
381 eina_lock_release(&priv->m);
384 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
385 ERR("invalide property");
391 evas_video_sink_dispose(GObject* object)
394 EvasVideoSinkPrivate* priv;
398 sink = EVAS_VIDEO_SINK(object);
401 eina_lock_free(&priv->m);
402 eina_condition_free(&priv->c);
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 fprintf(stderr, "Found '%s'\n", colorspace_fourcc_convertion[i].name);
434 priv->eformat = colorspace_fourcc_convertion[i].eformat;
435 priv->func = colorspace_fourcc_convertion[i].func;
436 if (colorspace_fourcc_convertion[i].force_height)
438 priv->height = (priv->height >> 1) << 1;
441 priv->ev->kill_buffer = EINA_TRUE;
445 if (fourcc == GST_MAKE_FOURCC('S', 'T', '1', '2'))
447 fprintf(stderr, "Found '%s'\n", "ST12");
448 priv->eformat = EVAS_COLORSPACE_YCBCR420TM12601_PL;
449 priv->samsung = EINA_TRUE;
453 priv->ev->samsung = EINA_TRUE;
454 priv->ev->kill_buffer = EINA_TRUE;
460 INF("fallback code !");
461 if (!gst_video_format_parse_caps(caps, &format, (int*) &priv->width, (int*) &priv->height))
463 ERR("Unable to parse caps.");
467 priv->source_height = priv->height;
469 for (i = 0; i < sizeof (colorspace_format_convertion) / sizeof (colorspace_format_convertion[0]); ++i)
470 if (format == colorspace_format_convertion[i].format)
472 fprintf(stderr, "Found '%s'\n", colorspace_format_convertion[i].name);
473 priv->eformat = colorspace_format_convertion[i].eformat;
474 priv->func = colorspace_format_convertion[i].func;
476 priv->ev->kill_buffer = EINA_FALSE;
480 ERR("unsupported : %d\n", format);
485 evas_video_sink_start(GstBaseSink* base_sink)
487 EvasVideoSinkPrivate* priv;
492 priv = EVAS_VIDEO_SINK(base_sink)->priv;
493 eina_lock_take(&priv->m);
497 priv->unlocked = EINA_FALSE;
498 eina_lock_release(&priv->m);
503 evas_video_sink_stop(GstBaseSink* base_sink)
505 EvasVideoSinkPrivate* priv = EVAS_VIDEO_SINK(base_sink)->priv;
509 unlock_buffer_mutex(priv);
514 evas_video_sink_unlock(GstBaseSink* object)
520 sink = EVAS_VIDEO_SINK(object);
522 unlock_buffer_mutex(sink->priv);
524 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock,
529 evas_video_sink_unlock_stop(GstBaseSink* object)
532 EvasVideoSinkPrivate* priv;
534 sink = EVAS_VIDEO_SINK(object);
537 INF("sink unlock stop");
539 eina_lock_take(&priv->m);
540 priv->unlocked = FALSE;
541 eina_lock_release(&priv->m);
543 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock_stop,
548 evas_video_sink_preroll(GstBaseSink* bsink, GstBuffer* buffer)
550 Emotion_Gstreamer_Buffer *send;
551 EvasVideoSinkPrivate *priv;
554 INF("sink preroll %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
556 sink = EVAS_VIDEO_SINK(bsink);
559 if (GST_BUFFER_SIZE(buffer) <= 0 && !priv->samsung)
565 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_TRUE);
573 GstStructure *structure;
575 gboolean is_multiplane = FALSE;
577 caps = GST_BUFFER_CAPS(buffer);
578 structure = gst_caps_get_structure (caps, 0);
579 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
580 gst_caps_unref(caps);
583 priv->func = _evas_video_st12_multiplane;
585 priv->func = _evas_video_st12;
588 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
591 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
598 evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer)
600 Emotion_Gstreamer_Buffer *send;
601 EvasVideoSinkPrivate *priv;
604 INF("sink render %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
606 sink = EVAS_VIDEO_SINK(bsink);
609 eina_lock_take(&priv->m);
611 if (priv->unlocked) {
613 eina_lock_release(&priv->m);
617 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_FALSE);
619 eina_lock_release(&priv->m);
620 return GST_FLOW_ERROR;
627 GstStructure *structure;
629 gboolean is_multiplane = FALSE;
631 caps = GST_BUFFER_CAPS(buffer);
632 structure = gst_caps_get_structure (caps, 0);
633 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
634 gst_caps_unref(caps);
637 priv->func = _evas_video_st12_multiplane;
639 priv->func = _evas_video_st12;
642 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
645 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
647 eina_condition_wait(&priv->c);
648 eina_lock_release(&priv->m);
654 evas_video_sink_samsung_main_render(void *data)
656 Emotion_Gstreamer_Buffer *send;
657 Emotion_Video_Stream *vstream;
658 EvasVideoSinkPrivate* priv;
660 unsigned char *evas_data;
661 const guint8 *gst_data;
662 GstFormat fmt = GST_FORMAT_TIME;
665 int stride, elevation;
670 if (!send) goto exit_point;
673 buffer = send->frame;
674 preroll = send->preroll;
676 if (!priv || !priv->o || priv->unlocked)
679 _emotion_gstreamer_video_pipeline_parse(send->ev, EINA_TRUE);
681 /* Getting stride to compute the right size and then fill the object properly */
682 /* Y => [0] and UV in [1] */
683 if (priv->func == _evas_video_st12_multiplane)
685 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) buffer;
687 stride = mp_buf->stride[0];
688 elevation = mp_buf->elevation[0];
689 priv->width = mp_buf->width[0];
690 priv->height = mp_buf->height[0];
692 gst_data = (const guint8 *) mp_buf;
696 const SCMN_IMGB *imgb = (const SCMN_IMGB *) GST_BUFFER_MALLOCDATA(buffer);
698 stride = imgb->stride[0];
699 elevation = imgb->elevation[0];
700 priv->width = imgb->width[0];
701 priv->height = imgb->height[0];
703 gst_data = (const guint8 *) imgb;
706 evas_object_geometry_get(priv->o, NULL, NULL, &w, &h);
707 INF("sink main render [%i, %i] - [%i, %i] => [%i, %i] - [%i, %i]",
708 priv->width, priv->height,
711 stride * w / priv->width, elevation * h / priv->height);
713 send->ev->fill.width = stride * w / priv->width;
714 send->ev->fill.height = elevation * h / priv->height;
716 evas_object_image_alpha_set(priv->o, 0);
717 evas_object_image_colorspace_set(priv->o, priv->eformat);
718 evas_object_image_size_set(priv->o, stride, elevation);
719 evas_object_image_fill_set(priv->o, 0, 0, send->ev->fill.width, send->ev->fill.height);
721 evas_data = evas_object_image_data_get(priv->o, 1);
724 priv->func(evas_data, gst_data, stride, elevation, elevation);
726 WRN("No way to decode %x colorspace !", priv->eformat);
728 evas_object_image_data_set(priv->o, evas_data);
729 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
730 evas_object_image_pixels_dirty_set(priv->o, 0);
732 _emotion_frame_new(send->ev->obj);
734 vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1);
736 gst_element_query_position(send->ev->pipeline, &fmt, &pos);
737 send->ev->position = (double)pos / (double)GST_SECOND;
739 vstream->width = priv->width;
740 vstream->height = priv->height;
741 send->ev->ratio = (double) priv->width / (double) priv->height;
743 _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time);
744 _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio);
747 emotion_gstreamer_buffer_free(send);
749 if (preroll || !priv->o) return ;
751 eina_lock_take(&priv->m);
753 eina_condition_signal(&priv->c);
755 eina_lock_release(&priv->m);
759 evas_video_sink_main_render(void *data)
761 Emotion_Gstreamer_Buffer *send;
762 Emotion_Gstreamer_Video *ev = NULL;
763 Emotion_Video_Stream *vstream;
764 EvasVideoSinkPrivate* priv;
766 unsigned char *evas_data;
767 GstFormat fmt = GST_FORMAT_TIME;
773 if (!send) goto exit_point;
776 buffer = send->frame;
777 preroll = send->preroll;
780 if (!priv || !priv->o || priv->unlocked)
783 _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE);
785 INF("sink main render [%i, %i] (source height: %i)", priv->width, priv->height, priv->source_height);
787 evas_object_image_alpha_set(priv->o, 0);
788 evas_object_image_colorspace_set(priv->o, priv->eformat);
789 evas_object_image_size_set(priv->o, priv->width, priv->height);
791 evas_data = evas_object_image_data_get(priv->o, 1);
794 priv->func(evas_data, GST_BUFFER_DATA(buffer), priv->width, priv->source_height, priv->height);
796 WRN("No way to decode %x colorspace !", priv->eformat);
798 evas_object_image_data_set(priv->o, evas_data);
799 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
800 evas_object_image_pixels_dirty_set(priv->o, 0);
802 _emotion_frame_new(ev->obj);
804 gst_element_query_position(ev->pipeline, &fmt, &pos);
805 ev->position = (double)pos / (double)GST_SECOND;
807 vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
811 vstream->width = priv->width;
812 vstream->height = priv->height;
813 _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
816 ev->ratio = (double) priv->width / (double) priv->height;
818 _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
820 buffer = gst_buffer_ref(buffer);
821 if (ev->last_buffer) gst_buffer_unref(ev->last_buffer);
822 ev->last_buffer = buffer;
825 emotion_gstreamer_buffer_free(send);
827 if (preroll || !priv->o) return ;
829 eina_lock_take(&priv->m);
831 eina_condition_signal(&priv->c);
833 eina_lock_release(&priv->m);
837 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
839 eina_lock_take(&priv->m);
840 priv->unlocked = EINA_TRUE;
842 eina_condition_signal(&priv->c);
843 eina_lock_release(&priv->m);
847 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
848 guint n_param_values, const GValue * param_values,
849 gpointer invocation_hint __UNUSED__, gpointer marshal_data)
851 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
852 marshalfunc_VOID__MINIOBJECT callback;
854 gpointer data1, data2;
856 cc = (GCClosure *) closure;
858 g_return_if_fail(n_param_values == 2);
860 if (G_CCLOSURE_SWAP_DATA(closure)) {
861 data1 = closure->data;
862 data2 = g_value_peek_pointer(param_values + 0);
864 data1 = g_value_peek_pointer(param_values + 0);
865 data2 = closure->data;
867 callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
869 callback(data1, gst_value_get_mini_object(param_values + 1), data2);
873 evas_video_sink_class_init(EvasVideoSinkClass* klass)
875 GObjectClass* gobject_class;
876 GstBaseSinkClass* gstbase_sink_class;
878 gobject_class = G_OBJECT_CLASS(klass);
879 gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
881 g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
883 gobject_class->set_property = evas_video_sink_set_property;
884 gobject_class->get_property = evas_video_sink_get_property;
886 g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
887 g_param_spec_pointer ("evas-object", "Evas Object",
888 "The Evas object where the display of the video will be done",
891 g_object_class_install_property (gobject_class, PROP_WIDTH,
892 g_param_spec_int ("width", "Width",
893 "The width of the video",
894 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
896 g_object_class_install_property (gobject_class, PROP_HEIGHT,
897 g_param_spec_int ("height", "Height",
898 "The height of the video",
899 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
900 g_object_class_install_property (gobject_class, PROP_EV,
901 g_param_spec_pointer ("ev", "Emotion_Gstreamer_Video",
902 "THe internal data of the emotion object",
905 gobject_class->dispose = evas_video_sink_dispose;
907 gstbase_sink_class->set_caps = evas_video_sink_set_caps;
908 gstbase_sink_class->stop = evas_video_sink_stop;
909 gstbase_sink_class->start = evas_video_sink_start;
910 gstbase_sink_class->unlock = evas_video_sink_unlock;
911 gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
912 gstbase_sink_class->render = evas_video_sink_render;
913 gstbase_sink_class->preroll = evas_video_sink_preroll;
915 evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
916 G_TYPE_FROM_CLASS(klass),
917 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
921 marshal_VOID__MINIOBJECT,
922 G_TYPE_NONE, 1, GST_TYPE_BUFFER);
926 gstreamer_plugin_init (GstPlugin * plugin)
928 return gst_element_register (plugin,
931 EVAS_TYPE_VIDEO_SINK);
935 _emotion_gstreamer_pause(void *data, Ecore_Thread *thread)
937 Emotion_Gstreamer_Video *ev = data;
939 if (ecore_thread_check(thread) || !ev->pipeline) return ;
941 gst_element_set_state(ev->pipeline, GST_STATE_PAUSED);
945 _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread)
947 Emotion_Gstreamer_Video *ev = data;
949 ev->threads = eina_list_remove(ev->threads, thread);
951 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"));
953 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
958 _emotion_gstreamer_end(void *data, Ecore_Thread *thread)
960 Emotion_Gstreamer_Video *ev = data;
962 ev->threads = eina_list_remove(ev->threads, thread);
966 gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
967 ev->play_started = 1;
970 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"));
972 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
975 _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE);
979 _on_post_clear(void *data, Evas *e __UNUSED__, void *event_info __UNUSED__)
981 Emotion_Gstreamer_Video *ev = data;
983 if (!ev->kill_buffer) return ;
985 if (ev->last_buffer) gst_buffer_unref(ev->last_buffer);
986 ev->last_buffer = NULL;
990 _on_resize_fill(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
992 Emotion_Gstreamer_Video *ev = data;
995 evas_object_image_fill_set(obj, 0, 0, ev->fill.width, ev->fill.height);
999 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
1003 GstElement *playbin;
1008 obj = emotion_object_image_get(o);
1011 ERR("Not Evas_Object specified");
1015 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev);
1016 evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_RENDER_FLUSH_POST, _on_post_clear, ev);
1021 playbin = gst_element_factory_make("playbin2", "playbin");
1024 ERR("Unable to create 'playbin' GstElement.");
1028 sink = gst_element_factory_make("emotion-sink", "sink");
1031 ERR("Unable to create 'emotion-sink' GstElement.");
1032 goto unref_pipeline;
1035 #define GST_PLAY_FLAG_NATIVE_VIDEO (1 << 6)
1036 #define GST_PLAY_FLAG_DOWNLOAD (1 << 7)
1038 g_object_set(G_OBJECT(sink), "evas-object", obj, NULL);
1039 g_object_set(G_OBJECT(sink), "ev", ev, NULL);
1041 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1043 g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
1044 g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD, NULL);
1045 g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL);
1046 g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
1048 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1049 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev);
1050 evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_RENDER_FLUSH_POST, _on_post_clear, ev);
1052 ev->pipeline = playbin;
1054 ev->threads = eina_list_append(ev->threads,
1055 ecore_thread_run(_emotion_gstreamer_pause,
1056 _emotion_gstreamer_end,
1057 _emotion_gstreamer_cancel,
1060 /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
1061 /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
1062 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"));
1067 gst_object_unref(playbin);