summaryrefslogtreecommitdiff
path: root/src/libflac
diff options
context:
space:
mode:
Diffstat (limited to 'src/libflac')
-rw-r--r--src/libflac/decoder_flac.c87
-rw-r--r--src/libflac/demux_flac.c172
2 files changed, 105 insertions, 154 deletions
diff --git a/src/libflac/decoder_flac.c b/src/libflac/decoder_flac.c
index aaca2ea9b..8c7d39ad0 100644
--- a/src/libflac/decoder_flac.c
+++ b/src/libflac/decoder_flac.c
@@ -30,15 +30,16 @@
#include <FLAC/stream_decoder.h>
+#define LOG_MODULE "flac_decoder"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
#include "xine_internal.h"
#include "audio_out.h"
#include "buffer.h"
-/*
-#define LOG 1
-*/
-
#include "demux_flac.h"
typedef struct {
@@ -82,18 +83,14 @@ flac_read_callback (const FLAC__StreamDecoder *decoder,
flac_decoder_t *this = (flac_decoder_t *)client_data;
int number_of_bytes_to_copy;
-#ifdef LOG
- printf("libflac: flac_read_callback: %d\n", *bytes);
-#endif
+ lprintf("flac_read_callback: %d\n", *bytes);
if (this->buf_pos > *bytes)
number_of_bytes_to_copy = *bytes;
else
number_of_bytes_to_copy = this->buf_pos;
-#ifdef LOG
- printf("libflac: number_of_bytes_to_copy: %d\n", number_of_bytes_to_copy);
-#endif
+ lprintf("number_of_bytes_to_copy: %d\n", number_of_bytes_to_copy);
*bytes = number_of_bytes_to_copy;
@@ -123,9 +120,7 @@ flac_write_callback (const FLAC__StreamDecoder *decoder,
int16_t *data16;
int i,j;
-#ifdef LOG
- printf("libflac: flac_write_callback\n");
-#endif
+ lprintf("flac_write_callback\n");
while( samples_left ) {
@@ -168,24 +163,22 @@ flac_metadata_callback (const FLAC__StreamDecoder *decoder,
const FLAC__StreamMetadata *metadata,
void *client_data)
{
- flac_decoder_t *this = (flac_decoder_t *)client_data;
+ /* flac_decoder_t *this = (flac_decoder_t *)client_data; */
+
+ lprintf("Metadata callback called!\n");
#ifdef LOG
- printf("libflac: Metadata callback called!\n");
-#endif
-
- if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
-#ifdef LOG
- printf("libflac: min_blocksize = %d\n", metadata->data.stream_info.min_blocksize);
- printf("libflac: max_blocksize = %d\n", metadata->data.stream_info.max_blocksize);
- printf("libflac: min_framesize = %d\n", metadata->data.stream_info.min_framesize);
- printf("libflac: max_framesize = %d\n", metadata->data.stream_info.max_framesize);
+ if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
+ printf("libflac: min_blocksize = %d\n", metadata->data.stream_info.min_blocksize);
+ printf("libflac: max_blocksize = %d\n", metadata->data.stream_info.max_blocksize);
+ printf("libflac: min_framesize = %d\n", metadata->data.stream_info.min_framesize);
+ printf("libflac: max_framesize = %d\n", metadata->data.stream_info.max_framesize);
+ /* does not work well:
+ this->min_size = 2 * metadata->data.stream_info.max_blocksize; */
+ }
#endif
-
- /* does not work well:
- this->min_size = 2 * metadata->data.stream_info.max_blocksize; */
- }
- return;
+
+ return;
}
static void
@@ -194,17 +187,17 @@ flac_error_callback (const FLAC__StreamDecoder *decoder,
void *client_data)
{
/* This will be called if there is an error in the flac stream */
+ lprintf("flac_error_callback\n");
+
#ifdef LOG
- printf("libflac: flac_error_callback\n");
-
- if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
- printf("libflac: Decoder lost synchronization.\n");
- else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER)
- printf("libflac: Decoder encounted a corrupted frame header.\n");
- else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH)
- printf("libflac: Frame's data did not match the CRC in the footer.\n");
- else
- printf("libflac: unknown error.\n");
+ if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
+ printf("libflac: Decoder lost synchronization.\n");
+ else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER)
+ printf("libflac: Decoder encounted a corrupted frame header.\n");
+ else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH)
+ printf("libflac: Frame's data did not match the CRC in the footer.\n");
+ else
+ printf("libflac: unknown error.\n");
#endif
return;
@@ -235,9 +228,8 @@ flac_discontinuity (audio_decoder_t *this_gen)
flac_decoder_t *this = (flac_decoder_t *) this_gen;
this->pts = 0;
-#ifdef LOG
- printf("libflac: Discontinuity!\n");
-#endif
+
+ lprintf("Discontinuity!\n");
}
static void
@@ -299,9 +291,7 @@ flac_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
{
this->buf_size += 2 * buf->size;
this->buf = realloc (this->buf, this->buf_size);
-#ifdef LOG
- printf("libflac: reallocating buffer to %d\n", this->buf_size);
-#endif
+ lprintf("reallocating buffer to %d\n", this->buf_size);
}
xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size);
@@ -315,14 +305,11 @@ flac_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
if( FLAC__stream_decoder_get_state(this->flac_decoder) ==
FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) {
-#ifdef LOG
- printf("libflac: process_until_end_of_metadata\n");
-#endif
+ lprintf("process_until_end_of_metadata\n");
+
ret = FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder);
} else {
-#ifdef LOG
- printf("libflac: process_single\n");
-#endif
+ lprintf("process_single\n");
ret = FLAC__stream_decoder_process_single (this->flac_decoder);
}
}
diff --git a/src/libflac/demux_flac.c b/src/libflac/demux_flac.c
index a329fad2b..086f20fa9 100644
--- a/src/libflac/demux_flac.c
+++ b/src/libflac/demux_flac.c
@@ -38,14 +38,16 @@
#include <FLAC/seekable_stream_decoder.h>
+#define LOG_MODULE "demux_flac"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
#include "xine_internal.h"
#include "xineutils.h"
#include "../demuxers/demux.h"
-/*
-#define LOG 1
-*/
-
#include "demux_flac.h"
/* FLAC Demuxer plugin */
@@ -97,9 +99,7 @@ flac_read_callback (const FLAC__SeekableStreamDecoder *decoder,
input_plugin_t *input = this->input;
off_t offset = *bytes;
-#ifdef LOG
- printf("demux_flac: flac_read_callback\n");
-#endif
+ lprintf("flac_read_callback\n");
/* This should only be called when flac is reading the metadata
* of the flac stream.
@@ -107,26 +107,22 @@ flac_read_callback (const FLAC__SeekableStreamDecoder *decoder,
offset = input->read (input, buffer, offset);
-#ifdef LOG
- printf("demux_flac: Read %lld / %u bytes into buffer\n", offset, *bytes);
-#endif
+ lprintf("Read %lld / %u bytes into buffer\n", offset, *bytes);
*bytes = offset;
/* This is the way to detect EOF with xine input plugins */
if ( (offset != *bytes) && (*bytes != 0) )
{
-#ifdef LOG
- printf("demux_flac: Marking EOF\n");
-#endif
- this->status = DEMUX_FINISHED;
- return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
+ lprintf("Marking EOF\n");
+
+ this->status = DEMUX_FINISHED;
+ return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
}
else
{
-#ifdef LOG
- printf("demux_flac: Read was perfect\n");
-#endif
- return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
+ lprintf("Read was perfect\n");
+
+ return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
}
}
@@ -138,9 +134,7 @@ flac_seek_callback (const FLAC__SeekableStreamDecoder *decoder,
input_plugin_t *input = ((demux_flac_t *)client_data)->input;
off_t offset;
-#ifdef LOG
- printf("demux_flac: flac_seek_callback\n");
-#endif
+ lprintf("flac_seek_callback\n");
offset = input->seek (input, absolute_byte_offset, SEEK_SET);
@@ -158,9 +152,8 @@ flac_tell_callback (const FLAC__SeekableStreamDecoder *decoder,
input_plugin_t *input = ((demux_flac_t *)client_data)->input;
off_t offset;
-#ifdef LOG
- printf("demux_flac: flac_tell_callback\n");
-#endif
+ lprintf("flac_tell_callback\n");
+
offset = input->get_current_pos (input);
*absolute_byte_offset = offset;
@@ -176,9 +169,8 @@ flac_length_callback (const FLAC__SeekableStreamDecoder *decoder,
input_plugin_t *input = ((demux_flac_t *)client_data)->input;
off_t offset;
-#ifdef LOG
- printf("demux_flac: flac_length_callback\n");
-#endif
+ lprintf("flac_length_callback\n");
+
offset = input->get_length (input);
/* FIXME, can flac handle -1 as offset ? */
@@ -190,23 +182,20 @@ flac_eof_callback (const FLAC__SeekableStreamDecoder *decoder,
void *client_data)
{
demux_flac_t *this = (demux_flac_t *)client_data;
-#ifdef LOG
- printf("demux_flac: flac_eof_callback\n");
-#endif
+
+ lprintf("flac_eof_callback\n");
if (this->status == DEMUX_FINISHED)
{
-#ifdef LOG
- printf("demux_flac: flac_eof_callback: True!\n");
-#endif
- return true;
+ lprintf("flac_eof_callback: True!\n");
+
+ return true;
}
else
{
-#ifdef LOG
- printf("demux_flac: flac_eof_callback: False!\n");
-#endif
- return false;
+ lprintf("flac_eof_callback: False!\n");
+
+ return false;
}
}
@@ -220,11 +209,9 @@ flac_write_callback (const FLAC__SeekableStreamDecoder *decoder,
* is seeking. We do the decoding in the decoder
*/
-#ifdef LOG
- printf("demux_flac: Error: Write callback was called!\n");
-#endif
+ lprintf("Error: Write callback was called!\n");
- return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
static void
@@ -234,21 +221,19 @@ flac_metadata_callback (const FLAC__SeekableStreamDecoder *decoder,
{
demux_flac_t *this = (demux_flac_t *)client_data;
-#ifdef LOG
- printf("demux_flac: IN: Metadata callback\n");
-#endif
+ lprintf("IN: Metadata callback\n");
+
/* This should be called when we first look at a flac stream,
* We get information about the stream here.
*/
if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
-#ifdef LOG
- printf("demux_flac: Got METADATA!\n");
-#endif
- this->total_samples = metadata->data.stream_info.total_samples;
- this->bits_per_sample = metadata->data.stream_info.bits_per_sample;
- this->channels = metadata->data.stream_info.channels;
- this->sample_rate = metadata->data.stream_info.sample_rate;
- this->length_in_msec = (this->total_samples * 10 /
+ lprintf("Got METADATA!\n");
+
+ this->total_samples = metadata->data.stream_info.total_samples;
+ this->bits_per_sample = metadata->data.stream_info.bits_per_sample;
+ this->channels = metadata->data.stream_info.channels;
+ this->sample_rate = metadata->data.stream_info.sample_rate;
+ this->length_in_msec = (this->total_samples * 10 /
(this->sample_rate / 100))/1000;
}
return;
@@ -327,12 +312,11 @@ demux_flac_send_chunk (demux_plugin_t *this_gen) {
remaining_sample_bytes -= buf->size;
if (this->input->read (this->input,buf->content,buf->size)!=buf->size) {
-#ifdef LOG
- printf("demux_flac: buf->size != input->read()\n");
-#endif
- buf->free_buffer (buf);
- this->status = DEMUX_FINISHED;
- break;
+ lprintf("buf->size != input->read()\n");
+
+ buf->free_buffer (buf);
+ this->status = DEMUX_FINISHED;
+ break;
}
/*
@@ -353,9 +337,7 @@ demux_flac_send_headers (demux_plugin_t *this_gen) {
buf_element_t *buf;
-#ifdef LOG
- printf("demux_flac: demux_flac_send_headers\n");
-#endif
+ lprintf("demux_flac_send_headers\n");
this->video_fifo = this->stream->video_fifo;
this->audio_fifo = this->stream->audio_fifo;
@@ -387,9 +369,8 @@ static void
demux_flac_dispose (demux_plugin_t *this_gen) {
demux_flac_t *this = (demux_flac_t *) this_gen;
-#ifdef LOG
- printf("demux_flac: demux_flac_dispose\n");
-#endif
+ lprintf("demux_flac_dispose\n");
+
if (this->flac_decoder)
FLAC__seekable_stream_decoder_delete (this->flac_decoder);
@@ -401,9 +382,7 @@ static int
demux_flac_get_status (demux_plugin_t *this_gen) {
demux_flac_t *this = (demux_flac_t *) this_gen;
-#ifdef LOG
- printf("demux_flac: demux_flac_get_status\n");
-#endif
+ lprintf("demux_flac_get_status\n");
return this->status;
}
@@ -413,15 +392,12 @@ static int
demux_flac_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time, int playing) {
demux_flac_t *this = (demux_flac_t *) this_gen;
-#ifdef LOG
- printf("demux_flac: demux_flac_seek\n");
-#endif
+ lprintf("demux_flac_seek\n");
+
if (start_pos || !start_time) {
this->input->seek (this->input, start_pos, SEEK_SET);
-#ifdef LOG
- printf ("Seek to position: %lld\n", start_pos);
-#endif
+ lprintf ("Seek to position: %lld\n", start_pos);
} else {
@@ -439,9 +415,7 @@ demux_flac_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time, int
target_sample);
if (s) {
-#ifdef LOG
- printf ("Seek to: %d successfull!\n", start_time);
-#endif
+ lprintf ("Seek to: %d successfull!\n", start_time);
} else
this->status = DEMUX_FINISHED;
}
@@ -455,9 +429,7 @@ static int
demux_flac_get_stream_length (demux_plugin_t *this_gen) {
demux_flac_t *this = (demux_flac_t *) this_gen;
-#ifdef LOG
- printf("demux_flac: demux_flac_get_stream_length\n");
-#endif
+ lprintf("demux_flac_get_stream_length\n");
if (this->flac_decoder)
return this->length_in_msec;
@@ -467,18 +439,16 @@ demux_flac_get_stream_length (demux_plugin_t *this_gen) {
static uint32_t
demux_flac_get_capabilities (demux_plugin_t *this_gen) {
-#ifdef LOG
- printf("demux_flac: demux_flac_get_capabilities\n");
-#endif
- return DEMUX_CAP_NOCAP;
+ lprintf("demux_flac_get_capabilities\n");
+
+ return DEMUX_CAP_NOCAP;
}
static int
demux_flac_get_optional_data (demux_plugin_t *this_gen, void *data, int dtype) {
-#ifdef LOG
- printf("demux_flac: demux_flac_get_optional_data\n");
-#endif
- return DEMUX_OPTIONAL_UNSUPPORTED;
+ lprintf("demux_flac_get_optional_data\n");
+
+ return DEMUX_OPTIONAL_UNSUPPORTED;
}
static demux_plugin_t *
@@ -487,9 +457,7 @@ open_plugin (demux_class_t *class_gen,
input_plugin_t *input) {
demux_flac_t *this;
-#ifdef LOG
- printf("demux_flac: open_plugin\n");
-#endif
+ lprintf("open_plugin\n");
switch (stream->content_detection_method) {
case METHOD_BY_CONTENT:
@@ -565,9 +533,8 @@ open_plugin (demux_class_t *class_gen,
/* Get a new FLAC decoder and hook up callbacks */
this->flac_decoder = FLAC__seekable_stream_decoder_new();
-#ifdef LOG
- printf("demux_flac: this->flac_decoder: %p\n", this->flac_decoder);
-#endif
+ lprintf("this->flac_decoder: %p\n", this->flac_decoder);
+
FLAC__seekable_stream_decoder_set_md5_checking (this->flac_decoder, false);
FLAC__seekable_stream_decoder_set_read_callback (this->flac_decoder,
flac_read_callback);
@@ -599,9 +566,8 @@ open_plugin (demux_class_t *class_gen,
*/
this->status = DEMUX_OK;
FLAC__seekable_stream_decoder_process_until_end_of_metadata (this->flac_decoder);
-#ifdef LOG
- printf("demux_flac: Processed file until end of metadata\n");
-#endif
+
+ lprintf("Processed file until end of metadata\n");
return &this->demux_plugin;
}
@@ -633,9 +599,8 @@ static void
class_dispose (demux_class_t *this_gen) {
demux_flac_class_t *this = (demux_flac_class_t *) this_gen;
-#ifdef LOG
- printf("demux_flac: class_dispose\n");
-#endif
+ lprintf("class_dispose\n");
+
free (this);
}
@@ -644,9 +609,8 @@ demux_flac_init_class (xine_t *xine, void *data) {
demux_flac_class_t *this;
-#ifdef LOG
- printf("demux_flac: demux_flac_init_class\n");
-#endif
+ lprintf("demux_flac_init_class\n");
+
this = xine_xmalloc (sizeof (demux_flac_class_t));
this->config = xine->config;
this->xine = xine;