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

shans at svn.annodex.net shans at svn.annodex.net
Mon Jun 18 03:43:05 PDT 2007


Author: shans
Date: 2007-06-18 03:43:05 -0700 (Mon, 18 Jun 2007)
New Revision: 2990

Modified:
   liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
Log:
Modified tcp_reader to keep a persistent buffer of the entire movie.  Might
modify this later to allocate enough memory for the whole movie in advance,
when available.  Commented out oggz io functions also at the bottom of this
file - watch for these becoming active soon!!



Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c	2007-06-18 09:07:01 UTC (rev 2989)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c	2007-06-18 10:43:05 UTC (rev 2990)
@@ -295,6 +295,7 @@
     if (me->buffer == NULL) {
       me->buffer = (unsigned char*)malloc(TCP_READER_MAX_BUFFER_SIZE);
       me->buffer_size = 0;
+      printf("creating buffer at %p, 0 filled\n", me->buffer);
     }
 
     START_TIMEOUT(time_ref);
@@ -326,7 +327,7 @@
       if (pos != NULL) {
         break;
       }
-      /* TODO: make this more robust */
+      /* TODO: make this more robust - won't this break on a loop??? */
       if (strncmp((char *)me->buffer, "HTTP/1.1 200 OK", 15) != 0 &&
           strncmp((char *)me->buffer, "HTTP/1.0 200 OK", 15) != 0) {
         return E_OGGPLAY_BAD_INPUT;
@@ -345,6 +346,8 @@
     me->state = OTRS_HTTP_RESPONDED;
   }
 
+  printf("OggS packet found, buffer now: %d@%p\n", me->buffer_size, me->buffer);
+    
   /*
    * Read in enough data to fill the buffer.
    */
@@ -378,6 +381,8 @@
     me->state = OTRS_INIT_COMPLETE;
   }
 
+  printf("filled, buffer now: %d@%p\n", me->buffer_size, me->buffer);
+    
   /*
    * Set the socket back to blocking mode.
    */
@@ -418,15 +423,10 @@
   int remaining;
   int r;
 
+  printf("grab_some_data %s\n", block ? "and block" : "if available");
+  
   /*
    * see if we can grab some more data
-   */
-  
-  if (me->buffer_size == TCP_READER_MAX_BUFFER_SIZE) {
-    return E_OGGPLAY_OK;
-  }
-
-  /*
    * if we're not blocking, make sure there's some available data
    */  
   if (!block) {
@@ -443,7 +443,10 @@
       return E_OGGPLAY_OK;
     }
   }
-  remaining = TCP_READER_MAX_BUFFER_SIZE - me->buffer_size;
+  me->buffer = realloc(me->buffer, 
+                TCP_READER_MAX_BUFFER_SIZE + me->buffer_size);
+  printf("buffer realloced to %p, size %d\n", me->buffer, me->buffer_size);
+  remaining = TCP_READER_MAX_BUFFER_SIZE;
 #ifdef WIN32
   r = recv(me->socket, (char*)(me->buffer + me->buffer_size), remaining, 0);
 #else
@@ -456,6 +459,7 @@
   }
 
   me->buffer_size += r;
+  printf("buffer now %p, size %d\n", me->buffer, me->buffer_size);
 
   return E_OGGPLAY_OK;
 }
@@ -465,10 +469,9 @@
 oggplay_tcp_reader_get_next_chunk(OggPlayReader * opr, 
                 unsigned char ** position, int * size, int * base) {
 
-  OggPlayTCPReader * me;
+  OggPlayTCPReader * me               = (OggPlayTCPReader *)opr;
+  int                old_buffer_size  = me->buffer_size;
 
-  me = (OggPlayTCPReader *)opr;
-
   /*
    * check for end of file condition
    */
@@ -476,8 +479,10 @@
     return E_OGGPLAY_END_OF_FILE;
   }
  
-  *position = me->buffer;
-  *size = me->buffer_size;
+  grab_some_data(me, 0);
+
+  *position = me->buffer + me->current_position;
+  *size = me->buffer_size - me->current_position;
  
   /*
    * last chunk
@@ -486,16 +491,12 @@
     return E_OGGPLAY_OK;
   }
   
-  if (me->buffer_size == 0) {
+  if (me->buffer_size == old_buffer_size) {
     grab_some_data(me, 1);
-    *size = me->buffer_size;
+    *position = me->buffer + me->current_position;
+    *size = me->buffer_size - me->current_position;
   }
   
-  me->buffer = (unsigned char*)malloc(TCP_READER_MAX_BUFFER_SIZE);
-  me->buffer_size = 0;
-  
-  grab_some_data(me, 0);
-  
   me->current_position += *size;
   *base = me->current_position;
 
@@ -509,7 +510,7 @@
 
   OggPlayTCPReader * me;
   me = (OggPlayTCPReader *)opr;
-  free(position);
+
   if (me->socket == INVALID_SOCKET) 
     return E_OGGPLAY_OK;
   grab_some_data(me, 0);
@@ -536,3 +537,52 @@
   
   return (OggPlayReader *)me;
 }
+
+/*
+#define MIN(a,b) ((a)<(b)?(a):(b))
+
+static size_t
+my_io_read(void * user_handle, void * buf, size_t n) {
+
+  OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
+  int                 len;
+
+  len = MIN(n, me->buffer_size - me->current_position);
+  memcpy(buf, me->buffer, len);
+    
+  me->current_position += len;
+
+  return len;
+}
+    
+static int
+my_io_seek(void * user_handle, long offset, int whence) {
+
+  OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
+  
+  switch (whence) {
+  case SEEK_SET:
+    me->current_position = offset;
+    break;
+  case SEEK_CUR:
+    me->current_position += offset;
+    break;
+  case SEEK_END:
+    me->current_position = me->buffer_size + offset;
+    break;
+  default:
+    return -1;
+  }
+
+  return 0;
+}
+
+static long
+my_io_tell(void * user_handle) {
+
+  OggPlayTCPReader  * me = (OggPlayTCPReader *)user_handle;
+
+  return me->current_position;
+
+}
+*/ 



More information about the commits mailing list