diff options
Diffstat (limited to 'src/demuxers/demux_cda.c')
-rw-r--r-- | src/demuxers/demux_cda.c | 96 |
1 files changed, 63 insertions, 33 deletions
diff --git a/src/demuxers/demux_cda.c b/src/demuxers/demux_cda.c index 064e83b81..e7a5731a8 100644 --- a/src/demuxers/demux_cda.c +++ b/src/demuxers/demux_cda.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: demux_cda.c,v 1.10 2002/03/27 15:30:16 miguelfreitas Exp $ + * $Id: demux_cda.c,v 1.11 2002/04/09 03:38:00 miguelfreitas Exp $ */ #ifdef HAVE_CONFIG_H @@ -52,7 +52,8 @@ typedef struct { input_plugin_t *input; pthread_t thread; - + pthread_mutex_t mutex; + off_t start; int status; @@ -92,17 +93,22 @@ static void *demux_cda_loop (void *this_gen) { this->send_end_buffers = 1; - this->input->seek(this->input, this->start, SEEK_SET); - - do { - + while(1) { + + pthread_mutex_lock( &this->mutex ); + + if( this->status != DEMUX_OK) + break; + xine_usec_sleep(100000); if (!demux_cda_next(this)) this->status = DEMUX_FINISHED; - - } while (this->status == DEMUX_OK) ; - + + pthread_mutex_unlock( &this->mutex ); + + } + this->status = DEMUX_FINISHED; if (this->send_end_buffers) { @@ -118,6 +124,8 @@ static void *demux_cda_loop (void *this_gen) { this->audio_fifo->put (this->audio_fifo, buf); } } + + pthread_mutex_unlock( &this->mutex ); pthread_exit(NULL); } @@ -130,23 +138,23 @@ static void demux_cda_stop (demux_plugin_t *this_gen) { buf_element_t *buf; void *p; + pthread_mutex_lock( &this->mutex ); + if (this->status != DEMUX_OK) { printf ("demux_cda: stop...ignored\n"); return; } - + /* Force stop */ this->input->stop(this->input); this->send_end_buffers = 0; - this->status = DEMUX_FINISHED; + this->status = DEMUX_FINISHED; - pthread_cancel(this->thread); - pthread_join(this->thread, &p); + pthread_mutex_unlock( &this->mutex ); + pthread_join (this->thread, &p); - this->video_fifo->clear(this->video_fifo); - if (this->audio_fifo) - this->audio_fifo->clear(this->audio_fifo); + xine_flush_engine(this->xine); buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); buf->type = BUF_CONTROL_END; @@ -182,33 +190,51 @@ static void demux_cda_start (demux_plugin_t *this_gen, buf_element_t *buf; int err; - this->video_fifo = video_fifo; - this->audio_fifo = audio_fifo; - - this->status = DEMUX_OK; + pthread_mutex_lock( &this->mutex ); + this->start = start_pos; this->blocksize = this->input->get_blocksize(this->input); - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - buf->type = BUF_CONTROL_START; - this->video_fifo->put (this->video_fifo, buf); + if( this->status != DEMUX_OK ) { + this->video_fifo = video_fifo; + this->audio_fifo = audio_fifo; - if(this->audio_fifo) { - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); buf->type = BUF_CONTROL_START; - this->audio_fifo->put (this->audio_fifo, buf); - } + this->video_fifo->put (this->video_fifo, buf); + if(this->audio_fifo) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = BUF_CONTROL_START; + this->audio_fifo->put (this->audio_fifo, buf); + } + } + /* * now start demuxing */ - - if ((err = pthread_create (&this->thread, - NULL, demux_cda_loop, this)) != 0) { - printf ("demux_cda: can't create new thread (%s)\n", strerror(err)); - exit(1); + this->input->seek(this->input, this->start, SEEK_SET); + + if( this->status != DEMUX_OK ) { + + this->status = DEMUX_OK; + if ((err = pthread_create (&this->thread, + NULL, demux_cda_loop, this)) != 0) { + printf ("demux_cda: can't create new thread (%s)\n", strerror(err)); + exit(1); + } } + pthread_mutex_unlock( &this->mutex ); +} + + +static void demux_cda_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time) { + demux_cda_t *this = (demux_cda_t *) this_gen; + + demux_cda_start (this_gen, this->video_fifo, this->audio_fifo, + start_pos, start_time); } /* @@ -280,7 +306,7 @@ static int demux_cda_get_stream_length (demux_plugin_t *this_gen) { demux_plugin_t *init_demuxer_plugin(int iface, xine_t *xine) { demux_cda_t *this; - if (iface != 6) { + if (iface != 7) { printf ("demux_cda: plugin doesn't support plugin API version %d.\n" " this means there's a version mismatch between xine and this " " demuxer plugin.\nInstalling current demux plugins should help.\n", @@ -295,6 +321,7 @@ demux_plugin_t *init_demuxer_plugin(int iface, xine_t *xine) { this->demux_plugin.interface_version = DEMUX_CDA_IFACE_VERSION; this->demux_plugin.open = demux_cda_open; this->demux_plugin.start = demux_cda_start; + this->demux_plugin.seek = demux_cda_seek; this->demux_plugin.stop = demux_cda_stop; this->demux_plugin.close = demux_cda_close; this->demux_plugin.get_status = demux_cda_get_status; @@ -302,5 +329,8 @@ demux_plugin_t *init_demuxer_plugin(int iface, xine_t *xine) { this->demux_plugin.get_stream_length = demux_cda_get_stream_length; this->demux_plugin.get_mimetypes = demux_cda_get_mimetypes; + this->status = DEMUX_FINISHED; + pthread_mutex_init( &this->mutex, NULL ); + return &this->demux_plugin; } |