Commit e2a08fa8 authored by Max Kellermann's avatar Max Kellermann

decoder/faad: make variables more local

parent d403749d
...@@ -66,7 +66,7 @@ adts_check_frame(const unsigned char *data) ...@@ -66,7 +66,7 @@ adts_check_frame(const unsigned char *data)
static size_t static size_t
adts_find_frame(DecoderBuffer *buffer) adts_find_frame(DecoderBuffer *buffer)
{ {
size_t length, frame_length; size_t length;
while (true) { while (true) {
const uint8_t *data = (const uint8_t *) const uint8_t *data = (const uint8_t *)
...@@ -95,7 +95,7 @@ adts_find_frame(DecoderBuffer *buffer) ...@@ -95,7 +95,7 @@ adts_find_frame(DecoderBuffer *buffer)
} }
/* is it a frame? */ /* is it a frame? */
frame_length = adts_check_frame(data); size_t frame_length = adts_check_frame(data);
if (frame_length == 0) { if (frame_length == 0) {
/* it's just some random 0xff byte; discard it /* it's just some random 0xff byte; discard it
and continue searching */ and continue searching */
...@@ -128,17 +128,15 @@ adts_find_frame(DecoderBuffer *buffer) ...@@ -128,17 +128,15 @@ adts_find_frame(DecoderBuffer *buffer)
static float static float
adts_song_duration(DecoderBuffer *buffer) adts_song_duration(DecoderBuffer *buffer)
{ {
unsigned int frames, frame_length;
unsigned sample_rate = 0; unsigned sample_rate = 0;
float frames_per_second;
/* Read all frames to ensure correct time and bitrate */ /* Read all frames to ensure correct time and bitrate */
for (frames = 0;; frames++) { unsigned frames = 0;
frame_length = adts_find_frame(buffer); for (;; frames++) {
unsigned frame_length = adts_find_frame(buffer);
if (frame_length == 0) if (frame_length == 0)
break; break;
if (frames == 0) { if (frames == 0) {
size_t buffer_length; size_t buffer_length;
const uint8_t *data = (const uint8_t *) const uint8_t *data = (const uint8_t *)
...@@ -152,7 +150,7 @@ adts_song_duration(DecoderBuffer *buffer) ...@@ -152,7 +150,7 @@ adts_song_duration(DecoderBuffer *buffer)
decoder_buffer_consume(buffer, frame_length); decoder_buffer_consume(buffer, frame_length);
} }
frames_per_second = (float)sample_rate / 1024.0; float frames_per_second = (float)sample_rate / 1024.0;
if (frames_per_second <= 0) if (frames_per_second <= 0)
return -1; return -1;
...@@ -162,21 +160,17 @@ adts_song_duration(DecoderBuffer *buffer) ...@@ -162,21 +160,17 @@ adts_song_duration(DecoderBuffer *buffer)
static float static float
faad_song_duration(DecoderBuffer *buffer, InputStream &is) faad_song_duration(DecoderBuffer *buffer, InputStream &is)
{ {
size_t fileread;
size_t tagsize;
size_t length;
bool success;
const auto size = is.GetSize(); const auto size = is.GetSize();
fileread = size >= 0 ? size : 0; const size_t fileread = size >= 0 ? size : 0;
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);
size_t length;
const uint8_t *data = (const uint8_t *) const uint8_t *data = (const uint8_t *)
decoder_buffer_read(buffer, &length); decoder_buffer_read(buffer, &length);
if (data == nullptr) if (data == nullptr)
return -1; return -1;
tagsize = 0; size_t tagsize = 0;
if (length >= 10 && !memcmp(data, "ID3", 3)) { if (length >= 10 && !memcmp(data, "ID3", 3)) {
/* skip the ID3 tag */ /* skip the ID3 tag */
...@@ -185,7 +179,7 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is) ...@@ -185,7 +179,7 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is)
tagsize += 10; tagsize += 10;
success = decoder_buffer_skip(buffer, tagsize) && bool success = decoder_buffer_skip(buffer, tagsize) &&
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);
if (!success) if (!success)
return -1; return -1;
...@@ -239,9 +233,7 @@ static bool ...@@ -239,9 +233,7 @@ static bool
faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer, faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
AudioFormat &audio_format, Error &error) AudioFormat &audio_format, Error &error)
{ {
int32_t nbytes;
uint32_t sample_rate; 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
...@@ -259,11 +251,12 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer, ...@@ -259,11 +251,12 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
return false; return false;
} }
nbytes = NeAACDecInit(decoder, uint8_t channels;
/* deconst hack, libfaad requires this */ int32_t nbytes = NeAACDecInit(decoder,
const_cast<unsigned char *>(data), /* deconst hack, libfaad requires this */
length, const_cast<unsigned char *>(data),
sample_rate_p, &channels); length,
sample_rate_p, &channels);
if (nbytes < 0) { if (nbytes < 0) {
error.Set(faad_decoder_domain, "Not an AAC stream"); error.Set(faad_decoder_domain, "Not an AAC stream");
return false; return false;
...@@ -303,17 +296,12 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer, ...@@ -303,17 +296,12 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer,
static float static float
faad_get_file_time_float(InputStream &is) faad_get_file_time_float(InputStream &is)
{ {
DecoderBuffer *buffer; DecoderBuffer *buffer =
float length; decoder_buffer_new(nullptr, is,
FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
buffer = decoder_buffer_new(nullptr, is, float length = faad_song_duration(buffer, is);
FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
length = faad_song_duration(buffer, is);
if (length < 0) { if (length < 0) {
bool ret;
AudioFormat audio_format;
NeAACDecHandle decoder = NeAACDecOpen(); NeAACDecHandle decoder = NeAACDecOpen();
NeAACDecConfigurationPtr config = NeAACDecConfigurationPtr config =
...@@ -323,9 +311,9 @@ faad_get_file_time_float(InputStream &is) ...@@ -323,9 +311,9 @@ faad_get_file_time_float(InputStream &is)
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);
ret = faad_decoder_init(decoder, buffer, audio_format, AudioFormat audio_format;
IgnoreError()); if (faad_decoder_init(decoder, buffer, audio_format,
if (ret) IgnoreError()))
length = 0; length = 0;
NeAACDecClose(decoder); NeAACDecClose(decoder);
...@@ -356,15 +344,10 @@ faad_get_file_time(InputStream &is) ...@@ -356,15 +344,10 @@ faad_get_file_time(InputStream &is)
static void static void
faad_stream_decode(Decoder &mpd_decoder, InputStream &is) faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
{ {
float total_time = 0; DecoderBuffer *buffer =
AudioFormat audio_format; decoder_buffer_new(&mpd_decoder, is,
bool ret; FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
uint16_t bit_rate = 0; const float total_time = faad_song_duration(buffer, is);
DecoderBuffer *buffer;
buffer = decoder_buffer_new(&mpd_decoder, is,
FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
total_time = faad_song_duration(buffer, is);
/* create the libfaad decoder */ /* create the libfaad decoder */
...@@ -386,8 +369,8 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is) ...@@ -386,8 +369,8 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
/* initialize it */ /* initialize it */
Error error; Error error;
ret = faad_decoder_init(decoder, buffer, audio_format, error); AudioFormat audio_format;
if (!ret) { if (!faad_decoder_init(decoder, buffer, audio_format, error)) {
LogError(error); LogError(error);
NeAACDecClose(decoder); NeAACDecClose(decoder);
return; return;
...@@ -400,6 +383,7 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is) ...@@ -400,6 +383,7 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
/* the decoder loop */ /* the decoder loop */
DecoderCommand cmd; DecoderCommand cmd;
unsigned bit_rate = 0;
do { do {
size_t frame_size; size_t frame_size;
const void *decoded; const void *decoded;
...@@ -478,7 +462,7 @@ static const char *const faad_mime_types[] = { ...@@ -478,7 +462,7 @@ static const char *const faad_mime_types[] = {
"audio/aac", "audio/aacp", nullptr "audio/aac", "audio/aacp", nullptr
}; };
const struct DecoderPlugin faad_decoder_plugin = { const DecoderPlugin faad_decoder_plugin = {
"faad", "faad",
nullptr, nullptr,
nullptr, nullptr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment