diff options
author | Mike Melanson <mike@multimedia.cx> | 2002-10-03 00:08:47 +0000 |
---|---|---|
committer | Mike Melanson <mike@multimedia.cx> | 2002-10-03 00:08:47 +0000 |
commit | 8f315332beb0f45b1c7ed840bf0dd10ee082aa20 (patch) | |
tree | f40d6f16108a7b569b62ee87986214abfbe05ac3 | |
parent | e012cdb963c9e7d4a5cde2adb3a7de09b5f06a42 (diff) | |
download | xine-lib-8f315332beb0f45b1c7ed840bf0dd10ee082aa20.tar.gz xine-lib-8f315332beb0f45b1c7ed840bf0dd10ee082aa20.tar.bz2 |
implemented seek on start for the audio-only demuxers, also fixed
temporal position reporting
CVS patchset: 2771
CVS date: 2002/10/03 00:08:47
-rw-r--r-- | src/demuxers/demux_aiff.c | 41 | ||||
-rw-r--r-- | src/demuxers/demux_snd.c | 45 | ||||
-rw-r--r-- | src/demuxers/demux_voc.c | 106 | ||||
-rw-r--r-- | src/demuxers/demux_wav.c | 45 |
4 files changed, 89 insertions, 148 deletions
diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c index 73b5debea..7bf2c5b8d 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.6 2002/09/21 18:18:46 tmmm Exp $ + * $Id: demux_aiff.c,v 1.7 2002/10/03 00:08:47 tmmm Exp $ * */ @@ -93,7 +93,6 @@ typedef struct { off_t data_start; off_t data_size; - off_t data_end; int seek_flag; /* this is set when a seek just occurred */ } demux_aiff_t; @@ -121,10 +120,10 @@ static void *demux_aiff_loop (void *this_gen) { /* 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); + current_file_pos = + this->input->get_current_pos(this->input) - this->data_start; current_pts = current_file_pos; - current_pts -= this->data_start; current_pts *= 90000; current_pts /= this->audio_bytes_per_second; @@ -137,7 +136,7 @@ static void *demux_aiff_loop (void *this_gen) { 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_end; + buf->input_length = this->data_size; buf->input_time = current_pts / 90000; buf->pts = current_pts; @@ -248,7 +247,6 @@ static int load_aiff_and_send_headers(demux_aiff_t *this) { this->data_size = this->audio_frames * this->audio_channels * (this->audio_bits / 8); this->running_time = this->audio_frames / this->audio_sample_rate; - this->data_end = this->data_start + this->data_size; this->audio_block_align = PCM_BLOCK_ALIGN; @@ -344,6 +342,9 @@ static int demux_aiff_open(demux_plugin_t *this_gen, return DEMUX_CANNOT_HANDLE; } +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) { @@ -351,6 +352,8 @@ static int demux_aiff_start (demux_plugin_t *this_gen, buf_element_t *buf; int err; + demux_aiff_seek(this_gen, start_pos, start_time); + pthread_mutex_lock(&this->mutex); /* if thread is not running, initialize demuxer */ @@ -405,29 +408,27 @@ static int demux_aiff_seek (demux_plugin_t *this_gen, demux_aiff_t *this = (demux_aiff_t *) this_gen; int status; - off_t data_offset; - pthread_mutex_lock(&this->mutex); /* check the boundary offsets */ - if (start_pos < this->data_start) + if (start_pos < 0) this->input->seek(this->input, this->data_start, SEEK_SET); - else if (start_pos >= this->data_end) { + else if (start_pos >= this->data_size) { this->status = DEMUX_FINISHED; status = this->status; pthread_mutex_unlock(&this->mutex); return status; } else { - /* This function must seek along the block alignment. Determine how - * far into the data the requested offset lies, divide the diff - * by the block alignment integer-wise, and multiply that by the - * block alignment to get the new aligned offset. */ - data_offset = start_pos - this->data_start; - data_offset /= this->audio_block_align; - data_offset *= this->audio_block_align; - data_offset += this->data_start; - - this->input->seek(this->input, data_offset, SEEK_SET); + /* 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 + * the block alignment integer-wise, and multiply the quotient by the + * block alignment to get the new aligned offset. Add the data start + * offset and seek to the new position. */ + start_pos /= this->audio_block_align; + start_pos *= this->audio_block_align; + start_pos += this->data_start; + + this->input->seek(this->input, start_pos, SEEK_SET); } this->seek_flag = 1; diff --git a/src/demuxers/demux_snd.c b/src/demuxers/demux_snd.c index 1f47d9cea..edb46bb1b 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.7 2002/09/21 18:18:46 tmmm Exp $ + * $Id: demux_snd.c,v 1.8 2002/10/03 00:08:47 tmmm Exp $ * */ @@ -81,7 +81,6 @@ typedef struct { off_t data_start; off_t data_size; - off_t data_end; int seek_flag; /* this is set when a seek just occurred */ } demux_snd_t; @@ -97,8 +96,6 @@ static void *demux_snd_loop (void *this_gen) { pthread_mutex_lock( &this->mutex ); this->seek_flag = 1; - this->input->seek(this->input, this->data_start, SEEK_SET); - /* do-while needed to seek after demux finished */ do { /* main demuxer loop */ @@ -111,10 +108,10 @@ static void *demux_snd_loop (void *this_gen) { /* 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); + current_file_pos = + this->input->get_current_pos(this->input) - this->data_start; current_pts = current_file_pos; - current_pts -= this->data_start; current_pts *= 90000; current_pts /= this->audio_bytes_per_second; @@ -127,7 +124,7 @@ static void *demux_snd_loop (void *this_gen) { 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_end; + buf->input_length = this->data_size; buf->input_time = current_pts / 90000; buf->pts = current_pts; @@ -204,7 +201,6 @@ static int load_snd_and_send_headers(demux_snd_t *this) { encoding = BE_32(&header[0x0C]); this->audio_sample_rate = BE_32(&header[0x10]); this->audio_channels = BE_32(&header[0x14]); - this->data_end = this->data_start + this->data_size; /* basic sanity checks on the loaded audio parameters */ if ((!this->audio_sample_rate) || @@ -331,6 +327,9 @@ static int demux_snd_open(demux_plugin_t *this_gen, return DEMUX_CANNOT_HANDLE; } +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) { @@ -338,6 +337,10 @@ static int demux_snd_start (demux_plugin_t *this_gen, buf_element_t *buf; 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) { /* print vital stats */ @@ -389,29 +392,27 @@ static int demux_snd_seek (demux_plugin_t *this_gen, demux_snd_t *this = (demux_snd_t *) this_gen; int status; - off_t data_offset; - pthread_mutex_lock(&this->mutex); /* check the boundary offsets */ - if (start_pos < this->data_start) + if (start_pos < 0) this->input->seek(this->input, this->data_start, SEEK_SET); - else if (start_pos >= this->data_end) { + else if (start_pos >= this->data_size) { this->status = DEMUX_FINISHED; status = this->status; pthread_mutex_unlock(&this->mutex); return status; } else { - /* This function must seek along the block alignment. Determine how - * far into the data the requested offset lies, divide the diff - * by the block alignment integer-wise, and multiply that by the - * block alignment to get the new aligned offset. */ - data_offset = start_pos - this->data_start; - data_offset /= this->audio_block_align; - data_offset *= this->audio_block_align; - data_offset += this->data_start; - - this->input->seek(this->input, data_offset, SEEK_SET); + /* 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 + * the block alignment integer-wise, and multiply the quotient by the + * block alignment to get the new aligned offset. Add the data start + * offset and seek to the new position. */ + start_pos /= this->audio_block_align; + start_pos *= this->audio_block_align; + start_pos += this->data_start; + + this->input->seek(this->input, start_pos, SEEK_SET); } this->seek_flag = 1; diff --git a/src/demuxers/demux_voc.c b/src/demuxers/demux_voc.c index 2d669c494..d18f445f9 100644 --- a/src/demuxers/demux_voc.c +++ b/src/demuxers/demux_voc.c @@ -23,7 +23,7 @@ * It will only play that block if it is PCM data. More variations will be * supported as they are encountered. * - * $Id: demux_voc.c,v 1.7 2002/09/21 18:18:46 tmmm Exp $ + * $Id: demux_voc.c,v 1.8 2002/10/03 00:08:47 tmmm Exp $ * */ @@ -81,7 +81,6 @@ typedef struct { off_t data_start; off_t data_size; - off_t data_end; unsigned int running_time; int seek_flag; /* this is set when a seek just occurred */ @@ -110,10 +109,10 @@ static void *demux_voc_loop (void *this_gen) { /* just load data chunks from wherever the stream happens to be * pointing; issue a DEMUX_FINISHED status if EOF is reached */ remaining_sample_bytes = PCM_BLOCK_ALIGN; - current_file_pos = this->input->get_current_pos(this->input); + current_file_pos = + this->input->get_current_pos(this->input) - this->data_start; current_pts = current_file_pos; - current_pts -= this->data_start; current_pts *= 90000; current_pts /= this->audio_sample_rate; @@ -126,7 +125,7 @@ static void *demux_voc_loop (void *this_gen) { 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_end; + buf->input_length = this->data_size; buf->input_time = current_pts / 90000; buf->pts = current_pts; @@ -248,7 +247,6 @@ static int load_voc_and_send_headers(demux_voc_t *this) { sample_rate_divisor = preamble[0]; this->audio_sample_rate = 256 - (1000000 / sample_rate_divisor); this->data_start = this->input->get_current_pos(this->input); - this->data_end = this->data_start + this->data_size; this->audio_bits = 8; this->audio_channels = 1; this->running_time = this->data_size / this->audio_sample_rate; @@ -328,6 +326,9 @@ static int demux_voc_open(demux_plugin_t *this_gen, return DEMUX_CANNOT_HANDLE; } +static int demux_voc_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time); + static int demux_voc_start (demux_plugin_t *this_gen, off_t start_pos, int start_time) { @@ -335,73 +336,12 @@ static int demux_voc_start (demux_plugin_t *this_gen, buf_element_t *buf; int err; + demux_voc_seek(this_gen, start_pos, start_time); + pthread_mutex_lock(&this->mutex); /* if thread is not running, initialize demuxer */ if (!this->thread_running) { -#if 0 - this->video_fifo = video_fifo; - this->audio_fifo = audio_fifo; - - /* load the header */ - this->input->seek(this->input, 0, SEEK_SET); - if (this->input->read(this->input, header, VOC_HEADER_SIZE) != - VOC_HEADER_SIZE) { - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - return DEMUX_FINISHED; - } - - first_block_offset = LE_16(&header[0x14]); - this->input->seek(this->input, first_block_offset, SEEK_SET); - - /* load the block preamble */ - if (this->input->read(this->input, preamble, BLOCK_PREAMBLE_SIZE) != - BLOCK_PREAMBLE_SIZE) { - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - return DEMUX_FINISHED; - } - - /* so far, this demuxer only cares about type 1 blocks */ - if (preamble[0] != 1) { - xine_log(this->xine, XINE_LOG_MSG, - _("unknown VOC block type (0x%02X); please report to xine developers\n"), - preamble[0]); - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - return DEMUX_FINISHED; - } - - /* assemble 24-bit, little endian length */ - this->data_size = preamble[1] | (preamble[2] << 8) | (preamble[3] << 16); - - /* get the next 2 bytes (re-use preamble bytes) */ - if (this->input->read(this->input, preamble, 2) != 2) { - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - return DEMUX_FINISHED; - } - - /* this app only knows how to deal with format 0 data (raw PCM) */ - if (preamble[1] != 0) { - xine_log(this->xine, XINE_LOG_MSG, - _("unknown VOC compression type (0x%02X); please report to xine developers\n"), - preamble[1]); - this->status = DEMUX_FINISHED; - pthread_mutex_unlock(&this->mutex); - return DEMUX_FINISHED; - } - - this->audio_type = BUF_AUDIO_LPCM_BE; - sample_rate_divisor = preamble[0]; - this->audio_sample_rate = 256 - (1000000 / sample_rate_divisor); - this->data_start = this->input->get_current_pos(this->input); - this->data_end = this->data_start + this->data_size; - this->audio_bits = 8; - this->audio_channels = 1; - this->running_time = this->data_size / this->audio_sample_rate; -#endif /* print vital stats */ xine_log(this->xine, XINE_LOG_MSG, @@ -447,29 +387,27 @@ static int demux_voc_seek (demux_plugin_t *this_gen, demux_voc_t *this = (demux_voc_t *) this_gen; int status; - off_t data_offset; pthread_mutex_lock(&this->mutex); /* check the boundary offsets */ - if (start_pos < this->data_start) + if (start_pos < 0) this->input->seek(this->input, this->data_start, SEEK_SET); - else if (start_pos >= this->data_end) { - this->status = DEMUX_FINISHED; - status = this->status; + else if (start_pos >= this->data_size) { + status = this->status = DEMUX_FINISHED; pthread_mutex_unlock(&this->mutex); return status; } else { - /* This function must seek along the block alignment. Determine how - * far into the data the requested offset lies, divide the diff - * by the block alignment integer-wise, and multiply that by the - * block alignment to get the new aligned offset. */ - data_offset = start_pos - this->data_start; - data_offset /= PCM_BLOCK_ALIGN; - data_offset *= PCM_BLOCK_ALIGN; - data_offset += this->data_start; - - this->input->seek(this->input, data_offset, SEEK_SET); + /* 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 + * the block alignment integer-wise, and multiply the quotient by the + * block alignment to get the new aligned offset. Add the data start + * offset and seek to the new position. */ + start_pos /= PCM_BLOCK_ALIGN; + start_pos *= PCM_BLOCK_ALIGN; + start_pos += this->data_start; + + this->input->seek(this->input, start_pos, SEEK_SET); } this->seek_flag = 1; diff --git a/src/demuxers/demux_wav.c b/src/demuxers/demux_wav.c index c57ba4fde..1e3ab75dd 100644 --- a/src/demuxers/demux_wav.c +++ b/src/demuxers/demux_wav.c @@ -20,7 +20,7 @@ * MS WAV File Demuxer by Mike Melanson (melanson@pcisys.net) * based on WAV specs that are available far and wide * - * $Id: demux_wav.c,v 1.13 2002/09/21 18:18:45 tmmm Exp $ + * $Id: demux_wav.c,v 1.14 2002/10/03 00:08:47 tmmm Exp $ * */ @@ -76,7 +76,6 @@ typedef struct { off_t data_start; off_t data_size; - off_t data_end; int seek_flag; /* this is set when a seek just occurred */ } demux_wav_t; @@ -104,10 +103,10 @@ static void *demux_wav_loop (void *this_gen) { /* 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); + current_file_pos = + this->input->get_current_pos(this->input) - this->data_start; current_pts = current_file_pos; - current_pts -= this->data_start; current_pts *= 90000; current_pts /= this->wave->nAvgBytesPerSec; @@ -120,7 +119,7 @@ static void *demux_wav_loop (void *this_gen) { 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_end; + buf->input_length = this->data_size; buf->input_time = current_pts / 90000; buf->pts = current_pts; @@ -212,7 +211,7 @@ static int load_wav_and_send_headers(demux_wav_t *this) { } /* traverse through the chunks to find the 'data' chunk */ - this->data_start = this->data_size = this->data_end = 0; + this->data_start = this->data_size = 0; while (this->data_start == 0) { if (this->input->read(this->input, chunk_preamble, 8) != 8) { @@ -226,7 +225,6 @@ static int load_wav_and_send_headers(demux_wav_t *this) { if (chunk_tag == data_TAG) { this->data_start = this->input->get_current_pos(this->input); this->data_size = chunk_size; - this->data_end = this->data_start + chunk_size; } else { this->input->seek(this->input, chunk_size, SEEK_CUR); } @@ -318,6 +316,9 @@ static int demux_wav_open(demux_plugin_t *this_gen, return DEMUX_CANNOT_HANDLE; } +static int demux_wav_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time); + static int demux_wav_start (demux_plugin_t *this_gen, off_t start_pos, int start_time) { @@ -325,6 +326,8 @@ static int demux_wav_start (demux_plugin_t *this_gen, buf_element_t *buf; int err; + demux_wav_seek(this_gen, start_pos, start_time); + pthread_mutex_lock(&this->mutex); /* if thread is not running, initialize demuxer */ @@ -390,29 +393,27 @@ static int demux_wav_seek (demux_plugin_t *this_gen, demux_wav_t *this = (demux_wav_t *) this_gen; int status; - off_t data_offset; pthread_mutex_lock(&this->mutex); /* check the boundary offsets */ - if (start_pos < this->data_start) + if (start_pos <= 0) this->input->seek(this->input, this->data_start, SEEK_SET); - else if (start_pos >= this->data_end) { - this->status = DEMUX_FINISHED; - status = this->status; + else if (start_pos >= this->data_size) { + status = this->status = DEMUX_FINISHED; pthread_mutex_unlock(&this->mutex); return status; } else { - /* This function must seek along the block alignment. Determine how - * far into the data the requested offset lies, divide the diff - * by the block alignment integer-wise, and multiply that by the - * block alignment to get the new aligned offset. */ - data_offset = start_pos - this->data_start; - data_offset /= this->wave->nBlockAlign; - data_offset *= this->wave->nBlockAlign; - data_offset += this->data_start; - - this->input->seek(this->input, data_offset, SEEK_SET); + /* 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 + * the block alignment integer-wise, and multiply the quotient by the + * block alignment to get the new aligned offset. Add the data start + * offset and seek to the new position. */ + start_pos /= this->wave->nBlockAlign; + start_pos *= this->wave->nBlockAlign; + start_pos += this->data_start; + + this->input->seek(this->input, start_pos, SEEK_SET); } this->seek_flag = 1; |