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
ICYStreamT< T > Class Template Reference

Icecast/Shoutcast Audio Stream which splits the data into metadata and audio data. The Audio data is provided via the regular stream functions. The metadata is handled with the help of the MetaDataICY state machine and provided via a callback method. More...

#include <ICYStreamT.h>

Inheritance diagram for ICYStreamT< T >:
AbstractURLStream AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 ICYStreamT (Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE)
 
 ICYStreamT (const char *ssid, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE)
 Default constructor.
 
 ICYStreamT (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) override
 Adds/Updates a request header.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int available () override
 provides the available method from the URLStream
 
int availableForWrite () override
 Writes are not supported.
 
virtual bool begin ()
 
virtual bool begin (const char *urlStr, const char *acceptMime=nullptr, MethodID action=GET, const char *reqMime="", const char *reqData="") override
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
int contentLength () override
 Provides the reported data size from the http reply.
 
virtual void end () override
 Ends the processing.
 
virtual void flush () override
 
const char * getReplyHeader (const char *key) override
 Provides reply header info.
 
virtual HttpRequesthttpRequest () override
 provides access to the HttpRequest
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
 operator bool ()
 
virtual int read () override
 
virtual size_t readBytes (uint8_t *data, size_t len) override
 reads the audio bytes
 
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 setCACert (const char *cert)
 Define the Root PEM Certificate for SSL:
 
void setClient (Client &client) override
 (Re-)defines the client
 
void setConnectionClose (bool flag) override
 Add Connection: close to request header.
 
virtual bool setMetadataCallback (void(*fn)(MetaDataType info, const char *str, int len)) override
 Defines the meta data callback function.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setPassword (const char *password) override
 Sets the password that will be used for logging in (when calling begin)
 
void setPowerSave (bool active)
 
void setReadBufferSize (int readBufferSize)
 
void setSSID (const char *ssid) override
 Sets the ssid that will be used for logging in (when calling begin)
 
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
 
virtual size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
void(* callback )(MetaDataType info, const char *str, int len) = nullptr
 
MetaDataICY icy
 
AudioInfo info
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
url
 

Detailed Description

template<class T>
class audio_tools::ICYStreamT< T >

Icecast/Shoutcast Audio Stream which splits the data into metadata and audio data. The Audio data is provided via the regular stream functions. The metadata is handled with the help of the MetaDataICY state machine and provided via a callback method.

This is basically just a URLStream with the metadata turned on.

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()

template<class T >
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()

template<class T >
virtual int available ( )
inlineoverridevirtual

provides the available method from the URLStream

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]

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

Implements AbstractURLStream.

◆ contentLength()

template<class T >
int contentLength ( )
inlineoverridevirtual

Provides the reported data size from the http reply.

Implements AbstractURLStream.

◆ end()

template<class T >
virtual void end ( )
inlineoverridevirtual

Ends the processing.

Implements AbstractURLStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

Reimplemented from Print.

Reimplemented in ResampleStream, BufferedTaskStream, and BufferedStream.

◆ getReplyHeader()

template<class T >
const char * getReplyHeader ( const char *  key)
inlineoverridevirtual

Provides reply header info.

Implements AbstractURLStream.

◆ httpRequest()

template<class T >
virtual HttpRequest & httpRequest ( )
inlineoverridevirtual

provides access to the HttpRequest

Implements AbstractURLStream.

◆ operator bool()

template<class T >
operator bool ( )
inlinevirtual

Reimplemented from AudioStream.

◆ readBytes()

template<class T >
virtual size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

reads the audio bytes

Reimplemented from AudioStream.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setCACert()

template<class T >
void setCACert ( const char *  cert)
inlinevirtual

Define the Root PEM Certificate for SSL:

Implements AbstractURLStream.

◆ setClient()

template<class T >
void setClient ( Client client)
inlineoverridevirtual

(Re-)defines the client

Implements AbstractURLStream.

◆ setConnectionClose()

template<class T >
void setConnectionClose ( bool  flag)
inlineoverridevirtual

Add Connection: close to request header.

Implements AbstractURLStream.

◆ setMetadataCallback()

template<class T >
virtual bool setMetadataCallback ( void(*)(MetaDataType info, const char *str, int len)  fn)
inlineoverridevirtual

Defines the meta data callback function.

Reimplemented from AbstractURLStream.

◆ setPassword()

template<class T >
void setPassword ( const char *  password)
inlineoverridevirtual

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

Implements AbstractURLStream.

◆ setPowerSave()

template<class T >
void setPowerSave ( bool  active)
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()

template<class T >
void setSSID ( const char *  ssid)
inlineoverridevirtual

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

Implements AbstractURLStream.

◆ totalRead()

template<class T >
size_t totalRead ( )
inlineoverridevirtual

Total amout of data that was consumed so far.

Implements AbstractURLStream.

◆ urlStr()

template<class T >
const char * urlStr ( )
inlineoverridevirtual

Provides the url as string.

Implements AbstractURLStream.

◆ waitForData()

template<class T >
bool waitForData ( int  timeout)
inlineoverridevirtual

Waits the indicated time for the data to be available waits for some data - returns false if the request has failed

Implements AbstractURLStream.

◆ write() [1/2]

virtual size_t write ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtualinherited

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

Reimplemented in BufferedTaskStream, and BufferedStream.


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