summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2003-05-13 16:38:04 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2003-05-13 16:38:04 +0000
commit8f0f8da380bec0778a0b0bc89b28b352e1a39e05 (patch)
tree4cba85a58b9f93b5ed36e2599f287221c8a548c5 /src
parente65499e620848d325ad5a147ae84b712a71979d2 (diff)
downloadxine-lib-8f0f8da380bec0778a0b0bc89b28b352e1a39e05.tar.gz
xine-lib-8f0f8da380bec0778a0b0bc89b28b352e1a39e05.tar.bz2
support multiple callback registration
CVS patchset: 4840 CVS date: 2003/05/13 16:38:04
Diffstat (limited to 'src')
-rw-r--r--src/input/net_buf_ctrl.c64
-rw-r--r--src/xine-engine/buffer.c110
-rw-r--r--src/xine-engine/buffer.h14
3 files changed, 124 insertions, 64 deletions
diff --git a/src/input/net_buf_ctrl.c b/src/input/net_buf_ctrl.c
index a53bab639..2de2764bf 100644
--- a/src/input/net_buf_ctrl.c
+++ b/src/input/net_buf_ctrl.c
@@ -126,38 +126,6 @@ static void display_stats (nbc_t *this) {
}
}
-void nbc_close (nbc_t *this) {
- fifo_buffer_t *video_fifo = this->stream->video_fifo;
- fifo_buffer_t *audio_fifo = this->stream->audio_fifo;
-
-#ifdef LOG
- printf("\nnet_buf_ctrl: nbc_close\n");
-#endif
-
- video_fifo->register_put_cb(video_fifo, NULL, NULL);
- video_fifo->register_get_cb(video_fifo, NULL, NULL);
-
- if (audio_fifo) {
- audio_fifo->register_put_cb(audio_fifo, NULL, NULL);
- audio_fifo->register_get_cb(audio_fifo, NULL, NULL);
- }
-
- pthread_mutex_lock(&this->mutex);
- this->stream->xine->clock->set_option (this->stream->xine->clock, CLOCK_SCR_ADJUSTABLE, 1);
-
- if (this->buffering) {
- this->buffering = 0;
- nbc_set_speed_normal(this->stream);
- }
-
- pthread_mutex_unlock(&this->mutex);
-
- free (this);
-#ifdef LOG
- printf("\nnet_buf_ctrl: nbc_close: done\n");
-#endif
-}
-
/* Try to compute the length of the fifo in 1/1000 s
* 2 methods :
* if the bitrate is known
@@ -454,6 +422,38 @@ nbc_t *nbc_init (xine_stream_t *stream) {
return this;
}
+void nbc_close (nbc_t *this) {
+ fifo_buffer_t *video_fifo = this->stream->video_fifo;
+ fifo_buffer_t *audio_fifo = this->stream->audio_fifo;
+
+#ifdef LOG
+ printf("\nnet_buf_ctrl: nbc_close\n");
+#endif
+
+ video_fifo->unregister_put_cb(video_fifo, nbc_put_cb);
+ video_fifo->unregister_get_cb(video_fifo, nbc_get_cb);
+
+ if (audio_fifo) {
+ audio_fifo->unregister_put_cb(audio_fifo, nbc_put_cb);
+ audio_fifo->unregister_get_cb(audio_fifo, nbc_get_cb);
+ }
+
+ pthread_mutex_lock(&this->mutex);
+ this->stream->xine->clock->set_option (this->stream->xine->clock, CLOCK_SCR_ADJUSTABLE, 1);
+
+ if (this->buffering) {
+ this->buffering = 0;
+ nbc_set_speed_normal(this->stream);
+ }
+
+ pthread_mutex_unlock(&this->mutex);
+
+ free (this);
+#ifdef LOG
+ printf("\nnet_buf_ctrl: nbc_close: done\n");
+#endif
+}
+
void nbc_set_high_water_mark(nbc_t *this, int value) {
/*
diff --git a/src/xine-engine/buffer.c b/src/xine-engine/buffer.c
index 64142da08..0deca48b4 100644
--- a/src/xine-engine/buffer.c
+++ b/src/xine-engine/buffer.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: buffer.c,v 1.28 2003/05/12 11:51:18 jcdutton Exp $
+ * $Id: buffer.c,v 1.29 2003/05/13 16:38:05 miguelfreitas Exp $
*
*
* contents:
@@ -137,11 +137,12 @@ static buf_element_t *buffer_pool_try_alloc (fifo_buffer_t *this) {
* append buffer element to fifo buffer
*/
static void fifo_buffer_put (fifo_buffer_t *fifo, buf_element_t *element) {
-
+ int i;
+
pthread_mutex_lock (&fifo->mutex);
- if (fifo->put_cb)
- fifo->put_cb(fifo, element, fifo->put_cb_data);
+ for(i = 0; fifo->put_cb[i]; i++)
+ fifo->put_cb[i](fifo, element, fifo->put_cb_data[i]);
if (fifo->last)
fifo->last->next = element;
@@ -184,6 +185,7 @@ static void fifo_buffer_insert (fifo_buffer_t *fifo, buf_element_t *element) {
* get element from fifo buffer
*/
static buf_element_t *fifo_buffer_get (fifo_buffer_t *fifo) {
+ int i;
buf_element_t *buf;
@@ -202,8 +204,8 @@ static buf_element_t *fifo_buffer_get (fifo_buffer_t *fifo) {
fifo->fifo_size--;
fifo->fifo_data_size -= buf->size;
- if (fifo->get_cb)
- fifo->get_cb(fifo, buf, fifo->get_cb_data);
+ for(i = 0; fifo->get_cb[i]; i++)
+ fifo->get_cb[i](fifo, buf, fifo->get_cb_data[i]);
pthread_mutex_unlock (&fifo->mutex);
@@ -337,9 +339,15 @@ static void fifo_register_put_cb (fifo_buffer_t *this,
buf_element_t *buf,
void *data_cb),
void *data_cb) {
+ int i;
pthread_mutex_lock(&this->mutex);
- this->put_cb = cb;
- this->put_cb_data = data_cb;
+ for(i = 0; this->put_cb[i]; i++)
+ ;
+ if( i != BUF_MAX_CALLBACKS-1 ) {
+ this->put_cb[i] = cb;
+ this->put_cb_data[i] = data_cb;
+ this->put_cb[i+1] = NULL;
+ }
pthread_mutex_unlock(&this->mutex);
}
@@ -351,9 +359,55 @@ static void fifo_register_get_cb (fifo_buffer_t *this,
buf_element_t *buf,
void *data_cb),
void *data_cb) {
+ int i;
+ pthread_mutex_lock(&this->mutex);
+ for(i = 0; this->get_cb[i]; i++)
+ ;
+ if( i != BUF_MAX_CALLBACKS-1 ) {
+ this->get_cb[i] = cb;
+ this->get_cb_data[i] = data_cb;
+ this->get_cb[i+1] = NULL;
+ }
+ pthread_mutex_unlock(&this->mutex);
+}
+
+/*
+ * Unregister a "put" callback
+ */
+static void fifo_unregister_put_cb (fifo_buffer_t *this,
+ void (*cb)(fifo_buffer_t *this,
+ buf_element_t *buf,
+ void *data_cb) ) {
+ int i,j;
+ pthread_mutex_lock(&this->mutex);
+ for(i = 0; this->put_cb[i]; i++) {
+ if( this->put_cb[i] == cb ) {
+ for(j = i; this->put_cb[j]; j++) {
+ this->put_cb[j] = this->put_cb[j+1];
+ this->put_cb_data[j] = this->put_cb_data[j+1];
+ }
+ }
+ }
+ pthread_mutex_unlock(&this->mutex);
+}
+
+/*
+ * Unregister a "get" callback
+ */
+static void fifo_unregister_get_cb (fifo_buffer_t *this,
+ void (*cb)(fifo_buffer_t *this,
+ buf_element_t *buf,
+ void *data_cb) ) {
+ int i,j;
pthread_mutex_lock(&this->mutex);
- this->get_cb = cb;
- this->get_cb_data = data_cb;
+ for(i = 0; this->get_cb[i]; i++) {
+ if( this->get_cb[i] == cb ) {
+ for(j = i; this->get_cb[j]; j++) {
+ this->get_cb[j] = this->get_cb[j+1];
+ this->get_cb_data[j] = this->get_cb_data[j+1];
+ }
+ }
+ }
pthread_mutex_unlock(&this->mutex);
}
@@ -369,19 +423,21 @@ fifo_buffer_t *fifo_buffer_new (int num_buffers, uint32_t buf_size) {
this = xine_xmalloc (sizeof (fifo_buffer_t));
- this->first = NULL;
- this->last = NULL;
- this->fifo_size = 0;
- this->put = fifo_buffer_put;
- this->insert = fifo_buffer_insert;
- this->get = fifo_buffer_get;
- this->clear = fifo_buffer_clear;
- this->size = fifo_buffer_size;
- this->num_free = fifo_buffer_num_free;
- this->data_size = fifo_buffer_data_size;
- this->dispose = fifo_buffer_dispose;
- this->register_get_cb = fifo_register_get_cb;
- this->register_put_cb = fifo_register_put_cb;
+ this->first = NULL;
+ this->last = NULL;
+ this->fifo_size = 0;
+ this->put = fifo_buffer_put;
+ this->insert = fifo_buffer_insert;
+ this->get = fifo_buffer_get;
+ this->clear = fifo_buffer_clear;
+ this->size = fifo_buffer_size;
+ this->num_free = fifo_buffer_num_free;
+ this->data_size = fifo_buffer_data_size;
+ this->dispose = fifo_buffer_dispose;
+ this->register_get_cb = fifo_register_get_cb;
+ this->register_put_cb = fifo_register_put_cb;
+ this->unregister_get_cb = fifo_unregister_get_cb;
+ this->unregister_put_cb = fifo_unregister_put_cb;
pthread_mutex_init (&this->mutex, NULL);
pthread_cond_init (&this->not_empty, NULL);
@@ -426,10 +482,10 @@ fifo_buffer_t *fifo_buffer_new (int num_buffers, uint32_t buf_size) {
buffer_pool_free (buf);
}
- this->get_cb = NULL;
- this->put_cb = NULL;
- this->get_cb_data = NULL;
- this->put_cb_data = NULL;
+ this->get_cb[0] = NULL;
+ this->put_cb[0] = NULL;
+ this->get_cb_data[0] = NULL;
+ this->put_cb_data[0] = NULL;
return this;
}
diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h
index cb737a4ca..91a930f06 100644
--- a/src/xine-engine/buffer.h
+++ b/src/xine-engine/buffer.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: buffer.h,v 1.111 2003/05/10 04:26:18 tmmm Exp $
+ * $Id: buffer.h,v 1.112 2003/05/13 16:38:06 miguelfreitas Exp $
*
*
* contents:
@@ -48,6 +48,8 @@ extern "C" {
#include <sys/types.h>
#include "attributes.h"
+#define BUF_MAX_CALLBACKS 5
+
/*
* buffer types
*
@@ -451,6 +453,8 @@ struct fifo_buffer_s
void (*register_put_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *), void *cb_data);
void (*register_get_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *), void *cb_data);
+ void (*unregister_put_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *));
+ void (*unregister_get_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *));
/*
* private variables for buffer pool management
@@ -462,10 +466,10 @@ struct fifo_buffer_s
int buffer_pool_capacity;
int buffer_pool_buf_size;
void *buffer_pool_base; /*used to free mem chunk */
- void (*put_cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *data_cb);
- void (*get_cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *data_cb);
- void *put_cb_data;
- void *get_cb_data;
+ void (*put_cb[BUF_MAX_CALLBACKS])(fifo_buffer_t *fifo, buf_element_t *buf, void *data_cb);
+ void (*get_cb[BUF_MAX_CALLBACKS])(fifo_buffer_t *fifo, buf_element_t *buf, void *data_cb);
+ void *put_cb_data[BUF_MAX_CALLBACKS];
+ void *get_cb_data[BUF_MAX_CALLBACKS];
} ;
/*