decoder/flac: moved code to flac_data_get_audio_format()
Remove the audio_format attribute, add "frame_size" instead. The audio_format initialization and check is moved both to flac_data_get_audio_format().
This commit is contained in:
parent
08b139f37c
commit
37181c9181
@ -58,19 +58,41 @@ flac_data_deinit(struct flac_data *data)
|
|||||||
tag_free(data->tag);
|
tag_free(data->tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
flac_data_get_audio_format(struct flac_data *data,
|
||||||
|
struct audio_format *audio_format)
|
||||||
|
{
|
||||||
|
if (!data->have_stream_info) {
|
||||||
|
g_warning("no STREAMINFO packet found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
audio_format_init(audio_format, data->stream_info.sample_rate,
|
||||||
|
data->stream_info.bits_per_sample,
|
||||||
|
data->stream_info.channels);
|
||||||
|
|
||||||
|
if (!audio_format_valid(audio_format)) {
|
||||||
|
g_warning("Invalid audio format: %u:%u:%u\n",
|
||||||
|
audio_format->sample_rate,
|
||||||
|
audio_format->bits,
|
||||||
|
audio_format->channels);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->frame_size = audio_format_frame_size(audio_format);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
||||||
struct flac_data *data)
|
struct flac_data *data)
|
||||||
{
|
{
|
||||||
const FLAC__StreamMetadata_StreamInfo *si = &(block->data.stream_info);
|
|
||||||
|
|
||||||
switch (block->type) {
|
switch (block->type) {
|
||||||
case FLAC__METADATA_TYPE_STREAMINFO:
|
case FLAC__METADATA_TYPE_STREAMINFO:
|
||||||
data->stream_info = block->data.stream_info;
|
data->stream_info = block->data.stream_info;
|
||||||
data->have_stream_info = true;
|
data->have_stream_info = true;
|
||||||
|
|
||||||
audio_format_init(&data->audio_format, si->sample_rate,
|
|
||||||
si->bits_per_sample, si->channels);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
||||||
if (data->replay_gain_info)
|
if (data->replay_gain_info)
|
||||||
replay_gain_info_free(data->replay_gain_info);
|
replay_gain_info_free(data->replay_gain_info);
|
||||||
@ -113,8 +135,7 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
|
|||||||
FLAC__uint64 nbytes)
|
FLAC__uint64 nbytes)
|
||||||
{
|
{
|
||||||
enum decoder_command cmd;
|
enum decoder_command cmd;
|
||||||
size_t buffer_size = frame->header.blocksize *
|
size_t buffer_size = frame->header.blocksize * data->frame_size;
|
||||||
audio_format_frame_size(&data->audio_format);
|
|
||||||
void *buffer;
|
void *buffer;
|
||||||
float position;
|
float position;
|
||||||
unsigned bit_rate;
|
unsigned bit_rate;
|
||||||
|
@ -38,6 +38,11 @@
|
|||||||
struct flac_data {
|
struct flac_data {
|
||||||
struct pcm_buffer buffer;
|
struct pcm_buffer buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size of one frame in the output buffer.
|
||||||
|
*/
|
||||||
|
unsigned frame_size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the #stream_info member valid?
|
* Is the #stream_info member valid?
|
||||||
*/
|
*/
|
||||||
@ -62,7 +67,6 @@ struct flac_data {
|
|||||||
*/
|
*/
|
||||||
FLAC__uint64 next_frame;
|
FLAC__uint64 next_frame;
|
||||||
|
|
||||||
struct audio_format audio_format;
|
|
||||||
FLAC__uint64 position;
|
FLAC__uint64 position;
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
struct input_stream *input_stream;
|
struct input_stream *input_stream;
|
||||||
@ -78,6 +82,17 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
|
|||||||
void
|
void
|
||||||
flac_data_deinit(struct flac_data *data);
|
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,
|
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
||||||
struct flac_data *data);
|
struct flac_data *data);
|
||||||
|
|
||||||
|
@ -391,28 +391,20 @@ static bool
|
|||||||
flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
|
flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
|
||||||
bool seekable, FLAC__uint64 duration)
|
bool seekable, FLAC__uint64 duration)
|
||||||
{
|
{
|
||||||
|
struct audio_format audio_format;
|
||||||
|
|
||||||
if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) {
|
if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) {
|
||||||
g_warning("problem reading metadata");
|
g_warning("problem reading metadata");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data->have_stream_info) {
|
if (!flac_data_get_audio_format(data, &audio_format))
|
||||||
g_warning("no STREAMINFO packet found");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (!audio_format_valid(&data->audio_format)) {
|
|
||||||
g_warning("Invalid audio format: %u:%u:%u\n",
|
|
||||||
data->audio_format.sample_rate,
|
|
||||||
data->audio_format.bits,
|
|
||||||
data->audio_format.channels);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (duration == 0)
|
if (duration == 0)
|
||||||
duration = data->stream_info.total_samples;
|
duration = data->stream_info.total_samples;
|
||||||
|
|
||||||
decoder_initialized(data->decoder, &data->audio_format,
|
decoder_initialized(data->decoder, &audio_format,
|
||||||
seekable,
|
seekable,
|
||||||
(float)duration /
|
(float)duration /
|
||||||
(float)data->stream_info.sample_rate);
|
(float)data->stream_info.sample_rate);
|
||||||
|
@ -288,6 +288,7 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *input_stream)
|
|||||||
{
|
{
|
||||||
OggFLAC__SeekableStreamDecoder *decoder = NULL;
|
OggFLAC__SeekableStreamDecoder *decoder = NULL;
|
||||||
struct flac_data data;
|
struct flac_data data;
|
||||||
|
struct audio_format audio_format;
|
||||||
|
|
||||||
if (ogg_stream_type_detect(input_stream) != FLAC)
|
if (ogg_stream_type_detect(input_stream) != FLAC)
|
||||||
return;
|
return;
|
||||||
@ -302,20 +303,10 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *input_stream)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.have_stream_info) {
|
if (!flac_data_get_audio_format(&data, &audio_format))
|
||||||
g_warning("no STREAMINFO packet found");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
|
|
||||||
if (!audio_format_valid(&data.audio_format)) {
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
g_warning("Invalid audio format: %u:%u:%u\n",
|
|
||||||
data.audio_format.sample_rate,
|
|
||||||
data.audio_format.bits,
|
|
||||||
data.audio_format.channels);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder_initialized(mpd_decoder, &data.audio_format,
|
|
||||||
input_stream->seekable,
|
input_stream->seekable,
|
||||||
(float)data.stream_info.total_samples /
|
(float)data.stream_info.total_samples /
|
||||||
(float)data.stream_info.sample_rate);
|
(float)data.stream_info.sample_rate);
|
||||||
|
Loading…
Reference in New Issue
Block a user