mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 19:47:02 +03:00
better alac management
This commit is contained in:
@@ -19,7 +19,7 @@ extern "C" {
|
|||||||
|
|
||||||
struct alac_codec_s *alac_create_decoder(int magic_cookie_size, unsigned char *magic_cookie,
|
struct alac_codec_s *alac_create_decoder(int magic_cookie_size, unsigned char *magic_cookie,
|
||||||
unsigned char *sample_size, unsigned *sample_rate,
|
unsigned char *sample_size, unsigned *sample_rate,
|
||||||
unsigned char *channels);
|
unsigned char *channels, unsigned int *block_size);
|
||||||
void alac_delete_decoder(struct alac_codec_s *codec);
|
void alac_delete_decoder(struct alac_codec_s *codec);
|
||||||
bool alac_to_pcm(struct alac_codec_s *codec, unsigned char* input,
|
bool alac_to_pcm(struct alac_codec_s *codec, unsigned char* input,
|
||||||
unsigned char *output, char channels, unsigned *out_frames);
|
unsigned char *output, char channels, unsigned *out_frames);
|
||||||
|
|||||||
Binary file not shown.
@@ -168,7 +168,7 @@ static void rtp_thread_func(void *arg);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static struct alac_codec_s* alac_init(int fmtp[32]) {
|
static struct alac_codec_s* alac_init(int fmtp[32]) {
|
||||||
struct alac_codec_s *alac;
|
struct alac_codec_s *alac;
|
||||||
unsigned sample_rate, block_size;
|
unsigned sample_rate, block_size;
|
||||||
unsigned char sample_size, channels;
|
unsigned char sample_size, channels;
|
||||||
@@ -196,7 +196,7 @@ static struct alac_codec_s* alac_init(int fmtp[32]) {
|
|||||||
config.maxRun = htons(fmtp[8]);
|
config.maxRun = htons(fmtp[8]);
|
||||||
config.maxFrameBytes = htonl(fmtp[9]);
|
config.maxFrameBytes = htonl(fmtp[9]);
|
||||||
config.avgBitRate = htonl(fmtp[10]);
|
config.avgBitRate = htonl(fmtp[10]);
|
||||||
config.sampleRate = htonl(fmtp[11]);
|
config.sampleRate = htonl(fmtp[11]);
|
||||||
|
|
||||||
alac = alac_create_decoder(sizeof(config), (unsigned char*) &config, &sample_size, &sample_rate, &channels, &block_size);
|
alac = alac_create_decoder(sizeof(config), (unsigned char*) &config, &sample_size, &sample_rate, &channels, &block_size);
|
||||||
if (!alac) {
|
if (!alac) {
|
||||||
|
|||||||
@@ -119,8 +119,16 @@ static int read_mp4_header(void) {
|
|||||||
// extract audio config from within alac
|
// extract audio config from within alac
|
||||||
if (!strcmp(type, "alac") && bytes > len) {
|
if (!strcmp(type, "alac") && bytes > len) {
|
||||||
u8_t *ptr = streambuf->readp + 36;
|
u8_t *ptr = streambuf->readp + 36;
|
||||||
l->decoder = alac_create_decoder(len - 36, ptr, &l->sample_size, &l->sample_rate, &l->channels);
|
unsigned int block_size;
|
||||||
|
l->decoder = alac_create_decoder(len - 36, ptr, &l->sample_size, &l->sample_rate, &l->channels, &block_size);
|
||||||
l->play = l->trak;
|
l->play = l->trak;
|
||||||
|
l->writebuf = malloc(block_size + 256);
|
||||||
|
if (!l->writebuf) {
|
||||||
|
LOG_ERROR("cannot allocate write buffer for %u bytes", block_size);
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
LOG_INFO("write buffer of %u bytes", block_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract the total number of samples from stts
|
// extract the total number of samples from stts
|
||||||
@@ -510,12 +518,11 @@ static decode_state alac_decode(void) {
|
|||||||
|
|
||||||
static void alac_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
static void alac_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
||||||
if (l->decoder) alac_delete_decoder(l->decoder);
|
if (l->decoder) alac_delete_decoder(l->decoder);
|
||||||
else l->writebuf = malloc(BLOCK_SIZE * 2);
|
if (l->writebuf) free(l->writebuf);
|
||||||
|
|
||||||
if (l->chunkinfo) free(l->chunkinfo);
|
if (l->chunkinfo) free(l->chunkinfo);
|
||||||
if (l->block_size) free(l->block_size);
|
if (l->block_size) free(l->block_size);
|
||||||
if (l->stsc) free(l->stsc);
|
if (l->stsc) free(l->stsc);
|
||||||
l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
|
l->writebuf = l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
|
||||||
l->skip = 0;
|
l->skip = 0;
|
||||||
l->samples = l->sttssamples = 0;
|
l->samples = l->sttssamples = 0;
|
||||||
l->empty = false;
|
l->empty = false;
|
||||||
@@ -524,11 +531,11 @@ static void alac_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
|||||||
|
|
||||||
static void alac_close(void) {
|
static void alac_close(void) {
|
||||||
if (l->decoder) alac_delete_decoder(l->decoder);
|
if (l->decoder) alac_delete_decoder(l->decoder);
|
||||||
|
if (l->writebuf) free(l->writebuf);
|
||||||
if (l->chunkinfo) free(l->chunkinfo);
|
if (l->chunkinfo) free(l->chunkinfo);
|
||||||
if (l->block_size) free(l->block_size);
|
if (l->block_size) free(l->block_size);
|
||||||
if (l->stsc) free(l->stsc);
|
if (l->stsc) free(l->stsc);
|
||||||
l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
|
l->writebuf = l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
|
||||||
free(l->writebuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct codec *register_alac(void) {
|
struct codec *register_alac(void) {
|
||||||
@@ -547,7 +554,7 @@ struct codec *register_alac(void) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
|
l->writebuf = l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
|
||||||
|
|
||||||
LOG_INFO("using alac to decode alc");
|
LOG_INFO("using alac to decode alc");
|
||||||
return &ret;
|
return &ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user