[xiph-commits] r3131 - liboggplay/trunk/plugin

tahn at svn.annodex.net tahn at svn.annodex.net
Thu Jun 28 17:26:05 PDT 2007


Author: tahn
Date: 2007-06-28 17:26:05 -0700 (Thu, 28 Jun 2007)
New Revision: 3131

Modified:
   liboggplay/trunk/plugin/plugin.cpp
   liboggplay/trunk/plugin/plugin.h
Log:
Implemented playlist progression freezing. Some tidying up.


Modified: liboggplay/trunk/plugin/plugin.cpp
===================================================================
--- liboggplay/trunk/plugin/plugin.cpp	2007-06-29 00:18:28 UTC (rev 3130)
+++ liboggplay/trunk/plugin/plugin.cpp	2007-06-29 00:26:05 UTC (rev 3131)
@@ -233,6 +233,8 @@
   mProxyHost(NULL),
   mProxyPort(80),
   mPlaylistPos(0),
+  mPlaylistFreeze(FALSE),
+  mPlaylistFrozen(FALSE),
   mReachedEndOfMovie(FALSE),
   mAsyncCmmlString(NULL),
   mCmmlCallback(NULL),
@@ -321,14 +323,6 @@
   SEM_CLOSE(mCrossThreadSem);
 }
 
-void
-nsPluginInstance::clearCmmlStrings() {
-  for (unsigned int i = 0; i < mCmmlStrings.size(); i++) {
-    free(mCmmlStrings[i]);
-  }
-  mCmmlStrings.clear();
-}
-
 NPBool 
 nsPluginInstance::init(NPWindow* aWindow)
 {  
@@ -353,7 +347,7 @@
 NPBool 
 nsPluginInstance::isInitialized()
 {
-  return mPluginInitialised;
+  return (NPBool)mPluginInitialised;
 }
 
 NPError
@@ -533,6 +527,14 @@
 //
 // Private helper functions
 //
+void
+nsPluginInstance::clearCmmlStrings() {
+  for (unsigned int i = 0; i < mCmmlStrings.size(); i++) {
+    free(mCmmlStrings[i]);
+  }
+  mCmmlStrings.clear();
+}
+
 char *
 nsPluginInstance::curMovie() const {
   return mPlaylist[mPlaylistPos];
@@ -543,6 +545,12 @@
   return (index >= 0 && index < (long)mPlaylist.size());
 }
 
+int
+nsPluginInstance::playlistLastIndex() const {
+  return (int)mPlaylist.size() - 1;
+}
+
+
 ////////////////////////////////////////
 //
 // Javascript API - standard playback
@@ -573,6 +581,7 @@
 void
 nsPluginInstance::restart() {
   if (curMovie() != NULL) {
+    mPlaylistFrozen = FALSE;
     mOggHandle = initialise_oggplay(curMovie(), mProxyHost, mProxyPort);
     update_gui_with_new_oggplay(mGuiHandle, mOggHandle);
     gui_play(mGuiHandle);
@@ -653,12 +662,16 @@
 //
 void
 nsPluginInstance::freezePlaylistProgression() {
-//!todo
+  mPlaylistFreeze = TRUE;
 }
 
 void
 nsPluginInstance::unfreezePlaylistProgression() {
-//!todo
+  mPlaylistFreeze = FALSE;
+  if (mPlaylistFrozen) {
+    mPlaylistPos++;
+    restart();
+  }
 }
 
 long
@@ -683,7 +696,7 @@
 
 bool
 nsPluginInstance::playlistNext() {
-  if (mPlaylistPos == (int)mPlaylist.size() - 1) {
+  if (mPlaylistPos == playlistLastIndex()) {
     return FALSE;
   }
   mPlaylistPos++;
@@ -723,6 +736,7 @@
   if (position == mPlaylistPos) {
     // We can just discard our reference to the old oggplay handle; the gui
     // code will destroy it before swapping over to the new one.
+    mPlaylistFrozen = FALSE;
     mOggHandle = initialise_oggplay(curMovie(), mProxyHost, mProxyPort);
     update_gui_with_new_oggplay(mGuiHandle, mOggHandle);
   }
@@ -751,14 +765,24 @@
   if (!playlistIndexOk(position) || mPlaylist.size() <= 1) {
     return FALSE;
   }
+
+  // If we're removing the current movie, we should start playing the next
+  // one in the playlist. If we're already at the last movie in the playlist,
+  // ideally we'd skip to the end of the previous one and stop playing, but
+  // that's too hard, so we'll just start playing the previous movie.
+  bool startNextMovie = (position == mPlaylistPos);
+
   free(mPlaylist[position]);
   mPlaylist.erase(mPlaylist.begin() + position);
-  // remember that mPlaylist.size() has been decremented now!
+
+  // Remember that mPlaylist.size() has been decremented now!
   if ((position < mPlaylistPos && mPlaylistPos > 0) ||
       (mPlaylistPos == (int)mPlaylist.size())) {
     mPlaylistPos--;
   }
-  //!todo - if this is current movie, need to progress to next...
+  if (startNextMovie) {
+    restart();
+  }
   return TRUE;
 }
 
@@ -911,7 +935,7 @@
 // This method must protected by mCrossThreadSem; if it's being called
 // from somewhere already thus protected, set useSemaphore to FALSE.
 void
-nsPluginInstance::processCrossThreadCalls(NPBool useSemaphore) {
+nsPluginInstance::processCrossThreadCalls(bool useSemaphore) {
   if (useSemaphore) {
     SEM_WAIT(mCrossThreadSem);
   }
@@ -944,7 +968,7 @@
     // If we've reached the end of playlist, just throw the end-play callback
     // and we're done. Otherwise, throw the playlist callback and advance to
     // the next movie.
-    if (mPlaylistPos == (int)mPlaylist.size() - 1) {
+    if (mPlaylistPos == playlistLastIndex()) {
       if (mEndPlayCallback != NULL) {
         mEndPlayCallback->Call();
       }
@@ -952,8 +976,16 @@
       if (mPlaylistCallback != NULL) {
         mPlaylistCallback->Call();
       }
-      mPlaylistPos++;
-      restart();
+
+      // Don't advance if the user has frozen playlist progression. This is
+      // handled by two separate flags, so the user can change to a different
+      // movie in the playlist and have that start playing, but still freeze
+      // again when it reaches the end.
+      mPlaylistFrozen = mPlaylistFreeze;
+      if (!mPlaylistFrozen) {
+        mPlaylistPos++;
+        restart();
+      }
     }
   }
 

Modified: liboggplay/trunk/plugin/plugin.h
===================================================================
--- liboggplay/trunk/plugin/plugin.h	2007-06-29 00:18:28 UTC (rev 3130)
+++ liboggplay/trunk/plugin/plugin.h	2007-06-29 00:26:05 UTC (rev 3131)
@@ -124,16 +124,17 @@
 
   // This is only public so the Windows "heartbeat" function can
   // access it. If you're not PluginCallbackProc, don't touch!
-  void    processCrossThreadCalls(NPBool useSemaphore);
+  void    processCrossThreadCalls(bool useSemaphore);
 
 private:
+  void    clearCmmlStrings();
   char  * curMovie() const;
   bool    playlistIndexOk(long index) const;
-  void    clearCmmlStrings();
+  int     playlistLastIndex() const;
 
   NPP                         mInstance;
-  NPBool                      mPluginInitialised;
-  NPBool                      mWindowInitialised;
+  bool                        mPluginInitialised;
+  bool                        mWindowInitialised;
   NPWindow                  * mWindow;
   nsScriptablePeer          * mScriptablePeer;
   void                      * mOggHandle;
@@ -143,7 +144,9 @@
   int                         mProxyPort;
   std::vector<char*>          mPlaylist;
   int                         mPlaylistPos;
-  NPBool                      mReachedEndOfMovie;
+  bool                        mPlaylistFreeze;
+  bool                        mPlaylistFrozen;
+  bool                        mReachedEndOfMovie;
   std::vector<char*>          mCmmlStrings;
   char                      * mAsyncCmmlString;
   nsILibOggCallbackString   * mCmmlCallback;
@@ -156,7 +159,7 @@
   bool                        mPollingStarted;
   UINT                        mPollingPeriod;  
 #elif defined(XP_MACOSX)
-  NPBool                      mOutputCleared;
+  bool                        mOutputCleared;
 #endif
 };
 



More information about the commits mailing list