mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
Improve AirPlay robustness to bad network conditions - release
need to add a decent PID loop ...
This commit is contained in:
@@ -510,14 +510,14 @@ static void buffer_push_packet(rtp_t *ctx) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
// not ready to play yet
|
// not ready to play yet
|
||||||
if (!ctx->playing || ctx->synchro.status != (RTP_SYNC | NTP_SYNC)) return;
|
|
||||||
|
|
||||||
// maybe re-evaluate time in loop in case data callback blocks ...
|
|
||||||
if (!ctx->playing || ctx->synchro.status != (RTP_SYNC | NTP_SYNC)) return;
|
if (!ctx->playing || ctx->synchro.status != (RTP_SYNC | NTP_SYNC)) return;
|
||||||
|
|
||||||
|
// there is always at least one frame in the buffer
|
||||||
|
do {
|
||||||
// re-evaluate time in loop in case data callback blocks ...
|
// re-evaluate time in loop in case data callback blocks ...
|
||||||
|
now = gettime_ms();
|
||||||
|
|
||||||
|
// try to manage playtime so that we overflow as late as possible if we miss NTP (2^31 / 10 / 44100)
|
||||||
curframe = ctx->audio_buffer + BUFIDX(ctx->ab_read);
|
curframe = ctx->audio_buffer + BUFIDX(ctx->ab_read);
|
||||||
playtime = ctx->synchro.time + (((s32_t)(curframe->rtptime - ctx->synchro.rtp)) * 10) / (RAOP_SAMPLE_RATE / 100);
|
playtime = ctx->synchro.time + (((s32_t)(curframe->rtptime - ctx->synchro.rtp)) * 10) / (RAOP_SAMPLE_RATE / 100);
|
||||||
|
|
||||||
@@ -653,9 +653,14 @@ static void *rtp_thread_func(void *arg) {
|
|||||||
u32_t rtp_now_latency = ntohl(*(u32_t*)(pktp+4));
|
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));
|
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));
|
u32_t rtp_now = ntohl(*(u32_t*)(pktp+16));
|
||||||
u16_t flags = ntohs(*(u16_t*)(pktp+2));
|
u16_t flags = ntohs(*(u16_t*)(pktp+2));
|
||||||
|
u32_t remote_gap = NTP2MS(remote - ctx->timing.remote);
|
||||||
|
|
||||||
|
// try to get NTP every 3 sec or every time if we are not synced
|
||||||
|
if (!count-- || !(ctx->synchro.status && NTP_SYNC)) {
|
||||||
|
rtp_request_timing(ctx);
|
||||||
|
count = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// something is wrong, we should not have such gap
|
// something is wrong, we should not have such gap
|
||||||
if (remote_gap > 10000) {
|
if (remote_gap > 10000) {
|
||||||
@@ -683,11 +688,6 @@ static void *rtp_thread_func(void *arg) {
|
|||||||
|
|
||||||
pthread_mutex_unlock(&ctx->ab_mutex);
|
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)",
|
|
||||||
ctx, ctx->latency, rtp_now_latency, rtp_now, remote, ctx->synchro.time, ctx->synchro.rtp, gettime_ms());
|
|
||||||
|
|
||||||
if (!count--) {
|
|
||||||
rtp_request_timing(ctx);
|
|
||||||
LOG_DEBUG("[%p]: sync packet latency:%d rtp_latency:%u rtp:%u remote ntp:%llx, local time:%u local rtp:%u (now:%u)",
|
LOG_DEBUG("[%p]: sync packet latency:%d rtp_latency:%u rtp:%u remote ntp:%llx, local time:%u local rtp:%u (now:%u)",
|
||||||
ctx, ctx->latency, rtp_now_latency, rtp_now, remote, ctx->synchro.time, ctx->synchro.rtp, gettime_ms());
|
ctx, ctx->latency, rtp_now_latency, rtp_now, remote, ctx->synchro.time, ctx->synchro.rtp, gettime_ms());
|
||||||
|
|
||||||
@@ -785,7 +785,7 @@ static bool rtp_request_resend(rtp_t *ctx, seq_t first, seq_t last) {
|
|||||||
static bool rtp_request_resend(rtp_t *ctx, seq_t first, seq_t last) {
|
static bool rtp_request_resend(rtp_t *ctx, seq_t first, seq_t last) {
|
||||||
unsigned char req[8]; // *not* a standard RTCP NACK
|
unsigned char req[8]; // *not* a standard RTCP NACK
|
||||||
|
|
||||||
// do not request silly ranges (happens in case of network large blackouts)
|
// do not request silly ranges (happens in case of network large blackouts)
|
||||||
if (seq_order(last, first) || last - first > BUFFER_FRAMES / 2) return false;
|
if (seq_order(last, first) || last - first > BUFFER_FRAMES / 2) return false;
|
||||||
|
|
||||||
ctx->resent_req += (seq_t) (last - first) + 1;
|
ctx->resent_req += (seq_t) (last - first) + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user