Skip to content

Commit efc181c

Browse files
committed
cleanup processMessageLoop
1 parent 2d1b564 commit efc181c

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

examples/SnapClientAudioKit/SnapClientAudioKit.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
#include "SnapClient.h"
88
#include "AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver
99
#include "AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus
10-
//#include "AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git
11-
//#include "AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec
1210

1311
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
1412

1513
AudioBoardStream out(AudioKitEs8388V1);
16-
//FLACDecoder flac;
17-
//VorbisDecoder ogg;
1814
//WAVDecoder pcm;
1915
OpusAudioDecoder opus;
2016
WiFiClient wifi;

examples/SnapClientFreeRTOS/SnapClientFreeRTOS.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
#include "api/SnapProcessorRTOS.h" // install https://github.com/pschatzmann/arduino-freertos-addons
44
#include "AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver
55
#include "AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus
6-
//#include "AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git
7-
//#include "AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec
86

97

108
AudioBoardStream out(AudioKitEs8388V1); // or replace with e.g. I2SStream out;
11-
//FLACDecoder flac;
12-
//VorbisDecoder ogg;
139
//WAVDecoder pcm;
1410
OpusAudioDecoder opus;
1511
WiFiClient wifi;

src/api/SnapProcessor.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,11 @@ class SnapProcessor {
141141
bool rc = true;
142142
while (rc) {
143143
rc = processMessageLoop();
144-
logHeap();
144+
processExt();
145+
//logHeap();
145146
checkHeap();
146147
}
147148

148-
// ESP_LOGI(TAG, "... done reading from socket");
149-
// p_client->stop();
150-
151149
if (id_counter % 100 == 0) {
152150
logHeap();
153151
}
@@ -156,6 +154,11 @@ class SnapProcessor {
156154
return true;
157155
}
158156

157+
/// additional processing
158+
void processExt() {
159+
delay(5);
160+
}
161+
159162
bool resizeData() {
160163
audio.resize(frame_size);
161164
send_receive_buffer.resize(CONFIG_SNAPCAST_BUFF_LEN);
@@ -165,14 +168,16 @@ class SnapProcessor {
165168

166169
bool processMessageLoop() {
167170
ESP_LOGD(TAG, "processMessageLoop");
171+
// Wait for data
172+
if (p_client->available() < BASE_MESSAGE_SIZE) {
173+
return true;
174+
}
168175

169176
if (!readBaseMessage())
170177
return false;
171-
delay(1);
172178

173179
if (!readData())
174180
return false;
175-
delay(1);
176181

177182
switch (base_message.type) {
178183
case SNAPCAST_MESSAGE_CODEC_HEADER:
@@ -199,15 +204,12 @@ class SnapProcessor {
199204
default:
200205
ESP_LOGD(TAG, "Invalid Message: %u", base_message.type);
201206
}
202-
delay(1);
203207

204208
// If it's been a second or longer since our last time message was
205209
// sent, do so now
206210
if (!writeTimedMessage())
207211
return false;
208212

209-
delay(1);
210-
211213
return true;
212214
}
213215

@@ -269,11 +271,6 @@ class SnapProcessor {
269271

270272
bool readBaseMessage() {
271273
ESP_LOGD(TAG, "%d", BASE_MESSAGE_SIZE);
272-
// Wait for timeout
273-
// uint64_t end = millis() + CONFIG_WEBSOCKET_SERVER_TIMEOUT_SEC * 1000;
274-
while (p_client->available() < BASE_MESSAGE_SIZE) {
275-
delay(10);
276-
}
277274

278275
// Read Header Record with size
279276
size = p_client->readBytes(&send_receive_buffer[0], BASE_MESSAGE_SIZE);

0 commit comments

Comments
 (0)