[xiph-commits] r3031 - in liboggplay/trunk: include/oggplay plugin src/liboggplay src/tools

shans at svn.annodex.net shans at svn.annodex.net
Sun Jun 24 17:03:40 PDT 2007


Author: shans
Date: 2007-06-24 17:03:40 -0700 (Sun, 24 Jun 2007)
New Revision: 3031

Modified:
   liboggplay/trunk/include/oggplay/oggplay.h
   liboggplay/trunk/plugin/plugin_oggplay.c
   liboggplay/trunk/src/liboggplay/Version_script.in
   liboggplay/trunk/src/liboggplay/oggplay.c
   liboggplay/trunk/src/liboggplay/oggplay_buffer.c
   liboggplay/trunk/src/liboggplay/oggplay_private.h
   liboggplay/trunk/src/liboggplay/oggplay_seek.c
   liboggplay/trunk/src/tools/glut-player.c
Log:
Pulled semaphore out of plugin_oggplay.c, added oggplay_prepare_for_close 
function to allow semaphore to be safely released by non-decoding thread.



Modified: liboggplay/trunk/include/oggplay/oggplay.h
===================================================================
--- liboggplay/trunk/include/oggplay/oggplay.h	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/include/oggplay/oggplay.h	2007-06-25 00:03:40 UTC (rev 3031)
@@ -119,6 +119,9 @@
 OggPlayErrorCode
 oggplay_buffer_release(OggPlay *player, OggPlayCallbackInfo **track_info);
 
+void
+oggplay_prepare_for_close(OggPlay *me);
+
 OggPlayErrorCode
 oggplay_close(OggPlay *player);
 

Modified: liboggplay/trunk/plugin/plugin_oggplay.c
===================================================================
--- liboggplay/trunk/plugin/plugin_oggplay.c	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/plugin/plugin_oggplay.c	2007-06-25 00:03:40 UTC (rev 3031)
@@ -62,7 +62,6 @@
   OggPlay     * player;
   int           shutdown_oggplay;
   char        * location;
-  semaphore     sem;
   semaphore     start_stop_sem;
   long          last_displayed_frame_time;
 #if defined(XP_UX)
@@ -130,7 +129,6 @@
   }
   
   oggplay_use_buffer(player, LIBOGGPLAY_BUFFER_SIZE);
-  SEM_CREATE(pointers->sem, LIBOGGPLAY_BUFFER_SIZE);
   SEM_SIGNAL(pointers->start_stop_sem);
   
   /*
@@ -205,9 +203,6 @@
   while (1) {
     OggPlayErrorCode r;
 
-    SEM_WAIT(pointers->sem);
-    
-   
     r = E_OGGPLAY_TIMEOUT;
     while (r == E_OGGPLAY_TIMEOUT) {      
       if (pointers->shutdown_oggplay) {
@@ -232,7 +227,6 @@
 thread_shutdown:
   pointers->shutdown_oggplay = 0;
 
-  SEM_CLOSE(pointers->sem); 
   oggplay_close(pointers->player);
 
   SEM_SIGNAL(pointers->start_stop_sem);
@@ -281,17 +275,13 @@
   PluginPointers * pointers = (PluginPointers *)handle;
 
   pointers->shutdown_oggplay = 1;
-  
-  /*
-   * This is safe, because the decode loop always checks shutdown_oggplay
-   * immediately after waiting on the semaphore.  Hence, either it's already 
-   * doing something, in which case space is already available for the newly
-   * decoded frame, or it's waiting, in which case it won't get to decode a
-   * frame because shutdown_oggplay is set.
-   */  
-  SEM_SIGNAL(pointers->sem);
 
   /*
+   * tell oggplay it's about to be shutdown
+   */
+  oggplay_prepare_for_close(pointers->player);
+  
+  /*
    * wait for the oggplay object to shut itself down.
    */
   SEM_WAIT(pointers->start_stop_sem);
@@ -469,8 +459,6 @@
   oggplay_buffer_release(player,
     (OggPlayCallbackInfo **)(frame_data->oggplay_info));
 
-  SEM_SIGNAL(pointers->sem);
-  
 }
 
 

Modified: liboggplay/trunk/src/liboggplay/Version_script.in
===================================================================
--- liboggplay/trunk/src/liboggplay/Version_script.in	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/src/liboggplay/Version_script.in	2007-06-25 00:03:40 UTC (rev 3031)
@@ -13,6 +13,7 @@
                 oggplay_initialise;
                 oggplay_file_reader_new;
                 oggplay_tcp_reader_new;
+                oggplay_prepare_for_close;
                 oggplay_close;
                 
                 oggplay_get_num_tracks;

Modified: liboggplay/trunk/src/liboggplay/oggplay.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay.c	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/src/liboggplay/oggplay.c	2007-06-25 00:03:40 UTC (rev 3031)
@@ -66,6 +66,7 @@
   me->target = 0L;
   me->active_tracks = 0;
   me->buffer = NULL;  
+  me->shutdown = 0;
 
   return me;
 
@@ -476,6 +477,9 @@
   }
 
   me->target += me->callback_period;
+  if (me->shutdown) {
+    return E_OGGPLAY_OK;
+  }
   if (r == -1) {
     return E_OGGPLAY_USER_INTERRUPT;
   }
@@ -523,7 +527,19 @@
   return E_OGGPLAY_OK;
 }
 
+/*
+ * this function is required to release the frame_sem in the buffer, if 
+ * the buffer is being used.
+ */
+void
+oggplay_prepare_for_close(OggPlay *me) {
 
+  me->shutdown = 1;
+  if (me->buffer != NULL) {
+    SEM_SIGNAL(((OggPlayBuffer *)(me->buffer))->frame_sem);
+  }
+}
+
 ogg_int64_t
 oggplay_sys_time_in_ms(void) {
 #ifdef WIN32

Modified: liboggplay/trunk/src/liboggplay/oggplay_buffer.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_buffer.c	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/src/liboggplay/oggplay_buffer.c	2007-06-25 00:03:40 UTC (rev 3031)
@@ -132,6 +132,10 @@
   }
 
   SEM_WAIT(buffer->frame_sem);
+
+  if (me->shutdown) {
+    return -1;
+  }
   
   /*
    * lock the item going into the buffer so that it doesn't get cleaned up

Modified: liboggplay/trunk/src/liboggplay/oggplay_private.h
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_private.h	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/src/liboggplay/oggplay_private.h	2007-06-25 00:03:40 UTC (rev 3031)
@@ -187,6 +187,7 @@
   volatile OggPlayBuffer  * buffer;  
   ogg_int64_t               presentation_time;
   OggPlaySeekTrash        * trash;
+  int                       shutdown;
 };
 
 void

Modified: liboggplay/trunk/src/liboggplay/oggplay_seek.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_seek.c	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/src/liboggplay/oggplay_seek.c	2007-06-25 00:03:40 UTC (rev 3031)
@@ -87,9 +87,9 @@
   for (i = 0; i < me->num_tracks; i++) {
     OggPlayDecode *track = me->decode_data[i];
     if (track->data_list != NULL) {
-      //*(end_of_list_p) = track->data_list;
-      //end_of_list_p = &(track->end_of_data_list->next);
-      //oggplay_data_free_list(track->untimed_data_list);
+      *(end_of_list_p) = track->data_list;
+      end_of_list_p = &(track->end_of_data_list->next);
+      oggplay_data_free_list(track->untimed_data_list);
     }
     track->data_list = track->end_of_data_list = NULL;
     track->untimed_data_list = NULL;

Modified: liboggplay/trunk/src/tools/glut-player.c
===================================================================
--- liboggplay/trunk/src/tools/glut-player.c	2007-06-24 12:55:23 UTC (rev 3030)
+++ liboggplay/trunk/src/tools/glut-player.c	2007-06-25 00:03:40 UTC (rev 3031)
@@ -512,20 +512,20 @@
   glutMainLoop();
 
 #else
-  while (1) {
   for (i = 0; i < 100; i++) {
     display_frame();
   }
-  key_pressed('l', 0, 0);
-  for (i = 0; i < 10; i++) {
-    display_frame();
+  while (1) {
+    key_pressed('l', 0, 0);
+    for (i = 0; i < 100; i++) {
+      display_frame();
+    }
+    key_pressed('k', 0, 0);
+    for (i = 0; i < 100; i++) {
+      display_frame();
+    }
   }
-  key_pressed('k', 0, 0);
-  }
-  for (i = 0; i < 100; i++) {
-    display_frame();
-  }
-  key_pressed('q', 0, 0);
+ key_pressed('q', 0, 0);
 #endif
  
   printf("there were %d frames\n", n_frames);



More information about the commits mailing list