decoder/flac: moved decoder initialization to _flac_common.c
Invoke decoder_initialized() in the libFLAC metadata callback. This merges code from the FLAC and the OggFLAC decoder plugin into the common library.
This commit is contained in:
parent
ae9c02b3a8
commit
550c9319e9
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user