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

tahn at svn.annodex.net tahn at svn.annodex.net
Tue Jun 26 01:18:08 PDT 2007


Author: tahn
Date: 2007-06-26 01:18:08 -0700 (Tue, 26 Jun 2007)
New Revision: 3056

Modified:
   liboggplay/trunk/plugin/plugin.cpp
   liboggplay/trunk/plugin/plugin_gui_mac.c
   liboggplay/trunk/plugin/plugin_oggplay.c
   liboggplay/trunk/plugin/plugin_oggplay.h
Log:
Implemented seeking in the plugin.


Modified: liboggplay/trunk/plugin/plugin.cpp
===================================================================
--- liboggplay/trunk/plugin/plugin.cpp	2007-06-26 08:09:34 UTC (rev 3055)
+++ liboggplay/trunk/plugin/plugin.cpp	2007-06-26 08:18:08 UTC (rev 3056)
@@ -640,8 +640,7 @@
 
 bool
 nsPluginInstance::setPlayPosition(long milliseconds) {
-//!todo
-  return TRUE;
+  return set_oggplay_play_position(mOggHandle, milliseconds);
 }
 
 long
@@ -824,7 +823,6 @@
   if (mPlaylistCallback != NULL) {
     NS_ADDREF(mPlaylistCallback);
   }
-mPlaylistCallback->Call();//!#
   SEM_SIGNAL(mPlaylistSem);
 }
 

Modified: liboggplay/trunk/plugin/plugin_gui_mac.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_mac.c	2007-06-26 08:09:34 UTC (rev 3055)
+++ liboggplay/trunk/plugin/plugin_gui_mac.c	2007-06-26 08:18:08 UTC (rev 3056)
@@ -420,6 +420,17 @@
     }
 
     /*
+     * If the user seeks in the oggplay stream, we need to flush the audio
+     * buffers.
+     */
+    switch (get_oggplay_stream_info(info->oggplay_handle, &td.frame_data)) {
+      case OGGPLAY_STREAM_JUST_SEEKED:
+        shutdown_audio(info, &td);
+        playback_target = 0;
+        break;
+    }
+
+    /*
      * Notify the plugin class that we've got some CMML data.
      */
     if (td.frame_data.cmml_strings != NULL) {
@@ -434,7 +445,9 @@
     bool have_video = (td.frame_data.video_data != NULL);
     bool have_audio = (td.frame_data.samples != NULL && td.frame_data.size > 0);
     if (!have_video && !have_audio) {
-      free_oggplay_frame(info->oggplay_handle, &td.frame_data);
+      if (!paused) {
+        free_oggplay_frame(info->oggplay_handle, &td.frame_data);
+      }
       oggplay_millisleep(5);
       continue;
     }

Modified: liboggplay/trunk/plugin/plugin_oggplay.c
===================================================================
--- liboggplay/trunk/plugin/plugin_oggplay.c	2007-06-26 08:09:34 UTC (rev 3055)
+++ liboggplay/trunk/plugin/plugin_oggplay.c	2007-06-26 08:18:08 UTC (rev 3056)
@@ -59,22 +59,26 @@
 #include <math.h>
 
 typedef struct {
-  OggPlay     * player;
-  int           shutdown_oggplay;
-  char        * location;
-  semaphore     start_stop_sem;
-  long          last_displayed_frame_time;
+  OggPlay         * player;
+  int               shutdown_oggplay;
+  char            * location;
+  int               seek_flag;
+  long              seek_pos;
+  OggPlayErrorCode  seek_err;
+  semaphore         seek_sem;
+  semaphore         start_stop_sem;
+  long              last_displayed_frame_time;
 #if defined(XP_UX)
-  pthread_t     thread;
+  pthread_t         thread;
 #elif defined(XP_WIN)
-  HANDLE        thread;
+  HANDLE            thread;
 #elif defined(XP_MACOSX)
-  pthread_t     thread;
+  pthread_t         thread;
 #endif
-  int           audio_rate;
-  int           video_rate;
-  int           audio_channels;
-  int           callback_period;
+  int               audio_rate;
+  int               video_rate;
+  int               audio_channels;
+  int               callback_period;
 } PluginPointers;
 
 int get_audio_rate(void *ptrs) {
@@ -208,6 +212,14 @@
       if (pointers->shutdown_oggplay) {
         goto thread_shutdown;
       }
+
+      if (pointers->seek_flag) {
+        SEM_WAIT(pointers->seek_sem);
+        pointers->seek_err = oggplay_seek(pointers->player, pointers->seek_pos);
+        pointers->seek_flag = 0;
+        SEM_SIGNAL(pointers->seek_sem);
+      }
+
       r = oggplay_step_decoding(pointers->player);
     }
 
@@ -255,6 +267,11 @@
   pointers->audio_channels = 0;
   pointers->callback_period = 0;
 
+  pointers->seek_flag = 0;
+  pointers->seek_pos = 0;
+  pointers->seek_err = E_OGGPLAY_OK;
+  SEM_CREATE(pointers->seek_sem, 1);
+
   SEM_CREATE(pointers->start_stop_sem, 1);
   SEM_WAIT(pointers->start_stop_sem);
   
@@ -288,6 +305,8 @@
   SEM_WAIT(pointers->start_stop_sem);
   SEM_CLOSE(pointers->start_stop_sem);
 
+  SEM_CLOSE(pointers->seek_sem);
+
   free(pointers->location);
   free(pointers);
  
@@ -463,6 +482,33 @@
 }
 
 
+OggPlayStreamInfo
+get_oggplay_stream_info(void *handle, PluginOggFrame *frame_data) {
+
+  PluginPointers        * pointers = (PluginPointers *)handle;
+  OggPlayCallbackInfo  ** track_info = frame_data->oggplay_info;
+  OggPlayDataType         data_type;
+  int                     i;
+
+  if (track_info == NULL) {
+    return E_OGGPLAY_BAD_CALLBACK_INFO;
+  }
+
+  /*
+   * Use the video track if it's present, otherwise use audio.
+   */
+  data_type =
+    (pointers->video_rate > 0) ? OGGPLAY_YUV_VIDEO : OGGPLAY_FLOATS_AUDIO;
+
+  for (i = 0; i < oggplay_get_num_tracks(pointers->player); i++) {
+    if (oggplay_callback_info_get_type(track_info[i]) == data_type) {
+      return oggplay_callback_info_get_stream_info(track_info[i]);
+    }
+  }
+  return E_OGGPLAY_BAD_CALLBACK_INFO;
+}
+
+
 /**
  * Scripting, dude, ... scripting
  */
@@ -471,5 +517,22 @@
 
   PluginPointers *pointers = (PluginPointers *)handle;
   return pointers->last_displayed_frame_time;
-  
 }
+
+bool
+set_oggplay_play_position(void *handle, long milliseconds) {
+
+  PluginPointers *pointers = (PluginPointers *)handle;
+  SEM_WAIT(pointers->seek_sem);
+  pointers->seek_pos = milliseconds;
+  pointers->seek_flag = 1;
+  SEM_SIGNAL(pointers->seek_sem);
+
+  while (pointers->seek_flag) {
+    if (pointers->shutdown_oggplay) {
+      return TRUE;
+    }
+    oggplay_millisleep(1);
+  }
+  return (pointers->seek_err == E_OGGPLAY_OK);
+}

Modified: liboggplay/trunk/plugin/plugin_oggplay.h
===================================================================
--- liboggplay/trunk/plugin/plugin_oggplay.h	2007-06-26 08:09:34 UTC (rev 3055)
+++ liboggplay/trunk/plugin/plugin_oggplay.h	2007-06-26 08:18:08 UTC (rev 3056)
@@ -34,6 +34,8 @@
 #ifndef _PLUGIN_OGGPLAY_H
 #define _PLUGIN_OGGPLAY_H
 
+#include <oggplay/oggplay_enums.h>
+
 typedef enum {
   E_OK          = 0,
   E_BAD_MEDIA   = -1
@@ -77,13 +79,16 @@
 void
 free_oggplay_frame(void *handle, PluginOggFrame* frame_data);
 
+OggPlayStreamInfo
+get_oggplay_stream_info(void *handle, PluginOggFrame *frame_data);
+
 // scripting implementation
-void
-pause_oggplay();
-
 long
 get_oggplay_play_position(void *handle);
 
+bool
+set_oggplay_play_position(void *handle, long milliseconds);
+
 int get_audio_rate(void *ptrs);
 int get_audio_channels(void *ptrs);
 int get_video_rate(void *ptrs);



More information about the commits mailing list