Skip to content

Commit 684bc58

Browse files
committed
Support for URLStreamBufferedESP32 and ICYStreamBufferedESP32
1 parent ffe5cb5 commit 684bc58

File tree

7 files changed

+73
-158
lines changed

7 files changed

+73
-158
lines changed

src/AudioTools/CoreAudio/AudioHttp/AbstractURLStream.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "AudioTools/CoreAudio/BaseStream.h"
44
#include "AudioTools/CoreAudio/AudioMetaData/AbstractMetaData.h"
5+
#include "AudioTools/CoreAudio/AudioMetaData/MetaDataICY.h"
56
#include "HttpTypes.h"
67
#include "HttpRequest.h"
78
#include "Client.h"
@@ -45,6 +46,10 @@ class AbstractURLStream : public AudioStream {
4546
/// of performance! - By default this is deactivated. ESP32 Only!
4647
virtual void setPowerSave(bool ps) = 0;
4748

49+
/// Define the Root PEM Certificate for SSL
50+
void setCACert(const char* cert);
51+
4852
};
4953

54+
5055
} // namespace audio_tools

src/AudioTools/CoreAudio/AudioHttp/AudioHttp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
**/
77

88
#include "URLStream.h"
9-
#include "URLStreamBuffered.h"
109
#include "AudioServer.h"
11-
#include "ICYStream.h"
12-
#include "ICYStreamBuffered.h"
1310
#ifdef ESP32
1411
# include "URLStreamESP32.h"
1512
#endif

src/AudioTools/CoreAudio/AudioHttp/ICYStreamBuffered.h

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/AudioTools/CoreAudio/AudioHttp/ICYStream.h renamed to src/AudioTools/CoreAudio/AudioHttp/ICYURLStreamT.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#pragma once
2-
#ifdef USE_URL_ARDUINO
3-
42
#include "AudioConfig.h"
5-
#include "URLStreamBuffered.h"
6-
#include "AudioTools/CoreAudio/AudioMetaData/MetaDataICY.h"
3+
#if defined(USE_CONCURRENCY) && defined(USE_URL_ARDUINO)
4+
#include "URLStream.h"
75

86
namespace audio_tools {
9-
107
/**
118
* @brief Icecast/Shoutcast Audio Stream which splits the data into metadata and
129
* audio data. The Audio data is provided via the regular stream functions. The
@@ -24,25 +21,24 @@ namespace audio_tools {
2421
* @copyright GPLv3
2522
*/
2623

27-
class ICYStream : public AbstractURLStream {
24+
template<class T>
25+
class ICYStreamT : public AbstractURLStream {
2826
public:
29-
ICYStream(int readBufferSize = DEFAULT_BUFFER_SIZE) {
27+
ICYStreamT(int readBufferSize = DEFAULT_BUFFER_SIZE) {
3028
TRACEI();
3129
setReadBufferSize(readBufferSize);
3230
}
3331

34-
ICYStream(Client& clientPar, int readBufferSize = DEFAULT_BUFFER_SIZE) {
32+
ICYStreamT(Client& clientPar, int readBufferSize = DEFAULT_BUFFER_SIZE) : ICYStreamT(readBufferSize) {
3533
TRACEI();
36-
setReadBufferSize(readBufferSize);
3734
setClient(clientPar);
3835
}
3936

4037
/// Default constructor
41-
ICYStream(const char* network, const char* password,
42-
int readBufferSize = DEFAULT_BUFFER_SIZE) {
38+
ICYStreamT(const char* ssid, const char* password,
39+
int readBufferSize = DEFAULT_BUFFER_SIZE) : ICYStreamT(readBufferSize) {
4340
TRACEI();
44-
setReadBufferSize(readBufferSize);
45-
setSSID(network);
41+
setSSID(ssid);
4642
setPassword(password);
4743
}
4844

@@ -152,11 +148,17 @@ class ICYStream : public AbstractURLStream {
152148
/// of performance! - By default this is deactivated. ESP32 Only!
153149
void setPowerSave(bool active) { url.setPowerSave(active);}
154150

151+
/// Define the Root PEM Certificate for SSL:
152+
void setCACert(const char* cert){
153+
url.setCACert(cert);
154+
}
155+
155156
protected:
156-
URLStream url;
157+
T url;
157158
MetaDataICY icy; // icy state machine
158159
void (*callback)(MetaDataType info, const char* str, int len) = nullptr;
159160
};
160161

161-
} // namespace audio_tools
162-
#endif
162+
}
163+
164+
#endif

src/AudioTools/CoreAudio/AudioHttp/URLStream.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
# include <esp_wifi.h>
1111
#endif
1212

13+
#include "AudioTools/CoreAudio/AudioBasic/Str.h"
1314
#include "AbstractURLStream.h"
1415
#include "HttpRequest.h"
15-
#include "AudioTools/CoreAudio/AudioBasic/Str.h"
16+
#include "ICYURLStreamT.h"
17+
#include "URLStreamBufferedT.h"
18+
1619

1720
namespace audio_tools {
1821

@@ -259,6 +262,13 @@ class URLStream : public AbstractURLStream {
259262
#endif
260263
const char* urlStr() { return url_str.c_str(); }
261264

265+
/// Define the Root PEM Certificate for SSL
266+
void setCACert(const char* cert){
267+
#ifdef USE_WIFI_CLIENT_SECURE
268+
if (clientSecure!=nullptr) clientSecure->setCACert(cert);
269+
#endif
270+
}
271+
262272
protected:
263273
HttpRequest request;
264274
#if USE_AUDIO_LOGGING
@@ -427,6 +437,10 @@ class URLStream : public AbstractURLStream {
427437
}
428438
};
429439

440+
using URLStreamBuffered = URLStreamBufferedT<URLStream>;
441+
using ICYStream = ICYStreamT<URLStream>;
442+
using ICYStreamBuffered = URLStreamBufferedT<ICYStream>;
443+
430444
} // namespace audio_tools
431445

432446
#endif

src/AudioTools/CoreAudio/AudioHttp/URLStreamBuffered.h renamed to src/AudioTools/CoreAudio/AudioHttp/URLStreamBufferedT.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
#pragma once
22
#include "AudioConfig.h"
33
#if defined(USE_CONCURRENCY) && defined(USE_URL_ARDUINO)
4-
#include "URLStream.h"
54
#include "AudioTools/AudioLibs/Concurrency.h"
6-
#include "AudioTools/CoreAudio/AudioStreams.h"
5+
#include "AudioTools/CoreAudio/BaseStream.h"
6+
#include "URLStream.h"
77

88
#ifndef URL_STREAM_CORE
9-
# define URL_STREAM_CORE 0
9+
#define URL_STREAM_CORE 0
1010
#endif
1111

1212
#ifndef URL_STREAM_PRIORITY
13-
# define URL_STREAM_PRIORITY 2
13+
#define URL_STREAM_PRIORITY 2
1414
#endif
1515

1616
#ifndef URL_STREAM_BUFFER_COUNT
17-
# define URL_STREAM_BUFFER_COUNT 10
17+
#define URL_STREAM_BUFFER_COUNT 10
1818
#endif
1919

2020
#ifndef STACK_SIZE
21-
# define STACK_SIZE 30000
21+
#define STACK_SIZE 30000
2222
#endif
2323

24-
2524
namespace audio_tools {
2625

2726
/**
@@ -46,7 +45,7 @@ class BufferedTaskStream : public AudioStream {
4645
}
4746

4847
/// Define an explicit the buffer size in bytes
49-
void setBufferSize(int bufferSize, int bufferCount){
48+
void setBufferSize(int bufferSize, int bufferCount) {
5049
buffers.resize(bufferSize, bufferCount);
5150
}
5251

@@ -112,14 +111,12 @@ class BufferedTaskStream : public AudioStream {
112111
return result;
113112
}
114113

115-
116114
protected:
117115
AudioStream *p_stream = nullptr;
118116
bool active = false;
119117
Task task{"BufferedTaskStream", STACK_SIZE, URL_STREAM_PRIORITY,
120118
URL_STREAM_CORE};
121-
SynchronizedNBuffer buffers{DEFAULT_BUFFER_SIZE,
122-
URL_STREAM_BUFFER_COUNT};
119+
SynchronizedNBuffer buffers{DEFAULT_BUFFER_SIZE, URL_STREAM_BUFFER_COUNT};
123120
bool ready = false;
124121

125122
void processTask() {
@@ -147,29 +144,30 @@ class BufferedTaskStream : public AudioStream {
147144

148145
/**
149146
* @brief URLStream implementation for the ESP32 based on a separate FreeRTOS
150-
* task
147+
* task: the
151148
* @ingroup http
152149
* @author Phil Schatzmann
153150
* @copyright GPLv3
154151
*/
155152

156-
class URLStreamBuffered : public AbstractURLStream {
153+
template<class T>
154+
class URLStreamBufferedT : public AbstractURLStream {
157155
public:
158-
URLStreamBuffered(int readBufferSize = DEFAULT_BUFFER_SIZE) {
156+
URLStreamBufferedT(int readBufferSize = DEFAULT_BUFFER_SIZE) {
159157
TRACED();
160158
urlStream.setReadBufferSize(readBufferSize);
161159
taskStream.setInput(urlStream);
162160
}
163161

164-
URLStreamBuffered(Client &clientPar,
162+
URLStreamBufferedT(Client &clientPar,
165163
int readBufferSize = DEFAULT_BUFFER_SIZE) {
166164
TRACED();
167165
urlStream.setReadBufferSize(readBufferSize);
168166
setClient(clientPar);
169167
taskStream.setInput(urlStream);
170168
}
171169

172-
URLStreamBuffered(const char *network, const char *password,
170+
URLStreamBufferedT(const char *network, const char *password,
173171
int readBufferSize = DEFAULT_BUFFER_SIZE) {
174172
TRACED();
175173
urlStream.setReadBufferSize(readBufferSize);
@@ -179,7 +177,7 @@ class URLStreamBuffered : public AbstractURLStream {
179177
}
180178

181179
/// Defines the buffer that holds the with encoded data
182-
void setBufferSize(int bufferSize, int bufferCount){
180+
void setBufferSize(int bufferSize, int bufferCount) {
183181
taskStream.setBufferSize(bufferSize, bufferCount);
184182
}
185183

@@ -228,13 +226,15 @@ class URLStreamBuffered : public AbstractURLStream {
228226
urlStream.setPassword(password);
229227
}
230228

231-
/// ESP32 only: PowerSave off (= default setting) is much faster
229+
/// ESP32 only: PowerSave off (= default setting) is much faster
232230
void setPowerSave(bool ps) override { urlStream.setPowerSave(ps); }
233231

232+
/// Define the Root PEM Certificate for SSL
233+
void setCACert(const char *cert) { urlStream.setCACert(cert); }
234234

235235
protected:
236236
BufferedTaskStream taskStream;
237-
URLStream urlStream;
237+
T urlStream;
238238
};
239239

240240
} // namespace audio_tools

0 commit comments

Comments
 (0)