6
6
namespace audio_tools {
7
7
8
8
/* *
9
- * @brief Icecast/Shoutcast Audio Stream which splits the data into metadata and
10
- * audio data. The Audio data is provided via the regular stream functions. The
11
- * metadata is handled with the help of the MetaDataICY state machine and
12
- * provided via a callback method.
9
+ * @brief Icecast/Shoutcast audio stream that separates ICY metadata from audio bytes.
13
10
*
14
- * This is basically just a URLStream with the metadata turned on.
11
+ * ICY/Shoutcast servers interleave metadata blocks into the audio byte stream.
12
+ * This wrapper enables ICY metadata handling while exposing a clean audio-only
13
+ * stream via the standard read/available methods. Metadata is parsed by
14
+ * MetaDataICY and delivered through a user-supplied callback.
15
15
*
16
- * If you run into performance issues, check if the data is provided chunked.
17
- * In this chase you can check if setting the protocol to "HTTP/1.0" improves
18
- * the situation.
16
+ * The class inherits from AbstractURLStream and delegates network/HTTP work to
17
+ * an underlying URL-like stream instance of type T. ICY support is enabled by
18
+ * adding the request header "Icy-MetaData: 1" and by removing metadata bytes
19
+ * from the returned audio stream while forwarding metadata via the callback.
20
+ *
21
+ * Notes
22
+ * - If you run into performance issues, check if the server delivers data with
23
+ * HTTP chunked transfer encoding. In that case, using protocol "HTTP/1.0"
24
+ * can sometimes improve performance.
25
+ * - Audio bytes returned by read()/readBytes() contain no metadata; metadata is
26
+ * only available through the callback.
27
+ * - Use the following predefined usings:
28
+ * - using ICYStream = ICYStreamT<URLStream>;
29
+ * - using BufferedICYStream = ICYStreamT<BufferedURLStream>;
30
+ * - using ICYStreamESP32 = ICYStreamT<URLStreamESP32>;
31
+ *
32
+ * @tparam T Underlying URL stream type; must implement the AbstractURLStream
33
+ * interface (e.g., provide begin/end/read/available/httpRequest,
34
+ * credentials, headers, etc.).
19
35
*
20
36
* @ingroup http
21
37
* @author Phil Schatzmann
@@ -45,7 +61,7 @@ class ICYStreamT : public AbstractURLStream {
45
61
setClient (clientPar);
46
62
}
47
63
48
- // / Defines the meta data callback function
64
+ // / Defines the metadata callback function
49
65
virtual bool setMetadataCallback (void (*fn)(MetaDataType info,
50
66
const char * str,
51
67
int len)) override {
@@ -55,7 +71,7 @@ class ICYStreamT : public AbstractURLStream {
55
71
return true ;
56
72
}
57
73
58
- // Icy http get request to the indicated url
74
+ // Performs an HTTP request to the indicated URL with ICY metadata enabled
59
75
virtual bool begin (const char * urlStr, const char * acceptMime = nullptr ,
60
76
MethodID action = GET, const char * reqMime = " " ,
61
77
const char * reqData = " " ) override {
@@ -87,10 +103,10 @@ class ICYStreamT : public AbstractURLStream {
87
103
icy.end ();
88
104
}
89
105
90
- // / provides the available method from the URLStream
106
+ // / Delegates available() from the underlying stream
91
107
virtual int available () override { return url.available (); }
92
108
93
- // / reads the audio bytes
109
+ // / Reads audio bytes, stripping out any interleaved ICY metadata
94
110
virtual size_t readBytes (uint8_t * data, size_t len) override {
95
111
size_t result = 0 ;
96
112
if (icy.hasMetaData ()) {
@@ -113,7 +129,7 @@ class ICYStreamT : public AbstractURLStream {
113
129
return result;
114
130
}
115
131
116
- // Read character and processes using the MetaDataICY state engine
132
+ // Reads a single audio byte, skipping metadata via the MetaDataICY state engine
117
133
virtual int read () override {
118
134
int ch = -1 ;
119
135
@@ -129,6 +145,7 @@ class ICYStreamT : public AbstractURLStream {
129
145
return ch;
130
146
}
131
147
148
+ // / True if the underlying URL stream is ready/connected
132
149
operator bool () { return url; }
133
150
134
151
void setReadBufferSize (int readBufferSize) {
@@ -141,11 +158,10 @@ class ICYStreamT : public AbstractURLStream {
141
158
// / Sets the password that will be used for logging in (when calling begin)
142
159
void setPassword (const char * password) override { url.setPassword (password); }
143
160
144
- // / if set to true, it activates the power save mode which comes at the cost
145
- // / of performance! - By default this is deactivated. ESP32 Only!
161
+ // / If set to true, activates power save mode at the cost of performance (ESP32 only).
146
162
void setPowerSave (bool active) { url.setPowerSave (active); }
147
163
148
- // / Define the Root PEM Certificate for SSL:
164
+ // / Define the Root PEM certificate for TLS/ SSL
149
165
void setCACert (const char * cert) { url.setCACert (cert); }
150
166
// / Adds/Updates a request header
151
167
void addRequestHeader (const char * key, const char * value) override {
0 commit comments