From 6f24f7591d35dc22065f719ce5e4f5eeed9a6eca Mon Sep 17 00:00:00 2001 From: raster Date: Mon, 5 Mar 2012 09:33:05 +0000 Subject: [PATCH] From: Davide Andreoli Subject: [E-devel] Emotion buffer size patch Hi, here is a patch for emotion, it add a new function to retrive the status of the buffer while playing online stream. It is implemented only for the gstreamer backend, the xine one do not play at all here. What about the generic one? (xine does play - i implameneted this with the xine module, and generic is given a func that always returns 1.0 for now). git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/emotion@68684 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/emotion_test_main.c | 5 +++-- src/lib/Emotion.h | 17 +++++++++++++++++ src/lib/emotion_private.h | 1 + src/lib/emotion_smart.c | 12 ++++++++++++ src/modules/generic/emotion_generic.c | 12 +++++++++++- src/modules/gstreamer/emotion_gstreamer.c | 26 ++++++++++++++++++++++++++ src/modules/xine/emotion_xine.c | 16 +++++++++++++++- src/modules/xine/emotion_xine.h | 1 + 8 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/bin/emotion_test_main.c b/src/bin/emotion_test_main.c index 1ea3865..6f9b303 100644 --- a/src/bin/emotion_test_main.c +++ b/src/bin/emotion_test_main.c @@ -300,13 +300,14 @@ bg_key_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED static void video_obj_time_changed(Evas_Object *obj, Evas_Object *edje) { - double pos, len, scale; + double pos, len, scale, bsize; char buf[256]; int ph, pm, ps, pf, lh, lm, ls; pos = emotion_object_position_get(obj); len = emotion_object_play_length_get(obj); -// printf("%3.3f, %3.3f\n", pos, len); + bsize = emotion_object_buffer_size_get(obj); + // printf("%3.3f, %3.3f [%.2f]\n", pos, len, bsize); scale = (len > 0.0) ? pos / len : 0.0; edje_object_part_drag_value_set(edje, "video_progress", scale, 0.0); lh = len / 3600; diff --git a/src/lib/Emotion.h b/src/lib/Emotion.h index bfd448b..3e70b24 100644 --- a/src/lib/Emotion.h +++ b/src/lib/Emotion.h @@ -632,6 +632,23 @@ EAPI void emotion_object_position_set (Evas_Object *obj, double * media file. */ EAPI double emotion_object_position_get (const Evas_Object *obj); + +/** + * @brief Get the percentual size of the buffering cache. + * + * @param obj The emotion object from which the buffer size will be retrieved. + * @return The buffer percent size, ranging from 0.0 to 1.0 + * + * The buffer size is returned as a number between 0.0 and 1.0, 0.0 means + * the buffer if empty, 1.0 means full. + * If no buffering is in progress 1.0 is returned. In all other cases (maybe + * the backend don't support buffering) 1.0 is returned, thus you can always + * check for buffer_size < 1.0 to know if buffering is in progress. + * + * @warning xine backends don't implement this (will return 1.0). + */ +EAPI double emotion_object_buffer_size_get (const Evas_Object *obj); + /** * @brief Get whether the media file is seekable. * diff --git a/src/lib/emotion_private.h b/src/lib/emotion_private.h index 6595436..4f9458f 100644 --- a/src/lib/emotion_private.h +++ b/src/lib/emotion_private.h @@ -51,6 +51,7 @@ struct _Emotion_Video_Module void (*size_get) (void *ef, int *w, int *h); void (*pos_set) (void *ef, double pos); double (*len_get) (void *ef); + double (*buffer_size_get) (void *ef); int (*fps_num_get) (void *ef); int (*fps_den_get) (void *ef); double (*fps_get) (void *ef); diff --git a/src/lib/emotion_smart.c b/src/lib/emotion_smart.c index 4b37879..1411374 100644 --- a/src/lib/emotion_smart.c +++ b/src/lib/emotion_smart.c @@ -761,6 +761,18 @@ emotion_object_position_get(const Evas_Object *obj) return sd->pos; } +EAPI double +emotion_object_buffer_size_get(const Evas_Object *obj) +{ + Smart_Data *sd; + + E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 1.0); + if (!sd->module) return 1.0; + if (!sd->video_data) return 1.0; + if (!sd->module->buffer_size_get) return 1.0; + return sd->module->buffer_size_get(sd->video_data); +} + EAPI Eina_Bool emotion_object_seekable_get(const Evas_Object *obj) { diff --git a/src/modules/generic/emotion_generic.c b/src/modules/generic/emotion_generic.c index bf440f4..1e2d139 100644 --- a/src/modules/generic/emotion_generic.c +++ b/src/modules/generic/emotion_generic.c @@ -332,7 +332,7 @@ _player_position_changed(Emotion_Generic_Video *ev) ev->pos = position; _emotion_video_pos_update(ev->obj, ev->pos, ev->len); - +/* hmmm. no _emotion_progress_set() is for "buffering" progress. if (ev->len == 0) return; @@ -341,6 +341,7 @@ _player_position_changed(Emotion_Generic_Video *ev) snprintf(buf, sizeof(buf), "%0.1f%%", progress * 100); _emotion_progress_set(ev->obj, buf, progress); + */ } static void @@ -1162,6 +1163,14 @@ em_len_get(void *data) return ev->len; } +static double +em_buffer_size_get(void *data) +{ + Emotion_Generic_Video *ev = data; + return 1.0; + ev = NULL; +} + static int em_fps_num_get(void *data) { @@ -1597,6 +1606,7 @@ static Emotion_Video_Module em_module = em_size_get, /* size_get */ em_pos_set, /* pos_set */ em_len_get, /* len_get */ + em_buffer_size_get, /* buffer_size_get */ em_fps_num_get, /* fps_num_get */ em_fps_den_get, /* fps_den_get */ em_fps_get, /* fps_get */ diff --git a/src/modules/gstreamer/emotion_gstreamer.c b/src/modules/gstreamer/emotion_gstreamer.c index 9f0051b..9d6b213 100644 --- a/src/modules/gstreamer/emotion_gstreamer.c +++ b/src/modules/gstreamer/emotion_gstreamer.c @@ -67,6 +67,8 @@ static void em_pos_set (void *video, static double em_len_get (void *video); +static double em_buffer_size_get (void *video); + static int em_fps_num_get (void *video); static int em_fps_den_get (void *video); @@ -212,6 +214,7 @@ static Emotion_Video_Module em_module = em_size_get, /* size_get */ em_pos_set, /* pos_set */ em_len_get, /* len_get */ + em_buffer_size_get, /* buffer_size_get */ em_fps_num_get, /* fps_num_get */ em_fps_den_get, /* fps_den_get */ em_fps_get, /* fps_get */ @@ -685,6 +688,29 @@ em_len_get(void *video) return 0.0; } +static double +em_buffer_size_get(void *video) +{ + Emotion_Gstreamer_Video *ev; + + GstQuery *query; + gboolean busy; + gint percent; + + ev = video; + + if (!ev->pipeline) return 0.0; + + query = gst_query_new_buffering(GST_FORMAT_DEFAULT); + if (gst_element_query(ev->pipeline, query)) + gst_query_parse_buffering_percent(query, &busy, &percent); + else + percent = 100; + + gst_query_unref(query); + return ((float)(percent)) / 100.0; +} + static int em_fps_num_get(void *video) { diff --git a/src/modules/xine/emotion_xine.c b/src/modules/xine/emotion_xine.c index 4108e73..dd4a3a5 100644 --- a/src/modules/xine/emotion_xine.c +++ b/src/modules/xine/emotion_xine.c @@ -21,6 +21,7 @@ static void em_play (void *ef, double pos); static void em_stop (void *ef); static void em_size_get (void *ef, int *w, int *h); static void em_pos_set (void *ef, double pos); +static double em_buffer_size_get (void *ef); static double em_len_get (void *ef); static int em_fps_num_get (void *ef); static int em_fps_den_get (void *ef); @@ -425,6 +426,8 @@ em_init(Evas_Object *obj, void **emotion_video, Emotion_Module_Options *opt) pthread_create(&ev->slave_th, NULL, _em_slave, ev); pthread_detach(ev->slave_th); _em_slave_event(ev, 1, NULL); + + ev->buffer = 1.0; *emotion_video = ev; return 1; @@ -532,6 +535,15 @@ em_len_get(void *ef) return ev->len; } +static double +em_buffer_size_get(void *ef) +{ + Emotion_Xine_Video *ev; + + ev = (Emotion_Xine_Video *)ef; + return ev->buffer; +} + static int em_fps_num_get(void *ef) { @@ -1251,7 +1263,7 @@ _em_fd_ev_active(void *data __UNUSED__, Ecore_Fd_Handler *fdh) { int fd, len; void *buf[2]; - + fd = ecore_main_fd_handler_fd_get(fdh); while ((len = read(fd, buf, sizeof(buf))) > 0) { @@ -1399,6 +1411,7 @@ _em_fd_ev_active(void *data __UNUSED__, Ecore_Fd_Handler *fdh) e = (xine_progress_data_t *)eev->xine_event; DBG("PROGRESS: %i", e->percent); + ev->buffer = e->percent; _emotion_progress_set(ev->obj, (char *)e->description, (double)e->percent / 100.0); } break; @@ -1518,6 +1531,7 @@ static Emotion_Video_Module em_module = em_size_get, /* size_get */ em_pos_set, /* pos_set */ em_len_get, /* len_get */ + em_buffer_size_get, /* buffer_size_get */ em_fps_num_get, /* fps_num_get */ em_fps_den_get, /* fps_den_get */ em_fps_get, /* fps_get */ diff --git a/src/modules/xine/emotion_xine.h b/src/modules/xine/emotion_xine.h index 97aed72..c1cae2e 100644 --- a/src/modules/xine/emotion_xine.h +++ b/src/modules/xine/emotion_xine.h @@ -22,6 +22,7 @@ struct _Emotion_Xine_Video volatile double pos; volatile double last_pos; volatile double volume; + volatile double buffer; double fps; double ratio; int w, h; -- 2.7.4