mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
fixed airplay
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
static log_level *loglevel = &raop_loglevel;
|
||||
|
||||
//#define __RTP_STORE
|
||||
|
||||
|
||||
// default buffer size
|
||||
#define BUFFER_FRAMES ( (150 * 88200) / (352 * 100) )
|
||||
#define MAX_PACKET 1408
|
||||
@@ -126,7 +126,6 @@ typedef struct rtp_s {
|
||||
u32_t rtptime;
|
||||
} record;
|
||||
int latency; // rtp hold depth in samples
|
||||
u32_t resent_req, resent_rec; // total resent + recovered frames
|
||||
u32_t resent_req, resent_rec; // total resent + recovered frames
|
||||
u32_t silent_frames; // total silence frames
|
||||
u32_t discarded;
|
||||
@@ -141,7 +140,6 @@ typedef struct rtp_s {
|
||||
alac_file *alac_codec;
|
||||
int flush_seqno;
|
||||
bool playing;
|
||||
raop_data_cb_t data_cb;
|
||||
raop_data_cb_t data_cb;
|
||||
raop_cmd_cb_t cmd_cb;
|
||||
} rtp_t;
|
||||
@@ -239,7 +237,7 @@ rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv,
|
||||
|
||||
memset(fmtp, 0, sizeof(fmtp));
|
||||
while ((arg = strsep(&fmtpstr, " \t")) != NULL) fmtp[i++] = atoi(arg);
|
||||
|
||||
|
||||
ctx->frame_size = fmtp[1];
|
||||
ctx->frame_duration = (ctx->frame_size * 1000) / RAOP_SAMPLE_RATE;
|
||||
|
||||
@@ -461,14 +459,14 @@ static void buffer_put_packet(rtp_t *ctx, seq_t seqno, unsigned rtptime, bool fi
|
||||
if (abuf) {
|
||||
alac_decode(ctx, abuf->data, data, len, &abuf->len);
|
||||
abuf->ready = 1;
|
||||
// this is the local rtptime when this frame is expected to play
|
||||
abuf->rtptime = rtptime;
|
||||
buffer_push_packet(ctx);
|
||||
|
||||
#ifdef __RTP_STORE
|
||||
fwrite(data, len, 1, ctx->rtpIN);
|
||||
fwrite(abuf->data, abuf->len, 1, ctx->rtpOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&ctx->ab_mutex);
|
||||
@@ -476,7 +474,7 @@ static void buffer_put_packet(rtp_t *ctx, seq_t seqno, unsigned rtptime, bool fi
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
// push as many frames as possible through callback
|
||||
static void buffer_push_packet(rtp_t *ctx) {
|
||||
static void buffer_push_packet(rtp_t *ctx) {
|
||||
abuf_t *curframe = NULL;
|
||||
u32_t now, playtime, hold = max((ctx->latency * 1000) / (8 * RAOP_SAMPLE_RATE), 100);
|
||||
int i;
|
||||
@@ -489,10 +487,10 @@ static void buffer_push_packet(rtp_t *ctx) {
|
||||
|
||||
// there is always at least one frame in the buffer
|
||||
do {
|
||||
|
||||
|
||||
curframe = ctx->audio_buffer + BUFIDX(ctx->ab_read);
|
||||
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++;
|
||||
@@ -506,12 +504,13 @@ static void buffer_push_packet(rtp_t *ctx) {
|
||||
} else break;
|
||||
|
||||
ctx->ab_read++;
|
||||
ctx->out_frames++;
|
||||
ctx->out_frames++;
|
||||
|
||||
// need to be promoted to a signed int *before* addition
|
||||
} while ((s16_t) (ctx->ab_write - ctx->ab_read) + 1 > 0);
|
||||
|
||||
|
||||
if (ctx->out_frames > 1000) {
|
||||
LOG_INFO("[%p]: drain [level:%hd gap:%d] [W:%hu R:%hu] [R:%u S:%u F:%u D:%u] (head in %u ms) ",
|
||||
LOG_INFO("[%p]: drain [level:%hd head:%d ms] [W:%hu R:%hu] [req:%u sil:%u dis:%u]",
|
||||
ctx, ctx->ab_write - ctx->ab_read, playtime - now, ctx->ab_write, ctx->ab_read,
|
||||
ctx->resent_req, ctx->silent_frames, ctx->discarded);
|
||||
ctx->out_frames = 0;
|
||||
@@ -614,7 +613,7 @@ static void *rtp_thread_func(void *arg) {
|
||||
u32_t rtp_now_latency = ntohl(*(u32_t*)(pktp+4));
|
||||
u64_t remote = (((u64_t) ntohl(*(u32_t*)(pktp+8))) << 32) + ntohl(*(u32_t*)(pktp+12));
|
||||
u32_t rtp_now = ntohl(*(u32_t*)(pktp+16));
|
||||
|
||||
|
||||
pthread_mutex_lock(&ctx->ab_mutex);
|
||||
|
||||
// re-align timestamp and expected local playback time (and magic 11025 latency)
|
||||
@@ -628,8 +627,8 @@ static void *rtp_thread_func(void *arg) {
|
||||
// 1st sync packet received (signals a restart of playback)
|
||||
if (packet[0] & 0x10) {
|
||||
LOG_INFO("[%p]: 1st sync packet received", ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&ctx->ab_mutex);
|
||||
|
||||
LOG_DEBUG("[%p]: sync packet latency:%d rtp_latency:%u rtp:%u remote ntp:%llx, local time:%u local rtp:%u (now:%u)",
|
||||
@@ -670,7 +669,7 @@ static void *rtp_thread_func(void *arg) {
|
||||
s32_t delta = NTP2MS((s64_t) expected - (s64_t) ctx->timing.remote);
|
||||
ctx->cmd_cb(RAOP_TIMING, &delta);
|
||||
}
|
||||
|
||||
|
||||
// now we are synced on NTP (mutex not needed)
|
||||
ctx->synchro.status |= NTP_SYNC;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user