Arduino DLNA Server
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::MediaRenderer Class Reference

MediaRenderer DLNA Device. More...

#include <MediaRenderer.h>

Inheritance diagram for tiny_dlna::MediaRenderer:
Inheritance graph
[legend]
Collaboration diagram for tiny_dlna::MediaRenderer:
Collaboration graph
[legend]

Public Types

typedef void(* MediaEventHandler) (MediaEvent event, MediaRenderer &renderer)
 

Public Member Functions

 MediaRenderer ()
 Default constructor.
 
void setMediaEventHandler (MediaEventHandler cb)
 Register a media event handler callback.
 
bool setVolume (uint8_t volumePercent)
 Set the renderer volume (0..100 percent)
 
uint8_t getVolume ()
 Get current volume (0..100 percent)
 
bool setMute (bool mute)
 Enable or disable mute.
 
bool isMuted ()
 Query mute state.
 
bool isActive ()
 Query whether renderer is active (playing or ready)
 
void setActive (bool active)
 Set the active state (used by transport callbacks)
 
unsigned long getPosition ()
 Get estimated playback position (ms)
 
const char * getMime ()
 Provides the mime from the DIDL or nullptr.
 
const char * getCurrentUri ()
 
const char * getTransportState ()
 Get textual transport state.
 
- Public Member Functions inherited from tiny_dlna::DLNADeviceInfo
 DLNADeviceInfo (bool ok=true)
 
 ~DLNADeviceInfo ()
 
virtual bool begin ()
 Override to initialize the device.
 
void print (Print &out)
 renderes the device xml
 
void setDeviceType (const char *st)
 
const char * getDeviceType ()
 
void setUDN (const char *id)
 Define the udn uuid.
 
const char * getUDN ()
 Provide the udn uuid.
 
void setBaseURL (const char *url)
 Defines the base url.
 
void setBaseURL (IPAddress ip, int port, const char *path="")
 Defines the base URL.
 
const char * getBaseURL ()
 Provides the base url.
 
UrlgetDeviceURL ()
 This method returns base url/device.xml.
 
void setIPAddress (IPAddress address)
 Defines the local IP address.
 
IPAddress getIPAddress ()
 Provides the local IP address.
 
const char * getIPStr ()
 Provides the local address as string.
 
void setNS (const char *ns)
 
const char * getNS ()
 
void setFriendlyName (const char *name)
 
const char * getFriendlyName ()
 
void setManufacturer (const char *man)
 
const char * getManufacturer ()
 
void setManufacturerURL (const char *url)
 
const char * getManufacturerURL ()
 
void setModelDescription (const char *descr)
 
const char * getModelDescription ()
 
void setModelName (const char *name)
 
const char * getModelName ()
 
void setModelNumber (const char *number)
 
const char * getModelNumber ()
 
void setSerialNumber (const char *sn)
 
const char * getSerialNumber ()
 
void setUniveralProductCode (const char *upc)
 
const char * getUniveralProductCode ()
 
void addService (DLNAServiceInfo s)
 Adds a service defintion.
 
DLNAServiceInfogetService (const char *id)
 Finds a service definition by name.
 
Vector< DLNAServiceInfo > & getServices ()
 
void clear ()
 
void clearIcons ()
 Overwrite the default icon.
 
void addIcon (Icon icon)
 
Icon getIcon (int idx=0)
 
 operator bool ()
 
void updateTimestamp ()
 Update the timestamp.
 
uint32_t getTimestamp ()
 Returns the time when this object has been updated.
 
void setActive (bool flag)
 
virtual void loop ()
 

Protected Member Functions

void setupServices (HttpServer &server, IUDPService &udp)
 Setup the HTTP and UDP services.
 
bool play (const char *urlStr)
 Start playback of a network resource (returns true on success)
 
void setMime (const char *mime)
 Set MIME explicitly (used when DIDL-Lite metadata provides protocolInfo)
 
void playbackCompleted ()
 Notify the renderer that playback completed.
 
void setMimeFromDIDL (const char *didl)
 
void setupServicesImpl (HttpServer *server)
 
- Protected Member Functions inherited from tiny_dlna::DLNADeviceInfo
virtual void setupServices (HttpServer &server, IUDPService &udp)
 to be implemented by subclasses
 
size_t printRoot ()
 
size_t printDevice ()
 
size_t printSpecVersion ()
 
size_t printServiceList ()
 
size_t printService (void *srv)
 
size_t printIconList ()
 
size_t printIconDlnaInfo (Icon &icon)
 

Static Protected Member Functions

static const char * reply ()
 
static void transportControlCB (HttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 
static void renderingControlCB (HttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 

Protected Attributes

tiny_dlna::Str current_uri
 
tiny_dlna::Str current_mime
 
MediaEventHandler event_cb = nullptr
 
uint8_t current_volume = 50
 
bool is_muted = false
 
bool is_active = false
 
unsigned long start_time = 0
 
tiny_dlna::Str transport_state = "NO_MEDIA_PRESENT"
 
const char * st = "urn:schemas-upnp-org:device:MediaRenderer:1"
 
const char * usn = "uuid:09349455-2941-4cf7-9847-1dd5ab210e97"
 
- Protected Attributes inherited from tiny_dlna::DLNADeviceInfo
uint64_t timestamp = 0
 
bool is_active = true
 
XMLPrinter xml
 
Url device_url
 
IPAddress localhost
 
int version_major = 1
 
int version_minor = 0
 
const char * base_url = "http://localhost:9876/dlna"
 
const char * udn = "uuid:09349455-2941-4cf7-9847-0dd5ab210e97"
 
const char * ns = "xmlns=\"urn:schemas-upnp-org:device-1-0\""
 
const char * device_type = nullptr
 
const char * friendly_name = nullptr
 
const char * manufacturer = nullptr
 
const char * manufacturer_url = nullptr
 
const char * model_description = nullptr
 
const char * model_name = nullptr
 
const char * model_url = nullptr
 
const char * model_number = nullptr
 
const char * serial_number = nullptr
 
const char * universal_product_code = nullptr
 
Icon icon
 
Vector< DLNAServiceInfoservices
 
Vector< Iconicons
 
Str url_str
 

Detailed Description

MediaRenderer DLNA Device.

MediaRenderer implements a simple UPnP/DLNA Media Renderer device. It receives stream URIs via UPnP AVTransport actions and delegates actual playback and rendering to the application through an event callback API. This removes any dependency on an internal audio stack: applications handle playback themselves by registering a handler with setMediaEventHandler(). The device still supports rendering controls (volume, mute) and transport controls (play/pause/stop) and provides helper accessors like getCurrentUri() and getMime().

Usage summary:

This class is intentionally small and Arduino-friendly: methods return bool for success/failure and avoid heavy dynamic memory allocations in the hot path.

Author: Phil Schatzmann

Member Typedef Documentation

◆ MediaEventHandler

typedef void(* tiny_dlna::MediaRenderer::MediaEventHandler) (MediaEvent event, MediaRenderer &renderer)

Constructor & Destructor Documentation

◆ MediaRenderer()

tiny_dlna::MediaRenderer::MediaRenderer ( )
inline

Default constructor.

Initializes device metadata (friendly name, manufacturer, model) and sets default base URL and identifiers. It does not configure any audio pipeline components; use setOutput() and setDecoder() for that.

Member Function Documentation

◆ getCurrentUri()

const char * tiny_dlna::MediaRenderer::getCurrentUri ( )
inline

◆ getMime()

const char * tiny_dlna::MediaRenderer::getMime ( )
inline

Provides the mime from the DIDL or nullptr.

◆ getPosition()

unsigned long tiny_dlna::MediaRenderer::getPosition ( )
inline

Get estimated playback position (ms)

◆ getTransportState()

const char * tiny_dlna::MediaRenderer::getTransportState ( )
inline

Get textual transport state.

◆ getVolume()

uint8_t tiny_dlna::MediaRenderer::getVolume ( )
inline

Get current volume (0..100 percent)

◆ isActive()

bool tiny_dlna::MediaRenderer::isActive ( )
inline

Query whether renderer is active (playing or ready)

◆ isMuted()

bool tiny_dlna::MediaRenderer::isMuted ( )
inline

Query mute state.

◆ play()

bool tiny_dlna::MediaRenderer::play ( const char *  urlStr)
inlineprotected

Start playback of a network resource (returns true on success)

◆ playbackCompleted()

void tiny_dlna::MediaRenderer::playbackCompleted ( )
inlineprotected

Notify the renderer that playback completed.

This helper updates the internal transport state to "STOPPED", marks the renderer inactive, resets the start time, logs the event and notifies the application event handler with MediaEvent::STOP so the application can perform cleanup (release resources, update UI, etc.).

◆ renderingControlCB()

static void tiny_dlna::MediaRenderer::renderingControlCB ( HttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl 
)
inlinestaticprotected

◆ reply()

static const char * tiny_dlna::MediaRenderer::reply ( )
inlinestaticprotected

◆ setActive()

void tiny_dlna::MediaRenderer::setActive ( bool  active)
inline

Set the active state (used by transport callbacks)

◆ setMediaEventHandler()

void tiny_dlna::MediaRenderer::setMediaEventHandler ( MediaEventHandler  cb)
inline

Register a media event handler callback.

◆ setMime()

void tiny_dlna::MediaRenderer::setMime ( const char *  mime)
inlineprotected

Set MIME explicitly (used when DIDL-Lite metadata provides protocolInfo)

◆ setMimeFromDIDL()

void tiny_dlna::MediaRenderer::setMimeFromDIDL ( const char *  didl)
inlineprotected

Try to parse a DIDL-Lite snippet and extract the protocolInfo MIME from the <res> element. If found, set current_mime.

◆ setMute()

bool tiny_dlna::MediaRenderer::setMute ( bool  mute)
inline

Enable or disable mute.

◆ setupServices()

void tiny_dlna::MediaRenderer::setupServices ( HttpServer server,
IUDPService udp 
)
inlineprotectedvirtual

Setup the HTTP and UDP services.

Reimplemented from tiny_dlna::DLNADeviceInfo.

◆ setupServicesImpl()

void tiny_dlna::MediaRenderer::setupServicesImpl ( HttpServer server)
inlineprotected

◆ setVolume()

bool tiny_dlna::MediaRenderer::setVolume ( uint8_t  volumePercent)
inline

Set the renderer volume (0..100 percent)

◆ transportControlCB()

static void tiny_dlna::MediaRenderer::transportControlCB ( HttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl 
)
inlinestaticprotected

Member Data Documentation

◆ current_mime

tiny_dlna::Str tiny_dlna::MediaRenderer::current_mime
protected

◆ current_uri

tiny_dlna::Str tiny_dlna::MediaRenderer::current_uri
protected

◆ current_volume

uint8_t tiny_dlna::MediaRenderer::current_volume = 50
protected

◆ event_cb

MediaEventHandler tiny_dlna::MediaRenderer::event_cb = nullptr
protected

◆ is_active

bool tiny_dlna::MediaRenderer::is_active = false
protected

◆ is_muted

bool tiny_dlna::MediaRenderer::is_muted = false
protected

◆ st

const char* tiny_dlna::MediaRenderer::st = "urn:schemas-upnp-org:device:MediaRenderer:1"
protected

◆ start_time

unsigned long tiny_dlna::MediaRenderer::start_time = 0
protected

◆ transport_state

tiny_dlna::Str tiny_dlna::MediaRenderer::transport_state = "NO_MEDIA_PRESENT"
protected

◆ usn

const char* tiny_dlna::MediaRenderer::usn = "uuid:09349455-2941-4cf7-9847-1dd5ab210e97"
protected

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