mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 20:47:08 +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 raop_event_t raop_state;
|
||||||
static bool raop_expect_stop = false;
|
static bool raop_expect_stop = false;
|
||||||
static struct {
|
static struct {
|
||||||
bool start;
|
bool enabled, start;
|
||||||
s32_t error;
|
s32_t error;
|
||||||
u32_t start_time;
|
u32_t start_time;
|
||||||
u32_t playtime, len;
|
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();
|
u32_t ms, now = gettime_ms();
|
||||||
s32_t error;
|
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
|
// first must make sure we started on time
|
||||||
if (raop_sync.start) {
|
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;
|
if (abs(error) < 10 && abs(raop_sync.error) < 10) raop_sync.start = false;
|
||||||
} else {
|
} 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)
|
// 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;
|
error = (raop_sync.playtime - now) - ms;
|
||||||
LOG_INFO("head local:%u, remote:%u (delta:%d)", ms, raop_sync.playtime - now, error);
|
LOG_INFO("head local:%u, remote:%u (delta:%d)", ms, raop_sync.playtime - now, error);
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error < -10 && raop_sync.error < -10) {
|
if (error < -10 && raop_sync.error < -10) {
|
||||||
@@ -217,7 +216,8 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
|
|||||||
LOG_INFO("Stream", NULL);
|
LOG_INFO("Stream", NULL);
|
||||||
raop_state = event;
|
raop_state = event;
|
||||||
raop_sync.error = 0;
|
raop_sync.error = 0;
|
||||||
raop_sync.start = true;
|
raop_sync.start = true;
|
||||||
|
raop_sync.enabled = !strcasestr(output.device, "BT");
|
||||||
output.external = true;
|
output.external = true;
|
||||||
output.next_sample_rate = RAOP_SAMPLE_RATE;
|
output.next_sample_rate = RAOP_SAMPLE_RATE;
|
||||||
output.state = OUTPUT_STOPPED;
|
output.state = OUTPUT_STOPPED;
|
||||||
@@ -277,11 +277,7 @@ void register_other(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_AIRPLAY_SINK
|
#ifdef CONFIG_AIRPLAY_SINK
|
||||||
if (!strcasestr(output.device, "BT ")) {
|
raop_sink_init(raop_sink_cmd_handler, raop_sink_data_handler);
|
||||||
raop_sink_init(raop_sink_cmd_handler, raop_sink_data_handler);
|
LOG_INFO("Initializing AirPlay sink");
|
||||||
LOG_INFO("Initializing AirPlay sink");
|
|
||||||
} else {
|
|
||||||
LOG_WARN("Cannot be an AirPlay sink and BT source");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ int32_t output_bt_data(uint8_t *data, int32_t len) {
|
|||||||
if (wanted_len > 0) {
|
if (wanted_len > 0) {
|
||||||
SET_MIN_MAX(wanted_len, under);
|
SET_MIN_MAX(wanted_len, under);
|
||||||
}
|
}
|
||||||
|
output.frames_in_process = len-wanted_len;
|
||||||
|
|
||||||
UNLOCK;
|
UNLOCK;
|
||||||
SET_MIN_MAX(TIME_MEASUREMENT_GET(start_timer),lock_out_time);
|
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
|
// 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;
|
output.device_frames = DMA_BUF_COUNT * DMA_BUF_LEN - ((output.updated - fullness) * output.current_sample_rate) / 1000;
|
||||||
oframes = _output_frames( iframes );
|
oframes = _output_frames( iframes );
|
||||||
|
output.frames_in_process = oframes;
|
||||||
|
|
||||||
SET_MIN_MAX_SIZED(oframes,rec,iframes);
|
SET_MIN_MAX_SIZED(oframes,rec,iframes);
|
||||||
SET_MIN_MAX_SIZED(_buf_used(outputbuf),o,outputbuf->size);
|
SET_MIN_MAX_SIZED(_buf_used(outputbuf),o,outputbuf->size);
|
||||||
|
|||||||
@@ -676,6 +676,7 @@ struct outputstate {
|
|||||||
unsigned default_sample_rate;
|
unsigned default_sample_rate;
|
||||||
bool error_opening;
|
bool error_opening;
|
||||||
unsigned device_frames;
|
unsigned device_frames;
|
||||||
|
unsigned frames_in_process;
|
||||||
u32_t updated;
|
u32_t updated;
|
||||||
u32_t track_start_time;
|
u32_t track_start_time;
|
||||||
u32_t current_replay_gain;
|
u32_t current_replay_gain;
|
||||||
|
|||||||
Reference in New Issue
Block a user