1 #include "emotion_gstreamer.h"
3 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE("sink",
4 GST_PAD_SINK, GST_PAD_ALWAYS,
5 GST_STATIC_CAPS(GST_VIDEO_CAPS_YUV("{ I420, YV12, YUY2, NV12, ST12, TM12 }") ";"
6 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_BGR ";" GST_VIDEO_CAPS_BGRA));
8 GST_DEBUG_CATEGORY_STATIC(evas_video_sink_debug);
9 #define GST_CAT_DEFAULT evas_video_sink_debug
25 static guint evas_video_sink_signals[LAST_SIGNAL] = { 0, };
27 #define _do_init(bla) \
28 GST_DEBUG_CATEGORY_INIT(evas_video_sink_debug, \
33 GST_BOILERPLATE_FULL(EvasVideoSink,
40 static void unlock_buffer_mutex(EvasVideoSinkPrivate* priv);
41 static void evas_video_sink_main_render(void *data);
42 static void evas_video_sink_samsung_main_render(void *data);
45 _evas_video_bgrx_step(unsigned char *evas_data, const unsigned char *gst_data,
46 unsigned int w, unsigned int h __UNUSED__, unsigned int output_height, unsigned int step)
51 for (y = 0; y < output_height; ++y)
53 for (x = 0; x < w; x++)
55 evas_data[0] = gst_data[0];
56 evas_data[1] = gst_data[1];
57 evas_data[2] = gst_data[2];
66 _evas_video_bgr(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
68 _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 3);
72 _evas_video_bgrx(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height)
74 _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 4);
78 _evas_video_bgra(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
83 for (y = 0; y < output_height; ++y)
87 for (x = 0; x < w; ++x)
90 evas_data[0] = (gst_data[0] * alpha) / 255;
91 evas_data[1] = (gst_data[1] * alpha) / 255;
92 evas_data[2] = (gst_data[2] * alpha) / 255;
101 _evas_video_i420(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
103 const unsigned char **rows;
109 rows = (const unsigned char **)evas_data;
111 for (i = 0; i < rh; i++)
112 rows[i] = &gst_data[i * w];
114 for (j = 0; j < (rh / 2); j++, i++)
115 rows[i] = &gst_data[h * w + j * (w / 2)];
117 for (j = 0; j < (rh / 2); j++, i++)
118 rows[i] = &gst_data[h * w + rh * (w / 4) + j * (w / 2)];
122 _evas_video_yv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
124 const unsigned char **rows;
130 rows = (const unsigned char **)evas_data;
132 for (i = 0; i < rh; i++)
133 rows[i] = &gst_data[i * w];
135 for (j = 0; j < (rh / 2); j++, i++)
136 rows[i] = &gst_data[h * w + rh * (w / 4) + j * (w / 2)];
138 for (j = 0; j < (rh / 2); j++, i++)
139 rows[i] = &gst_data[h * w + j * (w / 2)];
143 _evas_video_yuy2(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height)
145 const unsigned char **rows;
148 rows = (const unsigned char **)evas_data;
150 for (i = 0; i < output_height; 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 __UNUSED__, unsigned int output_height)
157 const unsigned char **rows;
163 rows = (const unsigned char **)evas_data;
165 for (i = 0; i < rh; i++)
166 rows[i] = &gst_data[i * w];
168 for (j = 0; j < (rh / 2); j++, i++)
169 rows[i] = &gst_data[rh * w + j * w];
173 _evas_video_mt12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
175 const unsigned char **rows;
179 rows = (const unsigned char **)evas_data;
181 for (i = 0; i < (h / 32) / 2; i++)
182 rows[i] = &gst_data[i * w * 2 * 32];
186 rows[i] = &gst_data[i * w * 2 * 32];
190 for (j = 0; j < ((h / 2) / 32) / 2; ++j, ++i)
191 rows[i] = &gst_data[h * w + j * (w / 2) * 2 * 16];
195 _evas_video_st12_multiplane(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__)
197 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) gst_data;
198 const unsigned char **rows;
202 rows = (const unsigned char **)evas_data;
204 for (i = 0; i < (h / 32) / 2; i++)
205 rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
208 rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32;
212 for (j = 0; j < ((h / 2) / 16) / 2; j++, i++)
214 rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2;
216 if (((h / 2) / 16) % 2)
217 rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2;
221 _evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w __UNUSED__, 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 * imgb->stride[0] * 2 * 32;
233 rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32;
237 for (j = 0; j < (unsigned int) imgb->elevation[1] / 32 / 2; j++, i++)
238 rows[i] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2;
239 if ((imgb->elevation[1] / 32) % 2)
240 rows[i++] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2;
243 static const struct {
246 Evas_Colorspace eformat;
247 Evas_Video_Convert_Cb func;
248 Eina_Bool force_height;
249 } colorspace_fourcc_convertion[] = {
250 { "I420", GST_MAKE_FOURCC('I', '4', '2', '0'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420, EINA_TRUE },
251 { "YV12", GST_MAKE_FOURCC('Y', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12, EINA_TRUE },
252 { "YUY2", GST_MAKE_FOURCC('Y', 'U', 'Y', '2'), EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2, EINA_FALSE },
253 { "NV12", GST_MAKE_FOURCC('N', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE },
254 { "TM12", GST_MAKE_FOURCC('T', 'M', '1', '2'), EVAS_COLORSPACE_YCBCR420TM12601_PL, _evas_video_mt12, EINA_TRUE }
257 static const struct {
259 GstVideoFormat format;
260 Evas_Colorspace eformat;
261 Evas_Video_Convert_Cb func;
262 } colorspace_format_convertion[] = {
263 { "BGR", GST_VIDEO_FORMAT_BGR, EVAS_COLORSPACE_ARGB8888, _evas_video_bgr },
264 { "BGRx", GST_VIDEO_FORMAT_BGRx, EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx },
265 { "BGRA", GST_VIDEO_FORMAT_BGRA, EVAS_COLORSPACE_ARGB8888, _evas_video_bgra }
269 evas_video_sink_base_init(gpointer g_class)
271 GstElementClass* element_class;
273 element_class = GST_ELEMENT_CLASS(g_class);
274 gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&sinktemplate));
275 gst_element_class_set_details_simple(element_class, "Evas video sink",
276 "Sink/Video", "Sends video data from a GStreamer pipeline to an Evas object",
277 "Vincent Torri <vtorri@univ-evry.fr>");
281 evas_video_sink_init(EvasVideoSink* sink, EvasVideoSinkClass* klass __UNUSED__)
283 EvasVideoSinkPrivate* priv;
286 sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(sink, EVAS_TYPE_VIDEO_SINK, EvasVideoSinkPrivate);
291 priv->eformat = EVAS_COLORSPACE_ARGB8888;
292 priv->samsung = EINA_FALSE;
293 eina_lock_new(&priv->m);
294 eina_condition_new(&priv->c, &priv->m);
295 priv->unlocked = EINA_FALSE;
298 /**** Object methods ****/
300 _cleanup_priv(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
302 EvasVideoSinkPrivate* priv;
306 eina_lock_take(&priv->m);
309 eina_lock_release(&priv->m);
313 evas_video_sink_set_property(GObject * object, guint prop_id,
314 const GValue * value, GParamSpec * pspec)
317 EvasVideoSinkPrivate* priv;
319 sink = EVAS_VIDEO_SINK (object);
323 case PROP_EVAS_OBJECT:
324 eina_lock_take(&priv->m);
325 evas_object_event_callback_del(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv);
326 priv->o = g_value_get_pointer (value);
327 INF("sink set Evas_Object %p.", priv->o);
328 evas_object_event_callback_add(priv->o, EVAS_CALLBACK_FREE, _cleanup_priv, priv);
329 eina_lock_release(&priv->m);
333 eina_lock_take(&priv->m);
334 priv->ev = g_value_get_pointer (value);
336 priv->ev->samsung = EINA_TRUE;
337 eina_lock_release(&priv->m);
340 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
341 ERR("invalid property");
347 evas_video_sink_get_property(GObject * object, guint prop_id,
348 GValue * value, GParamSpec * pspec)
351 EvasVideoSinkPrivate* priv;
353 sink = EVAS_VIDEO_SINK (object);
357 case PROP_EVAS_OBJECT:
358 INF("sink get property.");
359 eina_lock_take(&priv->m);
360 g_value_set_pointer(value, priv->o);
361 eina_lock_release(&priv->m);
364 INF("sink get width.");
365 eina_lock_take(&priv->m);
366 g_value_set_int(value, priv->width);
367 eina_lock_release(&priv->m);
370 INF("sink get height.");
371 eina_lock_take(&priv->m);
372 g_value_set_int (value, priv->height);
373 eina_lock_release(&priv->m);
377 eina_lock_take(&priv->m);
378 g_value_set_pointer (value, priv->ev);
379 eina_lock_release(&priv->m);
382 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
383 ERR("invalide property");
389 evas_video_sink_dispose(GObject* object)
392 EvasVideoSinkPrivate* priv;
396 sink = EVAS_VIDEO_SINK(object);
399 eina_lock_free(&priv->m);
400 eina_condition_free(&priv->c);
402 G_OBJECT_CLASS(parent_class)->dispose(object);
406 /**** BaseSink methods ****/
408 gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps)
411 EvasVideoSinkPrivate* priv;
412 GstStructure *structure;
413 GstVideoFormat format;
417 sink = EVAS_VIDEO_SINK(bsink);
420 structure = gst_caps_get_structure(caps, 0);
422 if (gst_structure_get_int(structure, "width", (int*) &priv->width)
423 && gst_structure_get_int(structure, "height", (int*) &priv->height)
424 && gst_structure_get_fourcc(structure, "format", &fourcc))
426 priv->source_height = priv->height;
428 for (i = 0; i < sizeof (colorspace_fourcc_convertion) / sizeof (colorspace_fourcc_convertion[0]); ++i)
429 if (fourcc == colorspace_fourcc_convertion[i].fourcc)
431 fprintf(stderr, "Found '%s'\n", colorspace_fourcc_convertion[i].name);
432 priv->eformat = colorspace_fourcc_convertion[i].eformat;
433 priv->func = colorspace_fourcc_convertion[i].func;
434 if (colorspace_fourcc_convertion[i].force_height)
436 priv->height = (priv->height >> 1) << 1;
439 priv->ev->kill_buffer = EINA_TRUE;
443 if (fourcc == GST_MAKE_FOURCC('S', 'T', '1', '2'))
445 fprintf(stderr, "Found '%s'\n", "ST12");
446 priv->eformat = EVAS_COLORSPACE_YCBCR420TM12601_PL;
447 priv->samsung = EINA_TRUE;
451 priv->ev->samsung = EINA_TRUE;
452 priv->ev->kill_buffer = EINA_TRUE;
458 INF("fallback code !");
459 if (!gst_video_format_parse_caps(caps, &format, (int*) &priv->width, (int*) &priv->height))
461 ERR("Unable to parse caps.");
465 priv->source_height = priv->height;
467 for (i = 0; i < sizeof (colorspace_format_convertion) / sizeof (colorspace_format_convertion[0]); ++i)
468 if (format == colorspace_format_convertion[i].format)
470 fprintf(stderr, "Found '%s'\n", colorspace_format_convertion[i].name);
471 priv->eformat = colorspace_format_convertion[i].eformat;
472 priv->func = colorspace_format_convertion[i].func;
474 priv->ev->kill_buffer = EINA_FALSE;
478 ERR("unsupported : %d\n", format);
483 evas_video_sink_start(GstBaseSink* base_sink)
485 EvasVideoSinkPrivate* priv;
490 priv = EVAS_VIDEO_SINK(base_sink)->priv;
491 eina_lock_take(&priv->m);
495 priv->unlocked = EINA_FALSE;
496 eina_lock_release(&priv->m);
501 evas_video_sink_stop(GstBaseSink* base_sink)
503 EvasVideoSinkPrivate* priv = EVAS_VIDEO_SINK(base_sink)->priv;
507 unlock_buffer_mutex(priv);
512 evas_video_sink_unlock(GstBaseSink* object)
518 sink = EVAS_VIDEO_SINK(object);
520 unlock_buffer_mutex(sink->priv);
522 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock,
527 evas_video_sink_unlock_stop(GstBaseSink* object)
530 EvasVideoSinkPrivate* priv;
532 sink = EVAS_VIDEO_SINK(object);
535 INF("sink unlock stop");
537 eina_lock_take(&priv->m);
538 priv->unlocked = FALSE;
539 eina_lock_release(&priv->m);
541 return GST_CALL_PARENT_WITH_DEFAULT(GST_BASE_SINK_CLASS, unlock_stop,
546 evas_video_sink_preroll(GstBaseSink* bsink, GstBuffer* buffer)
548 Emotion_Gstreamer_Buffer *send;
549 EvasVideoSinkPrivate *priv;
552 INF("sink preroll %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
554 sink = EVAS_VIDEO_SINK(bsink);
557 if (GST_BUFFER_SIZE(buffer) <= 0 && !priv->samsung)
563 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_TRUE);
571 GstStructure *structure;
573 gboolean is_multiplane = FALSE;
575 caps = GST_BUFFER_CAPS(buffer);
576 structure = gst_caps_get_structure (caps, 0);
577 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
578 gst_caps_unref(caps);
581 priv->func = _evas_video_st12_multiplane;
583 priv->func = _evas_video_st12;
586 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
589 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
596 evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer)
598 Emotion_Gstreamer_Buffer *send;
599 EvasVideoSinkPrivate *priv;
602 INF("sink render %p", buffer);
604 sink = EVAS_VIDEO_SINK(bsink);
607 eina_lock_take(&priv->m);
609 if (priv->unlocked) {
611 eina_lock_release(&priv->m);
615 send = emotion_gstreamer_buffer_alloc(priv, buffer, EINA_FALSE);
617 eina_lock_release(&priv->m);
618 return GST_FLOW_ERROR;
625 GstStructure *structure;
627 gboolean is_multiplane = FALSE;
629 caps = GST_BUFFER_CAPS(buffer);
630 structure = gst_caps_get_structure (caps, 0);
631 gst_structure_get_boolean(structure, "multiplane", &is_multiplane);
632 gst_caps_unref(caps);
635 priv->func = _evas_video_st12_multiplane;
637 priv->func = _evas_video_st12;
640 ecore_main_loop_thread_safe_call_async(evas_video_sink_samsung_main_render, send);
643 ecore_main_loop_thread_safe_call_async(evas_video_sink_main_render, send);
645 eina_condition_wait(&priv->c);
646 eina_lock_release(&priv->m);
652 _update_emotion_fps(Emotion_Gstreamer_Video *ev)
656 if (!debug_fps) return ;
658 tim = ecore_time_get();
661 if (ev->rlapse == 0.0)
664 ev->flapse = ev->frames;
666 else if ((tim - ev->rlapse) >= 0.5)
668 printf("FRAME: %i, FPS: %3.1f\n",
670 (ev->frames - ev->flapse) / (tim - ev->rlapse));
672 ev->flapse = ev->frames;
677 evas_video_sink_samsung_main_render(void *data)
679 Emotion_Gstreamer_Buffer *send;
680 Emotion_Video_Stream *vstream;
681 EvasVideoSinkPrivate* priv;
683 unsigned char *evas_data;
684 const guint8 *gst_data;
685 GstFormat fmt = GST_FORMAT_TIME;
688 int stride, elevation;
693 if (!send) goto exit_point;
696 buffer = send->frame;
697 preroll = send->preroll;
699 if (!priv || !priv->o || priv->unlocked)
704 emotion_gstreamer_buffer_free(send->ev->send);
705 send->ev->send = NULL;
708 if (!send->ev->stream && !send->force)
710 send->ev->send = send;
711 _emotion_frame_new(send->ev->obj);
715 _emotion_gstreamer_video_pipeline_parse(send->ev, EINA_TRUE);
717 /* Getting stride to compute the right size and then fill the object properly */
718 /* Y => [0] and UV in [1] */
719 if (priv->func == _evas_video_st12_multiplane)
721 const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) buffer;
723 stride = mp_buf->stride[0];
724 elevation = mp_buf->elevation[0];
725 priv->width = mp_buf->width[0];
726 priv->height = mp_buf->height[0];
728 gst_data = (const guint8 *) mp_buf;
732 const SCMN_IMGB *imgb = (const SCMN_IMGB *) GST_BUFFER_MALLOCDATA(buffer);
734 stride = imgb->stride[0];
735 elevation = imgb->elevation[0];
736 priv->width = imgb->width[0];
737 priv->height = imgb->height[0];
739 gst_data = (const guint8 *) imgb;
742 evas_object_geometry_get(priv->o, NULL, NULL, &w, &h);
744 send->ev->fill.width = (double) stride / priv->width;
745 send->ev->fill.height = (double) elevation / priv->height;
747 evas_object_image_alpha_set(priv->o, 0);
748 evas_object_image_colorspace_set(priv->o, priv->eformat);
749 evas_object_image_size_set(priv->o, stride, elevation);
751 _update_emotion_fps(send->ev);
753 evas_data = evas_object_image_data_get(priv->o, 1);
756 priv->func(evas_data, gst_data, stride, elevation, elevation);
758 WRN("No way to decode %x colorspace !", priv->eformat);
760 evas_object_image_data_set(priv->o, evas_data);
761 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
762 evas_object_image_pixels_dirty_set(priv->o, 0);
764 if (!preroll && send->ev->play_started)
766 _emotion_playback_started(send->ev->obj);
767 send->ev->play_started = 0;
772 _emotion_frame_new(send->ev->obj);
775 vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1);
777 gst_element_query_position(send->ev->pipeline, &fmt, &pos);
778 send->ev->position = (double)pos / (double)GST_SECOND;
782 vstream->width = priv->width;
783 vstream->height = priv->height;
785 _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time);
788 send->ev->ratio = (double) priv->width / (double) priv->height;
789 _emotion_frame_refill(send->ev->obj, send->ev->fill.width, send->ev->fill.height);
790 _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio);
792 buffer = gst_buffer_ref(buffer);
793 if (send->ev->last_buffer) gst_buffer_unref(send->ev->last_buffer);
794 send->ev->last_buffer = buffer;
797 emotion_gstreamer_buffer_free(send);
800 if (preroll || !priv->o) return ;
803 eina_condition_signal(&priv->c);
807 evas_video_sink_main_render(void *data)
809 Emotion_Gstreamer_Buffer *send;
810 Emotion_Gstreamer_Video *ev = NULL;
811 Emotion_Video_Stream *vstream;
812 EvasVideoSinkPrivate* priv;
814 unsigned char *evas_data;
815 GstFormat fmt = GST_FORMAT_TIME;
821 if (!send) goto exit_point;
824 buffer = send->frame;
825 preroll = send->preroll;
828 if (!priv || !priv->o || priv->unlocked)
831 if (ev->send && send != ev->send)
833 emotion_gstreamer_buffer_free(ev->send);
837 if (!ev->stream && !send->force)
840 _emotion_frame_new(ev->obj);
841 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
845 _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE);
847 INF("sink main render [%i, %i] (source height: %i)", priv->width, priv->height, priv->source_height);
849 evas_object_image_alpha_set(priv->o, 0);
850 evas_object_image_colorspace_set(priv->o, priv->eformat);
851 evas_object_image_size_set(priv->o, priv->width, priv->height);
853 evas_data = evas_object_image_data_get(priv->o, 1);
856 priv->func(evas_data, GST_BUFFER_DATA(buffer), priv->width, priv->source_height, priv->height);
858 WRN("No way to decode %x colorspace !", priv->eformat);
860 evas_object_image_data_set(priv->o, evas_data);
861 evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height);
862 evas_object_image_pixels_dirty_set(priv->o, 0);
864 if (!preroll && ev->play_started)
866 _emotion_playback_started(ev->obj);
867 ev->play_started = 0;
872 _emotion_frame_new(ev->obj);
875 gst_element_query_position(ev->pipeline, &fmt, &pos);
876 ev->position = (double)pos / (double)GST_SECOND;
878 vstream = eina_list_nth(ev->video_streams, ev->video_stream_nbr - 1);
882 vstream->width = priv->width;
883 vstream->height = priv->height;
884 _emotion_video_pos_update(ev->obj, ev->position, vstream->length_time);
887 ev->ratio = (double) priv->width / (double) priv->height;
889 _emotion_frame_resize(ev->obj, priv->width, priv->height, ev->ratio);
891 buffer = gst_buffer_ref(buffer);
892 if (ev->last_buffer) gst_buffer_unref(ev->last_buffer);
893 ev->last_buffer = buffer;
896 emotion_gstreamer_buffer_free(send);
899 if (preroll || !priv->o) return ;
902 eina_condition_signal(&priv->c);
906 unlock_buffer_mutex(EvasVideoSinkPrivate* priv)
908 priv->unlocked = EINA_TRUE;
910 eina_condition_signal(&priv->c);
914 marshal_VOID__MINIOBJECT(GClosure * closure, GValue * return_value __UNUSED__,
915 guint n_param_values, const GValue * param_values,
916 gpointer invocation_hint __UNUSED__, gpointer marshal_data)
918 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1, gpointer data2);
919 marshalfunc_VOID__MINIOBJECT callback;
921 gpointer data1, data2;
923 cc = (GCClosure *) closure;
925 g_return_if_fail(n_param_values == 2);
927 if (G_CCLOSURE_SWAP_DATA(closure)) {
928 data1 = closure->data;
929 data2 = g_value_peek_pointer(param_values + 0);
931 data1 = g_value_peek_pointer(param_values + 0);
932 data2 = closure->data;
934 callback = (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback);
936 callback(data1, gst_value_get_mini_object(param_values + 1), data2);
940 evas_video_sink_class_init(EvasVideoSinkClass* klass)
942 GObjectClass* gobject_class;
943 GstBaseSinkClass* gstbase_sink_class;
945 gobject_class = G_OBJECT_CLASS(klass);
946 gstbase_sink_class = GST_BASE_SINK_CLASS(klass);
948 g_type_class_add_private(klass, sizeof(EvasVideoSinkPrivate));
950 gobject_class->set_property = evas_video_sink_set_property;
951 gobject_class->get_property = evas_video_sink_get_property;
953 g_object_class_install_property (gobject_class, PROP_EVAS_OBJECT,
954 g_param_spec_pointer ("evas-object", "Evas Object",
955 "The Evas object where the display of the video will be done",
958 g_object_class_install_property (gobject_class, PROP_WIDTH,
959 g_param_spec_int ("width", "Width",
960 "The width of the video",
961 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
963 g_object_class_install_property (gobject_class, PROP_HEIGHT,
964 g_param_spec_int ("height", "Height",
965 "The height of the video",
966 0, 65536, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
967 g_object_class_install_property (gobject_class, PROP_EV,
968 g_param_spec_pointer ("ev", "Emotion_Gstreamer_Video",
969 "THe internal data of the emotion object",
972 gobject_class->dispose = evas_video_sink_dispose;
974 gstbase_sink_class->set_caps = evas_video_sink_set_caps;
975 gstbase_sink_class->stop = evas_video_sink_stop;
976 gstbase_sink_class->start = evas_video_sink_start;
977 gstbase_sink_class->unlock = evas_video_sink_unlock;
978 gstbase_sink_class->unlock_stop = evas_video_sink_unlock_stop;
979 gstbase_sink_class->render = evas_video_sink_render;
980 gstbase_sink_class->preroll = evas_video_sink_preroll;
982 evas_video_sink_signals[REPAINT_REQUESTED] = g_signal_new("repaint-requested",
983 G_TYPE_FROM_CLASS(klass),
984 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
988 marshal_VOID__MINIOBJECT,
989 G_TYPE_NONE, 1, GST_TYPE_BUFFER);
993 gstreamer_plugin_init (GstPlugin * plugin)
995 return gst_element_register (plugin,
998 EVAS_TYPE_VIDEO_SINK);
1002 _emotion_gstreamer_pause(void *data, Ecore_Thread *thread)
1004 Emotion_Gstreamer_Video *ev = data;
1007 if (ecore_thread_check(thread) || !ev->pipeline) return ;
1009 gst_element_set_state(ev->pipeline, GST_STATE_PAUSED);
1010 res = gst_element_get_state(ev->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
1011 if (res == GST_STATE_CHANGE_NO_PREROLL)
1013 gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
1014 gst_element_get_state(ev->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
1019 _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread)
1021 Emotion_Gstreamer_Video *ev = data;
1023 ev->threads = eina_list_remove(ev->threads, thread);
1025 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"));
1027 if (ev->in == ev->out && ev->delete_me)
1032 _emotion_gstreamer_end(void *data, Ecore_Thread *thread)
1034 Emotion_Gstreamer_Video *ev = data;
1036 ev->threads = eina_list_remove(ev->threads, thread);
1040 gst_element_set_state(ev->pipeline, GST_STATE_PLAYING);
1041 ev->play_started = 1;
1044 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"));
1046 if (ev->in == ev->out && ev->delete_me)
1049 _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE);
1053 _video_resize(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__,
1054 Evas_Coord w, Evas_Coord h)
1056 Emotion_Gstreamer_Video *ev = data;
1059 ecore_x_window_resize(ev->win, w, h);
1061 fprintf(stderr, "resize: %i, %i\n", w, h);
1065 _video_move(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__,
1066 Evas_Coord x, Evas_Coord y)
1068 Emotion_Gstreamer_Video *ev = data;
1070 unsigned int pos[2];
1072 fprintf(stderr, "move: %i, %i\n", x, y);
1073 pos[0] = x; pos[1] = y;
1074 ecore_x_window_prop_card32_set(ev->win, ECORE_X_ATOM_E_VIDEO_POSITION, pos, 2);
1079 /* Much better idea to always feed the XvImageSink and let him handle optimizing the rendering as we do */
1081 _block_pad_unlink_cb(GstPad *pad, gboolean blocked, gpointer user_data)
1085 Emotion_Gstreamer_Video *ev = user_data;
1088 gst_pad_unlink(ev->teepad, ev->xvpad);
1089 gev = gst_event_new_eos();
1090 gst_pad_send_event(ev->xvpad, gev);
1091 gst_pad_set_blocked_async(pad, FALSE, _block_pad_unlink_cb, NULL);
1096 _block_pad_link_cb(GstPad *pad, gboolean blocked, gpointer user_data)
1100 Emotion_Gstreamer_Video *ev = user_data;
1102 gst_pad_link(ev->teepad, ev->xvpad);
1104 gst_element_set_state(ev->xvsink, GST_STATE_PLAYING);
1106 gst_element_set_state(ev->xvsink, GST_STATE_PAUSED);
1107 gst_pad_set_blocked_async(pad, FALSE, _block_pad_link_cb, NULL);
1113 _video_show(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__)
1115 Emotion_Gstreamer_Video *ev = data;
1117 fprintf(stderr, "show xv\n");
1119 ecore_x_window_show(ev->win);
1121 /* gst_pad_set_blocked_async(ev->teepad, TRUE, _block_pad_link_cb, ev); */
1125 _video_hide(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__)
1127 Emotion_Gstreamer_Video *ev = data;
1129 fprintf(stderr, "hide xv\n");
1131 ecore_x_window_hide(ev->win);
1133 /* gst_pad_set_blocked_async(ev->teepad, TRUE, _block_pad_unlink_cb, ev); */
1137 _video_update_pixels(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__)
1139 Emotion_Gstreamer_Video *ev = data;
1140 Emotion_Gstreamer_Buffer *send;
1142 if (!ev->send) return ;
1145 send->force = EINA_TRUE;
1147 evas_video_sink_main_render(send);
1151 gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev,
1155 GstElement *playbin;
1156 GstElement *bin = NULL;
1157 GstElement *esink = NULL;
1158 GstElement *xvsink = NULL;
1159 GstElement *tee = NULL;
1160 GstElement *queue = NULL;
1165 #if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H
1170 obj = emotion_object_image_get(o);
1173 ERR("Not Evas_Object specified");
1180 playbin = gst_element_factory_make("playbin2", "playbin");
1183 ERR("Unable to create 'playbin' GstElement.");
1187 bin = gst_bin_new(NULL);
1190 ERR("Unable to create GstBin !");
1191 goto unref_pipeline;
1194 tee = gst_element_factory_make("tee", NULL);
1197 ERR("Unable to create 'tee' GstElement.");
1198 goto unref_pipeline;
1201 #if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H
1202 if (window_manager_video)
1204 engines = evas_render_method_list();
1206 engine = eina_list_nth(engines, evas_output_method_get(evas_object_evas_get(obj)) - 1);
1208 if (ev->priority && engine && strstr(engine, "_x11") != NULL)
1211 Evas_Coord x, y, w, h;
1213 Ecore_X_Window parent;
1215 evas_object_geometry_get(obj, &x, &y, &w, &h);
1217 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
1222 /* Here we really need to have the help of the window manager, this code will change when we update E17. */
1223 parent = (Ecore_X_Window) ecore_evas_window_get(ee);
1224 fprintf(stderr, "parent: %x\n", parent);
1226 win = ecore_x_window_new(0, x, y, w, h);
1227 fprintf(stderr, "creating window: %x [%i, %i, %i, %i]\n", win, x, y, w, h);
1230 Ecore_X_Window_State state[] = { ECORE_X_WINDOW_STATE_SKIP_TASKBAR, ECORE_X_WINDOW_STATE_SKIP_PAGER };
1232 ecore_x_netwm_window_state_set(win, state, 2);
1233 ecore_x_window_hide(win);
1234 xvsink = gst_element_factory_make("xvimagesink", NULL);
1237 unsigned int pos[2];
1239 #ifdef HAVE_X_OVERLAY_SET
1240 gst_x_overlay_set_window_handle(GST_X_OVERLAY(xvsink), win);
1242 gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(xvsink), win);
1246 ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_E_VIDEO_PARENT, &parent, 1);
1248 pos[0] = x; pos[1] = y;
1249 ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_E_VIDEO_POSITION, pos, 2);
1253 fprintf(stderr, "destroying win: %x\n", win);
1254 ecore_x_window_free(win);
1258 evas_render_method_list_free(engines);
1261 # warning "no ecore_x or xoverlay"
1264 esink = gst_element_factory_make("emotion-sink", "sink");
1267 ERR("Unable to create 'emotion-sink' GstElement.");
1268 goto unref_pipeline;
1271 g_object_set(G_OBJECT(esink), "evas-object", obj, NULL);
1272 g_object_set(G_OBJECT(esink), "ev", ev, NULL);
1274 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1276 /* We need queue to force each video sink to be in its own thread */
1277 queue = gst_element_factory_make("queue", NULL);
1280 ERR("Unable to create 'queue' GstElement.");
1281 goto unref_pipeline;
1284 gst_bin_add_many(GST_BIN(bin), tee, queue, esink, NULL);
1285 gst_element_link_many(queue, esink, NULL);
1287 /* link both sink to GstTee */
1288 pad = gst_element_get_pad(queue, "sink");
1289 teepad = gst_element_get_request_pad(tee, "src%d");
1290 gst_pad_link(teepad, pad);
1291 gst_object_unref(pad);
1292 gst_object_unref(teepad);
1296 GstElement *fakeeos;
1298 queue = gst_element_factory_make("queue", NULL);
1299 fakeeos = GST_ELEMENT(GST_BIN(g_object_new(GST_TYPE_FAKEEOS_BIN, "name", "eosbin", NULL)));
1300 if (queue && fakeeos)
1304 gst_bin_add_many(GST_BIN(bin), fakeeos, NULL);
1306 gst_bin_add_many(GST_BIN(fakeeos), queue, xvsink, NULL);
1307 gst_element_link_many(queue, xvsink, NULL);
1308 queue_pad = gst_element_get_pad(queue, "sink");
1309 gst_element_add_pad(fakeeos, gst_ghost_pad_new("sink", queue_pad));
1311 pad = gst_element_get_pad(fakeeos, "sink");
1312 teepad = gst_element_get_request_pad(tee, "src%d");
1313 gst_pad_link(teepad, pad);
1317 ev->teepad = teepad;
1322 if (fakeeos) gst_object_unref(fakeeos);
1323 if (queue) gst_object_unref(queue);
1324 gst_object_unref(xvsink);
1329 teepad = gst_element_get_pad(tee, "sink");
1330 gst_element_add_pad(bin, gst_ghost_pad_new("sink", teepad));
1331 gst_object_unref(teepad);
1333 #define GST_PLAY_FLAG_NATIVE_VIDEO (1 << 6)
1334 #define GST_PLAY_FLAG_DOWNLOAD (1 << 7)
1335 #define GST_PLAY_FLAG_AUDIO (1 << 1)
1336 #define GST_PLAY_FLAG_NATIVE_AUDIO (1 << 5)
1338 g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
1339 g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD | GST_PLAY_FLAG_NATIVE_AUDIO, NULL);
1340 g_object_set(G_OBJECT(playbin), "video-sink", bin, NULL);
1341 g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
1343 evas_object_image_pixels_get_callback_set(obj, NULL, NULL);
1345 ev->stream = EINA_TRUE;
1349 Evas_Video_Surface video;
1351 video.version = EVAS_VIDEO_SURFACE_VERSION;
1353 video.parent = NULL;
1354 video.move = _video_move;
1355 video.resize = _video_resize;
1356 video.show = _video_show;
1357 video.hide = _video_hide;
1358 video.update_pixels = _video_update_pixels;
1360 evas_object_image_video_surface_set(obj, &video);
1361 ev->stream = EINA_FALSE;
1364 eina_stringshare_replace(&ev->uri, uri);
1365 ev->pipeline = playbin;
1368 ev->xvsink = xvsink;
1370 ev->threads = eina_list_append(ev->threads,
1371 ecore_thread_run(_emotion_gstreamer_pause,
1372 _emotion_gstreamer_end,
1373 _emotion_gstreamer_cancel,
1376 /** NOTE: you need to set: GST_DEBUG_DUMP_DOT_DIR=/tmp EMOTION_ENGINE=gstreamer to save the $EMOTION_GSTREAMER_DOT file in '/tmp' */
1377 /** then call dot -Tpng -oemotion_pipeline.png /tmp/$TIMESTAMP-$EMOTION_GSTREAMER_DOT.dot */
1378 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"));
1383 gst_object_unref(xvsink);
1384 gst_object_unref(esink);
1385 gst_object_unref(tee);
1386 gst_object_unref(bin);
1387 gst_object_unref(playbin);