66namespace audio_tools {
77
88/* *
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.
1310 *
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.
1515 *
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.).
1935 *
2036 * @ingroup http
2137 * @author Phil Schatzmann
@@ -45,7 +61,7 @@ class ICYStreamT : public AbstractURLStream {
4561 setClient (clientPar);
4662 }
4763
48- // / Defines the meta data callback function
64+ // / Defines the metadata callback function
4965 virtual bool setMetadataCallback (void (*fn)(MetaDataType info,
5066 const char * str,
5167 int len)) override {
@@ -55,7 +71,7 @@ class ICYStreamT : public AbstractURLStream {
5571 return true ;
5672 }
5773
58- // Icy http get request to the indicated url
74+ // Performs an HTTP request to the indicated URL with ICY metadata enabled
5975 virtual bool begin (const char * urlStr, const char * acceptMime = nullptr ,
6076 MethodID action = GET, const char * reqMime = " " ,
6177 const char * reqData = " " ) override {
@@ -87,10 +103,10 @@ class ICYStreamT : public AbstractURLStream {
87103 icy.end ();
88104 }
89105
90- // / provides the available method from the URLStream
106+ // / Delegates available() from the underlying stream
91107 virtual int available () override { return url.available (); }
92108
93- // / reads the audio bytes
109+ // / Reads audio bytes, stripping out any interleaved ICY metadata
94110 virtual size_t readBytes (uint8_t * data, size_t len) override {
95111 size_t result = 0 ;
96112 if (icy.hasMetaData ()) {
@@ -113,7 +129,7 @@ class ICYStreamT : public AbstractURLStream {
113129 return result;
114130 }
115131
116- // Read character and processes using the MetaDataICY state engine
132+ // Reads a single audio byte, skipping metadata via the MetaDataICY state engine
117133 virtual int read () override {
118134 int ch = -1 ;
119135
@@ -129,6 +145,7 @@ class ICYStreamT : public AbstractURLStream {
129145 return ch;
130146 }
131147
148+ // / True if the underlying URL stream is ready/connected
132149 operator bool () { return url; }
133150
134151 void setReadBufferSize (int readBufferSize) {
@@ -141,11 +158,10 @@ class ICYStreamT : public AbstractURLStream {
141158 // / Sets the password that will be used for logging in (when calling begin)
142159 void setPassword (const char * password) override { url.setPassword (password); }
143160
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).
146162 void setPowerSave (bool active) { url.setPowerSave (active); }
147163
148- // / Define the Root PEM Certificate for SSL:
164+ // / Define the Root PEM certificate for TLS/ SSL
149165 void setCACert (const char * cert) { url.setCACert (cert); }
150166 // / Adds/Updates a request header
151167 void addRequestHeader (const char * key, const char * value) override {
0 commit comments