summaryrefslogtreecommitdiff
path: root/decoders/decoder_flac.c
diff options
context:
space:
mode:
Diffstat (limited to 'decoders/decoder_flac.c')
-rw-r--r--decoders/decoder_flac.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/decoders/decoder_flac.c b/decoders/decoder_flac.c
index 805ab78..fd85f48 100644
--- a/decoders/decoder_flac.c
+++ b/decoders/decoder_flac.c
@@ -13,7 +13,8 @@ struct flac_decoder_data {
};
static FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) {
- struct flac_decoder_data *decoder_data = client_data;
+ struct decoder *_decoder = client_data;
+ struct flac_decoder_data *decoder_data = _decoder->data;
*bytes = g_input_stream_read(decoder_data->input, buffer, *bytes, NULL, NULL);
@@ -29,7 +30,8 @@ static FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *de
static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame,
const FLAC__int32 * const buffer[], void *client_data) {
- struct flac_decoder_data *decoder_data = client_data;
+ struct decoder *_decoder = client_data;
+ struct flac_decoder_data *decoder_data = _decoder->data;
unsigned channels = frame->header.channels;
//unsigned sample_rate = frame->header.sample_rate;
@@ -57,16 +59,28 @@ static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *
}
}
+static void metadata_callback(const FLAC__StreamDecoder *_decoder, const FLAC__StreamMetadata *metadata, void *client_data) {
+ struct decoder *decoder = client_data;
+ decoder->rate = metadata->data.stream_info.sample_rate;
+ switch(metadata->data.stream_info.bits_per_sample) {
+ case 16:
+ decoder->format = AUDIO_FORMAT_S16LE;
+ break;
+ }
+ decoder->channels = metadata->data.stream_info.channels;
+ g_debug("flac: %d Hz, %dch, %d bps", decoder->rate, decoder->channels, metadata->data.stream_info.bits_per_sample);
+}
+
static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) {
g_warning(FLAC__StreamDecoderErrorStatusString[status]);
}
-static gboolean flac_decoder_init(gpointer *data) {
+static gboolean flac_decoder_init(struct decoder *decoder) {
struct flac_decoder_data *decoder_data = g_new0(struct flac_decoder_data, 1);
decoder_data->decoder = FLAC__stream_decoder_new();
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder_data->decoder,
- read_callback, NULL, NULL, NULL, NULL, write_callback, NULL, error_callback, decoder_data);
- *data = decoder_data;
+ read_callback, NULL, NULL, NULL, NULL, write_callback, metadata_callback, error_callback, decoder);
+ decoder->data = decoder_data;
if(status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
g_warning(FLAC__StreamDecoderInitStatusString[status]);
@@ -78,9 +92,9 @@ static gboolean flac_decoder_init(gpointer *data) {
return TRUE;
}
-static gssize flac_decoder_decode(gpointer data, GInputStream *input,
+static gssize flac_decoder_decode(struct decoder *decoder, GInputStream *input,
GOutputStream *output, GError **error) {
- struct flac_decoder_data *decoder_data = data;
+ struct flac_decoder_data *decoder_data = decoder->data;
decoder_data->input = input;
decoder_data->output = output;
decoder_data->output_written = 0;
@@ -105,8 +119,8 @@ static gssize flac_decoder_decode(gpointer data, GInputStream *input,
return decoder_data->output_written;
}
-static void flac_decoder_close(gpointer data) {
- struct flac_decoder_data *decoder_data = data;
+static void flac_decoder_close(struct decoder *decoder) {
+ struct flac_decoder_data *decoder_data = decoder->data;
FLAC__stream_decoder_finish(decoder_data->decoder);
FLAC__stream_decoder_delete(decoder_data->decoder);
g_free(decoder_data);