From: Miguel F. <mig...@us...> - 2003-05-13 16:38:10
|
Update of /cvsroot/xine/xine-lib/src/xine-engine In directory sc8-pr-cvs1:/tmp/cvs-serv17373/src/xine-engine Modified Files: buffer.c buffer.h Log Message: support multiple callback registration Index: buffer.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/xine-engine/buffer.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- buffer.c 12 May 2003 11:51:18 -0000 1.28 +++ buffer.c 13 May 2003 16:38:05 -0000 1.29 @@ -137,11 +137,12 @@ * 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 @@ * 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; } Index: buffer.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/xine-engine/buffer.h,v retrieving revision 1.111 retrieving revision 1.112 diff -u -r1.111 -r1.112 --- buffer.h 10 May 2003 04:26:18 -0000 1.111 +++ buffer.h 13 May 2003 16:38:06 -0000 1.112 @@ -48,6 +48,8 @@ #include <sys/types.h> #include "attributes.h" +#define BUF_MAX_CALLBACKS 5 + /* * buffer types * @@ -451,6 +453,8 @@ 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 @@ 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]; } ; /* |