4
4
#if defined(USE_AUDIO_SERVER) && (defined(USE_ETHERNET) || defined(USE_WIFI))
5
5
6
6
#ifdef USE_WIFI
7
- # ifdef ESP8266
8
- # include < ESP8266WiFi.h>
9
- # else
10
- # include < WiFi.h>
11
- # endif
7
+ #ifdef ESP8266
8
+ #include < ESP8266WiFi.h>
9
+ #else
10
+ #include < WiFi.h>
11
+ #endif
12
12
#endif
13
13
14
14
#ifdef USE_ETHERNET
15
- # include < Ethernet.h>
15
+ #include < Ethernet.h>
16
16
#endif
17
17
18
- #include " AudioTools/AudioCodecs/CodecWAV.h"
19
18
#include " AudioTools.h"
19
+ #include " AudioTools/AudioCodecs/CodecWAV.h"
20
20
21
21
namespace audio_tools {
22
22
@@ -32,7 +32,7 @@ typedef void (*AudioServerDataCallback)(Print *out);
32
32
* @author Phil Schatzmann
33
33
* @copyright GPLv3
34
34
*/
35
- template <class Client ,class Server >
35
+ template <class Client , class Server >
36
36
class AudioServerT {
37
37
public:
38
38
/* *
@@ -135,11 +135,11 @@ class AudioServerT {
135
135
sent += copier.copy (*converter_ptr);
136
136
}
137
137
138
- if (max_bytes > 0 && sent >= max_bytes) {
138
+ if (max_bytes > 0 && sent >= max_bytes) {
139
139
LOGI (" range exhausted..." );
140
140
client_obj.stop ();
141
141
active = false ;
142
- }
142
+ }
143
143
144
144
// if we limit the size of the WAV the encoder gets automatically
145
145
// closed when all has been sent
@@ -169,9 +169,7 @@ class AudioServerT {
169
169
bool isClientConnected () { return client_obj.connected (); }
170
170
171
171
// / Changes the copy buffer size
172
- void setCopyBufferSize (int size){
173
- copier.resize (size);
174
- }
172
+ void setCopyBufferSize (int size) { copier.resize (size); }
175
173
176
174
protected:
177
175
// WIFI
@@ -225,9 +223,9 @@ class AudioServerT {
225
223
// and a content-type so the client knows what's coming, then a blank line:
226
224
char *response;
227
225
if (max_bytes > 0 ) {
228
- response = " HTTP/1.1 206 OK" ;
226
+ response = " HTTP/1.1 206 OK" ;
229
227
} else {
230
- response = " HTTP/1.1 200 OK" ;
228
+ response = " HTTP/1.1 200 OK" ;
231
229
}
232
230
client_obj.println (response);
233
231
LOGI (response);
@@ -237,9 +235,9 @@ class AudioServerT {
237
235
LOGI (" Content-type: %s" , content_type);
238
236
}
239
237
client_obj.println ();
240
- if (!client_obj.connected ()){
241
- LOGE (" connection was closed" );
242
- }
238
+ if (!client_obj.connected ()) {
239
+ LOGE (" connection was closed" );
240
+ }
243
241
}
244
242
245
243
virtual void sendReplyContent () {
@@ -253,7 +251,7 @@ class AudioServerT {
253
251
// provide data for stream
254
252
LOGI (" sendReply - Returning audio stream..." );
255
253
copier.begin (client_obj, *in);
256
- if (!client_obj.connected ()){
254
+ if (!client_obj.connected ()) {
257
255
LOGE (" connection was closed" );
258
256
}
259
257
}
@@ -274,21 +272,21 @@ class AudioServerT {
274
272
char c = client_obj.read (); // read a byte, then
275
273
if (c == ' \n ' ) { // if the byte is a newline character
276
274
LOGI (" Request: %s" , currentLine.c_str ());
277
- if (currentLine.startsWith (String (" Range: bytes=" ))) {
278
- int minuspos = currentLine.indexOf (' -' , 13 );
275
+ if (currentLine.startsWith (String (" Range: bytes=" ))) {
276
+ int minuspos = currentLine.indexOf (' -' , 13 );
279
277
280
- // toInt returns 0 if it's an invalid conversion, so it's "safe"
281
- firstbyte = currentLine.substring (13 , minuspos).toInt ();
282
- lastbyte = currentLine.substring (minuspos + 1 ).toInt ();
283
- }
278
+ // toInt returns 0 if it's an invalid conversion, so it's "safe"
279
+ firstbyte = currentLine.substring (13 , minuspos).toInt ();
280
+ lastbyte = currentLine.substring (minuspos + 1 ).toInt ();
281
+ }
284
282
// if the current line is blank, you got two newline characters in a
285
283
// row. that's the end of the client HTTP request, so send a
286
284
// response:
287
285
if (currentLine.length () == 0 ) {
288
286
sendReplyHeader ();
289
287
sendReplyContent ();
290
- max_bytes = lastbyte - firstbyte;
291
- sent = 0 ;
288
+ max_bytes = lastbyte - firstbyte;
289
+ sent = 0 ;
292
290
// break out of the while loop:
293
291
break ;
294
292
} else { // if you got a newline, then clear currentLine:
@@ -390,7 +388,7 @@ class AudioEncoderServer : public AudioServer {
390
388
encoder->setAudioInfo (audio_info);
391
389
encoded_stream.setOutput (&client_obj);
392
390
encoded_stream.setEncoder (encoder);
393
- if (!encoded_stream.begin (audio_info)){
391
+ if (!encoded_stream.begin (audio_info)) {
394
392
LOGE (" encoder begin failed" );
395
393
stop ();
396
394
}
@@ -440,15 +438,16 @@ class AudioEncoderServer : public AudioServer {
440
438
AudioEncoder *audioEncoder () { return encoder; }
441
439
442
440
protected:
443
- // Sound Generation - use EncodedAudioOutput with is more efficient then EncodedAudioStream
441
+ // Sound Generation - use EncodedAudioOutput with is more efficient then
442
+ // EncodedAudioStream
444
443
EncodedAudioOutput encoded_stream;
445
444
AudioInfo audio_info;
446
445
AudioEncoder *encoder = nullptr ;
447
446
448
- // moved to be part of reply content to avoid timeout issues in Chrome
449
- void sendReplyHeader () override {}
447
+ // moved to be part of reply content to avoid timeout issues in Chrome
448
+ void sendReplyHeader () override {}
450
449
451
- void sendReplyContent () override {
450
+ void sendReplyContent () override {
452
451
TRACED ();
453
452
// restart encoder
454
453
if (encoder) {
@@ -477,7 +476,7 @@ class AudioEncoderServer : public AudioServer {
477
476
encoded_stream.begin ();
478
477
479
478
copier.begin (encoded_stream, *in);
480
- if (!client_obj.connected ()){
479
+ if (!client_obj.connected ()) {
481
480
LOGE (" connection was closed" );
482
481
}
483
482
// Send delayed header
0 commit comments