summaryrefslogtreecommitdiff
path: root/src/demuxers/demux_wav.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers/demux_wav.c')
-rw-r--r--src/demuxers/demux_wav.c45
1 files changed, 23 insertions, 22 deletions
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;