From 606d1c45ddd9c0c2688a04592de5935b0d720ee5 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 13 Mar 2024 07:12:50 +0000 Subject: [PATCH] Crash when synchronizer is not defined --- src/SnapClient.h | 3 ++- src/api/SnapOutput.h | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/SnapClient.h b/src/SnapClient.h index 2e54d1e..080c560 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -161,7 +161,8 @@ class SnapClient { AudioOutput *p_output = nullptr; AudioDecoder *p_decoder = nullptr; Client *p_client = nullptr; - SnapTimeSync *p_time_sync = nullptr; + SnapTimeSyncDynamic time_sync_default; + SnapTimeSync *p_time_sync = &time_sync_default; IPAddress server_ip; int server_port = CONFIG_SNAPCAST_SERVER_PORT; diff --git a/src/api/SnapOutput.h b/src/api/SnapOutput.h index a5e98e2..b661850 100644 --- a/src/api/SnapOutput.h +++ b/src/api/SnapOutput.h @@ -132,6 +132,8 @@ class SnapOutput : public AudioInfoSupport { /// ignored - update playback speed bool synchronizePlayback() { bool result = true; + assert(p_snap_time_sync!=nullptr); + SnapTimeSync &ts = *p_snap_time_sync; // calculate how long we need to wait to playback the audio @@ -170,8 +172,7 @@ class SnapOutput : public AudioInfoSupport { bool is_mute = false; SnapAudioHeader header; SnapTime &snap_time = SnapTime::instance(); - SnapTimeSyncDynamic time_sync_default; - SnapTimeSync *p_snap_time_sync = &time_sync_default; + SnapTimeSync *p_snap_time_sync = nullptr; bool is_sync_started = false; bool is_audio_begin_called = false; @@ -181,6 +182,10 @@ class SnapOutput : public AudioInfoSupport { ESP_LOGI(TAG, "out is null"); return false; } + if (p_snap_time_sync==nullptr){ + ESP_LOGI(TAG, "p_snap_time_sync is null"); + return false; + } // open volume control: allow amplification auto vol_cfg = vol_stream.defaultConfig(); @@ -241,6 +246,7 @@ class SnapOutput : public AudioInfoSupport { } else { // wait for the audio to become valid ESP_LOGI(TAG, "starting after %d ms", delay_ms); + assert(p_snap_time_sync!=nullptr); setPlaybackFactor(p_snap_time_sync->getFactor()); is_sync_started = true; result = true; @@ -250,6 +256,7 @@ class SnapOutput : public AudioInfoSupport { /// Calculate the delay in ms int getDelayMs() { + assert(p_snap_time_sync!=nullptr); auto msg_time = snap_time.toMillis(header.sec, header.usec); auto server_time = snap_time.serverMillis(); // wait for the audio to become valid