arduino-audio-tools
ICYStreamBuffered.h
1 #pragma once
2 #include "AudioConfig.h"
3 #if defined(USE_CONCURRENCY) && defined(USE_URL_ARDUINO)
4 #include "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 
54  void setBufferSize(int bufferSize, int bufferCount){
55  taskStream.setBufferSize(bufferSize, bufferCount);
56  }
57 
58  virtual bool begin(const char* urlStr, const char* acceptMime = nullptr,
59  MethodID action = GET, const char* reqMime = "",
60  const char* reqData = "") override {
61  TRACED();
62  // start real stream
63  bool result = urlStream.begin(urlStr, acceptMime, action, reqMime, reqData);
64  // start reader task
65  taskStream.begin();
66  return result;
67  }
68 
69  virtual void end() override {
70  TRACED();
71  taskStream.end();
72  urlStream.end();
73  }
74 
75  virtual int available() override { return taskStream.available(); }
76 
77  virtual size_t readBytes(uint8_t* data, size_t len) override {
78  size_t result = taskStream.readBytes(data, len);
79  LOGD("%s: %zu -> %zu", LOG_METHOD, len, result);
80  return result;
81  }
82 
83  virtual int read() override { return taskStream.read(); }
84 
85  virtual int peek() override { return taskStream.peek(); }
86 
88  virtual void flush() override {}
89 
91  virtual HttpRequest& httpRequest() override {
92  return urlStream.httpRequest();
93  }
94 
96  void setClient(Client& client) override { urlStream.setClient(client); }
97 
99  void setSSID(const char* ssid) override { urlStream.setSSID(ssid); }
100 
102  void setPassword(const char* password) override {
103  urlStream.setPassword(password);
104  }
105  void setPowerSave(bool ps) override { urlStream.setPowerSave(ps); }
106 
107  protected:
108  BufferedTaskStream taskStream;
109  ICYStream urlStream;
110 };
111 
112 } // namespace audio_tools
113 
114 #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
void setBufferSize(int bufferSize, int bufferCount)
Define an explicit the buffer size in bytes.
Definition: URLStreamBuffered.h:49
virtual int read() override
reads a byte - to be avoided
Definition: URLStreamBuffered.h:83
virtual size_t readBytes(uint8_t *data, size_t len) override
Use this method !!
Definition: URLStreamBuffered.h:99
virtual int peek() override
peeks a byte - to be avoided
Definition: URLStreamBuffered.h:91
virtual int available() override
Returns the available bytes in the buffer: to be avoided.
Definition: URLStreamBuffered.h:108
Definition: NoArduino.h:139
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:91
void setBufferSize(int bufferSize, int bufferCount)
Define an explicit the buffer size in bytes.
Definition: ICYStreamBuffered.h:54
void setPowerSave(bool ps) override
Definition: ICYStreamBuffered.h:105
void setSSID(const char *ssid) override
Sets the ssid that will be used for logging in (when calling begin)
Definition: ICYStreamBuffered.h:99
void setClient(Client &client) override
(Re-)defines the client
Definition: ICYStreamBuffered.h:96
void setPassword(const char *password) override
Sets the password that will be used for logging in (when calling begin)
Definition: ICYStreamBuffered.h:102
virtual void flush() override
Not implemented.
Definition: ICYStreamBuffered.h:88
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 setPowerSave(bool active)
Definition: ICYStream.h:148
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: AudioConfig.h:823