diff options
Diffstat (limited to 'src/demuxers/demux_aiff.c')
-rw-r--r-- | src/demuxers/demux_aiff.c | 207 |
1 files changed, 43 insertions, 164 deletions
diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c index e1881e437..9a8ae2ad6 100644 --- a/src/demuxers/demux_aiff.c +++ b/src/demuxers/demux_aiff.c @@ -19,7 +19,7 @@ * * AIFF File Demuxer by Mike Melanson (melanson@pcisys.net) * - * $Id: demux_aiff.c,v 1.13 2002/10/27 16:14:22 tmmm Exp $ + * $Id: demux_aiff.c,v 1.14 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> @@ -71,10 +69,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; @@ -138,7 +132,6 @@ static int open_aiff_file(demux_aiff_t *this) { if (this->input->read(this->input, preamble, PREAMBLE_SIZE) != PREAMBLE_SIZE) { this->status = DEMUX_FINISHED; - pthread_mutex_lock(&this->mutex); return DEMUX_CANNOT_HANDLE; } chunk_type = BE_32(&preamble[0]); @@ -148,7 +141,6 @@ static int open_aiff_file(demux_aiff_t *this) { if (this->input->read(this->input, buffer, chunk_size) != chunk_size) { this->status = DEMUX_FINISHED; - pthread_mutex_lock(&this->mutex); return DEMUX_CANNOT_HANDLE; } @@ -187,7 +179,7 @@ static int open_aiff_file(demux_aiff_t *this) { return 1; } -static void *demux_aiff_loop (void *this_gen) { +static int demux_aiff_send_chunk (demux_plugin_t *this_gen) { demux_aiff_t *this = (demux_aiff_t *) this_gen; buf_element_t *buf = NULL; @@ -195,89 +187,49 @@ static void *demux_aiff_loop (void *this_gen) { off_t current_file_pos; int64_t current_pts; - pthread_mutex_lock( &this->mutex ); - this->seek_flag = 1; + /* 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; - /* 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; - } + current_pts = current_file_pos; + current_pts *= 90000; + current_pts /= this->audio_bytes_per_second; - 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); - } - } + if (this->seek_flag) { + xine_demux_control_newpts(this->stream, current_pts, 0); + this->seek_flag = 0; + } - /* 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 ); + 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; } - } while (this->status == DEMUX_OK); - - printf ("demux_aiff: demux loop finished (status: %d)\n", - this->status); - - /* seek back to the beginning of the data in preparation for another - * start */ - this->input->seek(this->input, this->data_start, SEEK_SET); - - 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_aiff_send_headers(demux_plugin_t *this_gen) { @@ -285,8 +237,6 @@ static void demux_aiff_send_headers(demux_plugin_t *this_gen) { demux_aiff_t *this = (demux_aiff_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; @@ -319,57 +269,19 @@ static void demux_aiff_send_headers(demux_plugin_t *this_gen) { } xine_demux_control_headers_done (this->stream); - - pthread_mutex_unlock (&this->mutex); -} - -static int demux_aiff_seek (demux_plugin_t *this_gen, - off_t start_pos, int start_time); - -static int demux_aiff_start (demux_plugin_t *this_gen, - off_t start_pos, int start_time) { - - demux_aiff_t *this = (demux_aiff_t *) this_gen; - int err; - - demux_aiff_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_aiff_loop, this)) != 0) { - printf ("demux_aiff: can't create new thread (%s)\n", strerror(err)); - abort(); - } - } - - pthread_mutex_unlock(&this->mutex); - - return DEMUX_OK; } static int demux_aiff_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time) { demux_aiff_t *this = (demux_aiff_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 @@ -384,46 +296,15 @@ static int demux_aiff_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_aiff_stop (demux_plugin_t *this_gen) { - demux_aiff_t *this = (demux_aiff_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_aiff_dispose (demux_plugin_t *this_gen) { demux_aiff_t *this = (demux_aiff_t *) this_gen; - demux_aiff_stop(this_gen); - - pthread_mutex_destroy (&this->mutex); free(this); } @@ -457,16 +338,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_aiff_send_headers; - this->demux_plugin.start = demux_aiff_start; + this->demux_plugin.send_chunk = demux_aiff_send_chunk; this->demux_plugin.seek = demux_aiff_seek; - this->demux_plugin.stop = demux_aiff_stop; this->demux_plugin.dispose = demux_aiff_dispose; this->demux_plugin.get_status = demux_aiff_get_status; this->demux_plugin.get_stream_length = demux_aiff_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) { @@ -574,6 +453,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, "aiff", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_DEMUX, 15, "aiff", XINE_VERSION_CODE, NULL, init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; |