[xiph-commits] r3043 - in liboggplay/trunk/src: liboggplay tools
shans at svn.annodex.net
shans at svn.annodex.net
Mon Jun 25 03:24:54 PDT 2007
Author: shans
Date: 2007-06-25 03:24:53 -0700 (Mon, 25 Jun 2007)
New Revision: 3043
Modified:
liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
liboggplay/trunk/src/tools/glut-player.c
Log:
Push all data into backing store, this gives much better estimates of
amount of movie downloaded
Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c 2007-06-25 06:02:39 UTC (rev 3042)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c 2007-06-25 10:24:53 UTC (rev 3043)
@@ -350,8 +350,11 @@
offset = pos - (char *)(me->buffer);
memmove(me->buffer, pos, nbytes - offset);
me->amount_in_memory = nbytes - offset;
- me->stored_offset = 0;
-
+ me->backing_store = tmpfile();
+ fwrite(me->buffer, 1, me->amount_in_memory, me->backing_store);
+ me->current_position = 0;
+ me->stored_offset = me->amount_in_memory;
+ me->amount_in_memory = 0;
me->state = OTRS_HTTP_RESPONDED;
}
@@ -360,7 +363,7 @@
* Read in enough data to fill the buffer.
*/
if (me->state == OTRS_HTTP_RESPONDED) {
- remaining = TCP_READER_MAX_IN_MEMORY - me->amount_in_memory;
+ remaining = TCP_READER_MAX_IN_MEMORY - me->stored_offset;
START_TIMEOUT(time_ref);
while (remaining > 0) {
#ifdef WIN32
@@ -387,6 +390,9 @@
me->amount_in_memory += nbytes;
remaining -= nbytes;
}
+ fwrite(me->buffer, 1, me->amount_in_memory, me->backing_store);
+ me->stored_offset += me->amount_in_memory;
+ me->amount_in_memory = 0;
me->state = OTRS_INIT_COMPLETE;
}
@@ -434,14 +440,6 @@
int r;
/*
- * woah, too much stuff in memory already and we're just speculatively
- * retrieving the data. How about we don't bother.
- */
- if (me->amount_in_memory == TCP_READER_MAX_IN_MEMORY && !block) {
- goto clean_data_out;
- }
-
- /*
* see if we can grab some more data
* if we're not blocking, make sure there's some available data
*/
@@ -456,98 +454,21 @@
FD_ZERO(&empty);
FD_SET(me->socket, &reads);
if (select(me->socket + 1, &reads, &empty, &empty, &tv) == 0) {
- printf("nuh, no data\n");
return E_OGGPLAY_OK;
}
}
- remaining = me->buffer_size - me->amount_in_memory;
- printf("reading %d bytes\n", remaining);
+ remaining = me->buffer_size;
#ifdef WIN32
r = recv(me->socket, (char*)(me->buffer + me->amount_in_memory),
remaining, 0);
#else
r = read(me->socket, me->buffer + me->amount_in_memory, remaining);
#endif
- if (r < 0) {
- return E_OGGPLAY_SOCKET_ERROR;
- } else if (r == 0) {
- return E_OGGPLAY_END_OF_FILE;
- }
- me->amount_in_memory += r;
-
-clean_data_out:
+ fwrite(me->buffer, 1, r, me->backing_store);
+ me->stored_offset += r;
- if (me->amount_in_memory > TCP_READER_WRITE_THRESHOLD) {
-
- int can_write;
-
- /*
- * we're going to try and dump some of this data on disk.
- * Note that we might not actually be able to open a backing store. If
- * we can't then we just continue in memory
- */
- if (me->backing_store == NULL) {
- me->backing_store = tmpfile();
- //me->backing_store = fopen("temp.ogg", "w");
- if (me->backing_store == NULL) {
- me->buffer_size *= 2;
- me->buffer = realloc(me->buffer, me->buffer_size);
- return E_OGGPLAY_OK;
- }
- }
-
- /*
- * So amount_in_memory is our currently resident amount, and we've used
- * up to position.
- *
- * position
- * v
- * [<---amount_in_memory-->|-----buffer_size--->]
- *
- * So the amount we COULD write is me->position (we don't want to write
- * out what we haven't used).
- */
-
- can_write = me->current_position;
-
- /*
- * BUT we don't really want to write more than we have to, so lets
- * leave TCP_READER_WRITE_THRESHOLD behind
- */
-
- if (me->amount_in_memory - can_write < TCP_READER_WRITE_THRESHOLD) {
- can_write = me->amount_in_memory - TCP_READER_WRITE_THRESHOLD;
- }
-
- /*
- * although, if we aren't writing anything to disk, why are we here?
- */
- if (can_write == 0) {
- return E_OGGPLAY_OK;
- }
-
- /*
- * OK Joe, flush it outa heeeeere!
- */
- fwrite(me->buffer, can_write, 1, me->backing_store);
-
- /*
- * now we need to pull everything back to the beginning of the buffer
- */
- memmove(me->buffer, me->buffer + can_write,
- me->amount_in_memory - can_write);
- me->amount_in_memory -= can_write;
- me->current_position -= can_write;
-
- /*
- * finally, fix the offset
- */
- me->stored_offset += can_write;
-
- }
-
return E_OGGPLAY_OK;
}
@@ -562,12 +483,9 @@
me = (OggPlayTCPReader *)opr;
- if (me->mode == TCP_READER_FROM_FILE) {
- return (int)((tpb * me->stored_offset) >> 16);
- }
+ grab_some_data(me, 0);
+ return (int)((tpb * me->stored_offset) >> 16);
- return (int)((tpb * (me->stored_offset + me->amount_in_memory)) >> 16);
-
}
static size_t
@@ -576,28 +494,13 @@
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 {
- int r = fread(buf, 1, n, me->backing_store);
- me->current_position += r;
- return r;
- }
- }
-
grab_some_data(me, 0);
- if (me->amount_in_memory - me->current_position == 0) {
- grab_some_data(me, 1);
- }
- len = MIN(n, me->buffer_size - me->current_position);
- memcpy(buf, me->buffer, len);
-
+ fseek(me->backing_store, me->current_position, SEEK_SET);
+ me->current_position = ftell(me->backing_store);
+ len = fread(buf, 1, n, me->backing_store);
me->current_position += len;
-
+ fseek(me->backing_store, 0, SEEK_END);
return len;
}
@@ -607,48 +510,10 @@
OggPlayTCPReader * me = (OggPlayTCPReader *)user_handle;
int r;
- /*
- * 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;
- }
-
- r = fseek(me->backing_store, offset, whence);
- me->current_position = ftell(me->backing_store);
+ 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);
- }
-
- return r;
- }
-
- 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;
+ return r;
}
static long
@@ -656,9 +521,6 @@
OggPlayTCPReader * me = (OggPlayTCPReader *)user_handle;
- if (me->mode == TCP_READER_FROM_MEMORY) {
- return me->current_position + me->stored_offset;
- }
return me->current_position;
}
Modified: liboggplay/trunk/src/tools/glut-player.c
===================================================================
--- liboggplay/trunk/src/tools/glut-player.c 2007-06-25 06:02:39 UTC (rev 3042)
+++ liboggplay/trunk/src/tools/glut-player.c 2007-06-25 10:24:53 UTC (rev 3043)
@@ -372,12 +372,14 @@
}
#endif
-static unsigned int buf_size = 20;
+static unsigned int buf_size = 20;
+static int saved_avail = 0;
void *drive_decoding(void *arg) {
while (1) {
OggPlayErrorCode r;
+ int avail;
if (sem_trywait(&msg_sem) == 0) {
if (msg == SEEK_FORWARD) {
@@ -396,7 +398,12 @@
while (r == E_OGGPLAY_TIMEOUT) {
r = oggplay_step_decoding(player);
}
- printf("available: %d\n", oggplay_get_available(player));
+
+ avail = oggplay_get_available(player);
+ if (avail != saved_avail) {
+ saved_avail = avail;
+ printf("available: %d\n", avail);
+ }
if (r != E_OGGPLAY_CONTINUE && r != E_OGGPLAY_USER_INTERRUPT) {
More information about the commits
mailing list