diff options
Diffstat (limited to 'src/demuxers/demux_idcin.c')
-rw-r--r-- | src/demuxers/demux_idcin.c | 337 |
1 files changed, 118 insertions, 219 deletions
diff --git a/src/demuxers/demux_idcin.c b/src/demuxers/demux_idcin.c index 76563f885..163caf8a3 100644 --- a/src/demuxers/demux_idcin.c +++ b/src/demuxers/demux_idcin.c @@ -63,7 +63,7 @@ * - if any bytes exceed 63, do not shift the bytes at all before * transmitting them to the video decoder * - * $Id: demux_idcin.c,v 1.22 2002/10/27 16:14:26 tmmm Exp $ + * $Id: demux_idcin.c,v 1.23 2002/10/28 03:24:43 miguelfreitas Exp $ */ #ifdef HAVE_CONFIG_H @@ -73,8 +73,6 @@ #include <stdio.h> #include <fcntl.h> #include <unistd.h> -#include <pthread.h> -#include <sched.h> #include <string.h> #include <stdlib.h> @@ -102,11 +100,6 @@ typedef struct { input_plugin_t *input; - pthread_t thread; - int thread_running; - pthread_mutex_t mutex; - int send_end_buffers; - off_t start; off_t filesize; int status; @@ -135,7 +128,7 @@ typedef struct { config_values_t *config; } demux_idcin_class_t; -static void *demux_idcin_loop (void *this_gen) { +static int demux_idcin_send_chunk(demux_plugin_t *this_gen) { demux_idcin_t *this = (demux_idcin_t *) this_gen; buf_element_t *buf = NULL; @@ -150,175 +143,134 @@ static void *demux_idcin_loop (void *this_gen) { int current_audio_chunk = 1; int scale_bits; - pthread_mutex_lock( &this->mutex ); - - /* reposition stream past the Huffman tables */ - this->input->seek(this->input, 0x14 + 0x10000, SEEK_SET); - - /* 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 ); + current_file_pos = this->input->get_current_pos(this->input); - current_file_pos = this->input->get_current_pos(this->input); - - /* figure out what the next data is */ - if (this->input->read(this->input, (unsigned char *)&command, 4) != 4) { - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - break; - } + /* figure out what the next data is */ + if (this->input->read(this->input, (unsigned char *)&command, 4) != 4) { + this->status = DEMUX_FINISHED; + return this->status; + } - command = le2me_32(command); - if (command == 2) { + command = le2me_32(command); + if (command == 2) { + this->status = DEMUX_FINISHED; + return this->status; + } else { + if (command == 1) { + /* load a 768-byte palette and pass it to the demuxer */ + if (this->input->read(this->input, disk_palette, PALETTE_SIZE * 3) != + PALETTE_SIZE * 3) { this->status = DEMUX_FINISHED; - break; - } else { - if (command == 1) { - /* load a 768-byte palette and pass it to the demuxer */ - if (this->input->read(this->input, disk_palette, PALETTE_SIZE * 3) != - PALETTE_SIZE * 3) { - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - break; - } - - /* scan the palette to figure out if it's 6- or 8-bit; - * assume 6-bit palette until a value > 63 is seen */ - scale_bits = 2; - for (i = 0; i < PALETTE_SIZE * 3; i++) - if (disk_palette[i] > 63) { - scale_bits = 0; - break; - } - - /* convert palette to internal structure */ - for (i = 0; i < PALETTE_SIZE; i++) { - /* these are VGA color DAC values, which means they only range - * from 0..63; adjust as appropriate */ - palette[i].r = disk_palette[i * 3 + 0] << scale_bits; - palette[i].g = disk_palette[i * 3 + 1] << scale_bits; - palette[i].b = disk_palette[i * 3 + 2] << scale_bits; - } - - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - buf->decoder_flags = BUF_FLAG_SPECIAL; - buf->decoder_info[1] = BUF_SPECIAL_PALETTE; - buf->decoder_info[2] = PALETTE_SIZE; - buf->decoder_info[3] = (unsigned int)&palette; - buf->size = 0; - buf->type = BUF_VIDEO_IDCIN; - this->video_fifo->put (this->video_fifo, buf); - } + return this->status; } - /* load the video frame */ - if (this->input->read(this->input, preamble, 8) != 8) { - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - break; - } - remaining_sample_bytes = LE_32(&preamble[0]) - 4; - - while (remaining_sample_bytes) { - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - buf->type = BUF_VIDEO_IDCIN; - buf->input_pos = this->input->get_current_pos(this->input); - buf->input_length = this->filesize; - buf->input_time = pts_counter / 90000; - buf->pts = pts_counter; - - 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; + /* scan the palette to figure out if it's 6- or 8-bit; + * assume 6-bit palette until a value > 63 is seen */ + scale_bits = 2; + for (i = 0; i < PALETTE_SIZE * 3; i++) + if (disk_palette[i] > 63) { + scale_bits = 0; break; } - /* all frames are intra-coded */ - buf->decoder_flags |= BUF_FLAG_KEYFRAME; - if (!remaining_sample_bytes) - buf->decoder_flags |= BUF_FLAG_FRAME_END; - - this->video_fifo->put(this->video_fifo, buf); + /* convert palette to internal structure */ + for (i = 0; i < PALETTE_SIZE; i++) { + /* these are VGA color DAC values, which means they only range + * from 0..63; adjust as appropriate */ + palette[i].r = disk_palette[i * 3 + 0] << scale_bits; + palette[i].g = disk_palette[i * 3 + 1] << scale_bits; + palette[i].b = disk_palette[i * 3 + 2] << scale_bits; } - /* load the audio frame */ - if (this->audio_fifo && this->audio_sample_rate) { + buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf->decoder_flags = BUF_FLAG_SPECIAL; + buf->decoder_info[1] = BUF_SPECIAL_PALETTE; + buf->decoder_info[2] = PALETTE_SIZE; + buf->decoder_info[3] = (unsigned int)&palette; + buf->size = 0; + buf->type = BUF_VIDEO_IDCIN; + this->video_fifo->put (this->video_fifo, buf); + } + } + + /* load the video frame */ + if (this->input->read(this->input, preamble, 8) != 8) { + this->status = DEMUX_FINISHED; + return this->status; + } + remaining_sample_bytes = LE_32(&preamble[0]) - 4; + + while (remaining_sample_bytes) { + buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf->type = BUF_VIDEO_IDCIN; + buf->input_pos = this->input->get_current_pos(this->input); + buf->input_length = this->filesize; + buf->input_time = pts_counter / 90000; + buf->pts = pts_counter; + + 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 (current_audio_chunk == 1) { - remaining_sample_bytes = this->audio_chunk_size1; - current_audio_chunk = 2; - } else { - remaining_sample_bytes = this->audio_chunk_size2; - current_audio_chunk = 1; - } + /* all frames are intra-coded */ + buf->decoder_flags |= BUF_FLAG_KEYFRAME; + if (!remaining_sample_bytes) + buf->decoder_flags |= BUF_FLAG_FRAME_END; - while (remaining_sample_bytes) { - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - buf->type = BUF_AUDIO_LPCM_LE; - buf->input_pos = this->input->get_current_pos(this->input); - buf->input_length = this->filesize; - buf->input_time = pts_counter / 90000; - buf->pts = pts_counter; - - 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); - } - } + this->video_fifo->put(this->video_fifo, buf); + } - pts_counter += IDCIN_FRAME_PTS_INC; - } + /* load the audio frame */ + if (this->audio_fifo && this->audio_sample_rate) { - /* wait before sending end buffers: user might want to do a new seek */ - while(this->send_end_buffers && this->video_fifo->size(this->video_fifo) && - this->status != DEMUX_OK){ - pthread_mutex_unlock( &this->mutex ); - xine_usec_sleep(100000); - pthread_mutex_lock( &this->mutex ); + if (current_audio_chunk == 1) { + remaining_sample_bytes = this->audio_chunk_size1; + current_audio_chunk = 2; + } else { + remaining_sample_bytes = this->audio_chunk_size2; + current_audio_chunk = 1; } - } while (this->status == DEMUX_OK); - - printf ("demux_idcin: demux loop finished (status: %d)\n", - this->status); + while (remaining_sample_bytes) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = BUF_AUDIO_LPCM_LE; + buf->input_pos = this->input->get_current_pos(this->input); + buf->input_length = this->filesize; + buf->input_time = pts_counter / 90000; + buf->pts = pts_counter; + + 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; + pts_counter += IDCIN_FRAME_PTS_INC; + + return this->status; } /* returns 1 if the CIN file was opened successfully, 0 otherwise */ @@ -366,8 +318,6 @@ static void demux_idcin_send_headers(demux_plugin_t *this_gen) { demux_idcin_t *this = (demux_idcin_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; @@ -425,80 +375,31 @@ static void demux_idcin_send_headers(demux_plugin_t *this_gen) { } xine_demux_control_headers_done (this->stream); - - pthread_mutex_unlock (&this->mutex); } -static int demux_idcin_start (demux_plugin_t *this_gen, +static int demux_idcin_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time) { demux_idcin_t *this = (demux_idcin_t *) this_gen; - int err; - - pthread_mutex_lock(&this->mutex); /* if thread is not running, initialize demuxer */ - if (!this->thread_running) { + if( !this->stream->demux_thread_running ) { /* send new pts */ xine_demux_control_newpts(this->stream, 0, 0); this->status = DEMUX_OK; - this->send_end_buffers = 1; - this->thread_running = 1; - - if ((err = pthread_create (&this->thread, NULL, demux_idcin_loop, this)) != 0) { - printf ("demux_idcin: can't create new thread (%s)\n", strerror(err)); - abort(); - } - - this->status = DEMUX_OK; - } - - pthread_mutex_unlock(&this->mutex); - - return DEMUX_OK; -} - -static int demux_idcin_seek (demux_plugin_t *this_gen, - off_t start_pos, int start_time) { - - /* Id CIN files are not meant to be seekable; don't even bother */ - - return 0; -} - -static void demux_idcin_stop (demux_plugin_t *this_gen) { - - demux_idcin_t *this = (demux_idcin_t *) this_gen; - void *p; + + /* reposition stream past the Huffman tables */ + this->input->seek(this->input, 0x14 + 0x10000, SEEK_SET); - pthread_mutex_lock( &this->mutex ); - - if (!this->thread_running) { - pthread_mutex_unlock( &this->mutex ); - return; } - /* seek to the start of the data in case there's another start command */ - this->input->seek(this->input, IDCIN_HEADER_SIZE + HUFFMAN_TABLE_SIZE, - 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_idcin_dispose (demux_plugin_t *this) { - demux_idcin_stop(this); - free(this); } @@ -531,16 +432,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_idcin_send_headers; - this->demux_plugin.start = demux_idcin_start; + this->demux_plugin.send_chunk = demux_idcin_send_chunk; this->demux_plugin.seek = demux_idcin_seek; - this->demux_plugin.stop = demux_idcin_stop; this->demux_plugin.dispose = demux_idcin_dispose; this->demux_plugin.get_status = demux_idcin_get_status; this->demux_plugin.get_stream_length = demux_idcin_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) { @@ -701,6 +600,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, "idcin", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_DEMUX, 15, "idcin", XINE_VERSION_CODE, NULL, init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; |