diff options
Diffstat (limited to 'src/libmusepack/xine_musepack_decoder.c')
-rw-r--r-- | src/libmusepack/xine_musepack_decoder.c | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/src/libmusepack/xine_musepack_decoder.c b/src/libmusepack/xine_musepack_decoder.c index 5977abd63..41b90b080 100644 --- a/src/libmusepack/xine_musepack_decoder.c +++ b/src/libmusepack/xine_musepack_decoder.c @@ -85,10 +85,10 @@ typedef struct mpc_decoder_s { #else mpc_demux *decoder; #endif - + int decoder_ok; unsigned int current_frame; - + int32_t file_size; } mpc_decoder_t; @@ -97,7 +97,7 @@ typedef struct mpc_decoder_s { /************************************************************************** * musepack specific functions *************************************************************************/ - + /* Reads size bytes of data into buffer at ptr. */ #ifndef HAVE_MPC_MPCDEC_H static int32_t mpc_reader_read(void *data, void *ptr, int size) { @@ -106,22 +106,22 @@ static int32_t mpc_reader_read(void *data, void *ptr, int size) { static int32_t mpc_reader_read(mpc_reader *data, void *ptr, int size) { mpc_decoder_t *this = (mpc_decoder_t *) data->data; #endif - + lprintf("mpc_reader_read: size=%d\n", size); - + /* Don't try to read more data than we have */ if (size > (this->size - this->read)) size = this->size - this->read; /* Copy the data */ xine_fast_memcpy(ptr, &this->buf[this->read], size); - + /* Update our position in the data buffer */ this->read += size; - + return size; } - + /* Seeks to byte position offset. */ #ifndef HAVE_MPC_MPCDEC_H static mpc_bool_t mpc_reader_seek(void *data, int32_t offset) { @@ -130,13 +130,13 @@ static mpc_bool_t mpc_reader_seek(void *data, int32_t offset) { static mpc_bool_t mpc_reader_seek(mpc_reader *data, int32_t offset) { mpc_decoder_t *this = (mpc_decoder_t *) data->data; #endif - + lprintf("mpc_reader_seek: offset=%d\n", offset); - + /* seek is only called when reading the header so we can assume * that the buffer starts at the start of the file */ this->read = offset; - + #ifndef HAVE_MPC_MPCDEC_H return TRUE; #else @@ -151,7 +151,7 @@ static int32_t mpc_reader_tell(void *data) { static int32_t mpc_reader_tell(mpc_reader *data) { #endif lprintf("mpc_reader_tell\n"); - + /* Tell isn't used so just return 0 */ return 0; } @@ -164,9 +164,9 @@ static int32_t mpc_reader_get_size(void *data) { static int32_t mpc_reader_get_size(mpc_reader *data) { mpc_decoder_t *this = (mpc_decoder_t *) data->data; #endif - + lprintf("mpc_reader_get_size\n"); - + return this->file_size; } @@ -174,7 +174,7 @@ static int32_t mpc_reader_get_size(mpc_reader *data) { #ifndef HAVE_MPC_MPCDEC_H static mpc_bool_t mpc_reader_canseek(void *data) { lprintf("mpc_reader_canseek\n"); - + return TRUE; #else static mpc_bool_t mpc_reader_canseek(mpc_reader *data) { @@ -204,9 +204,9 @@ static int mpc_decode_frame (mpc_decoder_t *this) { #ifdef HAVE_MPC_MPCDEC_H mpc_frame_info frame; #endif - + lprintf("mpd_decode_frame\n"); - + #ifndef HAVE_MPC_MPCDEC_H frames = mpc_decoder_decode(&this->decoder, buffer, 0, 0); #else @@ -214,26 +214,26 @@ static int mpc_decode_frame (mpc_decoder_t *this) { mpc_demux_decode(this->decoder, &frame); frames = frame.samples; #endif - + if (frames > 0) { - audio_buffer_t *audio_buffer; + audio_buffer_t *audio_buffer; int16_t *int_samples; - + lprintf("got %d samples\n", frames); - + /* Get audio buffer */ audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); audio_buffer->vpts = 0; audio_buffer->num_frames = frames; - + /* Convert samples */ int_samples = (int16_t *) audio_buffer->mem; float_to_int(buffer, int_samples, frames*this->channels); - + /* Output converted samples */ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); } - + return frames; } @@ -246,28 +246,28 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { int err; lprintf("mpc_decode_data\n"); - + if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED)) return; - + /* We don't handle special buffers */ if (buf->decoder_flags & BUF_FLAG_SPECIAL) return; - + /* Read header */ if (buf->decoder_flags & BUF_FLAG_HEADER) { - + lprintf("header\n"); - + /* File size is in decoder_info[0] */ this->file_size = buf->decoder_info[0]; - + /* Initialise the data accumulation buffer */ this->buf = calloc(1, INIT_BUFSIZE); this->buf_max = INIT_BUFSIZE; this->read = 0; this->size = 0; - + /* Initialise the reader */ this->reader.read = mpc_reader_read; this->reader.seek = mpc_reader_seek; @@ -275,11 +275,11 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { this->reader.get_size = mpc_reader_get_size; this->reader.canseek = mpc_reader_canseek; this->reader.data = this; - + /* Copy header to buffer */ xine_fast_memcpy(this->buf, buf->content, buf->size); this->size = buf->size; - + #ifdef HAVE_MPC_MPCDEC_H this->decoder = mpc_demux_init(&this->reader); if (!this->decoder) { @@ -292,28 +292,28 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { #else /* Initialise and read stream info */ mpc_streaminfo_init(&this->streaminfo); - + if ((err = mpc_streaminfo_read(&this->streaminfo, &this->reader))) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _("libmusepack: mpc_streaminfo_read failed: %d\n"), err); - + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); return; } #endif - + this->sample_rate = this->streaminfo.sample_freq; this->channels = this->streaminfo.channels; this->bits_per_sample = 16; - + /* After the header the demuxer starts sending data from an offset * of 28 bytes */ this->size = 28; - + /* We need to keep track of the current frame so we now when we've * reached the end of the stream */ this->current_frame = 0; - + /* Setup the decoder */ #ifndef HAVE_MPC_MPCDEC_H mpc_decoder_setup(&this->decoder, &this->reader); @@ -321,16 +321,16 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { this->decoder_ok = 0; /* Take this opportunity to initialize stream/meta information */ - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Musepack (libmusepack)"); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, (int) this->streaminfo.average_bitrate); return; } lprintf("data: %u size=%u read=%u\n", buf->size, this->size, this->read); - + /* if the audio output is not open yet, open the audio output */ if (!this->output_open) { this->output_open = (this->stream->audio_out->open) ( @@ -344,7 +344,7 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { /* if the audio still isn't open, do not go any further with the decode */ if (!this->output_open) return; - + /* If we run out of space in our internal buffer we discard what's * already been read */ if (((this->size + buf->size) > this->buf_max) && this->read) { @@ -353,7 +353,7 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { memmove(this->buf, &this->buf[this->read], this->size); this->read = 0; } - + /* If there still isn't space we have to increase the size of the * internal buffer */ if ((this->size + buf->size) > this->buf_max) { @@ -362,11 +362,11 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { this->buf_max += 2*buf->size; this->buf = realloc(this->buf, this->buf_max); } - + /* Copy data */ xine_fast_memcpy(&this->buf[this->size], buf->content, buf->size); this->size += buf->size; - + /* Time to decode */ if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* Increment frame count */ @@ -379,45 +379,45 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { _("libmusepack: data after last frame ignored\n")); return; } - + if (!this->decoder_ok) { /* We require MPC_DECODER_MEMSIZE bytes to initialise the decoder */ if ((this->size - this->read) >= MPC_DECODER_MEMSIZE) { lprintf("initialise"); - + #ifndef HAVE_MPC_MPCDEC_H if (!mpc_decoder_initialize(&this->decoder, &this->streaminfo)) { #else if (!this->decoder) { #endif xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: mpc_decoder_initialise failed\n")); - + _("libmusepack: mpc_decoder_initialise failed\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); return; } - + this->decoder_ok = 1; } else { /* Not enough data yet */ return; } } - + /* mpc_decoder_decode may cause a read of MPC_DECODER_MEMSIZE/2 bytes so * make sure we have enough data available */ if ((this->size - this->read) >= MPC_DECODER_MEMSIZE2) { lprintf("decoding\n"); - + if ((err = mpc_decode_frame(this)) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: mpc_decoder_decode failed: %d\n"), err); - + _("libmusepack: mpc_decoder_decode failed: %d\n"), err); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); return; } } - + /* If we are at the end of the stream we decode the remaining frames as we * know we'll have enough data */ #ifndef HAVE_MPC_MPCDEC_H @@ -426,14 +426,14 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { if (this->current_frame == this->streaminfo.samples) { #endif lprintf("flushing buffers\n"); - + do { if ((err = mpc_decode_frame(this)) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _("libmusepack: mpc_decoder_decode failed: %d\n"), err); } } while (err > 0); - + lprintf("buffers flushed\n"); } } @@ -466,7 +466,7 @@ static void mpc_dispose (audio_decoder_t *this_gen) { if (this->decoder) mpc_demux_exit(this->decoder); #endif - + free(this); } @@ -487,7 +487,7 @@ static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stre /* audio output is not open at the start */ this->output_open = 0; - + /* no buffer yet */ this->buf = NULL; @@ -529,7 +529,7 @@ static void *init_plugin (xine_t *xine, void *data) { return this; } -static uint32_t audio_types[] = { +static uint32_t audio_types[] = { BUF_AUDIO_MPC, 0 }; |