arduino-audio-tools
Loading...
Searching...
No Matches
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 MimeSource 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)
 
 ~URLStream ()
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
void addRequestHeader (const char *key, const char *value) override
 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
 returns the content length
 
virtual void end () override
 Ends the request and releases the memory.
 
virtual void flush () override
 
const chargetReplyHeader (const char *key) override
 Provides the value of the reply header for the given key.
 
virtual HttpRequesthttpRequest () override
 provides access to the HttpRequest
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
const charmime () override
 Provides the MIME type for the current stream.
 
 operator bool () override
 
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) override
 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) override
 
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 in ms.
 
void setWaitForData (bool flag)
 Defines if the stream should wait for data after the request has been sent.
 
void setWriteBufferSize (int size)
 
size_t size ()
 Returns the content length of the request.
 
size_t totalRead () override
 returns the total number of bytes read from the stream
 
const charurlStr () override
 returns 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 ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()
 

Protected Attributes

int _timeout = 10
 
bool active = false
 
Clientclient = nullptr
 
WiFiClientclient_insecure = nullptr
 
WiFiClientSecureclient_secure = nullptr
 
int client_timeout = URL_CLIENT_TIMEOUT
 
long content_length = 0
 
unsigned long handshake_timeout = URL_HANDSHAKE_TIMEOUT
 
AudioInfo info
 
bool is_notify_active = true
 
bool is_power_save = false
 
const charnetwork = nullptr
 
Vector< AudioInfoSupport * > notify_vector
 
const charpassword = nullptr
 
Vector< uint8_tread_buffer {0}
 
uint16_t read_buffer_size = DEFAULT_BUFFER_SIZE
 
uint16_t read_pos = 0
 
uint16_t read_size = 0
 
HttpRequest request
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
long total_read = 0
 
Url url
 
Str url_str
 
bool wait_for_data = true
 
int write_buffer_size = MAX_SINGLE_CHARS
 

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

Constructor & Destructor Documentation

◆ URLStream() [1/4]

URLStream ( int  readBufferSize = DEFAULT_BUFFER_SIZE)
inline

◆ URLStream() [2/4]

URLStream ( Client clientPar,
int  readBufferSize = DEFAULT_BUFFER_SIZE 
)
inline

◆ URLStream() [3/4]

URLStream ( const char network,
const char password,
int  readBufferSize = DEFAULT_BUFFER_SIZE 
)
inline

◆ URLStream() [4/4]

URLStream ( const URLStream )
delete

◆ ~URLStream()

~URLStream ( )
inline

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ addRequestHeader()

void addRequestHeader ( const char key,
const char value 
)
inlineoverridevirtual

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/3]

virtual bool begin ( )
inlinevirtualinherited

◆ begin() [2/3]

virtual bool begin ( const char urlStr,
const char acceptMime,
MethodID  action,
const char reqMime,
Stream reqData,
int  len = -1 
)
inlinevirtual

Execute e.g. http POST request which submits the content as a stream.

◆ begin() [3/3]

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.

◆ clear()

void clear ( )
inline

Releases the memory from the request and reply.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ contentLength()

int contentLength ( )
inlineoverridevirtual

returns the content length

Implements AbstractURLStream.

◆ end()

virtual void end ( )
inlineoverridevirtual

Ends the request and releases the memory.

Implements AbstractURLStream.

◆ fillBuffer()

void fillBuffer ( )
inlineprotected

◆ flush()

virtual void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ getClient()

Client & getClient ( bool  isSecure)
inlineprotected

Determines the client.

◆ getReplyHeader()

const char * getReplyHeader ( const char key)
inlineoverridevirtual

Provides the value of the reply header for the given key.

Implements AbstractURLStream.

◆ httpRequest()

virtual HttpRequest & httpRequest ( )
inlineoverridevirtual

provides access to the HttpRequest

Implements AbstractURLStream.

◆ isEOS()

bool isEOS ( )
inlineprotected

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ login()

bool login ( )
inlineprotected

◆ mime()

const char * mime ( )
inlineoverridevirtualinherited

Provides the MIME type for the current stream.

Implements MimeSource.

◆ not_supported()

virtual int not_supported ( int  out,
const char msg = "" 
)
inlineprotectedvirtualinherited

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Reimplemented from AudioStream.

◆ peek()

virtual int peek ( )
inlineoverridevirtual

◆ preProcess()

bool preProcess ( const char urlStr,
const char acceptMime 
)
inlineprotected

◆ process()

template<typename T >
int process ( MethodID  action,
Url url,
const char reqMime,
T  reqData,
int  len = -1 
)
inlineprotected

Process the Http request and handle redirects.

◆ read()

virtual int read ( )
inlineoverridevirtual

◆ readBytes()

virtual size_t readBytes ( uint8_t data,
size_t  len 
)
inlineoverridevirtual

Reimplemented from AudioStream.

◆ readSilence()

virtual size_t readSilence ( uint8_t buffer,
size_t  length 
)
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setAutoCreateLines()

void setAutoCreateLines ( bool  flag)
inline

If set to true, new undefined reply parameters will be stored.

◆ 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)
inlineoverridevirtual

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 ICYStreamBuffered, and ICYStreamT< T >.

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active)

◆ setOnConnectCallback()

void setOnConnectCallback ( void(*)(HttpRequest &request, Url &url, HttpRequestHeader &request_header)  callback)
inline

Callback which allows you to add additional paramters dynamically.

◆ 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)
inlineoverridevirtual

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.

◆ setReadBufferSize()

void setReadBufferSize ( int  readBufferSize)
inline

Defines the buffer that is used by individual read() or peek() calls.

◆ setSSID()

void setSSID ( const char ssid)
inlineoverridevirtual

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

Implements AbstractURLStream.

◆ setTimeout()

virtual void setTimeout ( int  ms)
inlinevirtual

Defines the client timeout in ms.

◆ setWaitForData()

void setWaitForData ( bool  flag)
inline

Defines if the stream should wait for data after the request has been sent.

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ size()

size_t size ( )
inline

Returns the content length of the request.

◆ totalRead()

size_t totalRead ( )
inlineoverridevirtual

returns the total number of bytes read from the stream

Implements AbstractURLStream.

◆ urlStr()

const char * urlStr ( )
inlineoverridevirtual

returns 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.

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ active

bool active = false
protected

◆ client

Client* client = nullptr
protected

◆ client_insecure

WiFiClient* client_insecure = nullptr
protected

◆ client_secure

WiFiClientSecure* client_secure = nullptr
protected

◆ client_timeout

int client_timeout = URL_CLIENT_TIMEOUT
protected

◆ content_length

long content_length = 0
protected

◆ handshake_timeout

unsigned long handshake_timeout = URL_HANDSHAKE_TIMEOUT
protected

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ is_power_save

bool is_power_save = false
protected

◆ network

const char* network = nullptr
protected

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ password

const char* password = nullptr
protected

◆ read_buffer

Vector<uint8_t> read_buffer {0}
protected

◆ read_buffer_size

uint16_t read_buffer_size = DEFAULT_BUFFER_SIZE
protected

◆ read_pos

uint16_t read_pos = 0
protected

◆ read_size

uint16_t read_size = 0
protected

◆ request

HttpRequest request
protected

◆ tmp_in

RingBuffer<uint8_t> tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer<uint8_t> tmp_out {0}
protectedinherited

◆ total_read

long total_read = 0
protected

◆ url

Url url
protected

◆ url_str

Str url_str
protected

◆ wait_for_data

bool wait_for_data = true
protected

◆ write_buffer_size

int write_buffer_size = MAX_SINGLE_CHARS
protectedinherited

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