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::ControlPointMediaRenderer Class Reference

Helper class to control a MediaRenderer device from a control point. More...

#include <ControlPointMediaRenderer.h>

Collaboration diagram for tiny_dlna::ControlPointMediaRenderer:
Collaboration graph
[legend]

Public Types

typedef void(* NotificationCallback) (void *reference, const char *sid, const char *varName, const char *newValue)
 

Public Member Functions

 ControlPointMediaRenderer (DLNAControlPointMgr &mgr)
 Construct the helper with a reference to the control point mgr.
 
void setDeviceTypeFilter (const char *filter)
 Restrict this helper to devices of the given device type.
 
bool begin (DLNAHttpRequest &http, IUDPService &udp, uint32_t minWaitMs=3000, uint32_t maxWaitMs=60000)
 Begin discovery and processing.
 
int getDeviceCount ()
 Return the number of discovered devices matching the renderer filter.
 
void setDeviceIndex (int idx)
 Select the active renderer by index (0-based)
 
bool subscribeNotifications (int timeoutSeconds=60, NotificationCallback cb=nullptr)
 Subscribe to event notifications for the selected renderer.
 
void setInstanceID (const char *id)
 Set the InstanceID used for AVTransport and RenderingControl actions.
 
bool setMediaURI (const char *uri)
 Set the media URI on the renderer.
 
bool play ()
 Start playback on the renderer.
 
bool play (const char *uri)
 Set the media URI and start playback.
 
bool pause ()
 Pause playback.
 
bool stop ()
 Stop playback.
 
bool setVolume (int volumePercent)
 Set renderer volume.
 
bool setMute (bool mute)
 Set mute state on the renderer.
 
int getVolume ()
 Query the current volume from the renderer.
 
int getMute ()
 Query mute state.
 
unsigned long getPositionMs ()
 Query current playback position (RelTime)
 
const char * getTransportState ()
 Query transport state (e.g. STOPPED, PLAYING, PAUSED_PLAYBACK)
 
const char * getCurrentURI ()
 Get the current media URI from the renderer.
 
int getNrTracks ()
 Get number of tracks in the current media.
 
unsigned long getMediaDurationMs ()
 Get total media duration in milliseconds (from MediaDuration)
 
int getTrackIndex ()
 Get current track index (from GetPositionInfo)
 
unsigned long getTrackDurationMs ()
 Get current track duration in milliseconds (from TrackDuration)
 
const ActionReplygetLastReply () const
 Return last ActionReply (from the most recent synchronous call)
 
bool isActive ()
 Query if the helper considers the renderer to be actively playing.
 
void setReference (void *ref)
 Attach an opaque reference object that will be passed to callbacks.
 
void onActiveChanged (std::function< void(bool, void *)> cb)
 Register a callback invoked when the active (playing) state changes.
 

Protected Member Functions

void setActiveState (bool s)
 
const char * findArgument (ActionReply &r, const char *name)
 
DLNAServiceInfoselectService (const char *id)
 

Static Protected Member Functions

static void processNotification (void *reference, const char *sid, const char *varName, const char *newValue)
 Notification callback.
 
static unsigned long parseTimeToMs (const char *t)
 

Protected Attributes

DLNAControlPointMgrmgr
 
bool is_active = false
 
std::function< void(bool, void *)> activeChangedCallback = nullptr
 
int device_index = 0
 
const char * instance_id = "0"
 
const char * device_type_filter_default
 
const char * device_type_filter = device_type_filter_default
 
ActionReply last_reply
 
void * reference = nullptr
 

Detailed Description

Helper class to control a MediaRenderer device from a control point.

This lightweight helper uses the DLNAControlPointMgr action API to send common AVTransport and RenderingControl actions to the first MediaRenderer service discovered. It is intentionally minimal and returns boolean success/failure for each operation.

Member Typedef Documentation

◆ NotificationCallback

typedef void(* tiny_dlna::ControlPointMediaRenderer::NotificationCallback) (void *reference, const char *sid, const char *varName, const char *newValue)

Constructor & Destructor Documentation

◆ ControlPointMediaRenderer()

tiny_dlna::ControlPointMediaRenderer::ControlPointMediaRenderer ( DLNAControlPointMgr mgr)
inline

Construct the helper with a reference to the control point mgr.

Parameters
mgrReference to the underlying DLNAControlPointMgr used to send actions and manage discovery/subscriptions

Member Function Documentation

◆ begin()

bool tiny_dlna::ControlPointMediaRenderer::begin ( DLNAHttpRequest http,
IUDPService udp,
uint32_t  minWaitMs = 3000,
uint32_t  maxWaitMs = 60000 
)
inline

Begin discovery and processing.

Parameters
httpHttp server wrapper used for subscription callbacks
udpUDP service used for SSDP discovery
minWaitMsMinimum time in milliseconds to wait before returning
maxWaitMsMaximum time in milliseconds to wait for discovery
Returns
true on success, false on error

◆ findArgument()

const char * tiny_dlna::ControlPointMediaRenderer::findArgument ( ActionReply r,
const char *  name 
)
inlineprotected

◆ getCurrentURI()

const char * tiny_dlna::ControlPointMediaRenderer::getCurrentURI ( )
inline

Get the current media URI from the renderer.

Returns
pointer to URI string (owned by reply registry) or nullptr

◆ getDeviceCount()

int tiny_dlna::ControlPointMediaRenderer::getDeviceCount ( )
inline

Return the number of discovered devices matching the renderer filter.

Returns
number of matching devices

◆ getLastReply()

const ActionReply & tiny_dlna::ControlPointMediaRenderer::getLastReply ( ) const
inline

Return last ActionReply (from the most recent synchronous call)

Returns
reference to the last ActionReply

◆ getMediaDurationMs()

unsigned long tiny_dlna::ControlPointMediaRenderer::getMediaDurationMs ( )
inline

Get total media duration in milliseconds (from MediaDuration)

Returns
milliseconds or 0 on error/unknown

◆ getMute()

int tiny_dlna::ControlPointMediaRenderer::getMute ( )
inline

Query mute state.

Returns
0 = unmuted, 1 = muted, -1 = error/unknown

◆ getNrTracks()

int tiny_dlna::ControlPointMediaRenderer::getNrTracks ( )
inline

Get number of tracks in the current media.

Returns
number of tracks or -1 on error

◆ getPositionMs()

unsigned long tiny_dlna::ControlPointMediaRenderer::getPositionMs ( )
inline

Query current playback position (RelTime)

Returns
position in milliseconds, or 0 if unknown/error

◆ getTrackDurationMs()

unsigned long tiny_dlna::ControlPointMediaRenderer::getTrackDurationMs ( )
inline

Get current track duration in milliseconds (from TrackDuration)

Returns
milliseconds or 0 on error

◆ getTrackIndex()

int tiny_dlna::ControlPointMediaRenderer::getTrackIndex ( )
inline

Get current track index (from GetPositionInfo)

Returns
track index (numeric) or -1 on error

◆ getTransportState()

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

Query transport state (e.g. STOPPED, PLAYING, PAUSED_PLAYBACK)

Returns
pointer to a string owned by the helper's registry, or nullptr on error

◆ getVolume()

int tiny_dlna::ControlPointMediaRenderer::getVolume ( )
inline

Query the current volume from the renderer.

Returns
current volume 0..100, or -1 on error

◆ isActive()

bool tiny_dlna::ControlPointMediaRenderer::isActive ( )
inline

Query if the helper considers the renderer to be actively playing.

Returns
true if playing, false otherwise

◆ onActiveChanged()

void tiny_dlna::ControlPointMediaRenderer::onActiveChanged ( std::function< void(bool, void *)>  cb)
inline

Register a callback invoked when the active (playing) state changes.

Parameters
cbFunction taking (bool active, void* reference). 'reference' is the pointer set via setReference().

◆ parseTimeToMs()

static unsigned long tiny_dlna::ControlPointMediaRenderer::parseTimeToMs ( const char *  t)
inlinestaticprotected

◆ pause()

bool tiny_dlna::ControlPointMediaRenderer::pause ( )
inline

Pause playback.

Returns
true on success, false on error

◆ play() [1/2]

bool tiny_dlna::ControlPointMediaRenderer::play ( )
inline

Start playback on the renderer.

Returns
true on success, false on error

◆ play() [2/2]

bool tiny_dlna::ControlPointMediaRenderer::play ( const char *  uri)
inline

Set the media URI and start playback.

Parameters
uriURI to play
Returns
true on success, false on error

◆ processNotification()

static void tiny_dlna::ControlPointMediaRenderer::processNotification ( void *  reference,
const char *  sid,
const char *  varName,
const char *  newValue 
)
inlinestaticprotected

Notification callback.

◆ selectService()

DLNAServiceInfo & tiny_dlna::ControlPointMediaRenderer::selectService ( const char *  id)
inlineprotected

◆ setActiveState()

void tiny_dlna::ControlPointMediaRenderer::setActiveState ( bool  s)
inlineprotected

◆ setDeviceIndex()

void tiny_dlna::ControlPointMediaRenderer::setDeviceIndex ( int  idx)
inline

Select the active renderer by index (0-based)

Parameters
idxIndex of the device to select; defaults to 0

◆ setDeviceTypeFilter()

void tiny_dlna::ControlPointMediaRenderer::setDeviceTypeFilter ( const char *  filter)
inline

Restrict this helper to devices of the given device type.

Parameters
filterDevice type filter, e.g. "urn:schemas-upnp-org:device:MediaRenderer:1". Pass nullptr to use the default MediaRenderer filter.

◆ setInstanceID()

void tiny_dlna::ControlPointMediaRenderer::setInstanceID ( const char *  id)
inline

Set the InstanceID used for AVTransport and RenderingControl actions.

Parameters
idC-string InstanceID (default is "0")

◆ setMediaURI()

bool tiny_dlna::ControlPointMediaRenderer::setMediaURI ( const char *  uri)
inline

Set the media URI on the renderer.

Parameters
uriThe media URI to play on the renderer
Returns
true on success, false on error

◆ setMute()

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

Set mute state on the renderer.

Parameters
mutetrue to mute, false to unmute
Returns
true on success, false on error

◆ setReference()

void tiny_dlna::ControlPointMediaRenderer::setReference ( void *  ref)
inline

Attach an opaque reference object that will be passed to callbacks.

Parameters
refOpaque pointer provided by the caller

◆ setVolume()

bool tiny_dlna::ControlPointMediaRenderer::setVolume ( int  volumePercent)
inline

Set renderer volume.

Parameters
volumePercentDesired volume 0..100
Returns
true on success, false on error

◆ stop()

bool tiny_dlna::ControlPointMediaRenderer::stop ( )
inline

Stop playback.

Returns
true on success, false on error

◆ subscribeNotifications()

bool tiny_dlna::ControlPointMediaRenderer::subscribeNotifications ( int  timeoutSeconds = 60,
NotificationCallback  cb = nullptr 
)
inline

Subscribe to event notifications for the selected renderer.

Parameters
timeoutSecondsSubscription timeout in seconds (suggested default: 60)
cbOptional callback to invoke for incoming notifications. If nullptr the helper's default processNotification will be used.
Returns
true on successful SUBSCRIBE, false otherwise

Member Data Documentation

◆ activeChangedCallback

std::function<void(bool, void*)> tiny_dlna::ControlPointMediaRenderer::activeChangedCallback = nullptr
protected

◆ device_index

int tiny_dlna::ControlPointMediaRenderer::device_index = 0
protected

◆ device_type_filter

const char* tiny_dlna::ControlPointMediaRenderer::device_type_filter = device_type_filter_default
protected

◆ device_type_filter_default

const char* tiny_dlna::ControlPointMediaRenderer::device_type_filter_default
protected
Initial value:
=
"urn:schemas-upnp-org:device:MediaRenderer:1"

◆ instance_id

const char* tiny_dlna::ControlPointMediaRenderer::instance_id = "0"
protected

◆ is_active

bool tiny_dlna::ControlPointMediaRenderer::is_active = false
protected

◆ last_reply

ActionReply tiny_dlna::ControlPointMediaRenderer::last_reply
protected

◆ mgr

DLNAControlPointMgr& tiny_dlna::ControlPointMediaRenderer::mgr
protected

◆ reference

void* tiny_dlna::ControlPointMediaRenderer::reference = nullptr
protected

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