Bug 462916 - Update liboggplay to pick up ability to compute Ogg duration - r+sr=roc
authorChris Double <chris.double@double.co.nz>
Tue, 04 Nov 2008 21:06:40 +1300
changeset 21265 0d7fa555b378c6be9004765734d230d68bf231b9
parent 21264 f923f7a759e2eb7299aeed2453345b846546ccf2
child 21266 a82181a232531c05729fc7d3a910232a7eb65c75
push id3446
push usercdouble@mozilla.com
push dateTue, 04 Nov 2008 08:06:52 +0000
treeherdermozilla-central@0d7fa555b378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs462916
milestone1.9.1b2pre
Bug 462916 - Update liboggplay to pick up ability to compute Ogg duration - r+sr=roc
content/media/video/public/nsChannelReader.h
content/media/video/src/nsChannelReader.cpp
media/liboggplay/README_MOZILLA
media/liboggplay/include/oggplay/oggplay.h
media/liboggplay/include/oggplay/oggplay_reader.h
media/liboggplay/src/liboggplay/oggplay.c
media/liboggplay/src/liboggplay/oggplay_seek.c
media/liboggplay/src/liboggplay/oggplay_tcp_reader.c
--- a/content/media/video/public/nsChannelReader.h
+++ b/content/media/video/public/nsChannelReader.h
@@ -82,16 +82,15 @@ public:
   nsIPrincipal* GetCurrentPrincipal();
   
   // Implementation of OggPlay Reader API.
   OggPlayErrorCode initialise(int aBlock);
   OggPlayErrorCode destroy();
   size_t io_read(char* aBuffer, size_t aCount);
   int io_seek(long aOffset, int aWhence);
   long io_tell();  
-  int duration();
   
 public:
   nsMediaStream mStream;
   unsigned long mCurrentPosition;
 };
 
 #endif
--- a/content/media/video/src/nsChannelReader.cpp
+++ b/content/media/video/src/nsChannelReader.cpp
@@ -95,21 +95,16 @@ int nsChannelReader::io_seek(long aOffse
   return OGGZ_STOP_ERR;
 }
 
 long nsChannelReader::io_tell()
 {
   return mStream.Tell();
 }
 
-int nsChannelReader::duration()
-{
-  return 3600000; // TODO: implement correctly
-}
-
 static OggPlayErrorCode oggplay_channel_reader_initialise(OggPlayReader* aReader, int aBlock) 
 {
   nsChannelReader * me = static_cast<nsChannelReader*>(aReader);
 
   if (me == NULL) {
     return E_OGGPLAY_BAD_READER;
   }
   return me->initialise(aBlock);
@@ -136,22 +131,16 @@ static int oggplay_channel_reader_io_see
 }
 
 static long oggplay_channel_reader_io_tell(void* aReader) 
 {
   nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
   return me->io_tell();
 }
 
-static int oggplay_channel_reader_duration(OggPlayReader* aReader) 
-{
-  nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
-  return me->duration();
-}
-
 nsresult nsChannelReader::Init(nsMediaDecoder* aDecoder, nsIURI* aURI,
                                nsIChannel* aChannel,
                                nsIStreamListener** aStreamListener)
 {
   mCurrentPosition = 0;
   return mStream.Open(aDecoder, aURI, aChannel, aStreamListener);
 }
 
@@ -165,16 +154,16 @@ nsChannelReader::nsChannelReader()
   MOZ_COUNT_CTOR(nsChannelReader);
   OggPlayReader* reader = this;
   reader->initialise = &oggplay_channel_reader_initialise;
   reader->destroy = &oggplay_channel_reader_destroy;
   reader->seek = nsnull;
   reader->io_read  = &oggplay_channel_reader_io_read;
   reader->io_seek  = &oggplay_channel_reader_io_seek;
   reader->io_tell  = &oggplay_channel_reader_io_tell;
-  reader->duration = &oggplay_channel_reader_duration;
+  reader->duration = nsnull;
 }
 
 nsIPrincipal*
 nsChannelReader::GetCurrentPrincipal()
 {
   return mStream.GetCurrentPrincipal();
 }
--- a/media/liboggplay/README_MOZILLA
+++ b/media/liboggplay/README_MOZILLA
@@ -1,11 +1,11 @@
 The source from this directory was copied from the liboggplay svn
 source using the update.sh script. The only changes made were those
 applied by update.sh and the addition/upate of Makefile.in files for
 the Mozilla build system.
 
 http://svn.annodex.net/liboggplay/trunk/
 
-The svn revision number used was r3757.
+The svn revision number used was r3761.
 
 The patch from Annodex trac ticket 421 is applied to fix bug 459938:
   http://trac.annodex.net/ticket/421
--- a/media/liboggplay/include/oggplay/oggplay.h
+++ b/media/liboggplay/include/oggplay/oggplay.h
@@ -129,17 +129,17 @@ void
 oggplay_prepare_for_close(OggPlay *me);
 
 OggPlayErrorCode
 oggplay_close(OggPlay *player);
 
 int
 oggplay_get_available(OggPlay *player);
 
-int
+ogg_int64_t
 oggplay_get_duration(OggPlay * player);
 
 int
 oggplay_media_finished_retrieving(OggPlay * player);
 
 #ifdef __cplusplus
 }
 #endif
--- a/media/liboggplay/include/oggplay/oggplay_reader.h
+++ b/media/liboggplay/include/oggplay/oggplay_reader.h
@@ -49,17 +49,17 @@ struct _OggPlayReader;
 typedef struct _OggPlayReader {
   OggPlayErrorCode  (*initialise)(struct _OggPlayReader * me, int block);
   OggPlayErrorCode  (*destroy)(struct _OggPlayReader * me);
   OggPlayErrorCode  (*seek)(struct _OggPlayReader *me, OGGZ *oggz, 
                                                     ogg_int64_t milliseconds);
   int               (*available)(struct _OggPlayReader *me,
                                               ogg_int64_t current_bytes,
                                               ogg_int64_t current_time);
-  int               (*duration)(struct _OggPlayReader *me);
+  ogg_int64_t       (*duration)(struct _OggPlayReader *me);
   int               (*finished_retrieving)(struct _OggPlayReader *me);
 
   /* low-level io functions for oggz */
   size_t            (*io_read)(void *user_handle, void *buf, size_t n);
   int               (*io_seek)(void *user_handle, long offset, int whence);
   long              (*io_tell)(void *user_handle);
 } OggPlayReader;
 
--- a/media/liboggplay/src/liboggplay/oggplay.c
+++ b/media/liboggplay/src/liboggplay/oggplay.c
@@ -629,24 +629,31 @@ oggplay_get_available(OggPlay *me) {
 
   current_time = oggz_tell_units(me->oggz);
   current_byte = (ogg_int64_t)oggz_tell(me->oggz);
 
   return me->reader->available(me->reader, current_byte, current_time);
 
 }
 
-int
+ogg_int64_t
 oggplay_get_duration(OggPlay *me) {
 
   if (me == NULL) {
     return E_OGGPLAY_BAD_OGGPLAY;
   }
 
-  return me->reader->duration(me->reader);
+  if (me->reader->duration) 
+    return me->reader->duration(me->reader);
+  else {
+    ogg_int64_t pos = oggz_tell_units(me->oggz);
+    ogg_int64_t duration = oggz_seek_units(me->oggz, 0, SEEK_END);
+    oggz_seek_units(me->oggz, pos, SEEK_SET);
+    return duration;
+  }
 }
 
 int
 oggplay_media_finished_retrieving(OggPlay *me) {
 
   if (me == NULL) {
     return E_OGGPLAY_BAD_OGGPLAY;
   }
--- a/media/liboggplay/src/liboggplay/oggplay_seek.c
+++ b/media/liboggplay/src/liboggplay/oggplay_seek.c
@@ -50,17 +50,17 @@ oggplay_seek(OggPlay *me, ogg_int64_t mi
   if (me == NULL) {
     return E_OGGPLAY_BAD_OGGPLAY;
   }
 
   if (milliseconds < 0) {
     return E_OGGPLAY_CANT_SEEK;
   }
 
-  eof = me->reader->duration(me->reader);
+  eof = oggplay_get_duration(me);
   if (eof > -1 && milliseconds > eof) {
     return E_OGGPLAY_CANT_SEEK;
   }
 
   if (me->reader->seek != NULL) {
     if
     (
       me->reader->seek(me->reader, me->oggz, milliseconds)
--- a/media/liboggplay/src/liboggplay/oggplay_tcp_reader.c
+++ b/media/liboggplay/src/liboggplay/oggplay_tcp_reader.c
@@ -592,17 +592,17 @@ oggplay_tcp_reader_available(OggPlayRead
   if (me->duration > -1 && ((tpb * me->stored_offset) >> 16) > me->duration)
   {
     return me->duration;
   }
   return (int)((tpb * me->stored_offset) >> 16);
 
 }
 
-int
+ogg_int64_t
 oggplay_tcp_reader_duration(OggPlayReader * opr) {
   OggPlayTCPReader    *me = (OggPlayTCPReader *)opr;
   return me->duration;
 }
 
 static size_t
 oggplay_tcp_reader_io_read(void * user_handle, void * buf, size_t n) {