[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/multimedia/kmplayer/src
From:       Koos Vriezen <koos.vriezen () gmail ! com>
Date:       2011-10-10 20:44:48
Message-ID: 20111010204448.A89D9AC887 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1258260 by vriezen:

Redo Smil av pausing prevention, now done in the process class

Code pulled over from the maemo port, which looks less hacky and
gains a paused state we may use in the UI. The main culprit though seems
to be that defering the MediaType, caused by the buffering state of the
backend process, first paused the document and then adjusted its state.
Since all media elements listen to document pausing events, a pause
command was issued.

 M  +1 -7      kmplayer_smil.cpp  
 M  +2 -1      kmplayerplaylist.cpp  
 M  +46 -1     kmplayerprocess.cpp  
 M  +5 -0      kmplayerprocess.h  
 M  +7 -15     mediaobject.cpp  
 M  +2 -3      mediaobject.h  


--- trunk/extragear/multimedia/kmplayer/src/kmplayer_smil.cpp #1258259:1258260
@@ -3406,25 +3406,19 @@
     if (region_node)
         convertNode <SMIL::RegionBase> (region_node)->repaint ();
     transition.finish (this);
-    if (unfinished ())
-        finish ();
     runtime->init ();
     Mrl::deactivate ();
     (void) surface ();
     region_node = 0L;
-    if (media_info) {
-        delete media_info;
-        media_info = NULL;
-    }
     postpone_lock = 0L;
 }
 
 KDE_NO_EXPORT void SMIL::MediaType::defer () {
     if (media_info) {
         //media_info->pause ();
+        setState (state_deferred);
         if (unfinished ())
             postpone_lock = document ()->postpone ();
-        setState (state_deferred);
     }
 }
 
--- trunk/extragear/multimedia/kmplayer/src/kmplayerplaylist.cpp #1258259:1258260
@@ -790,8 +790,9 @@
                 !isPlayable () && firstChild ()) {//if backend added child links
             state = state_activated;
             firstChild ()->activate ();
-        } else
+        } else if (unfinished ()) {
             finish ();
+        }
         break;
 
     default:
--- trunk/extragear/multimedia/kmplayer/src/kmplayerprocess.cpp #1258259:1258260
@@ -223,6 +223,9 @@
 void Process::pause () {
 }
 
+void Process::unpause () {
+}
+
 bool Process::seek (int /*pos*/, bool /*absolute*/) {
     return false;
 }
@@ -426,6 +429,16 @@
             this, SLOT (processStopped (int, QProcess::ExitStatus)));
 }
 
+bool MPlayerBase::removeQueued (const char *cmd) {
+    const QList<QByteArray>::iterator e = commands.end ();
+    for (QList<QByteArray>::iterator i = commands.begin (); i != e; ++i)
+        if (!strncmp ((*i).data (), cmd, strlen (cmd))) {
+            commands.erase (i);
+            return true;
+        }
+    return false;
+}
+
 KDE_NO_EXPORT bool MPlayerBase::sendCommand (const QString & cmd) {
     if (running ()) {
         commands.push_front (QString (cmd + '\n').toAscii ());
@@ -497,6 +510,7 @@
 MPlayer::MPlayer (QObject *parent, ProcessInfo *pinfo, Settings *settings)
  : MPlayerBase (parent, pinfo, settings, "mplayer"),
    m_widget (0L),
+   m_transition_state (NotRunning),
    aid (-1), sid (-1)
 {}
 
@@ -518,6 +532,8 @@
 KDE_NO_EXPORT bool MPlayer::deMediafiedPlay () {
     if (running ())
         return sendCommand (QString ("gui_play"));
+
+    m_transition_state = NotRunning;
     if (!m_needs_restarted && running ())
         quit (); // rescheduling of setState will reset state just-in-time
 
@@ -655,9 +671,23 @@
 }
 
 KDE_NO_EXPORT void MPlayer::pause () {
+    if (Paused != m_transition_state) {
+        m_transition_state = Paused;
+        if (!removeQueued ("pause"))
     sendCommand (QString ("pause"));
 }
+}
 
+KDE_NO_EXPORT void MPlayer::unpause () {
+    if (m_transition_state == Paused
+            || (Paused == m_state
+                && m_transition_state != Playing)) {
+        m_transition_state = Playing;
+        if (!removeQueued ("pause"))
+            sendCommand (QString ("pause"));
+    }
+}
+
 KDE_NO_EXPORT bool MPlayer::seek (int pos, bool absolute) {
     if (!m_source || !m_source->hasLength () ||
             (absolute && m_source->position () == pos))
@@ -790,10 +820,16 @@
         if (process_stats) {
             QRegExp & m_posRegExp = patterns[MPlayerPreferencesPage::pat_pos];
             QRegExp & m_cacheRegExp = patterns[MPlayerPreferencesPage::pat_cache];
-            if (m_source->hasLength () && m_posRegExp.search (out) > -1) {
+            if (m_posRegExp.search (out) > -1) {
+                if (m_source->hasLength ()) {
                 int pos = int (10.0 * m_posRegExp.cap (1).toFloat ());
                 m_source->setPosition (pos);
                 m_request_seek = -1;
+                }
+                if (Playing == m_transition_state) {
+                    m_transition_state = NotRunning;
+                    setState (Playing);
+                }
             } else if (m_cacheRegExp.search (out) > -1) {
                 m_source->setLoading (int (m_cacheRegExp.cap(1).toDouble()));
             }
@@ -805,6 +841,11 @@
                     m_source->setLength (mrl (), 10 * l);
                 }
             }
+        } else if (out.startsWith ("ID_PAUSED")) {
+            if (Paused == m_transition_state) {
+                m_transition_state = NotRunning;
+                setState (Paused);
+            }
         } else if (m_refURLRegExp.search(out) > -1) {
             kDebug () << "Reference mrl " << m_refURLRegExp.cap (1);
             if (!m_tmpURL.isEmpty () &&
@@ -1367,6 +1408,10 @@
     }
 }
 
+void MasterProcess::unpause () {
+    pause ();
+}
+
 bool MasterProcess::seek (int pos, bool) {
     if (IProcess::Playing == m_state) {
         MasterProcessInfo *mpi = static_cast<MasterProcessInfo *>(process_info);
--- trunk/extragear/multimedia/kmplayer/src/kmplayerprocess.h #1258259:1258260
@@ -88,6 +88,7 @@
     virtual void stop ();
     virtual void quit ();
     virtual void pause ();
+    virtual void unpause ();
     /* seek (pos, abs) seek position in deci-seconds */
     virtual bool seek (int pos, bool absolute);
     /* volume from 0 to 100 */
@@ -132,6 +133,7 @@
     virtual void quit ();
 protected:
     bool sendCommand (const QString &);
+    bool removeQueued (const char *cmd);
     QList<QByteArray> commands;
     bool m_needs_restarted;
 protected slots:
@@ -163,6 +165,7 @@
     virtual bool deMediafiedPlay ();
     virtual void stop ();
     virtual void pause ();
+    virtual void unpause ();
     virtual bool seek (int pos, bool absolute);
     virtual void volume (int pos, bool absolute);
     virtual bool saturation (int pos, bool absolute);
@@ -184,6 +187,7 @@
     WeakPtr <Source::LangInfo> alanglist_end;
     Source::LangInfoPtr slanglist;
     WeakPtr <Source::LangInfo> slanglist_end;
+    State m_transition_state;
     int aid, sid;
     int old_volume;
 };
@@ -314,6 +318,7 @@
     void playing ();
     void progress (uint64_t pos);
     void pause ();
+    void unpause ();
     bool seek (int pos, bool absolute);
     void volume (int pos, bool absolute);
     void eof ();
--- trunk/extragear/multimedia/kmplayer/src/mediaobject.cpp #1258259:1258260
@@ -168,7 +168,7 @@
 }
 
 static const QString statemap [] = {
-    i18n ("Not Running"), i18n ("Ready"), i18n ("Buffering"), i18n ("Playing")
+    i18n ("Not Running"), i18n ("Ready"), i18n ("Buffering"), i18n ("Playing"),  i18n ("Paused")
 };
 
 void MediaManager::stateChange (AudioVideoMedia *media,
@@ -193,11 +193,8 @@
     m_player->updateStatus (i18n ("Player %1 %2",
                 media->process->process_info->name, statemap[news]));
     if (IProcess::Playing == news) {
-        if (Element::state_deferred == mrl->state) {
-            media->ignore_pause = true;
+        if (Element::state_deferred == mrl->state)
             mrl->undefer ();
-            media->ignore_pause = false;
-        }
         bool has_video = !is_rec;
         if (is_rec) {
             const ProcessList::iterator i = m_recorders.find (media->process);
@@ -251,9 +248,7 @@
         if (AudioVideoMedia::ask_pause == media->request) {
             media->pause ();
         } else if (mrl->view_mode != Mrl::SingleMode) {
-            media->ignore_pause = true;
             mrl->defer (); // paused the SMIL
-            media->ignore_pause = false;
         }
     }
 }
@@ -289,7 +284,7 @@
 //------------------------%<----------------------------------------------------
 
 MediaObject::MediaObject (MediaManager *manager, Node *node)
- : m_manager (manager), m_node (node), paused (false) {
+ : m_manager (manager), m_node (node) {
     manager->medias ().push_back (this);
 }
 
@@ -851,8 +846,7 @@
  : MediaObject (manager, node),
    process (NULL),
    m_viewer (NULL),
-   request (ask_nothing),
-   ignore_pause (false) {
+   request (ask_nothing) {
     kDebug() << "AudioVideoMedia::AudioVideoMedia" << endl;
 }
 
@@ -914,9 +908,8 @@
 }
 
 void AudioVideoMedia::pause () {
-    if (!ignore_pause && !paused && process) {
+    if (process) {
         if (process->state () > IProcess::Ready) {
-            paused = true;
             request = ask_nothing;
             process->pause ();
         } else {
@@ -926,12 +919,11 @@
 }
 
 void AudioVideoMedia::unpause () {
-    if (!ignore_pause && paused && process) {
+    if (process) {
         if (request == ask_pause) {
             request = ask_nothing;
         } else {
-            paused = false;
-            process->pause ();
+            process->unpause ();
         }
     }
 }
--- trunk/extragear/multimedia/kmplayer/src/mediaobject.h #1258259:1258260
@@ -58,13 +58,14 @@
 
 class KMPLAYER_EXPORT IProcess {
 public:
-    enum State { NotRunning = 0, Ready, Buffering, Playing };
+    enum State { NotRunning = 0, Ready, Buffering, Playing, Paused };
 
     virtual ~IProcess () {}
 
     virtual bool ready () = 0;
     virtual bool play () = 0;
     virtual void pause () = 0;
+    virtual void unpause () = 0;
     virtual bool grabPicture (const QString &file, int frame) = 0;
     virtual void stop () = 0;
     virtual void quit () = 0;
@@ -203,7 +204,6 @@
 
     MediaManager *m_manager;
     NodePtrW m_node;
-    bool paused;
 };
 
 //------------------------%<----------------------------------------------------
@@ -309,7 +309,6 @@
     QString m_grab_file;
     int m_frame;
     Request request;
-    bool ignore_pause;
 
 protected:
     ~AudioVideoMedia ();
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic