arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
URLStream Class Reference

Represents the content of a URL as Stream. We use the WiFi.h API. If you run into performance issues, check if the data is provided chunked. In this chase you can check if setting the protocol to "HTTP/1.0" improves the situation. More...

#include <URLStream.h>

Inheritance diagram for URLStream:
AbstractURLStream AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 URLStream (Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE)
 
 URLStream (const char *network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE)
 
 URLStream (const URLStream &)=delete
 
 URLStream (int readBufferSize=DEFAULT_BUFFER_SIZE)
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
void addRequestHeader (const char *key, const char *value)
 Adds/Updates a request header.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int available () override
 
int availableForWrite () override
 Writes are not supported.
 
virtual bool begin ()
 
virtual bool begin (const char *urlStr, const char *acceptMime, MethodID action, const char *reqMime, Stream &reqData, int len=-1)
 Execute e.g. http POST request which submits the content as a stream.
 
virtual bool begin (const char *urlStr, const char *acceptMime=nullptr, MethodID action=GET, const char *reqMime="", const char *reqData="") override
 Execute http request: by default we use a GET request.
 
void clear ()
 Releases the memory from the request and reply.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
int contentLength () override
 Provides the reported data size from the http reply.
 
virtual void end () override
 
virtual void flush () override
 
const char * getReplyHeader (const char *key)
 Provides reply header information.
 
virtual HttpRequesthttpRequest () override
 provides access to the HttpRequest
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
 operator bool ()
 
virtual int peek () override
 
virtual int read () override
 
virtual size_t readBytes (uint8_t *data, size_t len) override
 
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setAutoCreateLines (bool flag)
 If set to true, new undefined reply parameters will be stored.
 
void setCACert (const char *cert) override
 Define the Root PEM Certificate for SSL.
 
void setClient (Client &clientPar) override
 (Re-)defines the client
 
void setConnectionClose (bool close)
 Sets if the connection should be close automatically.
 
virtual bool setMetadataCallback (void(*fn)(MetaDataType info, const char *str, int len))
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setOnConnectCallback (void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
 Callback which allows you to add additional paramters dynamically.
 
void setPassword (const char *password) override
 Sets the password that will be used for logging in (when calling begin)
 
void setPowerSave (bool ps)
 
void setReadBufferSize (int readBufferSize)
 Defines the buffer that is used by individual read() or peek() calls.
 
void setSSID (const char *ssid) override
 Sets the ssid that will be used for logging in (when calling begin)
 
virtual void setTimeout (int ms)
 Defines the client timeout.
 
void setWaitForData (bool flag)
 
size_t totalRead () override
 Total amout of data that was consumed so far.
 
const char * urlStr () override
 Provides the url as string.
 
bool waitForData (int timeout) override
 waits for some data - returns false if the request has failed
 
virtual size_t write (const uint8_t *, size_t len) override
 
virtual size_t write (uint8_t) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

void fillBuffer ()
 
ClientgetClient (bool isSecure)
 Determines the client.
 
bool isEOS ()
 
bool login ()
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
bool preProcess (const char *urlStr, const char *acceptMime)
 
template<typename T >
int process (MethodID action, Url &url, const char *reqMime, T reqData, int len=-1)
 Process the Http request and handle redirects.
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
bool active = false
 
Clientclient = nullptr
 
WiFiClient * clientInsecure = nullptr
 
int clientTimeout = URL_CLIENT_TIMEOUT
 
unsigned long handshakeTimeout = URL_HANDSHAKE_TIMEOUT
 
AudioInfo info
 
bool is_notify_active = true
 
bool is_power_save = false
 
const char * network = nullptr
 
Vector< AudioInfoSupport * > notify_vector
 
const char * password = nullptr
 
Vector< uint8_t > read_buffer {0}
 
uint16_t read_buffer_size = DEFAULT_BUFFER_SIZE
 
uint16_t read_pos
 
uint16_t read_size
 
HttpRequest request
 
long size
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
long total_read
 
Url url
 
Str url_str
 
bool wait_for_data = true
 

Detailed Description

Represents the content of a URL as Stream. We use the WiFi.h API. If you run into performance issues, check if the data is provided chunked. In this chase you can check if setting the protocol to "HTTP/1.0" improves the situation.

Author
Phil Schatzmann

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ addRequestHeader()

void addRequestHeader ( const char *  key,
const char *  value 
)
inlinevirtual

Adds/Updates a request header.

Implements AbstractURLStream.

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

virtual int available ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ availableForWrite()

int availableForWrite ( )
inlineoverridevirtualinherited

Writes are not supported.

Reimplemented from BaseStream.

Reimplemented in URLStreamESP32.

◆ begin() [1/2]

virtual bool begin ( )
inlinevirtualinherited

◆ begin() [2/2]

virtual bool begin ( const char *  urlStr,
const char *  acceptMime = nullptr,
MethodID  action = GET,
const char *  reqMime = "",
const char *  reqData = "" 
)
inlineoverridevirtual

Execute http request: by default we use a GET request.

Implements AbstractURLStream.

◆ contentLength()

int contentLength ( )
inlineoverridevirtual

Provides the reported data size from the http reply.

Implements AbstractURLStream.

◆ end()

virtual void end ( )
inlineoverridevirtual

Implements AbstractURLStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ getReplyHeader()

const char * getReplyHeader ( const char *  header)
inlinevirtual

Provides reply header information.

Implements AbstractURLStream.

◆ httpRequest()

virtual HttpRequest & httpRequest ( )
inlineoverridevirtual

provides access to the HttpRequest

Implements AbstractURLStream.

◆ operator bool()

operator bool ( )
inlinevirtual

Reimplemented from AudioStream.

◆ readBytes()

virtual size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Reimplemented from AudioStream.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setCACert()

void setCACert ( const char *  cert)
inlineoverridevirtual

Define the Root PEM Certificate for SSL.

Implements AbstractURLStream.

◆ setClient()

void setClient ( Client clientPar)
inlineoverridevirtual

(Re-)defines the client

Implements AbstractURLStream.

◆ setConnectionClose()

void setConnectionClose ( bool  close)
inlinevirtual

Sets if the connection should be close automatically.

Implements AbstractURLStream.

◆ setMetadataCallback()

virtual bool setMetadataCallback ( void(*)(MetaDataType info, const char *str, int len)  fn)
inlinevirtualinherited

Reimplemented in ICYStreamT< T >.

◆ setPassword()

void setPassword ( const char *  password)
inlineoverridevirtual

Sets the password that will be used for logging in (when calling begin)

Implements AbstractURLStream.

◆ setPowerSave()

void setPowerSave ( bool  ps)
inlinevirtual

if set to true, it activates the power save mode which comes at the cost of performance! - By default this is deactivated. ESP32 Only!

Implements AbstractURLStream.

◆ setSSID()

void setSSID ( const char *  ssid)
inlineoverridevirtual

Sets the ssid that will be used for logging in (when calling begin)

Implements AbstractURLStream.

◆ totalRead()

size_t totalRead ( )
inlineoverridevirtual

Total amout of data that was consumed so far.

Implements AbstractURLStream.

◆ urlStr()

const char * urlStr ( )
inlineoverridevirtual

Provides the url as string.

Implements AbstractURLStream.

◆ waitForData()

bool waitForData ( int  timeout)
inlineoverridevirtual

waits for some data - returns false if the request has failed

Implements AbstractURLStream.

◆ write() [1/2]

virtual size_t write ( const uint8_t *  ,
size_t  len 
)
inlineoverridevirtual

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  )
inlineoverridevirtual

Reimplemented from BaseStream.


The documentation for this class was generated from the following file: