Skip to content

Commit

Permalink
airplay improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Nov 20, 2023
1 parent 1d54331 commit 807a0e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2023-11-19
- more robust (?) airplay RTP frame recovery
- initialize of scratch string in monitor (trying to figure out random reboot)

2023-11-16
- add SH1122 support
- optimize GDS DrawPixel function

2023-11-09
- force gpio_pad_select_gpio in dac_controlset in case somebody uses UART gpio's (or other pre-programmed)

Expand Down
32 changes: 20 additions & 12 deletions components/raop/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static void buffer_put_packet(rtp_t *ctx, seq_t seqno, unsigned rtptime, bool fi
return;
}
}

if (seqno == (u16_t) (ctx->ab_write+1)) {
// expected packet
abuf = ctx->audio_buffer + BUFIDX(seqno);
Expand Down Expand Up @@ -572,17 +572,25 @@ static void buffer_push_packet(rtp_t *ctx) {
}

LOG_SDEBUG("playtime %u %d [W:%hu R:%hu] %d", playtime, playtime - now, ctx->ab_write, ctx->ab_read, curframe->ready);

// each missing packet will be requested up to (latency_frames / 16) times
for (int i = 0; seq_order(ctx->ab_read + i, ctx->ab_write); i += 16) {
abuf_t *frame = ctx->audio_buffer + BUFIDX(ctx->ab_read + i);
if (!frame->ready && now - frame->last_resend > RESEND_TO) {
// stop if one fails
if (!rtp_request_resend(ctx, ctx->ab_read + i, ctx->ab_read + i)) break;
frame->last_resend = now;
}
}
}

// try to request resend missing packet in order, explore up to 32 frames
for (int step = max((ctx->ab_write - ctx->ab_read + 1) / 32, 1),
i = 0, first = 0;
seq_order(ctx->ab_read + i, ctx->ab_write); i += step) {

abuf_t* frame = ctx->audio_buffer + BUFIDX(ctx->ab_read + i);

// stop when we reach a ready frame or a recent pending resend
if (first && (frame->ready || now - frame->last_resend <= RESEND_TO)) {
if (!rtp_request_resend(ctx, first, ctx->ab_read + i - 1)) break;
first = 0;
i += step - 1;
} else if (!frame->ready && now - frame->last_resend > RESEND_TO) {
if (!first) first = ctx->ab_read + i;
frame->last_resend = now;
}
}
}


/*---------------------------------------------------------------------------*/
Expand Down
4 changes: 3 additions & 1 deletion components/services/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void task_stats( cJSON* top ) {
current.n = uxTaskGetSystemState( current.tasks, current.n, &current.total );
cJSON_AddNumberToObject(top,"ntasks",current.n);

char scratch[SCRATCH_SIZE] = { };
char scratch[SCRATCH_SIZE] = {0};

#ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
#pragma message("Compiled with runtime stats")
Expand Down Expand Up @@ -143,11 +143,13 @@ static void monitor_trace(uint32_t now) {
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA));

task_stats(top);

char * top_a= cJSON_PrintUnformatted(top);
if(top_a){
messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_STATS,top_a);
FREE_AND_NULL(top_a);
}

cJSON_Delete(top);
}

Expand Down

0 comments on commit 807a0e5

Please sign in to comment.