diff options
Diffstat (limited to 'src/demuxers/demux_snd.c')
-rw-r--r-- | src/demuxers/demux_snd.c | 210 |
1 files changed, 45 insertions, 165 deletions
diff --git a/src/demuxers/demux_snd.c b/src/demuxers/demux_snd.c index bc4bdf2dc..c2d40500c 100644 --- a/src/demuxers/demux_snd.c +++ b/src/demuxers/demux_snd.c @@ -19,7 +19,7 @@ * * SND/AU File Demuxer by Mike Melanson (melanson@pcisys.net) * - * $Id: demux_snd.c,v 1.14 2002/10/27 16:14:29 tmmm Exp $ + * $Id: demux_snd.c,v 1.15 2002/10/28 03:24:43 miguelfreitas Exp $ * */ @@ -30,8 +30,6 @@ #include <stdio.h> #include <fcntl.h> #include <unistd.h> -#include <pthread.h> -#include <sched.h> #include <string.h> #include <stdlib.h> #include <ctype.h> @@ -60,10 +58,6 @@ typedef struct { input_plugin_t *input; - pthread_t thread; - int thread_running; - pthread_mutex_t mutex; - int send_end_buffers; int status; unsigned int audio_type; @@ -169,7 +163,7 @@ static int open_snd_file(demux_snd_t *this) { return 1; } -static void *demux_snd_loop (void *this_gen) { +static int demux_snd_send_chunk(demux_plugin_t *this_gen) { demux_snd_t *this = (demux_snd_t *) this_gen; buf_element_t *buf = NULL; @@ -177,89 +171,48 @@ static void *demux_snd_loop (void *this_gen) { off_t current_file_pos; int64_t current_pts; - pthread_mutex_lock( &this->mutex ); - this->seek_flag = 1; - - /* do-while needed to seek after demux finished */ - do { - /* main demuxer loop */ - while (this->status == DEMUX_OK) { - - /* someone may want to interrupt us */ - pthread_mutex_unlock( &this->mutex ); - /* give demux_*_stop a chance to interrupt us */ - sched_yield(); - pthread_mutex_lock( &this->mutex ); - - /* just load data chunks from wherever the stream happens to be - * pointing; issue a DEMUX_FINISHED status if EOF is reached */ - remaining_sample_bytes = this->audio_block_align; - current_file_pos = - this->input->get_current_pos(this->input) - this->data_start; - - current_pts = current_file_pos; - current_pts *= 90000; - current_pts /= this->audio_bytes_per_second; - - if (this->seek_flag) { - xine_demux_control_newpts(this->stream, current_pts, 0); - this->seek_flag = 0; - } - - while (remaining_sample_bytes) { - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - buf->type = this->audio_type; - buf->input_pos = current_file_pos; - buf->input_length = this->data_size; - buf->input_time = current_pts / 90000; - buf->pts = current_pts; - - if (remaining_sample_bytes > buf->max_size) - buf->size = buf->max_size; - else - buf->size = remaining_sample_bytes; - remaining_sample_bytes -= buf->size; - - if (this->input->read(this->input, buf->content, buf->size) != - buf->size) { - buf->free_buffer(buf); - this->status = DEMUX_FINISHED; - break; - } - - if (!remaining_sample_bytes) - buf->decoder_flags |= BUF_FLAG_FRAME_END; - - this->audio_fifo->put (this->audio_fifo, buf); - } - } + /* just load data chunks from wherever the stream happens to be + * pointing; issue a DEMUX_FINISHED status if EOF is reached */ + remaining_sample_bytes = this->audio_block_align; + current_file_pos = + this->input->get_current_pos(this->input) - this->data_start; - /* wait before sending end buffers: user might want to do a new seek */ - while(this->send_end_buffers && this->audio_fifo->size(this->audio_fifo) && - this->status != DEMUX_OK){ - pthread_mutex_unlock( &this->mutex ); - xine_usec_sleep(100000); - pthread_mutex_lock( &this->mutex ); - } + current_pts = current_file_pos; + current_pts *= 90000; + current_pts /= this->audio_bytes_per_second; - } while (this->status == DEMUX_OK); - - printf ("demux_snd: demux loop finished (status: %d)\n", - this->status); + if (this->seek_flag) { + xine_demux_control_newpts(this->stream, current_pts, 0); + this->seek_flag = 0; + } - /* seek back to the beginning of the data in preparation for another - * start */ - this->input->seek(this->input, this->data_start, SEEK_SET); + while (remaining_sample_bytes) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = this->audio_type; + buf->input_pos = current_file_pos; + buf->input_length = this->data_size; + buf->input_time = current_pts / 90000; + buf->pts = current_pts; + + if (remaining_sample_bytes > buf->max_size) + buf->size = buf->max_size; + else + buf->size = remaining_sample_bytes; + remaining_sample_bytes -= buf->size; + + if (this->input->read(this->input, buf->content, buf->size) != + buf->size) { + buf->free_buffer(buf); + this->status = DEMUX_FINISHED; + break; + } - this->status = DEMUX_FINISHED; + if (!remaining_sample_bytes) + buf->decoder_flags |= BUF_FLAG_FRAME_END; - if (this->send_end_buffers) { - xine_demux_control_end(this->stream, BUF_FLAG_END_STREAM); + this->audio_fifo->put (this->audio_fifo, buf); } - - this->thread_running = 0; - pthread_mutex_unlock(&this->mutex); - return NULL; + return this->status; } static void demux_snd_send_headers(demux_plugin_t *this_gen) { @@ -267,8 +220,6 @@ static void demux_snd_send_headers(demux_plugin_t *this_gen) { demux_snd_t *this = (demux_snd_t *) this_gen; buf_element_t *buf; - pthread_mutex_lock(&this->mutex); - this->video_fifo = this->stream->video_fifo; this->audio_fifo = this->stream->audio_fifo; @@ -301,57 +252,19 @@ static void demux_snd_send_headers(demux_plugin_t *this_gen) { } xine_demux_control_headers_done (this->stream); - - pthread_mutex_unlock (&this->mutex); -} - -static int demux_snd_seek (demux_plugin_t *this_gen, - off_t start_pos, int start_time); - -static int demux_snd_start (demux_plugin_t *this_gen, - off_t start_pos, int start_time) { - - demux_snd_t *this = (demux_snd_t *) this_gen; - int err; - - demux_snd_seek(this_gen, start_pos, start_time); - - pthread_mutex_lock(&this->mutex); - - /* if thread is not running, initialize demuxer */ - if (!this->thread_running) { - - this->status = DEMUX_OK; - this->send_end_buffers = 1; - this->thread_running = 1; - - if ((err = pthread_create (&this->thread, NULL, demux_snd_loop, this)) != 0) { - printf ("demux_snd: can't create new thread (%s)\n", strerror(err)); - abort(); - } - } - - pthread_mutex_unlock(&this->mutex); - - return DEMUX_OK; } static int demux_snd_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time) { demux_snd_t *this = (demux_snd_t *) this_gen; - int status; - - pthread_mutex_lock(&this->mutex); - + /* check the boundary offsets */ if (start_pos < 0) this->input->seek(this->input, this->data_start, SEEK_SET); else if (start_pos >= this->data_size) { this->status = DEMUX_FINISHED; - status = this->status; - pthread_mutex_unlock(&this->mutex); - return status; + return this->status; } else { /* This function must seek along the block alignment. The start_pos * is in reference to the start of the data. Divide the start_pos by @@ -366,46 +279,15 @@ static int demux_snd_seek (demux_plugin_t *this_gen, } this->seek_flag = 1; - status = this->status = DEMUX_OK; + this->status = DEMUX_OK; xine_demux_flush_engine (this->stream); - pthread_mutex_unlock(&this->mutex); - - return status; -} - -static void demux_snd_stop (demux_plugin_t *this_gen) { - - demux_snd_t *this = (demux_snd_t *) this_gen; - void *p; - - pthread_mutex_lock( &this->mutex ); - - if (!this->thread_running) { - pthread_mutex_unlock( &this->mutex ); - return; - } - - /* seek back to the beginning of the data in preparation for another - * start */ - this->input->seek(this->input, this->data_start, SEEK_SET); - - this->send_end_buffers = 0; - this->status = DEMUX_FINISHED; - - pthread_mutex_unlock( &this->mutex ); - pthread_join (this->thread, &p); - - xine_demux_flush_engine(this->stream); - - xine_demux_control_end(this->stream, BUF_FLAG_END_USER); + + return this->status; } static void demux_snd_dispose (demux_plugin_t *this_gen) { demux_snd_t *this = (demux_snd_t *) this_gen; - demux_snd_stop(this_gen); - - pthread_mutex_destroy (&this->mutex); free(this); } @@ -439,16 +321,14 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str this->input = input; this->demux_plugin.send_headers = demux_snd_send_headers; - this->demux_plugin.start = demux_snd_start; + this->demux_plugin.send_chunk = demux_snd_send_chunk; this->demux_plugin.seek = demux_snd_seek; - this->demux_plugin.stop = demux_snd_stop; this->demux_plugin.dispose = demux_snd_dispose; this->demux_plugin.get_status = demux_snd_get_status; this->demux_plugin.get_stream_length = demux_snd_get_stream_length; this->demux_plugin.demux_class = class_gen; this->status = DEMUX_FINISHED; - pthread_mutex_init (&this->mutex, NULL); switch (stream->content_detection_method) { @@ -557,6 +437,6 @@ static void *init_plugin (xine_t *xine, void *data) { plugin_info_t xine_plugin_info[] = { /* type, API, "name", version, special_info, init_function */ - { PLUGIN_DEMUX, 14, "snd", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_DEMUX, 15, "snd", XINE_VERSION_CODE, NULL, init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; |