mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 11:36:59 +03:00
move to Apple alac decoder, update partition size
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
/*
|
||||
* HairTunes - RAOP packet handler and slave-clocked replay engine
|
||||
* Copyright (c) James Laird 2011
|
||||
@@ -47,14 +48,13 @@
|
||||
|
||||
#ifdef WIN32
|
||||
#include <openssl/aes.h>
|
||||
#include "alac.h"
|
||||
#include "alac_wrapper.h"
|
||||
#else
|
||||
#include "esp_pthread.h"
|
||||
#include "esp_system.h"
|
||||
#include <mbedtls/version.h>
|
||||
#include <mbedtls/aes.h>
|
||||
//#include "alac_wrapper.h"
|
||||
#include "alac.h"
|
||||
#include "alac_wrapper.h"
|
||||
#endif
|
||||
|
||||
#define NTP2MS(ntp) ((((ntp) >> 10) * 1000L) >> 22)
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
//#define __RTP_STORE
|
||||
|
||||
// default buffer size
|
||||
// default buffer size
|
||||
#define BUFFER_FRAMES ( (150 * RAOP_SAMPLE_RATE * 2) / (352 * 100) )
|
||||
#define MAX_PACKET 1408
|
||||
#define MIN_LATENCY 11025
|
||||
@@ -141,7 +141,8 @@ typedef struct rtp_s {
|
||||
#else
|
||||
TaskHandle_t thread, joiner;
|
||||
StaticTask_t *xTaskBuffer;
|
||||
StackType_t *xStack;
|
||||
StackType_t *xStack;
|
||||
#endif
|
||||
|
||||
struct alac_codec_s *alac_codec;
|
||||
int flush_seqno;
|
||||
@@ -160,35 +161,42 @@ static void* rtp_thread_func(void *arg);
|
||||
static bool rtp_request_timing(rtp_t *ctx);
|
||||
static void* rtp_thread_func(void *arg);
|
||||
static int seq_order(seq_t a, seq_t b);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static alac_file* alac_init(int fmtp[32]) {
|
||||
alac_file *alac;
|
||||
int sample_size = fmtp[3];
|
||||
|
||||
if (sample_size != 16) {
|
||||
LOG_ERROR("sample size must be 16 %d", sample_size);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct alac_codec_s* alac_init(int fmtp[32]) {
|
||||
struct alac_codec_s *alac;
|
||||
unsigned sample_rate;
|
||||
unsigned char sample_size, channels;
|
||||
struct {
|
||||
uint32_t frameLength;
|
||||
uint8_t compatibleVersion;
|
||||
uint8_t bitDepth;
|
||||
uint8_t pb;
|
||||
uint8_t mb;
|
||||
uint8_t kb;
|
||||
uint8_t numChannels;
|
||||
uint16_t maxRun;
|
||||
uint32_t maxFrameBytes;
|
||||
uint32_t avgBitRate;
|
||||
uint32_t sampleRate;
|
||||
}
|
||||
} config;
|
||||
|
||||
config.frameLength = htonl(fmtp[1]);
|
||||
config.compatibleVersion = fmtp[2];
|
||||
config.bitDepth = fmtp[3];
|
||||
config.pb = fmtp[4];
|
||||
config.mb = fmtp[5];
|
||||
config.kb = fmtp[6];
|
||||
config.numChannels = fmtp[7];
|
||||
config.maxRun = htons(fmtp[8]);
|
||||
config.maxFrameBytes = htonl(fmtp[9]);
|
||||
config.avgBitRate = htonl(fmtp[10]);
|
||||
config.sampleRate = htonl(fmtp[11]);
|
||||
|
||||
alac = alac_create_decoder(sizeof(config), (unsigned char*) &config, &sample_size, &sample_rate, &channels);
|
||||
if (!alac) {
|
||||
LOG_ERROR("cannot create alac codec", NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
alac->setinfo_max_samples_per_frame = fmtp[1];
|
||||
alac->setinfo_7a = fmtp[2];
|
||||
alac->setinfo_sample_size = sample_size;
|
||||
alac->setinfo_rice_historymult = fmtp[4];
|
||||
alac->setinfo_rice_initialhistory = fmtp[5];
|
||||
alac->setinfo_rice_kmodifier = fmtp[6];
|
||||
alac->setinfo_7f = fmtp[7];
|
||||
alac->setinfo_80 = fmtp[8];
|
||||
alac->setinfo_82 = fmtp[9];
|
||||
alac->setinfo_86 = fmtp[10];
|
||||
alac->setinfo_8a_rate = fmtp[11];
|
||||
}
|
||||
|
||||
return alac;
|
||||
@@ -294,7 +302,7 @@ void rtp_end(rtp_t *ctx)
|
||||
#if !defined WIN32
|
||||
ctx->joiner = xTaskGetCurrentTaskHandle();
|
||||
#endif
|
||||
ctx->running = false;
|
||||
ctx->running = false;
|
||||
#ifdef WIN32
|
||||
pthread_join(ctx->thread, NULL);
|
||||
#else
|
||||
@@ -304,7 +312,7 @@ void rtp_end(rtp_t *ctx)
|
||||
#endif
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) closesocket(ctx->rtp_sockets[i].sock);
|
||||
for (i = 0; i < 3; i++) closesocket(ctx->rtp_sockets[i].sock);
|
||||
|
||||
if (ctx->alac_codec) alac_delete_decoder(ctx->alac_codec);
|
||||
if (ctx->decrypt_buf) free(ctx->decrypt_buf);
|
||||
@@ -396,8 +404,12 @@ static void alac_decode(rtp_t *ctx, s16_t *dest, char *buf, int len, int *outsiz
|
||||
AES_cbc_encrypt((unsigned char*)buf, ctx->decrypt_buf, aeslen, &ctx->aes, iv, AES_DECRYPT);
|
||||
#else
|
||||
mbedtls_aes_crypt_cbc(&ctx->aes, MBEDTLS_AES_DECRYPT, aeslen, iv, (unsigned char*) buf, ctx->decrypt_buf);
|
||||
#endif
|
||||
memcpy(ctx->decrypt_buf+aeslen, buf+aeslen, len-aeslen);
|
||||
#endif
|
||||
memcpy(ctx->decrypt_buf+aeslen, buf+aeslen, len-aeslen);
|
||||
alac_to_pcm(ctx->alac_codec, (unsigned char*) ctx->decrypt_buf, (unsigned char*) dest, 2, (unsigned int*) outsize);
|
||||
} else {
|
||||
alac_to_pcm(ctx->alac_codec, (unsigned char*) buf, (unsigned char*) dest, 2, (unsigned int*) outsize);
|
||||
}
|
||||
|
||||
*outsize *= 4;
|
||||
}
|
||||
@@ -506,28 +518,8 @@ static void buffer_push_packet(rtp_t *ctx) {
|
||||
playtime = ctx->synchro.time + (((s32_t)(curframe->rtptime - ctx->synchro.rtp)) * 1000) / RAOP_SAMPLE_RATE;
|
||||
|
||||
if (now > playtime) {
|
||||
LOG_DEBUG("[%p]: discarded frame now:%u missed by:%d (W:%hu R:%hu)", ctx, now, now - playtime, ctx->ab_write, ctx->ab_read);
|
||||
ctx->discarded++;
|
||||
ctx->discarded++;
|
||||
} else if (curframe->ready) {
|
||||
/*
|
||||
// some dirty code to see if the click problem comes from i2s stage or decoder stage
|
||||
static s16_t sin_data[200];
|
||||
static bool gen = false;
|
||||
|
||||
if (!gen) {
|
||||
for (i = 0; i < 200; i++) sin_data[i] = 1024 * sin((2*3.14159*220.5*i)/44100.);
|
||||
gen = true;
|
||||
}
|
||||
|
||||
static int c = 0;
|
||||
int cnt = 0;
|
||||
s16_t *p = (s16_t*) curframe->data;
|
||||
|
||||
while (cnt++ < 352) {
|
||||
*p = sin_data[c++ % 200];
|
||||
*(p+1) = *p;
|
||||
p += 2;
|
||||
}
|
||||
curframe->ready = 0;
|
||||
} else if (curframe->ready) {
|
||||
ctx->data_cb((const u8_t*) curframe->data, curframe->len, playtime);
|
||||
|
||||
Reference in New Issue
Block a user