mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 20:17:04 +03:00
enable AirPlay to BT bridge
This commit is contained in:
@@ -39,7 +39,7 @@ extern log_level loglevel;
|
||||
static raop_event_t raop_state;
|
||||
static bool raop_expect_stop = false;
|
||||
static struct {
|
||||
bool start;
|
||||
bool enabled, start;
|
||||
s32_t error;
|
||||
u32_t start_time;
|
||||
u32_t playtime, len;
|
||||
@@ -176,7 +176,7 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
|
||||
u32_t ms, now = gettime_ms();
|
||||
s32_t error;
|
||||
|
||||
if (output.state < OUTPUT_RUNNING || output.frames_played_dmp < output.device_frames) break;
|
||||
if (!raop_sync.enabled || output.state < OUTPUT_RUNNING || output.frames_played_dmp < output.device_frames) break;
|
||||
|
||||
// first must make sure we started on time
|
||||
if (raop_sync.start) {
|
||||
@@ -187,10 +187,9 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
|
||||
if (abs(error) < 10 && abs(raop_sync.error) < 10) raop_sync.start = false;
|
||||
} else {
|
||||
// in how many ms will the most recent block play (there is one extra block of FRAME_BLOCK == MAX_SILENCE_FRAMES which is not in queue and not in outputbuf)
|
||||
ms = ((u64_t) ((_buf_used(outputbuf) - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + MAX_SILENCE_FRAMES) * 1000) / RAOP_SAMPLE_RATE - (now - output.updated);
|
||||
ms = ((u64_t) ((_buf_used(outputbuf) - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + output.frames_in_process) * 1000) / RAOP_SAMPLE_RATE - (now - output.updated);
|
||||
error = (raop_sync.playtime - now) - ms;
|
||||
LOG_INFO("head local:%u, remote:%u (delta:%d)", ms, raop_sync.playtime - now, error);
|
||||
//break;
|
||||
}
|
||||
|
||||
if (error < -10 && raop_sync.error < -10) {
|
||||
@@ -218,6 +217,7 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
|
||||
raop_state = event;
|
||||
raop_sync.error = 0;
|
||||
raop_sync.start = true;
|
||||
raop_sync.enabled = !strcasestr(output.device, "BT");
|
||||
output.external = true;
|
||||
output.next_sample_rate = RAOP_SAMPLE_RATE;
|
||||
output.state = OUTPUT_STOPPED;
|
||||
@@ -277,11 +277,7 @@ void register_other(void) {
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_AIRPLAY_SINK
|
||||
if (!strcasestr(output.device, "BT ")) {
|
||||
raop_sink_init(raop_sink_cmd_handler, raop_sink_data_handler);
|
||||
LOG_INFO("Initializing AirPlay sink");
|
||||
} else {
|
||||
LOG_WARN("Cannot be an AirPlay sink and BT source");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -150,6 +150,7 @@ int32_t output_bt_data(uint8_t *data, int32_t len) {
|
||||
if (wanted_len > 0) {
|
||||
SET_MIN_MAX(wanted_len, under);
|
||||
}
|
||||
output.frames_in_process = len-wanted_len;
|
||||
|
||||
UNLOCK;
|
||||
SET_MIN_MAX(TIME_MEASUREMENT_GET(start_timer),lock_out_time);
|
||||
|
||||
@@ -442,6 +442,7 @@ static void *output_thread_i2s() {
|
||||
// try to estimate how much we have consumed from the DMA buffer
|
||||
output.device_frames = DMA_BUF_COUNT * DMA_BUF_LEN - ((output.updated - fullness) * output.current_sample_rate) / 1000;
|
||||
oframes = _output_frames( iframes );
|
||||
output.frames_in_process = oframes;
|
||||
|
||||
SET_MIN_MAX_SIZED(oframes,rec,iframes);
|
||||
SET_MIN_MAX_SIZED(_buf_used(outputbuf),o,outputbuf->size);
|
||||
|
||||
@@ -676,6 +676,7 @@ struct outputstate {
|
||||
unsigned default_sample_rate;
|
||||
bool error_opening;
|
||||
unsigned device_frames;
|
||||
unsigned frames_in_process;
|
||||
u32_t updated;
|
||||
u32_t track_start_time;
|
||||
u32_t current_replay_gain;
|
||||
|
||||
Reference in New Issue
Block a user