[xiph-cvs] cvs commit: vorbis/lib vorbisfile.c

Monty xiphmont at xiph.org
Fri Oct 13 12:48:04 PDT 2000



xiphmont    00/10/13 12:48:03

  Modified:    examples Makefile.am
               include/vorbis vorbisfile.h
               lib      vorbisfile.c
  Log:
  Readded seeking_example.c to the build
  
  Added page-granularity seeking for a seek that's faster than
  ov_pcm_seek or ov_time_seek, but not quite as accurate.  See the
  comments in vorbisfile.c for ov_pcm_seek_page.
  
  Monty

Revision  Changes    Path
1.3       +3 -1      vorbis/examples/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis/examples/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Makefile.am	2000/10/12 03:12:39	1.2
+++ Makefile.am	2000/10/13 19:48:02	1.3
@@ -5,7 +5,7 @@
 INCLUDES = -I$(top_srcdir)/include
 
 noinst_PROGRAMS = decoder_example encoder_example chaining_example\
-		vorbisfile_example
+		vorbisfile_example seeking_example
 
 LDADD = $(top_srcdir)/lib/.libs/libvorbis.a
 
@@ -15,6 +15,8 @@
 chaining_example_LDADD = $(top_srcdir)/lib/.libs/libvorbisfile.a $(top_srcdir)/lib/.libs/libvorbis.a
 vorbisfile_example_SOURCES = vorbisfile_example.c
 vorbisfile_example_LDADD = $(top_srcdir)/lib/.libs/libvorbisfile.a $(top_srcdir)/lib/.libs/libvorbis.a
+seeking_example_SOURCES = seeking_example.c
+seeking_example_LDADD = $(top_srcdir)/lib/.libs/libvorbisfile.a $(top_srcdir)/lib/.libs/libvorbis.a
 
 debug:
         $(MAKE) all CFLAGS="@DEBUG@"

1.9       +3 -1      vorbis/include/vorbis/vorbisfile.h

Index: vorbisfile.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/include/vorbis/vorbisfile.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- vorbisfile.h	2000/10/12 03:12:41	1.8
+++ vorbisfile.h	2000/10/13 19:48:02	1.9
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.h,v 1.8 2000/10/12 03:12:41 xiphmont Exp $
+ last mod: $Id: vorbisfile.h,v 1.9 2000/10/13 19:48:02 xiphmont Exp $
 
  ********************************************************************/
 
@@ -97,7 +97,9 @@
 
 extern int ov_raw_seek(OggVorbis_File *vf,long pos);
 extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
+extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
 extern int ov_time_seek(OggVorbis_File *vf,double pos);
+extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
 
 extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
 extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);

1.30      +50 -8     vorbis/lib/vorbisfile.c

Index: vorbisfile.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/vorbisfile.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- vorbisfile.c	2000/10/12 03:12:54	1.29
+++ vorbisfile.c	2000/10/13 19:48:03	1.30
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.29 2000/10/12 03:12:54 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.30 2000/10/13 19:48:03 xiphmont Exp $
 
  ********************************************************************/
 
@@ -813,11 +813,13 @@
   return -1;
 }
 
-/* seek to a sample offset relative to the decompressed pcm stream 
-
-   returns zero on success, nonzero on failure */
+/* Page granularity seek (faster than sample granularity because we
+   don't do the last bit of decode to find a specific sample).
 
-int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
+   Seek to the last [granule marked] page preceeding the specified pos
+   location, such that decoding past the returned point will quickly
+   arrive at the requested position. */
+int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
   int link=-1;
   ogg_int64_t total=ov_pcm_total(vf,-1);
 
@@ -876,7 +878,21 @@
   /* verify result */
   if(vf->pcm_offset>=pos)goto seek_error;
   if(pos>ov_pcm_total(vf,-1))goto seek_error;
+  return(0);
+
+ seek_error:
+  /* dump machine so we're in a known state */
+  vf->pcm_offset=-1;
+  _decode_clear(vf);
+  return -1;
+}
 
+/* seek to a sample offset relative to the decompressed pcm stream 
+   returns zero on success, nonzero on failure */
+
+int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
+  if(ov_pcm_seek_page(vf,pos))return(-1);
+
   /* discard samples until we reach the desired position. Crossing a
      logical bitstream boundary with abandon is OK. */
   while(vf->pcm_offset<pos){
@@ -893,7 +909,33 @@
         vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
   }
   return 0;
+}
+
+/* seek to a playback time relative to the decompressed pcm stream 
+   returns zero on success, nonzero on failure */
+int ov_time_seek(OggVorbis_File *vf,double seconds){
+  /* translate time to PCM position and call ov_pcm_seek */
+
+  int link=-1;
+  ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
+  double time_total=ov_time_total(vf,-1);
+
+  if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */  
+  if(seconds<0 || seconds>time_total)goto seek_error;
   
+  /* which bitstream section does this time offset occur in? */
+  for(link=vf->links-1;link>=0;link--){
+    pcm_total-=vf->pcmlengths[link];
+    time_total-=ov_time_total(vf,link);
+    if(seconds>=time_total)break;
+  }
+
+  /* enough information to convert time offset to pcm offset */
+  {
+    ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
+    return(ov_pcm_seek(vf,target));
+  }
+
  seek_error:
   /* dump machine so we're in a known state */
   vf->pcm_offset=-1;
@@ -901,9 +943,9 @@
   return -1;
 }
 
-/* seek to a playback time relative to the decompressed pcm stream 
+/* page-granularity version of ov_time_seek 
    returns zero on success, nonzero on failure */
-int ov_time_seek(OggVorbis_File *vf,double seconds){
+int ov_time_seek_page(OggVorbis_File *vf,double seconds){
   /* translate time to PCM position and call ov_pcm_seek */
 
   int link=-1;
@@ -923,7 +965,7 @@
   /* enough information to convert time offset to pcm offset */
   {
     ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
-    return(ov_pcm_seek(vf,target));
+    return(ov_pcm_seek_page(vf,target));
   }
 
  seek_error:

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list