5
5
*/
6
6
7
7
#include " AudioTools.h"
8
+ #include " Client.h"
8
9
#include " SnapConfig.h"
9
10
#include " api/SnapCommon.h"
10
11
#include " api/SnapLogger.h"
11
- #include " Client.h"
12
-
13
12
14
13
#if CONFIG_NVS_FLASH
15
14
#include " nvs_flash.h"
@@ -35,8 +34,7 @@ namespace snap_arduino {
35
34
* @copyright Copyright (c) 2023
36
35
*/
37
36
class SnapClient {
38
-
39
- public:
37
+ public:
40
38
SnapClient (Client &client, AudioStream &stream, AudioDecoder &decoder) {
41
39
static AdapterAudioStreamToAudioOutput output_adapter;
42
40
output_adapter.setStream (stream);
@@ -62,7 +60,7 @@ class SnapClient {
62
60
p_output = &output;
63
61
p_client = &client;
64
62
server_ip.fromString (CONFIG_SNAPCAST_SERVER_HOST);
65
- }
63
+ }
66
64
67
65
SnapClient (Client &client, AudioOutput &output, StreamingDecoder &decoder,
68
66
int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
@@ -71,62 +69,41 @@ class SnapClient {
71
69
p_client = &client;
72
70
}
73
71
74
- //
75
- SnapClient (WiFiClient &client, AudioStream &stream, AudioDecoder &decoder) {
72
+ //
73
+ SnapClient (WiFiClient &client, AudioStream &stream, AudioDecoder &decoder)
74
+ : SnapClient((Client &)client, stream, decoder) {
76
75
is_wifi = true ;
77
- static AdapterAudioStreamToAudioOutput output_adapter;
78
- output_adapter.setStream (stream);
79
- p_decoder = &decoder;
80
- p_output = &output_adapter;
81
- p_client = &client;
82
- server_ip.fromString (CONFIG_SNAPCAST_SERVER_HOST);
83
76
}
84
77
85
78
SnapClient (WiFiClient &client, AudioStream &stream, StreamingDecoder &decoder,
86
- int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
79
+ int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER)
80
+ : SnapClient((Client &)client, stream, decoder, bufferSize) {
87
81
is_wifi = true ;
88
- static DecoderFromStreaming decoder_adapter (decoder, bufferSize);
89
- static AdapterAudioStreamToAudioOutput output_adapter;
90
- p_decoder = &decoder_adapter;
91
- output_adapter.setStream (stream);
92
- p_output = &output_adapter;
93
- p_client = &client;
94
- server_ip.fromString (CONFIG_SNAPCAST_SERVER_HOST);
95
82
}
96
83
97
- SnapClient (WiFiClient &client, AudioOutput &output, AudioDecoder &decoder) {
84
+ SnapClient (WiFiClient &client, AudioOutput &output, AudioDecoder &decoder)
85
+ : SnapClient((Client &)client, output, decoder) {
98
86
is_wifi = true ;
99
- p_decoder = &decoder;
100
- p_output = &output;
101
- p_client = &client;
102
- server_ip.fromString (CONFIG_SNAPCAST_SERVER_HOST);
103
- }
87
+ }
104
88
105
89
SnapClient (WiFiClient &client, AudioOutput &output, StreamingDecoder &decoder,
106
- int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
90
+ int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER)
91
+ : SnapClient((Client &)client, output, decoder, bufferSize) {
107
92
is_wifi = true ;
108
- p_decoder = new DecoderFromStreaming (decoder, bufferSize);
109
- p_output = &output;
110
- p_client = &client;
111
93
}
112
94
113
-
114
95
// / Destructor
115
- ~SnapClient () {
116
- end ();
117
- }
96
+ ~SnapClient () { end (); }
118
97
119
98
// / Defines an alternative commnuication client (default is WiFiClient)
120
99
void setClient (Client &client) { p_client = &client; }
121
100
122
101
// / @brief Defines the Snapcast Server IP address
123
- // / @param address
102
+ // / @param address
124
103
void setServerIP (IPAddress ipAddress) { this ->server_ip = ipAddress; }
125
104
126
105
// / Defines the time synchronization logic
127
- void setSnapTimeSync (SnapTimeSync &timeSync){
128
- p_time_sync = &timeSync;
129
- }
106
+ void setSnapTimeSync (SnapTimeSync &timeSync) { p_time_sync = &timeSync; }
130
107
131
108
// / Starts the processing
132
109
bool begin (SnapTimeSync &timeSync) {
@@ -137,7 +114,7 @@ class SnapClient {
137
114
// / Starts the processing
138
115
bool begin () {
139
116
#if defined(ESP32)
140
- if (is_wifi){
117
+ if (is_wifi) {
141
118
if (WiFi.status () != WL_CONNECTED) {
142
119
ESP_LOGE (TAG, " WiFi not connected" );
143
120
return false ;
@@ -191,19 +168,15 @@ class SnapClient {
191
168
}
192
169
193
170
// / Provides the actual processor
194
- SnapProcessor& snapProcessor (){
195
- return *p_snapprocessor;
196
- }
171
+ SnapProcessor &snapProcessor () { return *p_snapprocessor; }
197
172
198
173
// / Defines the Snap output implementation to be used
199
- void setSnapOutput (SnapOutput &out){
200
- p_snapprocessor->setSnapOutput (out);
201
- }
174
+ void setSnapOutput (SnapOutput &out) { p_snapprocessor->setSnapOutput (out); }
202
175
203
176
// / Call from Arduino Loop - to receive and process the audio data
204
177
bool doLoop () { return p_snapprocessor->doLoop (); }
205
178
206
- protected:
179
+ protected:
207
180
const char *TAG = " SnapClient" ;
208
181
SnapTime &snap_time = SnapTime::instance();
209
182
SnapProcessor default_processor;
@@ -238,7 +211,8 @@ class SnapClient {
238
211
server_ip[2 ], server_ip[3 ]);
239
212
server_port = MDNS.port (0 );
240
213
241
- ESP_LOGI (TAG, " MDNS: SNAPCAST ip: %s, port: %d" , str_address, server_port);
214
+ ESP_LOGI (TAG, " MDNS: SNAPCAST ip: %s, port: %d" , str_address,
215
+ server_port);
242
216
243
217
} else {
244
218
ESP_LOGE (TAG, " SNAPCAST server not found" );
@@ -262,7 +236,6 @@ class SnapClient {
262
236
#endif
263
237
}
264
238
265
-
266
239
void setupMACAddress () {
267
240
#ifdef ESP32
268
241
const char *adr = strdup (WiFi.macAddress ().c_str ());
@@ -273,4 +246,4 @@ class SnapClient {
273
246
}
274
247
};
275
248
276
- }
249
+ } // namespace snap_arduino
0 commit comments