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);
708 send->ev->fill.width = stride * w / priv->width;
709 send->ev->fill.height = elevation * h / priv->height;
711 evas_object_image_alpha_set(priv->o, 0);
712 evas_object_image_colorspace_set(priv->o, priv->eformat);
713 evas_object_image_size_set(priv->o, stride, elevation);
714 evas_object_image_fill_set(priv->o, 0, 0, send->ev->fill.width, send->ev->fill.height);
716 evas_data = evas_object_image_data_get(priv->o, 1);
719 priv->func(evas_data, gst_data, stride, elevation, elevation);
721 WRN("No way to decode %x colorspace !", priv->eformat);
723 evas_object_image_data_set(priv->o, evas_data);
724 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
725 evas_object_image_pixels_dirty_set(priv->o, 0);
727 _emotion_frame_new(send->ev->obj);
729 vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1);
731 gst_element_query_position(send->ev->pipeline, &fmt, &pos);
732 send->ev->position = (double)pos / (double)GST_SECOND;
734 vstream->width = priv->width;
735 vstream->height = priv->height;
736 send->ev->ratio = (double) priv->width / (double) priv->height;
738 _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time);
739 _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio);
741 /* FIXME: why is last buffer not protected ? */
744 emotion_gstreamer_buffer_free(send);
746 if (preroll || !priv->o) return ;
749 eina_condition_signal(&priv->c);
753 evas_video_sink_main_render(void *data)
755 Emotion_Gstreamer_Buffer *send;
756 Emotion_Gstreamer_Video *ev = NULL;
757 Emotion_Video_Stream *vstream;
758 EvasVideoSinkPrivate* priv;
760 unsigned char *evas_data;
761 GstFormat fmt = GST_FORMAT_TIME;
767 if (!send) goto exit_point;
770 buffer = send->frame;
771 preroll = send->preroll;
774 if (!priv || !priv->o || priv->unlocked)
777 _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE);
779 INF("sink main render [%i, %i] (source height: %i)", priv->width, priv->height, priv->source_height);
781 evas_object_image_alpha_set(priv->o, 0);
782 evas_object_image_colorspace_set(priv->o, priv->eformat);
783 evas_object_image_size_set(priv->o, priv->width, priv->height);
785 evas_data = evas_object_image_data_get(priv->o, 1);
788 priv->func(evas_data, GST_BUFFER_DATA(buffer), priv->width, priv->source_height, priv->height);
790 WRN("No way to decode %x colorspace !", priv->eformat);
792 evas_object_image_data_set(priv->o, evas_data);
793 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
794 evas_object_image_pixels_dirty_set(priv->o, 0);
796 _emotion_frame_new(ev->obj);
798 gst_element_query_position(ev->pipeline, &fmt, &pos);
799 ev->position = (double)pos / (double)GST_SECOND;
801 vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
805 vstream->width = priv->width;
806 vstream->height = priv->height;
807 _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
810 ev->ratio = (double) priv->width / (double) priv->height;
812 _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
814 buffer = gst_buffer_ref(buffer);
815 if (ev->last_buffer) gst_buffer_unref(ev->last_buffer);
816 ev->last_buffer = buffer;
819 emotion_gstreamer_buffer_free(send);
821 if (preroll || !priv->o) return ;
824 eina_condition_signal(&priv->c);
828 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
830 priv->unlocked = EINA_TRUE;
832 eina_condition_signal(&priv->c);
836 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
837 guint n_param_values, const GValue * param_values,
838 gpointer invocation_hint __UNUSED__, gpointer marshal_data)
840 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
841 marshalfunc_VOID__MINIOBJECT callback;
843 gpointer data1, data2;
845 cc = (GCClosure *) closure;
847 g_return_if_fail(n_param_values == 2);
849 if (G_CCLOSURE_SWAP_DATA(closure)) {
850 data1 = closure->data;
851 data2 = g_value_peek_pointer(param_values + 0);
853 data1 = g_value_peek_pointer(param_values + 0);
854 data2 = closure->data;
856 callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
858 callback(data1, gst_value_get_mini_object(param_values + 1), data2);
862 evas_video_sink_class_init(EvasVideoSinkClass* klass)
864 GObjectClass* gobject_class;
865 GstBaseSinkClass* gstbase_sink_class;
867 gobject_class = G_OBJECT_CLASS(klass);
868 gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
870 g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
872 gobject_class->set_property = evas_video_sink_set_property;
873 gobject_class->get_property = evas_video_sink_get_property;
875 g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
876 g_param_spec_pointer ("evas-object", "Evas Object",
877 "The Evas object where the display of the video will be done",
880 g_object_class_install_property (gobject_class, PROP_WIDTH,
881 g_param_spec_int ("width", "Width",
882 "The width of the video",
883 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
885 g_object_class_install_property (gobject_class, PROP_HEIGHT,
886 g_param_spec_int ("height", "Height",
887 "The height of the video",
888 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
889 g_object_class_install_property (gobject_class, PROP_EV,
890 g_param_spec_pointer ("ev", "Emotion_Gstreamer_Video",
891 "THe internal data of the emotion object",
894 gobject_class->dispose = evas_video_sink_dispose;
896 gstbase_sink_class->set_caps = evas_video_sink_set_caps;
897 gstbase_sink_class->stop = evas_video_sink_stop;
898 gstbase_sink_class->start = evas_video_sink_start;
899 gstbase_sink_class->unlock = evas_video_sink_unlock;
900 gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
901 gstbase_sink_class->render = evas_video_sink_render;
902 gstbase_sink_class->preroll = evas_video_sink_preroll;
904 evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
905 G_TYPE_FROM_CLASS(klass),
906 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
910 marshal_VOID__MINIOBJECT,
911 G_TYPE_NONE, 1, GST_TYPE_BUFFER);
915 gstreamer_plugin_init (GstPlugin * plugin)
917 return gst_element_register (plugin,
920 EVAS_TYPE_VIDEO_SINK);
924 _emotion_gstreamer_pause(void *data, Ecore_Thread *thread)
926 Emotion_Gstreamer_Video *ev = data;
928 if (ecore_thread_check(thread) || !ev->pipeline) return ;
930 gst_element_set_state(ev->pipeline, GST_STATE_PAUSED);
934 _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread)
936 Emotion_Gstreamer_Video *ev = data;
938 ev->threads = eina_list_remove(ev->threads, thread);
940 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"));
942 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
947 _emotion_gstreamer_end(void *data, Ecore_Thread *thread)
949 Emotion_Gstreamer_Video *ev = data;
951 ev->threads = eina_list_remove(ev->threads, thread);
955 gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
956 ev->play_started = 1;
959 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"));
961 if (ev->in == ev->out && ev->threads == NULL && ev->delete_me)
964 _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE);
968 _on_post_clear(void *data, Evas *e __UNUSED__, void *event_info __UNUSED__)
970 Emotion_Gstreamer_Video *ev = data;
972 if (!ev->kill_buffer) return ;
975 if (ev->last_buffer) gst_buffer_unref(ev->last_buffer);
976 ev->last_buffer = NULL;
981 _on_resize_fill(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
983 Emotion_Gstreamer_Video *ev = data;
986 evas_object_image_fill_set(obj, 0, 0, ev->fill.width, ev->fill.height);
990 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
999 obj = emotion_object_image_get(o);
1002 ERR("Not Evas_Object specified");
1006 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev);
1007 evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_RENDER_FLUSH_POST, _on_post_clear, ev);
1012 playbin = gst_element_factory_make("playbin2", "playbin");
1015 ERR("Unable to create 'playbin' GstElement.");
1019 sink = gst_element_factory_make("emotion-sink", "sink");
1022 ERR("Unable to create 'emotion-sink' GstElement.");
1023 goto unref_pipeline;
1026 #define GST_PLAY_FLAG_NATIVE_VIDEO (1 << 6)
1027 #define GST_PLAY_FLAG_DOWNLOAD (1 << 7)
1029 g_object_set(G_OBJECT(sink), "evas-object", obj, NULL);
1030 g_object_set(G_OBJECT(sink), "ev", ev, NULL);
1032 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1034 g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
1035 g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD, NULL);
1036 g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL);
1037 g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
1039 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1040 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev);
1041 evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_RENDER_FLUSH_POST, _on_post_clear, ev);
1043 ev->pipeline = playbin;
1045 ev->threads = eina_list_append(ev->threads,
1046 ecore_thread_run(_emotion_gstreamer_pause,
1047 _emotion_gstreamer_end,
1048 _emotion_gstreamer_cancel,
1051 /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
1052 /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
1053 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"));
1058 gst_object_unref(playbin);