Skip to content

Commit c039c5c

Browse files
committed
AudioServerT reformat
1 parent 6e17383 commit c039c5c

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

src/AudioTools/CoreAudio/AudioHttp/AudioServer.h

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
#if defined(USE_AUDIO_SERVER) && (defined(USE_ETHERNET) || defined(USE_WIFI))
55

66
#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
1212
#endif
1313

1414
#ifdef USE_ETHERNET
15-
# include <Ethernet.h>
15+
#include <Ethernet.h>
1616
#endif
1717

18-
#include "AudioTools/AudioCodecs/CodecWAV.h"
1918
#include "AudioTools.h"
19+
#include "AudioTools/AudioCodecs/CodecWAV.h"
2020

2121
namespace audio_tools {
2222

@@ -32,7 +32,7 @@ typedef void (*AudioServerDataCallback)(Print *out);
3232
* @author Phil Schatzmann
3333
* @copyright GPLv3
3434
*/
35-
template<class Client,class Server>
35+
template <class Client, class Server>
3636
class AudioServerT {
3737
public:
3838
/**
@@ -135,11 +135,11 @@ class AudioServerT {
135135
sent += copier.copy(*converter_ptr);
136136
}
137137

138-
if (max_bytes > 0 && sent >= max_bytes) {
138+
if (max_bytes > 0 && sent >= max_bytes) {
139139
LOGI("range exhausted...");
140140
client_obj.stop();
141141
active = false;
142-
}
142+
}
143143

144144
// if we limit the size of the WAV the encoder gets automatically
145145
// closed when all has been sent
@@ -169,9 +169,7 @@ class AudioServerT {
169169
bool isClientConnected() { return client_obj.connected(); }
170170

171171
/// Changes the copy buffer size
172-
void setCopyBufferSize(int size){
173-
copier.resize(size);
174-
}
172+
void setCopyBufferSize(int size) { copier.resize(size); }
175173

176174
protected:
177175
// WIFI
@@ -225,9 +223,9 @@ class AudioServerT {
225223
// and a content-type so the client knows what's coming, then a blank line:
226224
char *response;
227225
if (max_bytes > 0) {
228-
response = "HTTP/1.1 206 OK";
226+
response = "HTTP/1.1 206 OK";
229227
} else {
230-
response = "HTTP/1.1 200 OK";
228+
response = "HTTP/1.1 200 OK";
231229
}
232230
client_obj.println(response);
233231
LOGI(response);
@@ -237,9 +235,9 @@ class AudioServerT {
237235
LOGI("Content-type: %s", content_type);
238236
}
239237
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+
}
243241
}
244242

245243
virtual void sendReplyContent() {
@@ -253,7 +251,7 @@ class AudioServerT {
253251
// provide data for stream
254252
LOGI("sendReply - Returning audio stream...");
255253
copier.begin(client_obj, *in);
256-
if (!client_obj.connected()){
254+
if (!client_obj.connected()) {
257255
LOGE("connection was closed");
258256
}
259257
}
@@ -274,21 +272,21 @@ class AudioServerT {
274272
char c = client_obj.read(); // read a byte, then
275273
if (c == '\n') { // if the byte is a newline character
276274
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);
279277

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+
}
284282
// if the current line is blank, you got two newline characters in a
285283
// row. that's the end of the client HTTP request, so send a
286284
// response:
287285
if (currentLine.length() == 0) {
288286
sendReplyHeader();
289287
sendReplyContent();
290-
max_bytes = lastbyte - firstbyte;
291-
sent = 0;
288+
max_bytes = lastbyte - firstbyte;
289+
sent = 0;
292290
// break out of the while loop:
293291
break;
294292
} else { // if you got a newline, then clear currentLine:
@@ -390,7 +388,7 @@ class AudioEncoderServer : public AudioServer {
390388
encoder->setAudioInfo(audio_info);
391389
encoded_stream.setOutput(&client_obj);
392390
encoded_stream.setEncoder(encoder);
393-
if (!encoded_stream.begin(audio_info)){
391+
if (!encoded_stream.begin(audio_info)) {
394392
LOGE("encoder begin failed");
395393
stop();
396394
}
@@ -440,15 +438,16 @@ class AudioEncoderServer : public AudioServer {
440438
AudioEncoder *audioEncoder() { return encoder; }
441439

442440
protected:
443-
// Sound Generation - use EncodedAudioOutput with is more efficient then EncodedAudioStream
441+
// Sound Generation - use EncodedAudioOutput with is more efficient then
442+
// EncodedAudioStream
444443
EncodedAudioOutput encoded_stream;
445444
AudioInfo audio_info;
446445
AudioEncoder *encoder = nullptr;
447446

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 {}
450449

451-
void sendReplyContent() override {
450+
void sendReplyContent() override {
452451
TRACED();
453452
// restart encoder
454453
if (encoder) {
@@ -477,7 +476,7 @@ class AudioEncoderServer : public AudioServer {
477476
encoded_stream.begin();
478477

479478
copier.begin(encoded_stream, *in);
480-
if (!client_obj.connected()){
479+
if (!client_obj.connected()) {
481480
LOGE("connection was closed");
482481
}
483482
// Send delayed header

0 commit comments

Comments
 (0)