arduino-audio-tools
ICYStreamBuffered.h
1 #pragma once
2 #include "AudioConfig.h"
3 #if defined(USE_CONCURRENCY) && defined(USE_URL_ARDUINO)
4 #include "AudioHttp/ICYStream.h"
5 
6 namespace audio_tools {
7 
22  public:
23  ICYStreamBuffered(int readBufferSize = DEFAULT_BUFFER_SIZE) {
24  TRACEI();
25  urlStream.setReadBufferSize(readBufferSize);
26  taskStream.setInput(urlStream);
27  }
28 
29  ICYStreamBuffered(Client& clientPar,
30  int readBufferSize = DEFAULT_BUFFER_SIZE) {
31  TRACEI();
32  urlStream.setReadBufferSize(readBufferSize);
33  setClient(clientPar);
34  taskStream.setInput(urlStream);
35  }
36 
37  ICYStreamBuffered(const char* network, const char* password,
38  int readBufferSize = DEFAULT_BUFFER_SIZE) {
39  TRACEI();
40  urlStream.setReadBufferSize(readBufferSize);
41  setSSID(network);
42  setPassword(password);
43  taskStream.setInput(urlStream);
44  }
45 
46  virtual bool setMetadataCallback(void (*fn)(MetaDataType info,
47  const char* str,
48  int len)) override {
49  TRACED();
50  return urlStream.setMetadataCallback(fn);
51  }
52 
53  virtual bool begin(const char* urlStr, const char* acceptMime = nullptr,
54  MethodID action = GET, const char* reqMime = "",
55  const char* reqData = "") override {
56  TRACED();
57  // start real stream
58  bool result = urlStream.begin(urlStr, acceptMime, action, reqMime, reqData);
59  // start reader task
60  taskStream.begin();
61  return result;
62  }
63 
64  virtual void end() override {
65  TRACED();
66  taskStream.end();
67  urlStream.end();
68  }
69 
70  virtual int available() override { return taskStream.available(); }
71 
72  virtual size_t readBytes(uint8_t* buffer, size_t length) override {
73  size_t result = taskStream.readBytes(buffer, length);
74  LOGD("%s: %zu -> %zu", LOG_METHOD, length, result);
75  return result;
76  }
77 
78  virtual int read() override { return taskStream.read(); }
79 
80  virtual int peek() override { return taskStream.peek(); }
81 
83  virtual void flush() override {}
84 
86  virtual HttpRequest& httpRequest() override {
87  return urlStream.httpRequest();
88  }
89 
91  void setClient(Client& client) override { urlStream.setClient(client); }
92 
94  void setSSID(const char* ssid) override { urlStream.setSSID(ssid); }
95 
97  void setPassword(const char* password) override {
98  urlStream.setPassword(password);
99  }
100 
101  protected:
102  BufferedTaskStream taskStream;
103  ICYStream urlStream;
104 };
105 
106 } // namespace audio_tools
107 
108 #endif // USE_TASK
Abstract Base class for all URLStream implementations.
Definition: AbstractURLStream.h:11
A FreeRTOS task is filling the buffer from the indicated stream. Only to be used on the ESP32.
Definition: URLStreamBuffered.h:34
virtual size_t readBytes(uint8_t *data, size_t length) override
Use this method !!
Definition: URLStreamBuffered.h:94
virtual int read() override
reads a byte - to be avoided
Definition: URLStreamBuffered.h:78
virtual int peek() override
peeks a byte - to be avoided
Definition: URLStreamBuffered.h:86
virtual int available() override
Returns the available bytes in the buffer: to be avoided.
Definition: URLStreamBuffered.h:103
Definition: NoArduino.h:138
Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient,...
Definition: HttpRequest.h:26
ICYStream implementation for the ESP32 based on a FreeRTOS task This is a Icecast/Shoutcast Audio Str...
Definition: ICYStreamBuffered.h:21
virtual HttpRequest & httpRequest() override
provides access to the HttpRequest
Definition: ICYStreamBuffered.h:86
void setSSID(const char *ssid) override
Sets the ssid that will be used for logging in (when calling begin)
Definition: ICYStreamBuffered.h:94
void setClient(Client &client) override
(Re-)defines the client
Definition: ICYStreamBuffered.h:91
void setPassword(const char *password) override
Sets the password that will be used for logging in (when calling begin)
Definition: ICYStreamBuffered.h:97
virtual void flush() override
Not implemented.
Definition: ICYStreamBuffered.h:83
Icecast/Shoutcast Audio Stream which splits the data into metadata and audio data....
Definition: ICYStream.h:22
virtual HttpRequest & httpRequest() override
provides access to the HttpRequest
Definition: ICYStream.h:131
void setSSID(const char *ssid) override
Sets the ssid that will be used for logging in (when calling begin)
Definition: ICYStream.h:141
void setClient(Client &client) override
(Re-)defines the client
Definition: ICYStream.h:138
virtual bool setMetadataCallback(void(*fn)(MetaDataType info, const char *str, int len)) override
Defines the meta data callback function.
Definition: ICYStream.h:45
void setPassword(const char *password) override
Sets the password that will be used for logging in (when calling begin)
Definition: ICYStream.h:144
virtual void end() override
Ends the processing.
Definition: ICYStream.h:80
MetaDataType
Type of meta info.
Definition: AbstractMetaData.h:11
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10