Skip to content

Commit

Permalink
Crash when synchronizer is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Mar 13, 2024
1 parent 813b848 commit 606d1c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/SnapClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 9 additions & 2 deletions src/api/SnapOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 606d1c4

Please sign in to comment.