From a1eb01aa543d75c0e8301481a3849993e4264d42 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Sat, 7 Oct 2023 17:30:22 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20doxygen=20from=20@=20pschatzma?= =?UTF-8?q?nn/arduino-audio-tools@eaee87bbe6ed85837fa7eb778db7fbb07c06fcf4?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _u_r_l_stream_8h_source.html | 268 +++++++++--------- ...audio__tools_1_1_u_r_l_stream-members.html | 25 +- classaudio__tools_1_1_u_r_l_stream.html | 3 + 3 files changed, 151 insertions(+), 145 deletions(-) diff --git a/_u_r_l_stream_8h_source.html b/_u_r_l_stream_8h_source.html index eaa7c98a6c..2a21aaa275 100644 --- a/_u_r_l_stream_8h_source.html +++ b/_u_r_l_stream_8h_source.html @@ -157,7 +157,7 @@
96  url.setUrl(url_str.c_str());
97  int result = -1;
98 
-
99 // close it - if we have an active connection
+
99  // close it - if we have an active connection
100  if (active) end();
101 
102  // optional: login if necessary
@@ -189,8 +189,8 @@
128  }
129 
130  virtual void end() override {
-
131  active = false;
-
132  request.stop();
+
131  if (active) request.stop();
+
132  active = false;
133  clear();
134  }
135 
@@ -317,136 +317,140 @@
266  custom_log_level.set(level);
267  }
268 
-
269  protected:
-
270  HttpRequest request;
-
271  CustomLogLevel custom_log_level;
-
272  StrExt url_str;
-
273  Url url;
-
274  long size;
-
275  long total_read;
-
276  // buffered single byte read
-
277  Vector<uint8_t> read_buffer{0};
-
278  uint16_t read_buffer_size=DEFAULT_BUFFER_SIZE;
-
279  uint16_t read_pos;
-
280  uint16_t read_size;
-
281  bool active = false;
-
282  bool wait_for_data = true;
-
283  // optional
-
284  const char* network=nullptr;
-
285  const char* password=nullptr;
-
286  Client *client=nullptr;
-
287  WiFiClient *clientInsecure=nullptr;
-
288 #ifdef USE_WIFI_CLIENT_SECURE
-
289  WiFiClientSecure *clientSecure=nullptr;
-
290 #endif
-
291  int clientTimeout = URL_CLIENT_TIMEOUT; // 60000;
-
292  unsigned long handshakeTimeout = URL_HANDSHAKE_TIMEOUT; //120000
-
293  bool is_power_save = false;
-
294 
-
295 
-
297  int process(MethodID action, Url &url, const char* reqMime, const char *reqData, int len=-1) {
-
298  client = &getClient(url.isSecure());
-
299  request.setClient(*client);
-
300  // keep icy across redirect requests ?
-
301  const char* icy = request.header().get("Icy-MetaData");
-
302 
-
303  // set timeout
-
304  client->setTimeout(clientTimeout / 1000);
-
305  request.setTimeout(clientTimeout);
+
269  const char* urlStr() {
+
270  return url_str.c_str();
+
271  }
+
272 
+
273  protected:
+
274  HttpRequest request;
+
275  CustomLogLevel custom_log_level;
+
276  StrExt url_str;
+
277  Url url;
+
278  long size;
+
279  long total_read;
+
280  // buffered single byte read
+
281  Vector<uint8_t> read_buffer{0};
+
282  uint16_t read_buffer_size=DEFAULT_BUFFER_SIZE;
+
283  uint16_t read_pos;
+
284  uint16_t read_size;
+
285  bool active = false;
+
286  bool wait_for_data = true;
+
287  // optional
+
288  const char* network=nullptr;
+
289  const char* password=nullptr;
+
290  Client *client=nullptr;
+
291  WiFiClient *clientInsecure=nullptr;
+
292 #ifdef USE_WIFI_CLIENT_SECURE
+
293  WiFiClientSecure *clientSecure=nullptr;
+
294 #endif
+
295  int clientTimeout = URL_CLIENT_TIMEOUT; // 60000;
+
296  unsigned long handshakeTimeout = URL_HANDSHAKE_TIMEOUT; //120000
+
297  bool is_power_save = false;
+
298 
+
299 
+
301  int process(MethodID action, Url &url, const char* reqMime, const char *reqData, int len=-1) {
+
302  client = &getClient(url.isSecure());
+
303  request.setClient(*client);
+
304  // keep icy across redirect requests ?
+
305  const char* icy = request.header().get("Icy-MetaData");
306 
-
307 #ifdef ESP32
-
308  // There is a bug in IDF 4!
-
309  if (clientSecure!=nullptr){
-
310  clientSecure->setHandshakeTimeout(handshakeTimeout);
-
311  }
-
312 
-
313  // Performance optimization for ESP32
-
314  if (!is_power_save){
-
315  esp_wifi_set_ps(WIFI_PS_NONE);
-
316  }
-
317 #endif
-
318 
-
319  int status_code = request.process(action, url, reqMime, reqData, len);
-
320  // redirect
-
321  while (request.reply().isRedirectStatus()){
-
322  const char *redirect_url = request.reply().get(LOCATION);
-
323  if (redirect_url!=nullptr) {
-
324  LOGW("Redirected to: %s", redirect_url);
-
325  url.setUrl(redirect_url);
-
326  Client* p_client = &getClient(url.isSecure());
-
327  p_client->stop();
-
328  request.setClient(*p_client);
-
329  if (icy){
-
330  request.header().put("Icy-MetaData", icy);
-
331  }
-
332  status_code = request.process(action, url, reqMime, reqData, len);
-
333  } else {
-
334  LOGE("Location is null");
-
335  break;
-
336  }
-
337  }
-
338  return status_code;
-
339  }
-
340 
-
342  Client &getClient(bool isSecure){
-
343  if (client!=nullptr) return *client;
-
344 #ifdef USE_WIFI_CLIENT_SECURE
-
345  if (isSecure){
-
346  if (clientSecure==nullptr){
-
347  clientSecure = new WiFiClientSecure();
-
348  clientSecure->setInsecure();
-
349  }
-
350  LOGI("WiFiClientSecure");
-
351  return *clientSecure;
-
352  }
-
353 #endif
-
354 #ifdef USE_WIFI
-
355  if (clientInsecure==nullptr){
-
356  clientInsecure = new WiFiClient();
-
357  LOGI("WiFiClient");
-
358  }
-
359  return *clientInsecure;
-
360 #else
-
361  LOGE("Client not set");
-
362  stop();
-
363  return *client; // to avoid compiler warning
-
364 #endif
-
365  }
-
366 
-
367 
-
368  inline void fillBuffer() {
-
369  if (isEOS()){
-
370  // if we consumed all bytes we refill the buffer
-
371  read_size = readBytes(&read_buffer[0],read_buffer_size);
-
372  read_pos = 0;
-
373  }
-
374  }
-
375 
-
376  inline bool isEOS() {
-
377  return read_pos>=read_size;
+
307  // set timeout
+
308  client->setTimeout(clientTimeout / 1000);
+
309  request.setTimeout(clientTimeout);
+
310 
+
311 #ifdef ESP32
+
312  // There is a bug in IDF 4!
+
313  if (clientSecure!=nullptr){
+
314  clientSecure->setHandshakeTimeout(handshakeTimeout);
+
315  }
+
316 
+
317  // Performance optimization for ESP32
+
318  if (!is_power_save){
+
319  esp_wifi_set_ps(WIFI_PS_NONE);
+
320  }
+
321 #endif
+
322 
+
323  int status_code = request.process(action, url, reqMime, reqData, len);
+
324  // redirect
+
325  while (request.reply().isRedirectStatus()){
+
326  const char *redirect_url = request.reply().get(LOCATION);
+
327  if (redirect_url!=nullptr) {
+
328  LOGW("Redirected to: %s", redirect_url);
+
329  url.setUrl(redirect_url);
+
330  Client* p_client = &getClient(url.isSecure());
+
331  p_client->stop();
+
332  request.setClient(*p_client);
+
333  if (icy){
+
334  request.header().put("Icy-MetaData", icy);
+
335  }
+
336  status_code = request.process(action, url, reqMime, reqData, len);
+
337  } else {
+
338  LOGE("Location is null");
+
339  break;
+
340  }
+
341  }
+
342  return status_code;
+
343  }
+
344 
+
346  Client &getClient(bool isSecure){
+
347  if (client!=nullptr) return *client;
+
348 #ifdef USE_WIFI_CLIENT_SECURE
+
349  if (isSecure){
+
350  if (clientSecure==nullptr){
+
351  clientSecure = new WiFiClientSecure();
+
352  clientSecure->setInsecure();
+
353  }
+
354  LOGI("WiFiClientSecure");
+
355  return *clientSecure;
+
356  }
+
357 #endif
+
358 #ifdef USE_WIFI
+
359  if (clientInsecure==nullptr){
+
360  clientInsecure = new WiFiClient();
+
361  LOGI("WiFiClient");
+
362  }
+
363  return *clientInsecure;
+
364 #else
+
365  LOGE("Client not set");
+
366  stop();
+
367  return *client; // to avoid compiler warning
+
368 #endif
+
369  }
+
370 
+
371 
+
372  inline void fillBuffer() {
+
373  if (isEOS()){
+
374  // if we consumed all bytes we refill the buffer
+
375  read_size = readBytes(&read_buffer[0],read_buffer_size);
+
376  read_pos = 0;
+
377  }
378  }
379 
-
380  void login(){
-
381 #ifdef USE_WIFI
-
382  if (network!=nullptr && password != nullptr && WiFi.status() != WL_CONNECTED){
-
383  TRACEI();
-
384  WiFi.begin(network, password);
-
385  while (WiFi.status() != WL_CONNECTED){
-
386  Serial.print(".");
-
387  delay(500);
-
388  }
-
389  Serial.println();
-
390  delay(500);
-
391  }
-
392 #else
-
393 #endif
-
394  }
-
395 
-
396 };
-
397 
-
398 }
+
380  inline bool isEOS() {
+
381  return read_pos>=read_size;
+
382  }
+
383 
+
384  void login(){
+
385 #ifdef USE_WIFI
+
386  if (network!=nullptr && password != nullptr && WiFi.status() != WL_CONNECTED){
+
387  TRACEI();
+
388  WiFi.begin(network, password);
+
389  while (WiFi.status() != WL_CONNECTED){
+
390  Serial.print(".");
+
391  delay(500);
+
392  }
+
393  Serial.println();
+
394  delay(500);
+
395  }
+
396 #else
+
397 #endif
+
398  }
399 
-
400 #endif
+
400 };
+
401 
+
402 }
+
403 
+
404 #endif
Abstract Base class for all URLStream implementations.
Definition: AbstractURLStream.h:11
Definition: NoArduino.h:138
HttpHeader & clear(bool activeFlag=true)
clears the data - usually we do not delete but we just set the active flag
Definition: HttpHeader.h:75
@@ -456,7 +460,6 @@
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:153
void setOnConnectCallback(void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
Callback which allows you to add additional paramters dynamically.
Definition: HttpRequest.h:306
bool isReady()
returns true when the request has completed and ready for the data to be requested
Definition: HttpRequest.h:186
-
Str which keeps the data on the heap. We grow the allocated memory only if the copy source is not fit...
Definition: StrExt.h:23
virtual const char * c_str()
provides the string value as const char*
Definition: Str.h:412
Represents the content of a URL as Stream. We use the WiFi.h API.
Definition: URLStream.h:34
void setLogLevel(AudioLogger::LogLevel level)
Defines the class specific custom log level.
Definition: URLStream.h:265
@@ -464,8 +467,8 @@
virtual void setTimeout(int ms)
Defines the client timeout.
Definition: URLStream.h:196
virtual bool waitForData()
waits for some data - returns false if the request has failed
Definition: URLStream.h:247
void setPowerSave(bool ps)
if set to true, it activates the power save mode which comes at the cost of performance!...
Definition: URLStream.h:201
-
Client & getClient(bool isSecure)
Determines the client.
Definition: URLStream.h:342
-
int process(MethodID action, Url &url, const char *reqMime, const char *reqData, int len=-1)
Process the Http request and handle redirects.
Definition: URLStream.h:297
+
Client & getClient(bool isSecure)
Determines the client.
Definition: URLStream.h:346
+
int process(MethodID action, Url &url, const char *reqMime, const char *reqData, int len=-1)
Process the Http request and handle redirects.
Definition: URLStream.h:301
void setSSID(const char *ssid) override
Sets the ssid that will be used for logging in (when calling begin)
Definition: URLStream.h:79
void setClient(Client &clientPar) override
(Re-)defines the client
Definition: URLStream.h:74
void setOnConnectCallback(void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
Callback which allows you to add additional paramters dynamically.
Definition: URLStream.h:230
@@ -475,7 +478,6 @@
void setConnectionClose(bool close)
Sets if the connection should be close automatically.
Definition: URLStream.h:211
void setPassword(const char *password) override
Sets the password that will be used for logging in (when calling begin)
Definition: URLStream.h:84
URL parser which breaks a full url string up into its individual parts.
Definition: Url.h:23
-
void stop()
Public generic methods.
Definition: AudioRuntime.h:12
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:9
void delay(uint64_t ms)
Waits for the indicated milliseconds.
Definition: Millis.h:10
diff --git a/classaudio__tools_1_1_u_r_l_stream-members.html b/classaudio__tools_1_1_u_r_l_stream-members.html index d9afa7c8b2..dd795e7a85 100644 --- a/classaudio__tools_1_1_u_r_l_stream-members.html +++ b/classaudio__tools_1_1_u_r_l_stream-members.html @@ -136,18 +136,19 @@ totalRead() (defined in URLStream)URLStreaminline url (defined in URLStream)URLStreamprotected url_str (defined in URLStream)URLStreamprotected - URLStream(int readBufferSize=DEFAULT_BUFFER_SIZE) (defined in URLStream)URLStreaminline - URLStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE) (defined in URLStream)URLStreaminline - URLStream(const char *network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) (defined in URLStream)URLStreaminline - URLStream(const URLStream &)=delete (defined in URLStream)URLStream - validate(AudioInfo &info) (defined in AudioInfoSupport)AudioInfoSupportinlinevirtual - wait_for_data (defined in URLStream)URLStreamprotected - waitForData()URLStreaminlinevirtual - write(uint8_t) override (defined in URLStream)URLStreaminlinevirtual - write(const uint8_t *, size_t) override (defined in URLStream)URLStreaminlinevirtual - writeSilence(size_t len)AudioStreaminlinevirtual - ~AudioStream()=default (defined in AudioStream)AudioStreamvirtual - ~URLStream() (defined in URLStream)URLStreaminline + urlStr() (defined in URLStream)URLStreaminline + URLStream(int readBufferSize=DEFAULT_BUFFER_SIZE) (defined in URLStream)URLStreaminline + URLStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE) (defined in URLStream)URLStreaminline + URLStream(const char *network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) (defined in URLStream)URLStreaminline + URLStream(const URLStream &)=delete (defined in URLStream)URLStream + validate(AudioInfo &info) (defined in AudioInfoSupport)AudioInfoSupportinlinevirtual + wait_for_data (defined in URLStream)URLStreamprotected + waitForData()URLStreaminlinevirtual + write(uint8_t) override (defined in URLStream)URLStreaminlinevirtual + write(const uint8_t *, size_t) override (defined in URLStream)URLStreaminlinevirtual + writeSilence(size_t len)AudioStreaminlinevirtual + ~AudioStream()=default (defined in AudioStream)AudioStreamvirtual + ~URLStream() (defined in URLStream)URLStreaminline