[xiph-commits] r3021 - in liboggplay/trunk/src: liboggplay tools
shans at svn.annodex.net
shans at svn.annodex.net
Thu Jun 21 05:27:51 PDT 2007
Author: shans
Date: 2007-06-21 05:27:50 -0700 (Thu, 21 Jun 2007)
New Revision: 3021
Modified:
liboggplay/trunk/src/liboggplay/oggplay.c
liboggplay/trunk/src/liboggplay/oggplay_seek.c
liboggplay/trunk/src/tools/glut-player.c
Log:
File-based seeking:
Forward seeking works correctly, but a memory leak still exists.
Reverse seeking does not yet work.
Modified: liboggplay/trunk/src/liboggplay/oggplay.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay.c 2007-06-21 12:02:59 UTC (rev 3020)
+++ liboggplay/trunk/src/liboggplay/oggplay.c 2007-06-21 12:27:50 UTC (rev 3021)
@@ -164,8 +164,8 @@
}
/*
- * internal function that doesn't perform error checking. Used so the buffer can
- * register a callback!
+ * internal function that doesn't perform error checking. Used so the buffer
+ * can register a callback!
*/
void
oggplay_set_data_callback_force(OggPlay *me, OggPlayDataCallback callback,
Modified: liboggplay/trunk/src/liboggplay/oggplay_seek.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_seek.c 2007-06-21 12:02:59 UTC (rev 3020)
+++ liboggplay/trunk/src/liboggplay/oggplay_seek.c 2007-06-21 12:27:50 UTC (rev 3021)
@@ -41,6 +41,10 @@
OggPlayErrorCode
oggplay_seek(OggPlay *me, ogg_int64_t milliseconds) {
+ OggPlaySeekTrash * trash;
+ OggPlayDataHeader ** end_of_list_p;
+ int i;
+
if (me == NULL) {
return E_OGGPLAY_BAD_OGGPLAY;
}
@@ -55,6 +59,48 @@
return E_OGGPLAY_CANT_SEEK;
}
+ /*
+ * first, create a trash object to store the context that we want to
+ * delete but can't until the presentation thread is no longer using it -
+ * this will occur as soon as the thread calls oggplay_buffer_release_next
+ */
+
+ trash = malloc(sizeof(OggPlaySeekTrash));
+
+ /*
+ * store the old buffer in it next.
+ */
+ trash->old_buffer = me->buffer;
+
+ /*
+ * replace the buffer with a new one. From here on, the presentation thread
+ * will start using this buffer instead.
+ */
+ me->buffer = oggplay_buffer_new_buffer(me->buffer->buffer_size);
+ printf("installed buffer %p\n", me->buffer);
+
+ /*
+ * strip all of the data packets out of the streams and put them into the
+ * trash. We can free the untimed packets immediately - they are USELESS
+ * SCUM OF THE EARTH (and also unreferenced by the buffer).
+ */
+ end_of_list_p = &trash->old_data;
+ for (i = 0; i < me->num_tracks; i++) {
+ OggPlayDecode *track = me->decode_data[i];
+ *(end_of_list_p) = track->data_list;
+
+ end_of_list_p = &(track->end_of_data_list);
+ track->data_list = track->end_of_data_list = NULL;
+ oggplay_data_free_list(track->untimed_data_list);
+ track->untimed_data_list = NULL;
+ track->current_loc = -1;
+ }
+
+ /*
+ * set the presentation time
+ */
+ me->presentation_time = milliseconds;
+
return E_OGGPLAY_OK;
}
Modified: liboggplay/trunk/src/tools/glut-player.c
===================================================================
--- liboggplay/trunk/src/tools/glut-player.c 2007-06-21 12:02:59 UTC (rev 3020)
+++ liboggplay/trunk/src/tools/glut-player.c 2007-06-21 12:27:50 UTC (rev 3021)
@@ -318,6 +318,15 @@
//}
}
+typedef enum {
+ SEEK_FORWARD,
+ SEEK_BACKWARD
+} MessageEnum;
+
+MessageEnum msg;
+static sem_t msg_sem;
+
+
void key_pressed(unsigned char k, int a, int b) {
if (k == 'q') {
@@ -330,13 +339,11 @@
oggplay_close(player);
exit(0);
} else if (k == 'l') {
- if (oggplay_seek(player, ld_time + 5000) == E_OGGPLAY_CANT_SEEK) {
- printf("can't seek forwards!\n");
- }
+ msg = SEEK_FORWARD;
+ sem_post(&msg_sem);
} else if (k == 'k') {
- if (oggplay_seek(player, ld_time - 5000) == E_OGGPLAY_CANT_SEEK) {
- printf("cant seek backwards!\n");
- }
+ msg = SEEK_BACKWARD;
+ sem_post(&msg_sem);
}
}
@@ -369,6 +376,8 @@
}
#endif
+static unsigned int buf_size = 20;
+
void *drive_decoding(void *arg) {
while (1) {
@@ -376,9 +385,25 @@
sem_wait(&sem);
+ if (sem_trywait(&msg_sem) == 0) {
+ if (msg == SEEK_FORWARD) {
+ if (oggplay_seek(player, ld_time + 5000) == E_OGGPLAY_CANT_SEEK) {
+ printf("can't seek forwards!\n");
+ }
+ sem_init(&sem, 1, buf_size);
+ } else if (msg == SEEK_BACKWARD) {
+ if (oggplay_seek(player, ld_time - 5000) == E_OGGPLAY_CANT_SEEK) {
+ printf("cant seek backwards!\n");
+ }
+ sem_init(&sem, 1, buf_size);
+ }
+ msg = 0;
+ }
+
r = oggplay_step_decoding(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
sem_wait(&stop_sem);
#if DISPLAY_FRAMES
@@ -394,7 +419,6 @@
OggPlayReader * reader;
int i;
- unsigned int buf_size = 20;
pthread_t thread;
if (argc < 2) {
@@ -469,6 +493,9 @@
sem_init(&stop_sem, 1, 1);
sem_wait(&stop_sem);
+ sem_init(&msg_sem, 1, 1);
+ sem_wait(&msg_sem);
+
pthread_create(&thread, NULL, drive_decoding, NULL);
#if DISPLAY_FRAMES
More information about the commits
mailing list