diff options
Diffstat (limited to 'src/demuxers/demux_realaudio.c')
-rw-r--r-- | src/demuxers/demux_realaudio.c | 206 |
1 files changed, 46 insertions, 160 deletions
diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c index 570ae9851..d3a4eb453 100644 --- a/src/demuxers/demux_realaudio.c +++ b/src/demuxers/demux_realaudio.c @@ -19,7 +19,7 @@ * * RealAudio File Demuxer by Mike Melanson (melanson@pcisys.net) * - * $Id: demux_realaudio.c,v 1.1 2002/10/27 18:00:30 tmmm Exp $ + * $Id: demux_realaudio.c,v 1.2 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> @@ -58,10 +56,6 @@ typedef struct { input_plugin_t *input; - pthread_t thread; - int thread_running; - pthread_mutex_t mutex; - int send_end_buffers; int status; xine_waveformatex wave; @@ -121,7 +115,7 @@ static int open_ra_file(demux_ra_t *this) { return 1; } -static void *demux_ra_loop (void *this_gen) { +static int demux_ra_send_chunk(demux_plugin_t *this_gen) { demux_ra_t *this = (demux_ra_t *) this_gen; buf_element_t *buf = NULL; @@ -129,91 +123,50 @@ static void *demux_ra_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->wave.nBlockAlign; - current_file_pos = - this->input->get_current_pos(this->input) - this->data_start; - - - - current_pts = 0; /* let the engine sort out the pts for now */ - + /* 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->wave.nBlockAlign; + current_file_pos = + this->input->get_current_pos(this->input) - this->data_start; - 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; + current_pts = 0; /* let the engine sort out the pts for now */ - 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_ra: 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); + if (!remaining_sample_bytes) + buf->decoder_flags |= BUF_FLAG_FRAME_END; - this->status = DEMUX_FINISHED; - - 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_ra_send_headers(demux_plugin_t *this_gen) { @@ -221,8 +174,6 @@ static void demux_ra_send_headers(demux_plugin_t *this_gen) { demux_ra_t *this = (demux_ra_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; @@ -256,58 +207,19 @@ static void demux_ra_send_headers(demux_plugin_t *this_gen) { } xine_demux_control_headers_done (this->stream); - - pthread_mutex_unlock (&this->mutex); -} - -static int demux_ra_seek (demux_plugin_t *this_gen, - off_t start_pos, int start_time); - - -static int demux_ra_start (demux_plugin_t *this_gen, - off_t start_pos, int start_time) { - - demux_ra_t *this = (demux_ra_t *) this_gen; - int err; - - demux_ra_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_ra_loop, this)) != 0) - { - printf ("demux_ra: can't create new thread (%s)\n", strerror(err)); - abort(); - } - } - - pthread_mutex_unlock(&this->mutex); - - return DEMUX_OK; } static int demux_ra_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time) { demux_ra_t *this = (demux_ra_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) { - status = this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - return status; + this->status = DEMUX_FINISHED; + 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 @@ -322,46 +234,22 @@ static int demux_ra_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_ra_stop (demux_plugin_t *this_gen) { - - demux_ra_t *this = (demux_ra_t *) this_gen; - void *p; - - pthread_mutex_lock( &this->mutex ); + + /* if thread is not running, initialize demuxer */ + if( !this->stream->demux_thread_running ) { - if (!this->thread_running) { - pthread_mutex_unlock( &this->mutex ); - return; + this->status = DEMUX_OK; } - /* 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_ra_dispose (demux_plugin_t *this_gen) { demux_ra_t *this = (demux_ra_t *) this_gen; - demux_ra_stop(this_gen); - - pthread_mutex_destroy (&this->mutex); free(this); } @@ -395,16 +283,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_ra_send_headers; - this->demux_plugin.start = demux_ra_start; + this->demux_plugin.send_chunk = demux_ra_send_chunk; this->demux_plugin.seek = demux_ra_seek; - this->demux_plugin.stop = demux_ra_stop; this->demux_plugin.dispose = demux_ra_dispose; this->demux_plugin.get_status = demux_ra_get_status; this->demux_plugin.get_stream_length = demux_ra_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) { @@ -511,7 +397,7 @@ 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, "realaudio", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_DEMUX, 15, "realaudio", XINE_VERSION_CODE, NULL, init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; |