aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/decoder/_flac_common.c32
-rw-r--r--src/decoder/_flac_common.h21
-rw-r--r--src/decoder/flac_decoder_plugin.c19
-rw-r--r--src/decoder/oggflac_decoder_plugin.c2
4 files changed, 23 insertions, 51 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index 477a4ba10..2081f7b09 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.c
@@ -38,7 +38,8 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
pcm_buffer_init(&data->buffer);
data->unsupported = false;
- data->have_stream_info = false;
+ data->initialized = false;
+ data->total_frames = 0;
data->first_frame = 0;
data->next_frame = 0;
@@ -78,27 +79,11 @@ flac_sample_format(const FLAC__StreamMetadata_StreamInfo *si)
}
}
-bool
-flac_data_get_audio_format(struct flac_data *data,
- struct audio_format *audio_format)
-{
- if (data->unsupported)
- return false;
-
- if (!data->have_stream_info) {
- g_warning("no STREAMINFO packet found");
- return false;
- }
-
- *audio_format = data->audio_format;
- return true;
-}
-
static void
flac_got_stream_info(struct flac_data *data,
const FLAC__StreamMetadata_StreamInfo *stream_info)
{
- if (data->have_stream_info || data->unsupported)
+ if (data->initialized || data->unsupported)
return;
GError *error = NULL;
@@ -114,8 +99,15 @@ flac_got_stream_info(struct flac_data *data,
data->frame_size = audio_format_frame_size(&data->audio_format);
- data->total_frames = stream_info->total_samples;
- data->have_stream_info = true;
+ if (data->total_frames == 0)
+ data->total_frames = stream_info->total_samples;
+
+ decoder_initialized(data->decoder, &data->audio_format,
+ data->input_stream->seekable,
+ (float)data->total_frames /
+ (float)data->audio_format.sample_rate);
+
+ data->initialized = true;
}
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
diff --git a/src/decoder/_flac_common.h b/src/decoder/_flac_common.h
index d67a5a9e9..5c59ee123 100644
--- a/src/decoder/_flac_common.h
+++ b/src/decoder/_flac_common.h
@@ -44,9 +44,9 @@ struct flac_data {
unsigned frame_size;
/**
- * Is the #stream_info member valid?
+ * Has decoder_initialized() been called yet?
*/
- bool have_stream_info;
+ bool initialized;
/**
* Does the FLAC file contain an unsupported audio format?
@@ -55,12 +55,14 @@ struct flac_data {
/**
* The validated audio format of the FLAC file. This
- * attribute is defined if "have_stream_info" is true.
+ * attribute is defined if "initialized" is true.
*/
struct audio_format audio_format;
/**
- * The total number of frames in this song.
+ * The total number of frames in this song. The decoder
+ * plugin may initialize this attribute to override the value
+ * provided by libFLAC (e.g. for sub songs from a CUE sheet).
*/
FLAC__uint64 total_frames;
@@ -89,17 +91,6 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
void
flac_data_deinit(struct flac_data *data);
-/**
- * Obtains the audio format from the stream_info attribute, and copies
- * it to the specified #audio_format object. This also updates the
- * frame_size attribute.
- *
- * @return true on success, false the audio format is not supported
- */
-bool
-flac_data_get_audio_format(struct flac_data *data,
- struct audio_format *audio_format);
-
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
struct flac_data *data);
diff --git a/src/decoder/flac_decoder_plugin.c b/src/decoder/flac_decoder_plugin.c
index 1a81e3fd4..d139354b8 100644
--- a/src/decoder/flac_decoder_plugin.c
+++ b/src/decoder/flac_decoder_plugin.c
@@ -238,26 +238,16 @@ flac_decoder_new(void)
static bool
flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
- bool seekable, FLAC__uint64 duration)
+ FLAC__uint64 duration)
{
- struct audio_format audio_format;
+ data->total_frames = duration;
if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) {
g_warning("problem reading metadata");
return false;
}
- if (!flac_data_get_audio_format(data, &audio_format))
- return false;
-
- if (duration == 0)
- duration = data->total_frames;
-
- decoder_initialized(data->decoder, &audio_format,
- seekable,
- (float)duration /
- (float)data->audio_format.sample_rate);
- return true;
+ return data->initialized;
}
static void
@@ -365,8 +355,7 @@ flac_decode_internal(struct decoder * decoder,
}
}
- if (!flac_decoder_initialize(&data, flac_dec,
- input_stream->seekable, 0)) {
+ if (!flac_decoder_initialize(&data, flac_dec, 0)) {
flac_data_deinit(&data);
FLAC__stream_decoder_delete(flac_dec);
return;
diff --git a/src/decoder/oggflac_decoder_plugin.c b/src/decoder/oggflac_decoder_plugin.c
index 63438c2b9..7e5f48318 100644
--- a/src/decoder/oggflac_decoder_plugin.c
+++ b/src/decoder/oggflac_decoder_plugin.c
@@ -297,7 +297,7 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *input_stream)
goto fail;
}
- if (!flac_data_get_audio_format(&data, &audio_format))
+ if (!data.initialized)
goto fail;
decoder_initialized(mpd_decoder, &audio_format,