[xiph-commits] r3039 - in liboggplay/trunk: include/oggplay
src/liboggplay src/tools
shans at svn.annodex.net
shans at svn.annodex.net
Sun Jun 24 20:29:38 PDT 2007
Author: shans
Date: 2007-06-24 20:29:38 -0700 (Sun, 24 Jun 2007)
New Revision: 3039
Modified:
liboggplay/trunk/include/oggplay/oggplay_reader.h
liboggplay/trunk/src/liboggplay/Version_script.in
liboggplay/trunk/src/liboggplay/oggplay.c
liboggplay/trunk/src/liboggplay/oggplay_file_reader.c
liboggplay/trunk/src/liboggplay/oggplay_file_reader.h
liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
liboggplay/trunk/src/tools/glut-player.c
Log:
"Available" function to determine approximately how much data has been downloaded
Modified: liboggplay/trunk/include/oggplay/oggplay_reader.h
===================================================================
--- liboggplay/trunk/include/oggplay/oggplay_reader.h 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/include/oggplay/oggplay_reader.h 2007-06-25 03:29:38 UTC (rev 3039)
@@ -42,6 +42,7 @@
#include <stdlib.h>
#include <oggz/oggz.h>
+#include <ogg/ogg.h>
struct _OggPlayReader;
@@ -50,7 +51,10 @@
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);
+
/* 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);
Modified: liboggplay/trunk/src/liboggplay/Version_script.in
===================================================================
--- liboggplay/trunk/src/liboggplay/Version_script.in 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/src/liboggplay/Version_script.in 2007-06-25 03:29:38 UTC (rev 3039)
@@ -60,6 +60,7 @@
oggplay_millisleep;
oggplay_seek;
+ oggplay_get_available;
local:
*;
};
Modified: liboggplay/trunk/src/liboggplay/oggplay.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay.c 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/src/liboggplay/oggplay.c 2007-06-25 03:29:38 UTC (rev 3039)
@@ -551,6 +551,22 @@
}
}
+int
+oggplay_get_available(OggPlay *me) {
+
+ ogg_int64_t current_time, current_byte;
+
+ if (me == NULL) {
+ return E_OGGPLAY_BAD_OGGPLAY;
+ }
+
+ 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);
+
+}
+
ogg_int64_t
oggplay_sys_time_in_ms(void) {
#ifdef WIN32
Modified: liboggplay/trunk/src/liboggplay/oggplay_file_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_file_reader.c 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/src/liboggplay/oggplay_file_reader.c 2007-06-25 03:29:38 UTC (rev 3039)
@@ -59,6 +59,10 @@
return E_OGGPLAY_BAD_INPUT;
}
+ fseek(me->file, SEEK_END, 0);
+ me->size = ftell(me->file);
+ fseek(me->file, SEEK_SET, 0);
+
me->current_position = 0;
return E_OGGPLAY_OK;
@@ -77,6 +81,15 @@
return E_OGGPLAY_OK;
}
+int
+oggplay_file_reader_available(OggPlayReader * opr, ogg_int64_t current_bytes,
+ ogg_int64_t current_time) {
+
+ OggPlayFileReader *me = (OggPlayFileReader *)opr;
+ return me->size;
+
+}
+
static size_t
oggplay_file_reader_io_read(void * user_handle, void * buf, size_t n) {
@@ -122,6 +135,7 @@
me->functions.initialise = &oggplay_file_reader_initialise;
me->functions.destroy = &oggplay_file_reader_destroy;
+ me->functions.available = &oggplay_file_reader_available;
me->functions.seek = NULL;
me->functions.io_read = &oggplay_file_reader_io_read;
me->functions.io_seek = &oggplay_file_reader_io_seek;
Modified: liboggplay/trunk/src/liboggplay/oggplay_file_reader.h
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_file_reader.h 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/src/liboggplay/oggplay_file_reader.h 2007-06-25 03:29:38 UTC (rev 3039)
@@ -50,6 +50,7 @@
char * file_name;
FILE * file;
int current_position;
+ int size;
} OggPlayFileReader;
#endif
Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c 2007-06-25 03:29:38 UTC (rev 3039)
@@ -330,6 +330,7 @@
return E_OGGPLAY_END_OF_FILE;
}
me->buffer[me->amount_in_memory + nbytes] = '\0';
+ printf("%s\n",me->buffer);
pos = strstr((char *)(me->buffer), "OggS");
if (pos != NULL) {
break;
@@ -455,11 +456,13 @@
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);
#ifdef WIN32
r = recv(me->socket, (char*)(me->buffer + me->amount_in_memory),
remaining, 0);
@@ -550,6 +553,23 @@
#define MIN(a,b) ((a)<(b)?(a):(b))
+int
+oggplay_tcp_reader_available(OggPlayReader * opr, ogg_int64_t current_bytes,
+ ogg_int64_t current_time) {
+
+ OggPlayTCPReader * me;
+ ogg_int64_t tpb = (current_time << 16) / current_bytes;
+
+ me = (OggPlayTCPReader *)opr;
+
+ if (me->mode == TCP_READER_FROM_FILE) {
+ return (int)((tpb * me->stored_offset) >> 16);
+ }
+
+ return (int)((tpb * (me->stored_offset + me->amount_in_memory)) >> 16);
+
+}
+
static size_t
oggplay_tcp_reader_io_read(void * user_handle, void * buf, size_t n) {
@@ -662,6 +682,7 @@
me->functions.initialise = &oggplay_tcp_reader_initialise;
me->functions.destroy = &oggplay_tcp_reader_destroy;
me->functions.seek = NULL;
+ me->functions.available = &oggplay_tcp_reader_available;
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;
Modified: liboggplay/trunk/src/tools/glut-player.c
===================================================================
--- liboggplay/trunk/src/tools/glut-player.c 2007-06-25 02:44:02 UTC (rev 3038)
+++ liboggplay/trunk/src/tools/glut-player.c 2007-06-25 03:29:38 UTC (rev 3039)
@@ -396,7 +396,9 @@
while (r == E_OGGPLAY_TIMEOUT) {
r = oggplay_step_decoding(player);
}
+ printf("available: %d\n", oggplay_get_available(player));
+
if (r != E_OGGPLAY_CONTINUE && r != E_OGGPLAY_USER_INTERRUPT) {
printf("hmm, totally bogus, dude. r is %d\n", r);
// wait for display thread to finish
More information about the commits
mailing list