X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmodules%2Fgstreamer%2Femotion_sink.c;h=ae4b27ec63700d9becc8e43aefe5e87380c038e7;hb=a35ad3a70df5254ee4fc06e45d2577efa453ed6a;hp=d9a2392abfb57a1d2c90314bf8f3c22814f0a828;hpb=0d8ac1e382ea297fa13e3061bf18742f335ae9e4;p=profile%2Fivi%2Femotion.git diff --git a/src/modules/gstreamer/emotion_sink.c b/src/modules/gstreamer/emotion_sink.c index d9a2392..ae4b27e 100644 --- a/src/modules/gstreamer/emotion_sink.c +++ b/src/modules/gstreamer/emotion_sink.c @@ -42,230 +42,6 @@ static void evas_video_sink_main_render(void *data); static void evas_video_sink_samsung_main_render(void *data); static void -_evas_video_bgrx_step(unsigned char *evas_data, const unsigned char *gst_data, - unsigned int w, unsigned int h __UNUSED__, unsigned int output_height, unsigned int step) -{ - unsigned int x; - unsigned int y; - - for (y = 0; y < output_height; ++y) - { - for (x = 0; x < w; x++) - { - evas_data[0] = gst_data[0]; - evas_data[1] = gst_data[1]; - evas_data[2] = gst_data[2]; - evas_data[3] = 255; - gst_data += step; - evas_data += 4; - } - } -} - -static void -_evas_video_bgr(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height) -{ - _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 3); -} - -static void -_evas_video_bgrx(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height) -{ - _evas_video_bgrx_step(evas_data, gst_data, w, h, output_height, 4); -} - -static void -_evas_video_bgra(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height) -{ - unsigned int x; - unsigned int y; - - for (y = 0; y < output_height; ++y) - { - unsigned char alpha; - - for (x = 0; x < w; ++x) - { - alpha = gst_data[3]; - evas_data[0] = (gst_data[0] * alpha) / 255; - evas_data[1] = (gst_data[1] * alpha) / 255; - evas_data[2] = (gst_data[2] * alpha) / 255; - evas_data[3] = alpha; - gst_data += 4; - evas_data += 4; - } - } -} - -static void -_evas_video_i420(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height) -{ - const unsigned char **rows; - unsigned int i, j; - unsigned int rh; - - rh = output_height; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < rh; i++) - rows[i] = &gst_data[i * w]; - - for (j = 0; j < (rh / 2); j++, i++) - rows[i] = &gst_data[h * w + j * (w / 2)]; - - for (j = 0; j < (rh / 2); j++, i++) - rows[i] = &gst_data[h * w + rh * (w / 4) + j * (w / 2)]; -} - -static void -_evas_video_yv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height) -{ - const unsigned char **rows; - unsigned int i, j; - unsigned int rh; - - rh = output_height; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < rh; i++) - rows[i] = &gst_data[i * w]; - - for (j = 0; j < (rh / 2); j++, i++) - rows[i] = &gst_data[h * w + rh * (w / 4) + j * (w / 2)]; - - for (j = 0; j < (rh / 2); j++, i++) - rows[i] = &gst_data[h * w + j * (w / 2)]; -} - -static void -_evas_video_yuy2(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height) -{ - const unsigned char **rows; - unsigned int i; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < output_height; i++) - rows[i] = &gst_data[i * w * 2]; -} - -static void -_evas_video_nv12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h __UNUSED__, unsigned int output_height) -{ - const unsigned char **rows; - unsigned int i, j; - unsigned int rh; - - rh = output_height; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < rh; i++) - rows[i] = &gst_data[i * w]; - - for (j = 0; j < (rh / 2); j++, i++) - rows[i] = &gst_data[rh * w + j * w]; -} - -static void -_evas_video_mt12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__) -{ - const unsigned char **rows; - unsigned int i; - unsigned int j; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < (h / 32) / 2; i++) - rows[i] = &gst_data[i * w * 2 * 32]; - - if ((h / 32) % 2) - { - rows[i] = &gst_data[i * w * 2 * 32]; - i++; - } - - for (j = 0; j < ((h / 2) / 32) / 2; ++j, ++i) - rows[i] = &gst_data[h * w + j * (w / 2) * 2 * 16]; -} - -static void -_evas_video_st12_multiplane(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w, unsigned int h, unsigned int output_height __UNUSED__) -{ - const GstMultiPlaneImageBuffer *mp_buf = (const GstMultiPlaneImageBuffer *) gst_data; - const unsigned char **rows; - unsigned int i; - unsigned int j; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < (h / 32) / 2; i++) - rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32; - if ((h / 32) % 2) - { - rows[i] = mp_buf->uaddr[0] + i * w * 2 * 32; - i++; - } - - for (j = 0; j < ((h / 2) / 16) / 2; j++, i++) - { - rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2; - } - if (((h / 2) / 16) % 2) - rows[i] = mp_buf->uaddr[1] + j * w * 2 * 16 * 2; -} - -static void -_evas_video_st12(unsigned char *evas_data, const unsigned char *gst_data, unsigned int w __UNUSED__, unsigned int h, unsigned int output_height __UNUSED__) -{ - const SCMN_IMGB *imgb = (const SCMN_IMGB *) gst_data; - const unsigned char **rows; - unsigned int i, j; - - rows = (const unsigned char **)evas_data; - - for (i = 0; i < (h / 32) / 2; i++) - rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32; - if ((h / 32) % 2) - { - rows[i] = imgb->uaddr[0] + i * imgb->stride[0] * 2 * 32; - i++; - } - - for (j = 0; j < (unsigned int) imgb->elevation[1] / 32 / 2; j++, i++) - rows[i] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2; - if ((imgb->elevation[1] / 32) % 2) - rows[i++] = imgb->uaddr[1] + j * imgb->stride[1] * 32 * 2; -} - -static const struct { - const char *name; - guint32 fourcc; - Evas_Colorspace eformat; - Evas_Video_Convert_Cb func; - Eina_Bool force_height; -} colorspace_fourcc_convertion[] = { - { "I420", GST_MAKE_FOURCC('I', '4', '2', '0'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_i420, EINA_TRUE }, - { "YV12", GST_MAKE_FOURCC('Y', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR422P601_PL, _evas_video_yv12, EINA_TRUE }, - { "YUY2", GST_MAKE_FOURCC('Y', 'U', 'Y', '2'), EVAS_COLORSPACE_YCBCR422601_PL, _evas_video_yuy2, EINA_FALSE }, - { "NV12", GST_MAKE_FOURCC('N', 'V', '1', '2'), EVAS_COLORSPACE_YCBCR420NV12601_PL, _evas_video_nv12, EINA_TRUE }, - { "TM12", GST_MAKE_FOURCC('T', 'M', '1', '2'), EVAS_COLORSPACE_YCBCR420TM12601_PL, _evas_video_mt12, EINA_TRUE } -}; - -static const struct { - const char *name; - GstVideoFormat format; - Evas_Colorspace eformat; - Evas_Video_Convert_Cb func; -} colorspace_format_convertion[] = { - { "BGR", GST_VIDEO_FORMAT_BGR, EVAS_COLORSPACE_ARGB8888, _evas_video_bgr }, - { "BGRx", GST_VIDEO_FORMAT_BGRx, EVAS_COLORSPACE_ARGB8888, _evas_video_bgrx }, - { "BGRA", GST_VIDEO_FORMAT_BGRA, EVAS_COLORSPACE_ARGB8888, _evas_video_bgra } -}; - -static void evas_video_sink_base_init(gpointer g_class) { GstElementClass* element_class; @@ -425,7 +201,7 @@ gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps) { priv->source_height = priv->height; - for (i = 0; i < sizeof (colorspace_fourcc_convertion) / sizeof (colorspace_fourcc_convertion[0]); ++i) + for (i = 0; colorspace_fourcc_convertion[i].name != NULL; ++i) if (fourcc == colorspace_fourcc_convertion[i].fourcc) { fprintf(stderr, "Found '%s'\n", colorspace_fourcc_convertion[i].name); @@ -464,7 +240,7 @@ gboolean evas_video_sink_set_caps(GstBaseSink *bsink, GstCaps *caps) priv->source_height = priv->height; - for (i = 0; i < sizeof (colorspace_format_convertion) / sizeof (colorspace_format_convertion[0]); ++i) + for (i = 0; colorspace_format_convertion[i].name != NULL; ++i) if (format == colorspace_format_convertion[i].format) { fprintf(stderr, "Found '%s'\n", colorspace_format_convertion[i].name); @@ -599,7 +375,7 @@ evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer) EvasVideoSinkPrivate *priv; EvasVideoSink *sink; - INF("sink render %p [%i]", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer)); + INF("sink render %p", buffer); sink = EVAS_VIDEO_SINK(bsink); priv = sink->priv; @@ -649,6 +425,31 @@ evas_video_sink_render(GstBaseSink* bsink, GstBuffer* buffer) } static void +_update_emotion_fps(Emotion_Gstreamer_Video *ev) +{ + double tim; + + if (!debug_fps) return ; + + tim = ecore_time_get(); + ev->frames++; + + if (ev->rlapse == 0.0) + { + ev->rlapse = tim; + ev->flapse = ev->frames; + } + else if ((tim - ev->rlapse) >= 0.5) + { + printf("FRAME: %i, FPS: %3.1f\n", + ev->frames, + (ev->frames - ev->flapse) / (tim - ev->rlapse)); + ev->rlapse = tim; + ev->flapse = ev->frames; + } +} + +static void evas_video_sink_samsung_main_render(void *data) { Emotion_Gstreamer_Buffer *send; @@ -674,6 +475,19 @@ evas_video_sink_samsung_main_render(void *data) if (!priv || !priv->o || priv->unlocked) goto exit_point; + if (send->ev->send) + { + emotion_gstreamer_buffer_free(send->ev->send); + send->ev->send = NULL; + } + + if (!send->ev->stream && !send->force) + { + send->ev->send = send; + _emotion_frame_new(send->ev->obj); + goto exit_stream; + } + _emotion_gstreamer_video_pipeline_parse(send->ev, EINA_TRUE); /* Getting stride to compute the right size and then fill the object properly */ @@ -703,13 +517,14 @@ evas_video_sink_samsung_main_render(void *data) evas_object_geometry_get(priv->o, NULL, NULL, &w, &h); - send->ev->fill.width = stride * w / priv->width; - send->ev->fill.height = elevation * h / priv->height; + send->ev->fill.width = (double) stride / priv->width; + send->ev->fill.height = (double) elevation / priv->height; evas_object_image_alpha_set(priv->o, 0); evas_object_image_colorspace_set(priv->o, priv->eformat); evas_object_image_size_set(priv->o, stride, elevation); - evas_object_image_fill_set(priv->o, 0, 0, send->ev->fill.width, send->ev->fill.height); + + _update_emotion_fps(send->ev); evas_data = evas_object_image_data_get(priv->o, 1); @@ -722,25 +537,42 @@ evas_video_sink_samsung_main_render(void *data) evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height); evas_object_image_pixels_dirty_set(priv->o, 0); - _emotion_frame_new(send->ev->obj); + if (!preroll && send->ev->play_started) + { + _emotion_playback_started(send->ev->obj); + send->ev->play_started = 0; + } + + if (!send->force) + { + _emotion_frame_new(send->ev->obj); + } vstream = eina_list_nth(send->ev->video_streams, send->ev->video_stream_nbr - 1); gst_element_query_position(send->ev->pipeline, &fmt, &pos); send->ev->position = (double)pos / (double)GST_SECOND; - vstream->width = priv->width; - vstream->height = priv->height; - send->ev->ratio = (double) priv->width / (double) priv->height; + if (vstream) + { + vstream->width = priv->width; + vstream->height = priv->height; - _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time); + _emotion_video_pos_update(send->ev->obj, send->ev->position, vstream->length_time); + } + + send->ev->ratio = (double) priv->width / (double) priv->height; + _emotion_frame_refill(send->ev->obj, send->ev->fill.width, send->ev->fill.height); _emotion_frame_resize(send->ev->obj, priv->width, priv->height, send->ev->ratio); - /* FIXME: why is last buffer not protected ? */ + buffer = gst_buffer_ref(buffer); + if (send->ev->last_buffer) gst_buffer_unref(send->ev->last_buffer); + send->ev->last_buffer = buffer; exit_point: emotion_gstreamer_buffer_free(send); + exit_stream: if (preroll || !priv->o) return ; if (!priv->unlocked) @@ -772,6 +604,20 @@ evas_video_sink_main_render(void *data) if (!priv || !priv->o || priv->unlocked) goto exit_point; + if (ev->send && send != ev->send) + { + emotion_gstreamer_buffer_free(ev->send); + ev->send = NULL; + } + + if (!ev->stream && !send->force) + { + ev->send = send; + _emotion_frame_new(ev->obj); + evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height); + goto exit_stream; + } + _emotion_gstreamer_video_pipeline_parse(ev, EINA_TRUE); INF("sink main render [%i, %i] (source height: %i)", priv->width, priv->height, priv->source_height); @@ -791,7 +637,16 @@ evas_video_sink_main_render(void *data) evas_object_image_data_update_add(priv->o, 0, 0, priv->width, priv->height); evas_object_image_pixels_dirty_set(priv->o, 0); - _emotion_frame_new(ev->obj); + if (!preroll && ev->play_started) + { + _emotion_playback_started(ev->obj); + ev->play_started = 0; + } + + if (!send->force) + { + _emotion_frame_new(ev->obj); + } gst_element_query_position(ev->pipeline, &fmt, &pos); ev->position = (double)pos / (double)GST_SECOND; @@ -816,6 +671,7 @@ evas_video_sink_main_render(void *data) exit_point: emotion_gstreamer_buffer_free(send); + exit_stream: if (preroll || !priv->o) return ; if (!priv->unlocked) @@ -922,10 +778,17 @@ static void _emotion_gstreamer_pause(void *data, Ecore_Thread *thread) { Emotion_Gstreamer_Video *ev = data; + gboolean res; if (ecore_thread_check(thread) || !ev->pipeline) return ; gst_element_set_state(ev->pipeline, GST_STATE_PAUSED); + res = gst_element_get_state(ev->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); + if (res == GST_STATE_CHANGE_NO_PREROLL) + { + gst_element_set_state(ev->pipeline, GST_STATE_PLAYING); + gst_element_get_state(ev->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); + } } static void @@ -937,7 +800,7 @@ _emotion_gstreamer_cancel(void *data, Ecore_Thread *thread) 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")); - if (ev->in == ev->out && ev->threads == NULL && ev->delete_me) + if (ev->in == ev->out && ev->delete_me) em_shutdown(ev); } @@ -956,32 +819,108 @@ _emotion_gstreamer_end(void *data, Ecore_Thread *thread) 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")); - if (ev->in == ev->out && ev->threads == NULL && ev->delete_me) + if (ev->in == ev->out && ev->delete_me) em_shutdown(ev); else _emotion_gstreamer_video_pipeline_parse(data, EINA_TRUE); } static void -_on_post_clear(void *data, Evas *e __UNUSED__, void *event_info __UNUSED__) +_video_resize(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__, + Evas_Coord w, Evas_Coord h) { Emotion_Gstreamer_Video *ev = data; - if (!ev->kill_buffer) return ; +#ifdef HAVE_ECORE_X + ecore_x_window_resize(ev->win, w, h); +#endif + fprintf(stderr, "resize: %i, %i\n", w, h); +} + +static void +_video_move(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__, + Evas_Coord x, Evas_Coord y) +{ + Emotion_Gstreamer_Video *ev = data; +#ifdef HAVE_ECORE_X + unsigned int pos[2]; + + fprintf(stderr, "move: %i, %i\n", x, y); + pos[0] = x; pos[1] = y; + ecore_x_window_prop_card32_set(ev->win, ECORE_X_ATOM_E_VIDEO_POSITION, pos, 2); +#endif +} #if 0 - if (ev->last_buffer) gst_buffer_unref(ev->last_buffer); - ev->last_buffer = NULL; +/* Much better idea to always feed the XvImageSink and let him handle optimizing the rendering as we do */ +static void +_block_pad_unlink_cb(GstPad *pad, gboolean blocked, gpointer user_data) +{ + if (blocked) + { + Emotion_Gstreamer_Video *ev = user_data; + GstEvent *gev; + + gst_pad_unlink(ev->teepad, ev->xvpad); + gev = gst_event_new_eos(); + gst_pad_send_event(ev->xvpad, gev); + gst_pad_set_blocked_async(pad, FALSE, _block_pad_unlink_cb, NULL); + } +} + +static void +_block_pad_link_cb(GstPad *pad, gboolean blocked, gpointer user_data) +{ + if (blocked) + { + Emotion_Gstreamer_Video *ev = user_data; + + gst_pad_link(ev->teepad, ev->xvpad); + if (ev->play) + gst_element_set_state(ev->xvsink, GST_STATE_PLAYING); + else + gst_element_set_state(ev->xvsink, GST_STATE_PAUSED); + gst_pad_set_blocked_async(pad, FALSE, _block_pad_link_cb, NULL); + } +} #endif + +static void +_video_show(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__) +{ + Emotion_Gstreamer_Video *ev = data; + + fprintf(stderr, "show xv\n"); +#ifdef HAVE_ECORE_X + ecore_x_window_show(ev->win); +#endif + /* gst_pad_set_blocked_async(ev->teepad, TRUE, _block_pad_link_cb, ev); */ +} + +static void +_video_hide(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__) +{ + Emotion_Gstreamer_Video *ev = data; + + fprintf(stderr, "hide xv\n"); +#ifdef HAVE_ECORE_X + ecore_x_window_hide(ev->win); +#endif + /* gst_pad_set_blocked_async(ev->teepad, TRUE, _block_pad_unlink_cb, ev); */ } static void -_on_resize_fill(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) +_video_update_pixels(void *data, Evas_Object *obj __UNUSED__, const Evas_Video_Surface *surface __UNUSED__) { Emotion_Gstreamer_Video *ev = data; + Emotion_Gstreamer_Buffer *send; + + if (!ev->send) return ; - if (ev->samsung) - evas_object_image_fill_set(obj, 0, 0, ev->fill.width, ev->fill.height); + send = ev->send; + send->force = EINA_TRUE; + ev->send = NULL; + evas_video_sink_main_render(send); } GstElement * @@ -990,8 +929,14 @@ gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev, const char *uri) { GstElement *playbin; - GstElement *sink = NULL; + GstElement *bin = NULL; + GstElement *esink = NULL; + GstElement *xvsink = NULL; + GstElement *tee = NULL; + GstElement *queue = NULL; Evas_Object *obj; + GstPad *pad; + GstPad *teepad; int flags; #if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H const char *engine; @@ -1005,9 +950,6 @@ gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev, return NULL; } - evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev); - evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_RENDER_FLUSH_POST, _on_post_clear, ev); - if (!uri) return NULL; @@ -1018,69 +960,189 @@ gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev, return NULL; } -#if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H - engines = evas_render_method_list(); + bin = gst_bin_new(NULL); + if (!bin) + { + ERR("Unable to create GstBin !"); + goto unref_pipeline; + } - engine = eina_list_nth(engines, evas_output_method_get(evas_object_evas_get(obj)) - 1); + tee = gst_element_factory_make("tee", NULL); + if (!tee) + { + ERR("Unable to create 'tee' GstElement."); + goto unref_pipeline; + } - if (engine && strstr(engine, "_x11") != NULL) +#if defined HAVE_ECORE_X && defined HAVE_XOVERLAY_H + if (window_manager_video) { -#if 0 - Evas_Coord x, y, w, h; - Ecore_X_Window win; + engines = evas_render_method_list(); - evas_object_geometry_get(obj, &x, &y, &w, &h); + engine = eina_list_nth(engines, evas_output_method_get(evas_object_evas_get(obj)) - 1); - win = ecore_x_window_new(0, x, y, w, h); - if (win) - { - sink = gst_element_factory_make("xvimagesink", NULL); - if (sink) - { - gst_x_overlay_set_window_handle(GST_X_OVERLAY(sink), win); - ev->win = win; - } - else - { - ecore_x_window_free(win); - } - } + if (ev->priority && engine && strstr(engine, "_x11") != NULL) + { + Ecore_Evas *ee; + Evas_Coord x, y, w, h; + Ecore_X_Window win; + Ecore_X_Window parent; + + evas_object_geometry_get(obj, &x, &y, &w, &h); + + ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj)); + + if (w < 4) w = 4; + if (h < 2) h = 2; + + /* Here we really need to have the help of the window manager, this code will change when we update E17. */ + parent = (Ecore_X_Window) ecore_evas_window_get(ee); + fprintf(stderr, "parent: %x\n", parent); + + win = ecore_x_window_new(0, x, y, w, h); + fprintf(stderr, "creating window: %x [%i, %i, %i, %i]\n", win, x, y, w, h); + if (win) + { + Ecore_X_Window_State state[] = { ECORE_X_WINDOW_STATE_SKIP_TASKBAR, ECORE_X_WINDOW_STATE_SKIP_PAGER }; + + ecore_x_netwm_window_state_set(win, state, 2); + ecore_x_window_hide(win); + xvsink = gst_element_factory_make("xvimagesink", NULL); + if (xvsink) + { + unsigned int pos[2]; + +#ifdef HAVE_X_OVERLAY_SET + gst_x_overlay_set_window_handle(GST_X_OVERLAY(xvsink), win); +#else + gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(xvsink), win); #endif + ev->win = win; + + ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_E_VIDEO_PARENT, &parent, 1); + + pos[0] = x; pos[1] = y; + ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_E_VIDEO_POSITION, pos, 2); + } + else + { + fprintf(stderr, "destroying win: %x\n", win); + ecore_x_window_free(win); + } + } + } + evas_render_method_list_free(engines); } - evas_render_method_list_free(engines); #else # warning "no ecore_x or xoverlay" #endif - fprintf(stderr, "sink: %p\n", sink); - if (!sink) + + esink = gst_element_factory_make("emotion-sink", "sink"); + if (!esink) { - sink = gst_element_factory_make("emotion-sink", "sink"); - if (!sink) - { - ERR("Unable to create 'emotion-sink' GstElement."); - goto unref_pipeline; - } + ERR("Unable to create 'emotion-sink' GstElement."); + goto unref_pipeline; + } + + g_object_set(G_OBJECT(esink), "evas-object", obj, NULL); + g_object_set(G_OBJECT(esink), "ev", ev, NULL); + + evas_object_image_pixels_get_callback_set(obj, NULL, NULL); + + /* We need queue to force each video sink to be in its own thread */ + queue = gst_element_factory_make("queue", NULL); + if (!queue) + { + ERR("Unable to create 'queue' GstElement."); + goto unref_pipeline; + } + + gst_bin_add_many(GST_BIN(bin), tee, queue, esink, NULL); + gst_element_link_many(queue, esink, NULL); + + /* link both sink to GstTee */ + pad = gst_element_get_pad(queue, "sink"); + teepad = gst_element_get_request_pad(tee, "src%d"); + gst_pad_link(teepad, pad); + gst_object_unref(pad); + gst_object_unref(teepad); + + if (xvsink) + { + GstElement *fakeeos; + + queue = gst_element_factory_make("queue", NULL); + fakeeos = GST_ELEMENT(GST_BIN(g_object_new(GST_TYPE_FAKEEOS_BIN, "name", "eosbin", NULL))); + if (queue && fakeeos) + { + GstPad *queue_pad; + + gst_bin_add_many(GST_BIN(bin), fakeeos, NULL); - g_object_set(G_OBJECT(sink), "evas-object", obj, NULL); - g_object_set(G_OBJECT(sink), "ev", ev, NULL); + gst_bin_add_many(GST_BIN(fakeeos), queue, xvsink, NULL); + gst_element_link_many(queue, xvsink, NULL); + queue_pad = gst_element_get_pad(queue, "sink"); + gst_element_add_pad(fakeeos, gst_ghost_pad_new("sink", queue_pad)); - evas_object_image_pixels_get_callback_set(obj, NULL, NULL); + pad = gst_element_get_pad(fakeeos, "sink"); + teepad = gst_element_get_request_pad(tee, "src%d"); + gst_pad_link(teepad, pad); + + xvsink = fakeeos; + + ev->teepad = teepad; + ev->xvpad = pad; + } + else + { + if (fakeeos) gst_object_unref(fakeeos); + if (queue) gst_object_unref(queue); + gst_object_unref(xvsink); + xvsink = NULL; + } } + teepad = gst_element_get_pad(tee, "sink"); + gst_element_add_pad(bin, gst_ghost_pad_new("sink", teepad)); + gst_object_unref(teepad); + #define GST_PLAY_FLAG_NATIVE_VIDEO (1 << 6) #define GST_PLAY_FLAG_DOWNLOAD (1 << 7) +#define GST_PLAY_FLAG_AUDIO (1 << 1) +#define GST_PLAY_FLAG_NATIVE_AUDIO (1 << 5) g_object_get(G_OBJECT(playbin), "flags", &flags, NULL); - g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD, NULL); - g_object_set(G_OBJECT(playbin), "video-sink", sink, NULL); + g_object_set(G_OBJECT(playbin), "flags", flags | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_DOWNLOAD | GST_PLAY_FLAG_NATIVE_AUDIO, NULL); + g_object_set(G_OBJECT(playbin), "video-sink", bin, NULL); g_object_set(G_OBJECT(playbin), "uri", uri, NULL); evas_object_image_pixels_get_callback_set(obj, NULL, NULL); - evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize_fill, ev); - evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_RENDER_FLUSH_POST, _on_post_clear, ev); + ev->stream = EINA_TRUE; + + if (xvsink) + { + Evas_Video_Surface video; + + video.version = EVAS_VIDEO_SURFACE_VERSION; + video.data = ev; + video.parent = NULL; + video.move = _video_move; + video.resize = _video_resize; + video.show = _video_show; + video.hide = _video_hide; + video.update_pixels = _video_update_pixels; + + evas_object_image_video_surface_set(obj, &video); + ev->stream = EINA_FALSE; + } + + eina_stringshare_replace(&ev->uri, uri); ev->pipeline = playbin; - ev->sink = sink; + ev->sink = bin; + ev->esink = esink; + ev->xvsink = xvsink; + ev->tee = tee; ev->threads = eina_list_append(ev->threads, ecore_thread_run(_emotion_gstreamer_pause, _emotion_gstreamer_end, @@ -1094,6 +1156,10 @@ gstreamer_video_sink_new(Emotion_Gstreamer_Video *ev, return playbin; unref_pipeline: + gst_object_unref(xvsink); + gst_object_unref(esink); + gst_object_unref(tee); + gst_object_unref(bin); gst_object_unref(playbin); return NULL; }