[xiph-commits] r2997 - in liboggplay/trunk: include/oggplay src/liboggplay

shans at svn.annodex.net shans at svn.annodex.net
Tue Jun 19 00:26:00 PDT 2007


Author: shans
Date: 2007-06-19 00:26:00 -0700 (Tue, 19 Jun 2007)
New Revision: 2997

Modified:
   liboggplay/trunk/include/oggplay/oggplay_reader.h
   liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
   liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.h
Log:
Added slots in reader for seek and tell (not yet called by liboggplay).
Added implementations of seek and tell for tcp reader.


Modified: liboggplay/trunk/include/oggplay/oggplay_reader.h
===================================================================
--- liboggplay/trunk/include/oggplay/oggplay_reader.h	2007-06-19 06:27:25 UTC (rev 2996)
+++ liboggplay/trunk/include/oggplay/oggplay_reader.h	2007-06-19 07:26:00 UTC (rev 2997)
@@ -48,6 +48,8 @@
   OggPlayErrorCode  (*initialise)(struct _OggPlayReader * me, int block);
   OggPlayErrorCode  (*destroy)(struct _OggPlayReader * me);
   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;
 
 OggPlayReader *

Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c	2007-06-19 06:27:25 UTC (rev 2996)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c	2007-06-19 07:26:00 UTC (rev 2997)
@@ -390,6 +390,7 @@
   }
 
   me->backing_store = NULL;
+  me->mode = TCP_READER_FROM_MEMORY;
     
   /*
    * Set the socket back to blocking mode.
@@ -557,6 +558,16 @@
   OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
   int                 len;
 
+  if (me->mode == TCP_READER_FROM_FILE) {
+    me->current_position = ftell(me->backing_store);
+    if (me->current_position == me->stored_offset) {
+      me->mode = TCP_READER_FROM_MEMORY;
+      me->current_position = 0;
+    } else {
+      return fread(buf, n, 1, me->backing_store);
+    }
+  }
+
   grab_some_data(me, 0);
   if (me->amount_in_memory - me->current_position == 0) {
     grab_some_data(me, 1);
@@ -570,32 +581,39 @@
   return len;
 }
 
-OggPlayReader *
-oggplay_tcp_reader_new(char *location) {
+static int
+oggplay_tcp_reader_io_seek(void * user_handle, long offset, int whence) {
 
-  OggPlayTCPReader * me = (OggPlayTCPReader *)malloc (sizeof (OggPlayTCPReader));
+  OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
+  int                 r;
 
-  me->state = OTRS_UNINITIALISED;
-  me->socket = INVALID_SOCKET;
-  me->buffer = NULL;
-  me->buffer_size = 0;
-  me->current_position = 0;
-  me->location = strdup(location);
-
-  me->functions.initialise = &oggplay_tcp_reader_initialise;
-  me->functions.destroy = &oggplay_tcp_reader_destroy;
-  me->functions.io_read = &oggplay_tcp_reader_io_read;
+  /* 
+   * first write all the data we have back to disk.  This makes things
+   * easier.
+   */
+  if (me->backing_store != NULL) {
+    if (me->mode != TCP_READER_FROM_FILE) {
+      fwrite(me->buffer, me->amount_in_memory, 1, me->backing_store);
+      me->stored_offset += me->amount_in_memory;
+      me->amount_in_memory = 0;
+      me->mode = TCP_READER_FROM_FILE;
+    }
   
-  return (OggPlayReader *)me;
-}
+    r = fseek(me->backing_store, offset, whence);
+    me->current_position = ftell(me->backing_store);
 
+    /*
+     * back at the end of the file
+     */
+    if (me->current_position == me->stored_offset) {
+      me->mode = TCP_READER_FROM_MEMORY;
+      me->current_position = 0;
+      grab_some_data(me, 0);
+    }
 
-/*
-static int
-my_io_seek(void * user_handle, long offset, int whence) {
+    return r;
+  }
 
-  OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
-  
   switch (whence) {
   case SEEK_SET:
     me->current_position = offset;
@@ -614,11 +632,33 @@
 }
 
 static long
-my_io_tell(void * user_handle) {
+oggplay_tcp_reader_io_tell(void * user_handle) {
 
   OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
 
   return me->current_position;
 
 }
-*/
+
+OggPlayReader *
+oggplay_tcp_reader_new(char *location) {
+
+  OggPlayTCPReader * me = (OggPlayTCPReader *)malloc (sizeof (OggPlayTCPReader));
+
+  me->state = OTRS_UNINITIALISED;
+  me->socket = INVALID_SOCKET;
+  me->buffer = NULL;
+  me->buffer_size = 0;
+  me->current_position = 0;
+  me->location = strdup(location);
+
+  me->functions.initialise = &oggplay_tcp_reader_initialise;
+  me->functions.destroy = &oggplay_tcp_reader_destroy;
+  me->functions.io_read = &oggplay_tcp_reader_io_read;
+  me->functions.io_seek = &oggplay_tcp_reader_io_seek;
+  me->functions.io_tell = &oggplay_tcp_reader_io_tell;
+  
+  return (OggPlayReader *)me;
+}
+
+

Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.h
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.h	2007-06-19 06:27:25 UTC (rev 2996)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.h	2007-06-19 07:26:00 UTC (rev 2997)
@@ -49,6 +49,11 @@
 #define TCP_READER_WRITE_THRESHOLD           64*1024
 
 typedef enum {
+  TCP_READER_FROM_MEMORY,
+  TCP_READER_FROM_FILE
+} dataLocation;
+
+typedef enum {
   OTRS_UNINITIALISED,
   OTRS_SOCKET_CREATED,
   OTRS_CONNECTED,
@@ -72,6 +77,7 @@
   int               amount_in_memory;
   FILE            * backing_store;
   int               stored_offset;
+  dataLocation      mode;
 } OggPlayTCPReader;
 
 #endif



More information about the commits mailing list