From c2657bde789251c0b8e120861edb3f4f9989fc89 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 16 Apr 2004 16:34:22 +0000 Subject: - flush the events queue before returning from an open() so that the front-ends can receive error events before the end of xine_open() CVS patchset: 6410 CVS date: 2004/04/16 16:34:22 --- src/xine-engine/events.c | 11 +++++++++-- src/xine-engine/xine.c | 26 +++++++++++++++++++++++++- src/xine-engine/xine_internal.h | 8 +++++++- src/xine-utils/list.c | 4 ++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/xine-engine/events.c b/src/xine-engine/events.c index 2ac1c03b8..61fd01e04 100644 --- a/src/xine-engine/events.c +++ b/src/xine-engine/events.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: events.c,v 1.25 2004/04/15 19:36:57 f1rmb Exp $ + * $Id: events.c,v 1.26 2004/04/16 16:34:22 hadess Exp $ * * Event handling functions * @@ -112,6 +112,7 @@ xine_event_queue_t *xine_event_new_queue (xine_stream_t *stream) { pthread_mutex_init (&queue->lock, NULL); pthread_cond_init (&queue->new_event, NULL); + pthread_cond_init (&queue->events_processed, NULL); queue->events = xine_list_new (); queue->stream = stream; queue->listener_thread = NULL; @@ -198,10 +199,16 @@ static void *listener_loop (void *queue_gen) { if (event->type == XINE_EVENT_QUIT) running = 0; - + queue->callback (queue->user_data, event); xine_event_free (event); + + pthread_mutex_lock (&queue->lock); + if (xine_list_is_empty (queue->events)) { + pthread_cond_signal (&queue->events_processed); + } + pthread_mutex_unlock (&queue->lock); } return NULL; diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index ccc06b9de..625915008 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.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: xine.c,v 1.289 2004/04/09 11:26:10 f1rmb Exp $ + * $Id: xine.c,v 1.290 2004/04/16 16:34:22 hadess Exp $ */ /* @@ -623,6 +623,29 @@ static void __mrl_unescape(char *mrl) { mrl[len] = 0; } +void _x_flush_events_queues (xine_stream_t *stream) { + + xine_event_queue_t *queue; + + pthread_mutex_lock (&stream->event_queues_lock); + + /* No events queue? */ + for (queue = xine_list_first_content (stream->event_queues); + queue; queue = xine_list_next_content (stream->event_queues)) { + pthread_mutex_lock (&queue->lock); + pthread_mutex_unlock (&stream->event_queues_lock); + + while (!xine_list_is_empty (queue->events)) { + pthread_cond_wait (&queue->events_processed, &queue->lock); + } + + pthread_mutex_unlock (&queue->lock); + pthread_mutex_lock (&stream->event_queues_lock); + } + + pthread_mutex_unlock (&stream->event_queues_lock); +} + static int __open_internal (xine_stream_t *stream, const char *mrl) { const char *stream_setup; @@ -689,6 +712,7 @@ static int __open_internal (xine_stream_t *stream, const char *mrl) { if (!stream->input_plugin) { xine_log (stream->xine, XINE_LOG_MSG, _("xine: cannot find input plugin for MRL [%s]\n"),mrl); stream->err = XINE_ERROR_NO_INPUT_PLUGIN; + _x_flush_events_queues (stream); return 0; } diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h index 7638939e5..081baf9c9 100644 --- a/src/xine-engine/xine_internal.h +++ b/src/xine-engine/xine_internal.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: xine_internal.h,v 1.155 2004/03/23 22:54:32 valtri Exp $ + * $Id: xine_internal.h,v 1.156 2004/04/16 16:34:22 hadess Exp $ * */ @@ -178,6 +178,7 @@ struct xine_event_queue_s { xine_list_t *events; pthread_mutex_t lock; pthread_cond_t new_event; + pthread_cond_t events_processed; xine_stream_t *stream; pthread_t *listener_thread; xine_event_listener_cb_t callback; @@ -338,6 +339,11 @@ void _x_handle_stream_end (xine_stream_t *stream, int non_user); int _x_message(xine_stream_t *stream, int type, ...); +/* flush the message queues */ + +void _x_flush_events_queues (xine_stream_t *stream); + + /* find and instantiate input and demux plugins */ input_plugin_t *_x_find_input_plugin (xine_stream_t *stream, const char *mrl); diff --git a/src/xine-utils/list.c b/src/xine-utils/list.c index df57afcb7..15f646d96 100644 --- a/src/xine-utils/list.c +++ b/src/xine-utils/list.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: list.c,v 1.7 2003/12/09 00:02:38 f1rmb Exp $ + * $Id: list.c,v 1.8 2004/04/16 16:34:23 hadess Exp $ * */ #ifdef HAVE_CONFIG_H @@ -107,7 +107,7 @@ int xine_list_is_empty (xine_list_t *l) { fprintf(stderr, "%s(): list is NULL\n", __XINE_FUNCTION__); return -1; } - return (l->first != NULL); + return (l->first == NULL); } void *xine_list_last_content (xine_list_t *l) { -- cgit v1.2.3