[xiph-commits] r3848 - liboggplay/trunk/src/liboggplay

wiking at svn.annodex.net wiking at svn.annodex.net
Tue Feb 10 15:37:08 PST 2009


Author: wiking
Date: 2009-02-10 15:37:07 -0800 (Tue, 10 Feb 2009)
New Revision: 3848

Modified:
   liboggplay/trunk/src/liboggplay/oggplay.c
   liboggplay/trunk/src/liboggplay/oggplay_private.h
Log:
Added duration variable into OggPlay struct in order to cache the length of the content, 
because each time the oggplay_get_duration function is called it does a seek (oggz)
to find out the duration of the content.
Hopefully this will improve the performance of liboggplay seeks, as a liboggplay seek results 
in a call to oggplay_get_duration.
(thnx for the patch doublec)



Modified: liboggplay/trunk/src/liboggplay/oggplay.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay.c	2009-01-23 03:53:27 UTC (rev 3847)
+++ liboggplay/trunk/src/liboggplay/oggplay.c	2009-02-10 23:37:07 UTC (rev 3848)
@@ -64,6 +64,7 @@
   me->trash = NULL;
   me->oggz = NULL;
   me->pt_update_valid = 1;
+  me->duration = -1;
 
   return me;
 
@@ -644,17 +645,30 @@
     return E_OGGPLAY_BAD_OGGPLAY;
   }
 
-  if (me->reader->duration) 
-    return me->reader->duration(me->reader);
-  else {
+  /* If the reader has a duration function we always call that
+   * function to find the duration. We never cache the result
+   * of that function.
+   *
+   * If there is no reader duration function we use our cached
+   * duration value, or do a liboggz seek to find it and cache
+   * that.
+   */
+  if (me->reader->duration) {
+      ogg_int64_t d = me->reader->duration(me->reader);
+      if (d >= 0) {
+        me->duration = d;
+      }
+  }
+
+  if (me->duration < 0) {
     ogg_int64_t pos;
-    ogg_int64_t duration;
     pos = oggz_tell_units(me->oggz);
-    duration = oggz_seek_units(me->oggz, 0, SEEK_END);
+    me->duration = oggz_seek_units(me->oggz, 0, SEEK_END);
     oggz_seek_units(me->oggz, pos, SEEK_SET);
     oggplay_seek_cleanup(me, pos);
-    return duration;
   }
+
+  return me->duration;
 }
 
 int

Modified: liboggplay/trunk/src/liboggplay/oggplay_private.h
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_private.h	2009-01-23 03:53:27 UTC (rev 3847)
+++ liboggplay/trunk/src/liboggplay/oggplay_private.h	2009-02-10 23:37:07 UTC (rev 3848)
@@ -39,7 +39,10 @@
 #ifndef __OGGPLAY_PRIVATE_H__
 #define __OGGPLAY_PRIVATE_H__
 
+#ifdef HAVE_CONFIG_H 
 #include <config.h>
+#endif
+
 #include <oggplay/oggplay.h>
 
 #include <oggz/oggz.h>
@@ -216,6 +219,7 @@
   OggPlaySeekTrash        * trash;
   int                       shutdown;
   int                       pt_update_valid;
+  ogg_int64_t               duration;	 /**< The value of the duration the last time it was retrieved.*/
 };
 
 void



More information about the commits mailing list