servicemp3: use seeking un-pause only when necessary
authormx3L <mx3ldev@gmail.com>
Tue, 25 Aug 2015 08:48:02 +0000 (10:48 +0200)
committerErik Slagter <erik@openpli.org>
Thu, 19 Nov 2015 14:45:07 +0000 (15:45 +0100)
We are doing un-pause by flushing seek to current
position. It's neccessary only for sources which will
timeout.

http and file source will not timeout, so for them
we just unpause pipeline.

(cherry picked from commit bb84396bfb0bd8d1a3a4716ff25296a37909f1b9)
Signed-off-by: Erik Slagter <erik@openpli.org>

lib/service/servicemp3.cpp

index 0d9b7d9..de57b2f 100644 (file)
@@ -925,6 +925,62 @@ RESULT eServiceMP3::trickSeek(gdouble ratio)
                return 0;
        }
 
+#if GST_VERSION_MAJOR >= 1
+       bool unpause = (m_currentTrickRatio == 1.0 && ratio == 1.0);
+       if (unpause)
+       {
+               GstElement *source = NULL;
+               GstElementFactory *factory = NULL;
+               const gchar *name = NULL;
+               g_object_get (G_OBJECT (m_gst_playbin), "source", &source, NULL);
+               if (!source)
+               {
+                       eDebugNoNewLineStart("[eServiceMP3] trickSeek - cannot get source");
+                       goto seek_unpause;
+               }
+               factory = gst_element_get_factory(source);
+               g_object_unref(source);
+               if (!factory)
+               {
+                       eDebugNoNewLineStart("[eServiceMP3] trickSeek - cannot get source factory");
+                       goto seek_unpause;
+               }
+               name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
+               if (!name)
+               {
+                       eDebugNoNewLineStart("[eServiceMP3] trickSeek - cannot get source name");
+                       goto seek_unpause;
+               }
+               /*
+                * We know that filesrc and souphttpsrc will not timeout after long pause
+                * If there are other sources which will not timeout, add them here
+               */
+               if (!strcmp(name, "filesrc") || !strcmp(name, "souphttpsrc"))
+               {
+                       GstStateChangeReturn ret;
+                       GstState state, pending;
+                       /* make sure that last state change was successfull */
+                       ret = gst_element_get_state(m_gst_playbin, &state, &pending, 0);
+                       if (ret == GST_STATE_CHANGE_SUCCESS)
+                       {
+                               gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
+                               ret = gst_element_get_state(m_gst_playbin, &state, &pending, 0);
+                               if (ret == GST_STATE_CHANGE_SUCCESS)
+                                       return 0;
+                       }
+                       eDebugNoNewLineStart("[eServiceMP3] trickSeek - invalid state, state:%s pending:%s ret:%s",
+                               gst_element_state_get_name(state),
+                               gst_element_state_get_name(pending),
+                               gst_element_state_change_return_get_name(ret));
+               }
+               else
+               {
+                       eDebugNoNewLineStart("[eServiceMP3] trickSeek - source '%s' is not supported", name);
+               }
+seek_unpause:
+               eDebugNoNewLine(", doing seeking unpause\n");
+       }
+#endif
        m_currentTrickRatio = ratio;
 
        bool validposition = false;