Check if stream can not seek in media_streamer_set_play_position function 01/53301/1
authorAndrey Shelest <a.shelest@samsung.com>
Thu, 3 Dec 2015 13:49:06 +0000 (15:49 +0200)
committerAndrey Shelest <a.shelest@samsung.com>
Thu, 3 Dec 2015 13:49:06 +0000 (15:49 +0200)
Change-Id: I42559845129e4539712d5c317358a08c75f4bfb4
Signed-off-by: Andrey Shelest <a.shelest@samsung.com>
include/media_streamer_util.h
src/media_streamer.c
src/media_streamer_priv.c

index 0477a60..e8b468c 100644 (file)
@@ -82,6 +82,8 @@ extern "C" {
 #define MS_SAFE_UNREF(src)          {if (src) { gst_object_unref(GST_OBJECT(src)); src = NULL; } }
 #define MS_TABLE_SAFE_UNREF(src)    {if (src) { g_hash_table_unref(src); src = NULL; } }
 
+#define MS_TIME_NONE ((int)-1)
+
 /* Ini Utils */
 #define MEDIA_STREAMER_INI_DEFAULT_PATH        "/usr/etc/media_streamer.ini"
 #define MEDIA_STREAMER_INI_MAX_STRLEN  100
index a70efa2..67e2890 100644 (file)
@@ -496,12 +496,20 @@ int media_streamer_set_play_position(media_streamer_h streamer, int time, bool a
        ms_retvm_if(ms_streamer->is_seeking, MEDIA_STREAMER_ERROR_INVALID_STATE, "Media streamer is seeking");
 
        int ret = MEDIA_STREAMER_ERROR_NONE;
+       int duration = MS_TIME_NONE;
+
        g_mutex_lock(&ms_streamer->mutex_lock);
 
-       ms_streamer->seek_done_cb.callback = callback;
-       ms_streamer->seek_done_cb.user_data = user_data;
+       /* if query duration failed or returns duration value MS_TIME_NONE,
+        * we suppose that pipeline does not support seek. */
+       ret = __ms_get_duration(ms_streamer, &duration);
+       if (ret == MEDIA_STREAMER_ERROR_NONE && duration != MS_TIME_NONE) {
+               ms_streamer->seek_done_cb.callback = callback;
+               ms_streamer->seek_done_cb.user_data = user_data;
 
-       ret = __ms_streamer_seek(streamer, time, accurate);
+               ret = __ms_streamer_seek(streamer, time, accurate);
+       } else
+               ret = MEDIA_STREAMER_ERROR_NOT_SUPPORTED;
 
        g_mutex_unlock(&ms_streamer->mutex_lock);
 
index a3109dc..e0e6277 100644 (file)
@@ -19,6 +19,8 @@
 #include "media_streamer_node.h"
 #include "media_streamer_gst.h"
 
+#define GST_TIME_TO_MSEC(t) (t == GST_CLOCK_TIME_NONE ? t : (int)(((GstClockTime)(t)) / GST_MSECOND))
+
 int __ms_state_change(media_streamer_s * ms_streamer, media_streamer_state_e state)
 {
        int ret = MEDIA_STREAMER_ERROR_NONE;
@@ -85,13 +87,13 @@ int __ms_get_position(media_streamer_s * ms_streamer, int *time)
        ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL");
        ms_retvm_if(time == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Return value is NULL");
 
-       gint64 current = -1;
+       gint64 current = GST_CLOCK_TIME_NONE;
 
        if (!gst_element_query_position(ms_streamer->pipeline, GST_FORMAT_TIME, &current)) {
                ms_error("Could not query current position.");
                return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
        } else {
-               *time = (int)(((GstClockTime) (current)) / GST_MSECOND);
+               *time = GST_TIME_TO_MSEC(current);
                ms_info("Media streamer queried position at [%d] msec successfully.", *time);
        }
 
@@ -103,13 +105,13 @@ int __ms_get_duration(media_streamer_s *ms_streamer, int *time)
        ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL");
        ms_retvm_if(time == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Return value is NULL");
 
-       gint64 duration = -1;
+       gint64 duration = GST_CLOCK_TIME_NONE;
 
        if (!gst_element_query_duration(ms_streamer->pipeline, GST_FORMAT_TIME, &duration)) {
                ms_error("Could not query current duration.");
                return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
        } else {
-               *time = (int)(((GstClockTime)(duration)) / GST_MSECOND);
+               *time = GST_TIME_TO_MSEC(duration);
                ms_info("Media streamer queried duration [%d] msec successfully.", *time);
        }