summaryrefslogtreecommitdiff
path: root/src/demuxers/demux_fli.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers/demux_fli.c')
-rw-r--r--src/demuxers/demux_fli.c214
1 files changed, 61 insertions, 153 deletions
diff --git a/src/demuxers/demux_fli.c b/src/demuxers/demux_fli.c
index 4a8427721..1c2fc0842 100644
--- a/src/demuxers/demux_fli.c
+++ b/src/demuxers/demux_fli.c
@@ -22,7 +22,7 @@
* avoid while programming a FLI decoder, visit:
* http://www.pcisys.net/~melanson/codecs/
*
- * $Id: demux_fli.c,v 1.22 2002/10/27 16:14:23 tmmm Exp $
+ * $Id: demux_fli.c,v 1.23 2002/10/28 03:24:43 miguelfreitas Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -32,8 +32,6 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
-#include <pthread.h>
-#include <sched.h>
#include <string.h>
#include <stdlib.h>
@@ -61,11 +59,6 @@ typedef struct {
input_plugin_t *input;
- pthread_t thread;
- int thread_running;
- pthread_mutex_t mutex;
- int send_end_buffers;
-
off_t start;
int status;
@@ -81,6 +74,8 @@ typedef struct {
unsigned int frame_count;
char last_mrl[1024];
+
+ off_t stream_len;
} demux_fli_t;
typedef struct {
@@ -139,7 +134,7 @@ static int open_fli_file(demux_fli_t *this) {
return 1;
}
-static void *demux_fli_loop (void *this_gen) {
+static int demux_fli_send_chunk(demux_plugin_t *this_gen) {
demux_fli_t *this = (demux_fli_t *) this_gen;
buf_element_t *buf = NULL;
@@ -149,95 +144,59 @@ static void *demux_fli_loop (void *this_gen) {
unsigned int chunk_magic;
int64_t pts_counter = 0;
off_t current_file_pos;
- off_t stream_len;
-
- /* make sure to start just after the header */
- this->input->seek(this->input, FLI_HEADER_SIZE, SEEK_SET);
-
- stream_len = this->input->get_length(this->input);
-
- /* do-while needed to seek after demux finished */
- do {
- /* main demuxer loop */
- while (this->status == DEMUX_OK) {
- /* check if all the frames have been sent */
- if (i >= this->frame_count) {
- this->status = DEMUX_FINISHED;
- break;
- }
-
- current_file_pos = this->input->get_current_pos(this->input);
-
- /* get the chunk size nd magic number */
- if (this->input->read(this->input, fli_buf, 6) != 6) {
+ /* check if all the frames have been sent */
+ if (i >= this->frame_count) {
+ this->status = DEMUX_FINISHED;
+ return this->status;
+ }
+
+ current_file_pos = this->input->get_current_pos(this->input);
+
+ /* get the chunk size nd magic number */
+ if (this->input->read(this->input, fli_buf, 6) != 6) {
+ this->status = DEMUX_FINISHED;
+ return this->status;
+ }
+ chunk_size = LE_32(&fli_buf[0]);
+ chunk_magic = LE_16(&fli_buf[4]);
+
+ /* rewind over the size and packetize the chunk */
+ this->input->seek(this->input, -6, SEEK_CUR);
+
+ if ((chunk_magic == FLI_CHUNK_MAGIC_1) ||
+ (chunk_magic == FLI_CHUNK_MAGIC_2)) {
+ while (chunk_size) {
+ buf = this->video_fifo->buffer_pool_alloc (this->video_fifo);
+ buf->type = BUF_VIDEO_FLI;
+ buf->input_pos = current_file_pos;
+ buf->input_time = pts_counter / 90000;
+ buf->input_length = this->stream_len;
+ buf->pts = pts_counter;
+
+ if (chunk_size > buf->max_size)
+ buf->size = buf->max_size;
+ else
+ buf->size = chunk_size;
+ chunk_size -= buf->size;
+
+ if (this->input->read(this->input, buf->content, buf->size) !=
+ buf->size) {
this->status = DEMUX_FINISHED;
break;
}
- chunk_size = LE_32(&fli_buf[0]);
- chunk_magic = LE_16(&fli_buf[4]);
-
- /* rewind over the size and packetize the chunk */
- this->input->seek(this->input, -6, SEEK_CUR);
-
- if ((chunk_magic == FLI_CHUNK_MAGIC_1) ||
- (chunk_magic == FLI_CHUNK_MAGIC_2)) {
- while (chunk_size) {
- buf = this->video_fifo->buffer_pool_alloc (this->video_fifo);
- buf->type = BUF_VIDEO_FLI;
- buf->input_pos = current_file_pos;
- buf->input_time = pts_counter / 90000;
- buf->input_length = stream_len;
- buf->pts = pts_counter;
-
- if (chunk_size > buf->max_size)
- buf->size = buf->max_size;
- else
- buf->size = chunk_size;
- chunk_size -= buf->size;
-
- if (this->input->read(this->input, buf->content, buf->size) !=
- buf->size) {
- this->status = DEMUX_FINISHED;
- break;
- }
-
- if (!chunk_size)
- buf->decoder_flags |= BUF_FLAG_FRAME_END;
- this->video_fifo->put(this->video_fifo, buf);
- }
- pts_counter += this->frame_pts_inc;
- } else
- this->input->seek(this->input, chunk_size, SEEK_CUR);
-
- i++;
-
- /* 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 );
+
+ if (!chunk_size)
+ buf->decoder_flags |= BUF_FLAG_FRAME_END;
+ this->video_fifo->put(this->video_fifo, buf);
}
-
- /* 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 );
- }
- } while (this->status == DEMUX_OK);
-
- this->status = DEMUX_FINISHED;
-
- if (this->send_end_buffers) {
- xine_demux_control_end(this->stream, BUF_FLAG_END_STREAM);
- }
-
- this->thread_running = 0;
- pthread_mutex_unlock( &this->mutex );
-
- return NULL;
+ pts_counter += this->frame_pts_inc;
+ } else
+ this->input->seek(this->input, chunk_size, SEEK_CUR);
+
+ i++;
+
+ return this->status;
}
static void demux_fli_send_headers(demux_plugin_t *this_gen) {
@@ -245,8 +204,6 @@ static void demux_fli_send_headers(demux_plugin_t *this_gen) {
demux_fli_t *this = (demux_fli_t *) this_gen;
buf_element_t *buf;
- pthread_mutex_lock(&this->mutex);
-
this->video_fifo = this->stream->video_fifo;
/* video-only format, don't worry about audio_fifo */
@@ -273,78 +230,31 @@ static void demux_fli_send_headers(demux_plugin_t *this_gen) {
this->video_fifo->put (this->video_fifo, buf);
xine_demux_control_headers_done (this->stream);
-
- pthread_mutex_unlock (&this->mutex);
}
-static int demux_fli_start (demux_plugin_t *this_gen,
+static int demux_fli_seek (demux_plugin_t *this_gen,
off_t start_pos, int start_time) {
demux_fli_t *this = (demux_fli_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;
-
- /* kick off the demux thread */
- if ((err = pthread_create (&this->thread, NULL, demux_fli_loop, this)) != 0) {
- printf ("demux_fli: can't create new thread (%s)\n", strerror(err));
- abort();
- }
- }
-
- pthread_mutex_unlock(&this->mutex);
-
- return DEMUX_OK;
-}
-
-static int demux_fli_seek (demux_plugin_t *this_gen,
- off_t start_pos, int start_time) {
-
- /* FLI files are not meant to be seekable; don't even bother */
-
- return 0;
-}
-
-static void demux_fli_stop (demux_plugin_t *this_gen) {
-
- demux_fli_t *this = (demux_fli_t *) this_gen;
- void *p;
-
- pthread_mutex_lock( &this->mutex );
-
- if (!this->thread_running) {
- pthread_mutex_unlock( &this->mutex );
- return;
+
+ /* make sure to start just after the header */
+ this->input->seek(this->input, FLI_HEADER_SIZE, SEEK_SET);
+ this->stream_len = this->input->get_length(this->input);
}
-
- /* seek to the start of the data in case there's another start command */
- this->input->seek(this->input, FLI_HEADER_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_fli_dispose (demux_plugin_t *this) {
- demux_fli_stop(this);
-
free(this);
}
@@ -375,16 +285,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_fli_send_headers;
- this->demux_plugin.start = demux_fli_start;
+ this->demux_plugin.send_chunk = demux_fli_send_chunk;
this->demux_plugin.seek = demux_fli_seek;
- this->demux_plugin.stop = demux_fli_stop;
this->demux_plugin.dispose = demux_fli_dispose;
this->demux_plugin.get_status = demux_fli_get_status;
this->demux_plugin.get_stream_length = demux_fli_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) {