[xiph-commits] r3038 - in liboggplay/trunk/plugin: . support

tahn at svn.annodex.net tahn at svn.annodex.net
Sun Jun 24 19:44:02 PDT 2007


Author: tahn
Date: 2007-06-24 19:44:02 -0700 (Sun, 24 Jun 2007)
New Revision: 3038

Modified:
   liboggplay/trunk/plugin/nsILibOggPlugin.idl
   liboggplay/trunk/plugin/plugin.cpp
   liboggplay/trunk/plugin/plugin.h
   liboggplay/trunk/plugin/support/nsScriptablePeer.cpp
Log:
Added playlist-related functions to the Javascript API.


Modified: liboggplay/trunk/plugin/nsILibOggPlugin.idl
===================================================================
--- liboggplay/trunk/plugin/nsILibOggPlugin.idl	2007-06-25 01:42:38 UTC (rev 3037)
+++ liboggplay/trunk/plugin/nsILibOggPlugin.idl	2007-06-25 02:44:02 UTC (rev 3038)
@@ -58,40 +58,37 @@
 
   string getVersionString();
 
-  /* basic playback functions */
+  /* standard playback functions */
   void play();
   void pause();
   void restart();
   short getCurrentState();
-
-  /* movie and position control */
   void setCurrentMovie(in string URL);
   string getCurrentMovie();
   boolean setPlayPosition(in long milliseconds);
   long getPlayPosition();
-
-  /* audio related */
   void setVolume(in float volume);
   float getVolume();
-
-  /* miscellaneous queries */
   long getWindowWidth();
   long getWindowHeight();
   long getBufferedTime();
   long getMovieLength();
-
-  /* CMML related */
   string retrieveAnnotations();
-
-  /* callbacks */
   void registerCMMLCallback(in nsILibOggCallbackString callback);
   void registerEndPlayCallback(in nsILibOggCallbackNoArg callback);
 
-  /* playlist related */
-/* //!todo
-  void registerPlaylistCallback(in string playlistCallback);
-  string getMovieAt(in short position);
-  void setMovieAt(in short position, in string url);
+  /* playlist functions */
+  void freezePlaylistProgression();
+  void unfreezePlaylistProgression();
+  long getPlaylistLength();
+  long getCurrentPlaylistPosition();
+  string getMovieAt(in long position);
+  boolean setMovieAt(in long position, in string url);
   void appendMovie(in string url);
-*/
+  boolean insertMovieBefore(in long position, in string url);
+  long getPlayPositionWithinMovie();
+  boolean setPlayPositionWithinMovie(in long milliseconds);
+  string retrieveAnnotationsAt(in long position);
+  long getMovieLengthAt(in long position);
+  void registerPlaylistCallback(in nsILibOggCallbackNoArg callback);
 };

Modified: liboggplay/trunk/plugin/plugin.cpp
===================================================================
--- liboggplay/trunk/plugin/plugin.cpp	2007-06-25 01:42:38 UTC (rev 3037)
+++ liboggplay/trunk/plugin/plugin.cpp	2007-06-25 02:44:02 UTC (rev 3038)
@@ -274,7 +274,6 @@
 #if defined(XP_MACOSX) || defined(XP_WIN)
   clearCmmlStrings();
 #endif
-
 }
 
 #if defined(XP_MACOSX) || defined (XP_WIN)
@@ -332,6 +331,13 @@
   return mPluginInitialised;
 }
 
+NPError
+nsPluginInstance::NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
+{
+  printf("URL %s for this Mime-Type %s\n", (char*)type, stream->url);
+  return NPERR_NO_ERROR;
+}
+
 NPError 
 nsPluginInstance::SetWindow(NPWindow *aWindow)
 {
@@ -370,16 +376,7 @@
   return NPERR_NO_ERROR;
 }
 
-
-NPError nsPluginInstance::NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
-{
-  printf("URL %s for this Mime-Type %s\n", (char*)type, stream->url);
-  return NPERR_NO_ERROR;
-}
-
-/*
- * Event handling - this is for the GUI
- */
+// Event handling for the GUI
 uint16 
 nsPluginInstance::HandleEvent(void *aEvent)
 {  
@@ -424,6 +421,37 @@
   return 1;
 }
 
+#if defined(XP_WIN)
+VOID CALLBACK
+PluginCallbackProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {    
+  nsPluginInstance * plugin = NULL;
+  
+  plugin = (nsPluginInstance *)GetWindowLongPtr(hWnd, GWL_USERDATA);  
+  plugin->executeCmmlCallback();
+}
+#endif
+
+#if defined (XP_MACOSX) || defined(XP_WIN)
+void 
+nsPluginInstance::executeCmmlCallback() {
+  // Since this function is called very frequently, we don't want to grab
+  // the semaphore every time, but checking the pointer for null before locking
+  // introduces a potential race condition, so we need to double-check.
+  if (mCmmlCallback != NULL) {    
+    SEM_WAIT(mCmmlSem);
+    if (mCmmlCallback != NULL && mCmmlStrings.size() > 0) {
+      for (unsigned int i = 0; i < mCmmlStrings.size(); i++) {
+        //printf("Sending CMML to Javascript: %s\n", mCmmlStrings[i]);
+        mCmmlCallback->Call(mCmmlStrings[i]);
+      }
+      clearCmmlStrings();
+    }    
+    SEM_SIGNAL(mCmmlSem);
+  }  
+}
+#endif
+
+
 // ==============================
 // ! Scriptability related code !
 // ==============================
@@ -495,9 +523,10 @@
   return mScriptablePeer;
 }
 
+
 ////////////////////////////////////////
 //
-// Javascript API implementation
+// Javascript API - standard playback
 //
 void
 nsPluginInstance::getVersionString(
@@ -613,7 +642,97 @@
   return annotations;
 }
 
+////////////////////////////////////////
+//
+// Javascript API - playlist functions
+//
 void
+nsPluginInstance::freezePlaylistProgression() {
+//!todo
+}
+
+void
+nsPluginInstance::unfreezePlaylistProgression() {
+//!todo
+}
+
+long
+nsPluginInstance::getPlaylistLength() {
+//!todo
+  return 0;
+}
+
+long
+nsPluginInstance::getCurrentPlaylistPosition() {
+//!todo
+  return 0;
+}
+
+char *
+nsPluginInstance::getMovieAt(long position) {
+//!todo - remove bad pun
+  char *movie = NULL;
+
+  movie = (char *)NPN_MemAlloc(100);
+  if (movie != NULL) {
+    strcpy(movie, "nothing to see here, movie along");
+  }
+  return movie;
+}
+
+bool
+nsPluginInstance::setMovieAt(long position, const char *url) {
+//!todo
+  return TRUE;
+}
+
+void
+nsPluginInstance::appendMovie(const char *url) {
+//!todo
+  return;
+}
+
+bool
+nsPluginInstance::insertMovieBefore(long position, const char *url) {
+//!todo
+  return TRUE;
+}
+
+long
+nsPluginInstance::getPlayPositionWithinMovie() {
+//!todo
+  return 0;
+}
+
+bool
+nsPluginInstance::setPlayPositionWithinMovie(long milliseconds) {
+//!todo
+  return TRUE;
+}
+
+char *
+nsPluginInstance::retrieveAnnotationsAt(long position) {
+//!todo
+  char *annotations = NULL;
+
+  annotations = (char *)NPN_MemAlloc(100);
+  if (annotations != NULL) {
+    strcpy(annotations, "annotations ftw");
+  }
+  return annotations;
+}
+
+long
+nsPluginInstance::getMovieLengthAt(long position) {
+//!todo
+  return 0;
+}
+
+////////////////////////////////////////
+//
+// Javascript API - callback handling
+//
+void
 nsPluginInstance::registerCMMLCallback(nsILibOggCallbackString *cbObj) {
   SEM_WAIT(mCmmlSem);
   if (mCmmlCallback != NULL) {
@@ -623,7 +742,7 @@
   if (mCmmlCallback != NULL) {
     NS_ADDREF(mCmmlCallback);
   }
-#if defined(XP_MACOSX)
+#if defined(XP_MACOSX) || defined(XP_WIN)
   if (mCmmlCallback == NULL) {
     clearCmmlStrings();
   }
@@ -645,22 +764,37 @@
 }
 
 void
+nsPluginInstance::registerPlaylistCallback(nsILibOggCallbackNoArg *cbObj) {
+  SEM_WAIT(mPlaylistSem);
+  if (mPlaylistCallback != NULL) {
+    NS_RELEASE(mPlaylistCallback);
+  }
+  mPlaylistCallback = cbObj;
+  if (mPlaylistCallback != NULL) {
+    NS_ADDREF(mPlaylistCallback);
+  }
+mPlaylistCallback->Call();//!#
+  SEM_SIGNAL(mPlaylistSem);
+}
+
+void
 nsPluginInstance::onCMMLData(char **cmml_data, int cmml_size) {
   SEM_WAIT(mCmmlSem);
   if (mCmmlCallback != NULL) {
-#if defined(XP_MACOSX) || (XP_WIN)   
-    // The Mac and Windows don't like cross-thread calls between the GUI thread and
-    // the plugin/browser thread. We need to execute the cmml callback in the main browser
-    // thread, but this function is called from the GUI display thread. So we
-    // buffer up the cmml strings here.
+#if defined(XP_MACOSX) || defined(XP_WIN)   
+    // The Mac and Windows don't like cross-thread calls between the GUI thread
+    // and the plugin/browser thread. We need to execute the cmml callback in
+    // the main browser thread, but this function is called from the GUI
+    // display thread. So we buffer up the cmml strings here.
     // [MACOSX]
-    //   On Mac we piggyback on the browser-originated calls to HandleEvent to send the strings 
-    //   to the browser. 
+    //   On Mac we piggyback on the browser-originated calls to HandleEvent
+    //    to send the strings to the browser. 
     // [Win32]
-    //   On Windows we use a timer introduced to provide an artificial heartbeat 
-    //   similar to ongoing event processing on Mac.    
-    // We need to make copies of the strings because the oggplay frame can be freed before we
-    // get in to HandleEvent (Mac) or timer handler funtion (Win32).
+    //   On Windows we use a timer introduced to provide an artificial
+    //   heartbeat similar to ongoing event processing on Mac.
+    // We need to make copies of the strings because the oggplay frame can be
+    // freed before we get in to HandleEvent (Mac) or timer handler funtion
+    // (Win32).
     for (int i = 0; i < cmml_size; i++) {      
       mCmmlStrings.push_back(strdup(cmml_data[i]));
     }
@@ -674,7 +808,7 @@
 }
 
 void
-nsPluginInstance::onEndPlay() {
+nsPluginInstance::onEndOfPlay() {
   SEM_WAIT(mEndPlaySem);
   if (mEndPlayCallback != NULL) {
     mEndPlayCallback->Call();
@@ -682,36 +816,16 @@
   SEM_SIGNAL(mEndPlaySem);
 }
 
-#if defined (XP_MACOSX) || defined(XP_WIN)
-void 
-nsPluginInstance::executeCmmlCallback() {
-  // (since this function is called very frequently, we don't want to grab
-  // the semaphore every time, but checking the pointer for null before locking
-  // introduces a potential race condition, so we need to double-check).  
-  if (mCmmlCallback != NULL) {    
-    SEM_WAIT(mCmmlSem);
-    if (mCmmlCallback != NULL && mCmmlStrings.size() > 0) {
-      for (unsigned int i = 0; i < mCmmlStrings.size(); i++) {
-        //printf("Sending CMML to Javascript: %s\n", mCmmlStrings[i]);
-        mCmmlCallback->Call(mCmmlStrings[i]);
-      }
-      clearCmmlStrings();
-    }    
-    SEM_SIGNAL(mCmmlSem);
-  }  
+void
+nsPluginInstance::onPlaylistTrackChanged() {
+  SEM_WAIT(mPlaylistSem);
+  if (mPlaylistCallback != NULL) {
+    mPlaylistCallback->Call();
+  }
+  SEM_SIGNAL(mPlaylistSem);
 }
-#endif
 
-#if defined(XP_WIN)
-VOID CALLBACK
-PluginCallbackProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {    
-  nsPluginInstance * plugin = NULL;
-  
-  plugin = (nsPluginInstance *)GetWindowLongPtr(hWnd, GWL_USERDATA);  
-  plugin->executeCmmlCallback();
-}
-#endif
-
+// C hooks for the callback notification functions
 extern "C" {
 void
 onCMMLData(nsPluginInstance *i, char **cmml_data, int cmml_size) {  
@@ -719,30 +833,13 @@
 }
 
 void
-onEndPlay(nsPluginInstance *i) {
-  i->onEndPlay();
+onEndOfPlay(nsPluginInstance *i) {
+  i->onEndOfPlay();
 }
 
-} // extern "C"
-
-
-
-
-/* //!todo
 void
-nsPluginInstance::setPlaylistCallback(const char *callback) {
+onPlaylistTrackChanged(nsPluginInstance *i) {
+  i->onPlaylistTrackChanged();
 }
+} // extern "C"
 
-char*
-nsPluginInstance::getMovieAt(int position) {
-  return NULL;
-}
-
-void
-nsPluginInstance::setMovieAt(int position, const char *url) {
-}
-
-void
-nsPluginInstance::appendMovie(const char *url) {
-}
-*/

Modified: liboggplay/trunk/plugin/plugin.h
===================================================================
--- liboggplay/trunk/plugin/plugin.h	2007-06-25 01:42:38 UTC (rev 3037)
+++ liboggplay/trunk/plugin/plugin.h	2007-06-25 02:44:02 UTC (rev 3038)
@@ -106,18 +106,26 @@
   long    getMovieLength();
   char  * retrieveAnnotations();
 
+  void    freezePlaylistProgression();
+  void    unfreezePlaylistProgression();
+  long    getPlaylistLength();
+  long    getCurrentPlaylistPosition();
+  char  * getMovieAt(long position);
+  bool    setMovieAt(long position, const char *url);
+  void    appendMovie(const char *url);
+  bool    insertMovieBefore(long position, const char *url);
+  long    getPlayPositionWithinMovie();
+  bool    setPlayPositionWithinMovie(long milliseconds);
+  char  * retrieveAnnotationsAt(long position);
+  long    getMovieLengthAt(long position);
+
   void    registerCMMLCallback(nsILibOggCallbackString *cbObj);
   void    registerEndPlayCallback(nsILibOggCallbackNoArg *cbObj);
+  void    registerPlaylistCallback(nsILibOggCallbackNoArg *cbObj);
   void    onCMMLData(char **cmml_data, int cmml_size);
-  void    onEndPlay();
+  void    onEndOfPlay();
+  void    onPlaylistTrackChanged();
 
-/* //!todo
-  void setPlaylistCallback(const char *callback);
-  char *getMovieAt(int position);
-  void setMovieAt(int position, const char *url);
-  void appendMovie(const char *url); 
-*/
- 
 private:
   void    setSource(const char *source);
   char  * getSource();
@@ -133,8 +141,10 @@
 
   nsILibOggCallbackString   * mCmmlCallback;
   nsILibOggCallbackNoArg    * mEndPlayCallback;
+  nsILibOggCallbackNoArg    * mPlaylistCallback;
   semaphore                   mCmmlSem;
   semaphore                   mEndPlaySem;
+  semaphore                   mPlaylistSem;
 
 #if defined(XP_WIN)
   WNDPROC             lpOldProc;

Modified: liboggplay/trunk/plugin/support/nsScriptablePeer.cpp
===================================================================
--- liboggplay/trunk/plugin/support/nsScriptablePeer.cpp	2007-06-25 01:42:38 UTC (rev 3037)
+++ liboggplay/trunk/plugin/support/nsScriptablePeer.cpp	2007-06-25 02:44:02 UTC (rev 3038)
@@ -150,31 +150,27 @@
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::SetCurrentMovie(const char *URL) 
-{
+NS_IMETHODIMP nsScriptablePeer::SetCurrentMovie(const char *URL) {
   if (mPlugin)
     mPlugin->setCurrentMovie(URL);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::GetCurrentMovie(char **URL) 
-{  
+NS_IMETHODIMP nsScriptablePeer::GetCurrentMovie(char **URL) {  
   *URL = NULL;
   if (mPlugin)
     *URL = mPlugin->getCurrentMovie();
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::SetPlayPosition(PRInt32 milliseconds, PRBool *_retval)
-{
+NS_IMETHODIMP nsScriptablePeer::SetPlayPosition(PRInt32 milliseconds, PRBool *_retval) {
   *_retval = FALSE;
   if (mPlugin)
     *_retval = mPlugin->setPlayPosition(milliseconds);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::GetPlayPosition(PRInt32 *_retval)
-{
+NS_IMETHODIMP nsScriptablePeer::GetPlayPosition(PRInt32 *_retval) {
   *_retval = -1;
   if (mPlugin)
     *_retval = mPlugin->getPlayPosition();
@@ -229,37 +225,55 @@
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::RegisterCMMLCallback(nsILibOggCallbackString *cbObj)
-{
+NS_IMETHODIMP nsScriptablePeer::RegisterCMMLCallback(nsILibOggCallbackString *cbObj) {
   if (mPlugin)
     mPlugin->registerCMMLCallback(cbObj);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::RegisterEndPlayCallback(nsILibOggCallbackNoArg *cbObj)
-{
+NS_IMETHODIMP nsScriptablePeer::RegisterEndPlayCallback(nsILibOggCallbackNoArg *cbObj) {
   if (mPlugin)
     mPlugin->registerEndPlayCallback(cbObj);
   return NS_OK;
 }
 
-/* //!todo
-NS_IMETHODIMP nsScriptablePeer::RegisterPlaylistCallback(const char *playlistCallback) {
+NS_IMETHODIMP nsScriptablePeer::FreezePlaylistProgression(void) {
   if (mPlugin)
-    mPlugin->setPlaylistCallback(playlistCallback);
+    mPlugin->freezePlaylistProgression();
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::GetMovieAt(PRInt16 position, char **_retval) {
+NS_IMETHODIMP nsScriptablePeer::UnfreezePlaylistProgression(void) {
+  if (mPlugin)
+    mPlugin->unfreezePlaylistProgression();
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::GetPlaylistLength(PRInt32 *_retval) {
+  *_retval = -1;
+  if (mPlugin)
+    *_retval = mPlugin->getPlaylistLength();
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::GetCurrentPlaylistPosition(PRInt32 *_retval) {
+  *_retval = -1;
+  if (mPlugin)
+    *_retval = mPlugin->getCurrentPlaylistPosition();
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::GetMovieAt(PRInt32 position, char **_retval) {
   *_retval = NULL;
   if (mPlugin)
     *_retval = mPlugin->getMovieAt(position);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptablePeer::SetMovieAt(PRInt16 position, const char *url) {
+NS_IMETHODIMP nsScriptablePeer::SetMovieAt(PRInt32 position, const char *url, PRBool *_retval) {
+  *_retval = FALSE;
   if (mPlugin)
-    mPlugin->setMovieAt(position, url);
+    *_retval = mPlugin->setMovieAt(position, url);
   return NS_OK;
 }
 
@@ -268,4 +282,44 @@
     mPlugin->appendMovie(url);
   return NS_OK;
 }
-*/
+
+NS_IMETHODIMP nsScriptablePeer::InsertMovieBefore(PRInt32 position, const char *url, PRBool *_retval) {
+  *_retval = FALSE;
+  if (mPlugin)
+    *_retval = mPlugin->insertMovieBefore(position, url);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::GetPlayPositionWithinMovie(PRInt32 *_retval) {
+  *_retval = -1;
+  if (mPlugin)
+    *_retval = mPlugin->getPlayPositionWithinMovie();
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::SetPlayPositionWithinMovie(PRInt32 milliseconds, PRBool *_retval) {
+  *_retval = FALSE;
+  if (mPlugin)
+    *_retval = mPlugin->setPlayPositionWithinMovie(milliseconds);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::RetrieveAnnotationsAt(PRInt32 position, char **_retval) {
+  *_retval = NULL;
+  if (mPlugin)
+    *_retval = mPlugin->retrieveAnnotationsAt(position);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::GetMovieLengthAt(PRInt32 position, PRInt32 *_retval) {
+  *_retval = -1;
+  if (mPlugin)
+    *_retval = mPlugin->getMovieLengthAt(position);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::RegisterPlaylistCallback(nsILibOggCallbackNoArg *cbObj) {
+  if (mPlugin)
+    mPlugin->registerPlaylistCallback(cbObj);
+  return NS_OK;
+}



More information about the commits mailing list