faad: faad_decoder_init() returns an audio_format
Instead of returning the sample rate and channel count as separate values, fill an audio_format struct.
This commit is contained in:
@@ -223,7 +223,7 @@ faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is)
|
|||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
faad_decoder_init(faacDecHandle decoder, struct decoder_buffer *buffer,
|
faad_decoder_init(faacDecHandle decoder, struct decoder_buffer *buffer,
|
||||||
uint32_t *sample_rate, uint8_t *channels)
|
struct audio_format *audio_format)
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
/* deconst hack for libfaad */
|
/* deconst hack for libfaad */
|
||||||
@@ -232,13 +232,15 @@ faad_decoder_init(faacDecHandle decoder, struct decoder_buffer *buffer,
|
|||||||
} u;
|
} u;
|
||||||
size_t length;
|
size_t length;
|
||||||
int32_t nbytes;
|
int32_t nbytes;
|
||||||
|
uint32_t sample_rate;
|
||||||
|
uint8_t channels;
|
||||||
#ifdef HAVE_FAAD_LONG
|
#ifdef HAVE_FAAD_LONG
|
||||||
/* neaacdec.h declares all arguments as "unsigned long", but
|
/* neaacdec.h declares all arguments as "unsigned long", but
|
||||||
internally expects uint32_t pointers. To avoid gcc
|
internally expects uint32_t pointers. To avoid gcc
|
||||||
warnings, use this workaround. */
|
warnings, use this workaround. */
|
||||||
unsigned long *sample_rate_r = (unsigned long *)(void *)sample_rate;
|
unsigned long *sample_rate_r = (unsigned long *)(void *)&sample_rate;
|
||||||
#else
|
#else
|
||||||
uint32_t *sample_rate_r = sample_rate;
|
uint32_t *sample_rate_r = &sample_rate;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u.in = decoder_buffer_read(buffer, &length);
|
u.in = decoder_buffer_read(buffer, &length);
|
||||||
@@ -249,11 +251,18 @@ faad_decoder_init(faacDecHandle decoder, struct decoder_buffer *buffer,
|
|||||||
#ifdef HAVE_FAAD_BUFLEN_FUNCS
|
#ifdef HAVE_FAAD_BUFLEN_FUNCS
|
||||||
length,
|
length,
|
||||||
#endif
|
#endif
|
||||||
sample_rate_r, channels);
|
sample_rate_r, &channels);
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
decoder_buffer_consume(buffer, nbytes);
|
decoder_buffer_consume(buffer, nbytes);
|
||||||
|
|
||||||
|
*audio_format = (struct audio_format){
|
||||||
|
.bits = 16,
|
||||||
|
.channels = channels,
|
||||||
|
.sample_rate = sample_rate,
|
||||||
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,8 +303,6 @@ faad_get_file_time_float(const char *file)
|
|||||||
float length;
|
float length;
|
||||||
faacDecHandle decoder;
|
faacDecHandle decoder;
|
||||||
faacDecConfigurationPtr config;
|
faacDecConfigurationPtr config;
|
||||||
uint32_t sample_rate;
|
|
||||||
unsigned char channels;
|
|
||||||
struct input_stream is;
|
struct input_stream is;
|
||||||
|
|
||||||
if (!input_stream_open(&is, file))
|
if (!input_stream_open(&is, file))
|
||||||
@@ -307,6 +314,7 @@ faad_get_file_time_float(const char *file)
|
|||||||
|
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
bool ret;
|
bool ret;
|
||||||
|
struct audio_format audio_format;
|
||||||
|
|
||||||
decoder = faacDecOpen();
|
decoder = faacDecOpen();
|
||||||
|
|
||||||
@@ -316,9 +324,8 @@ faad_get_file_time_float(const char *file)
|
|||||||
|
|
||||||
decoder_buffer_fill(buffer);
|
decoder_buffer_fill(buffer);
|
||||||
|
|
||||||
ret = faad_decoder_init(decoder, buffer,
|
ret = faad_decoder_init(decoder, buffer, &audio_format);
|
||||||
&sample_rate, &channels);
|
if (ret && audio_format_valid(&audio_format))
|
||||||
if (ret && sample_rate > 0 && channels > 0)
|
|
||||||
length = 0;
|
length = 0;
|
||||||
|
|
||||||
faacDecClose(decoder);
|
faacDecClose(decoder);
|
||||||
@@ -351,8 +358,6 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
|
|||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
faacDecFrameInfo frame_info;
|
faacDecFrameInfo frame_info;
|
||||||
faacDecConfigurationPtr config;
|
faacDecConfigurationPtr config;
|
||||||
uint32_t sample_rate;
|
|
||||||
unsigned char channels;
|
|
||||||
unsigned long sample_count;
|
unsigned long sample_count;
|
||||||
bool ret;
|
bool ret;
|
||||||
const void *decoded;
|
const void *decoded;
|
||||||
@@ -384,20 +389,13 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
|
|||||||
decoder_buffer_fill(buffer);
|
decoder_buffer_fill(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = faad_decoder_init(decoder, buffer,
|
ret = faad_decoder_init(decoder, buffer, &audio_format);
|
||||||
&sample_rate, &channels);
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
g_warning("Error not a AAC stream.\n");
|
g_warning("Error not a AAC stream.\n");
|
||||||
faacDecClose(decoder);
|
faacDecClose(decoder);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_format = (struct audio_format){
|
|
||||||
.bits = 16,
|
|
||||||
.channels = channels,
|
|
||||||
.sample_rate = sample_rate,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!audio_format_valid(&audio_format)) {
|
if (!audio_format_valid(&audio_format)) {
|
||||||
g_warning("invalid audio format\n");
|
g_warning("invalid audio format\n");
|
||||||
faacDecClose(decoder);
|
faacDecClose(decoder);
|
||||||
@@ -421,16 +419,16 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame_info.channels != channels) {
|
if (frame_info.channels != audio_format.channels) {
|
||||||
g_warning("channel count changed from %u to %u",
|
g_warning("channel count changed from %u to %u",
|
||||||
channels, frame_info.channels);
|
audio_format.channels, frame_info.channels);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
|
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
|
||||||
if (frame_info.samplerate != sample_rate) {
|
if (frame_info.samplerate != audio_format.sample_rate) {
|
||||||
g_warning("sample rate changed from %u to %lu",
|
g_warning("sample rate changed from %u to %lu",
|
||||||
sample_rate,
|
audio_format.sample_rate,
|
||||||
(unsigned long)frame_info.samplerate);
|
(unsigned long)frame_info.samplerate);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -441,11 +439,11 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
|
|||||||
sample_count = (unsigned long)frame_info.samples;
|
sample_count = (unsigned long)frame_info.samples;
|
||||||
if (sample_count > 0) {
|
if (sample_count > 0) {
|
||||||
bit_rate = frame_info.bytesconsumed * 8.0 *
|
bit_rate = frame_info.bytesconsumed * 8.0 *
|
||||||
frame_info.channels * sample_rate /
|
frame_info.channels * audio_format.sample_rate /
|
||||||
frame_info.samples / 1000 + 0.5;
|
frame_info.samples / 1000 + 0.5;
|
||||||
file_time +=
|
file_time +=
|
||||||
(float)(frame_info.samples) / frame_info.channels /
|
(float)(frame_info.samples) / frame_info.channels /
|
||||||
sample_rate;
|
audio_format.sample_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded_length = sample_count * 2;
|
decoded_length = sample_count * 2;
|
||||||
|
Reference in New Issue
Block a user