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