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

Class to control a MediaRenderer device from a control point. More...

#include <DLNAControlPointMediaRenderer.h>

Public Types

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

Public Member Functions

 DLNAControlPointMediaRenderer ()=default
 Default constructor.
 
 DLNAControlPointMediaRenderer (DLNAControlPoint &m, DLNAHttpRequest &http, IUDPService &udp)
 Construct helper with references to control point manager and transport instances.
 
void setDLNAControlPoint (DLNAControlPoint &m)
 Set the control point manager instance (required before using helper)
 
void setDeviceTypeFilter (const char *filter)
 Restrict this helper to devices of the given device type.
 
bool begin (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)
 
void setHttp (DLNAHttpRequest &http)
 Setter for the HTTP wrapper used for subscriptions and callbacks.
 
void setUdp (IUDPService &udp)
 Setter for UDP service used for discovery (SSDP)
 
void setSubscribeNotificationsActive (bool flag)
 Activate/deactivate subscription notifications.
 
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 (bool fromRemote=true)
 Query the current volume from the renderer.
 
int getMute (bool fromRemote=true)
 Query mute state.
 
unsigned long getPositionMs ()
 Query current playback position (RelTime)
 
const char * getTransportState (bool fromRemote=true)
 Query transport state (e.g. STOPPED, PLAYING, PAUSED_PLAYBACK).
 
const char * getCurrentURI (bool fromRemote=true)
 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.
 
bool getCurrentTransportActions (Str &out)
 Query the AVTransport service for the current transport actions and return the raw Actions list into out.
 
bool getProtocalInfo (std::function< void(const char *entry, ProtocolRole role)> cb)
 Fetch protocol-info via SOAP GetProtocolInfo on the ConnectionManager service and invoke cb for each entry.
 

Protected Member Functions

void setActiveState (bool s)
 
DLNAServiceInfoselectService (const char *id)
 Select service by 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

DLNAControlPointp_mgr = nullptr
 
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
 
DLNAHttpRequestp_http = nullptr
 
IUDPServicep_udp = nullptr
 
int local_volume = 0
 
int local_mute = false
 
Str local_url
 
const char * local_transport_state = "STOPPED"
 

Detailed Description

Class to control a MediaRenderer device from a control point.

This lightweight implementation 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. Some getters can be configured to provide the cached value quickly or by using a query to the MediaRenderer.

Member Typedef Documentation

◆ NotificationCallback

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

Constructor & Destructor Documentation

◆ DLNAControlPointMediaRenderer() [1/2]

tiny_dlna::DLNAControlPointMediaRenderer::DLNAControlPointMediaRenderer ( )
default

Default constructor.

◆ DLNAControlPointMediaRenderer() [2/2]

tiny_dlna::DLNAControlPointMediaRenderer::DLNAControlPointMediaRenderer ( DLNAControlPoint m,
DLNAHttpRequest http,
IUDPService udp 
)
inline

Construct helper with references to control point manager and transport instances.

This convenience constructor binds the underlying DLNAControlPoint manager as well as the HTTP wrapper (used for subscription callbacks) and the UDP service (used for SSDP discovery). It is equivalent to default-constructing the helper and then calling setDLNAControlPoint(), setHttp() and setUdp(), but more concise for callers that already have the instances available.

Parameters
mReference to the DLNAControlPoint manager
httpReference to an HTTP request wrapper used for subscriptions
udpReference to a UDP service used for SSDP discovery

Member Function Documentation

◆ begin()

bool tiny_dlna::DLNAControlPointMediaRenderer::begin ( 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

◆ getCurrentTransportActions()

bool tiny_dlna::DLNAControlPointMediaRenderer::getCurrentTransportActions ( Str out)
inline

Query the AVTransport service for the current transport actions and return the raw Actions list into out.

Parameters
outStr reference that will receive the Actions text on success
Returns
true on success (and out filled), false on error

◆ getCurrentURI()

const char * tiny_dlna::DLNAControlPointMediaRenderer::getCurrentURI ( bool  fromRemote = true)
inline

Get the current media URI from the renderer.

Parameters
fromRemoteIf true (default) query the renderer remotely for the current URI. If false, return the locally cached URI previously set by this helper.
Returns
pointer to URI string (owned by reply registry) or nullptr

◆ getDeviceCount()

int tiny_dlna::DLNAControlPointMediaRenderer::getDeviceCount ( )
inline

Return the number of discovered devices matching the renderer filter.

Returns
number of matching devices

◆ getLastReply()

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

Return last ActionReply (from the most recent synchronous call)

Returns
reference to the last ActionReply

◆ getMediaDurationMs()

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

Get total media duration in milliseconds (from MediaDuration)

Returns
milliseconds or 0 on error/unknown

◆ getMute()

int tiny_dlna::DLNAControlPointMediaRenderer::getMute ( bool  fromRemote = true)
inline

Query mute state.

Parameters
fromRemoteIf true (default) query the renderer for the current mute state; if false, return the locally cached mute value maintained by the helper.
Returns
0 = unmuted, 1 = muted, -1 = error/unknown

◆ getNrTracks()

int tiny_dlna::DLNAControlPointMediaRenderer::getNrTracks ( )
inline

Get number of tracks in the current media.

Returns
number of tracks or -1 on error

◆ getPositionMs()

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

Query current playback position (RelTime)

Returns
position in milliseconds, or 0 if unknown/error

◆ getProtocalInfo()

bool tiny_dlna::DLNAControlPointMediaRenderer::getProtocalInfo ( std::function< void(const char *entry, ProtocolRole role)>  cb)
inline

Fetch protocol-info via SOAP GetProtocolInfo on the ConnectionManager service and invoke cb for each entry.

Parameters
cbcallback invoked for each parsed entry with role (IsSource/IsSink)
Returns
true on success (reply received), false on error

◆ getTrackDurationMs()

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

Get current track duration in milliseconds (from TrackDuration)

Returns
milliseconds or 0 on error

◆ getTrackIndex()

int tiny_dlna::DLNAControlPointMediaRenderer::getTrackIndex ( )
inline

Get current track index (from GetPositionInfo)

Returns
track index (numeric) or -1 on error

◆ getTransportState()

const char * tiny_dlna::DLNAControlPointMediaRenderer::getTransportState ( bool  fromRemote = true)
inline

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

Parameters
fromRemoteIf true (default) the helper will query the remote renderer for its current transport state. If false, the cached local transport state is returned.
Returns
pointer to a string owned by the helper's registry, or nullptr on error

◆ getVolume()

int tiny_dlna::DLNAControlPointMediaRenderer::getVolume ( bool  fromRemote = true)
inline

Query the current volume from the renderer.

Parameters
fromRemoteIf true (default) the helper will perform an RPC query against the remote renderer to obtain the current volume. If false, the method returns the locally cached value maintained by the helper.
Returns
current volume 0..100, or -1 on error

◆ isActive()

bool tiny_dlna::DLNAControlPointMediaRenderer::isActive ( )
inline

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

Returns
true if playing, false otherwise

◆ onActiveChanged()

void tiny_dlna::DLNAControlPointMediaRenderer::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::DLNAControlPointMediaRenderer::parseTimeToMs ( const char *  t)
inlinestaticprotected

◆ pause()

bool tiny_dlna::DLNAControlPointMediaRenderer::pause ( )
inline

Pause playback.

Returns
true on success, false on error

◆ play() [1/2]

bool tiny_dlna::DLNAControlPointMediaRenderer::play ( )
inline

Start playback on the renderer.

Returns
true on success, false on error

◆ play() [2/2]

bool tiny_dlna::DLNAControlPointMediaRenderer::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::DLNAControlPointMediaRenderer::processNotification ( void *  reference,
const char *  sid,
const char *  varName,
const char *  newValue 
)
inlinestaticprotected

Notification callback.

◆ selectService()

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

Select service by id.

◆ setActiveState()

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

◆ setDeviceIndex()

void tiny_dlna::DLNAControlPointMediaRenderer::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::DLNAControlPointMediaRenderer::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.

◆ setDLNAControlPoint()

void tiny_dlna::DLNAControlPointMediaRenderer::setDLNAControlPoint ( DLNAControlPoint m)
inline

Set the control point manager instance (required before using helper)

◆ setHttp()

void tiny_dlna::DLNAControlPointMediaRenderer::setHttp ( DLNAHttpRequest http)
inline

Setter for the HTTP wrapper used for subscriptions and callbacks.

◆ setInstanceID()

void tiny_dlna::DLNAControlPointMediaRenderer::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::DLNAControlPointMediaRenderer::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::DLNAControlPointMediaRenderer::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::DLNAControlPointMediaRenderer::setReference ( void *  ref)
inline

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

Parameters
refOpaque pointer provided by the caller

◆ setSubscribeNotificationsActive()

void tiny_dlna::DLNAControlPointMediaRenderer::setSubscribeNotificationsActive ( bool  flag)
inline

Activate/deactivate subscription notifications.

◆ setUdp()

void tiny_dlna::DLNAControlPointMediaRenderer::setUdp ( IUDPService udp)
inline

Setter for UDP service used for discovery (SSDP)

◆ setVolume()

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

Set renderer volume.

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

◆ stop()

bool tiny_dlna::DLNAControlPointMediaRenderer::stop ( )
inline

Stop playback.

Returns
true on success, false on error

Member Data Documentation

◆ activeChangedCallback

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

◆ device_index

int tiny_dlna::DLNAControlPointMediaRenderer::device_index = 0
protected

◆ device_type_filter

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

◆ device_type_filter_default

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

◆ instance_id

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

◆ is_active

bool tiny_dlna::DLNAControlPointMediaRenderer::is_active = false
protected

◆ last_reply

ActionReply tiny_dlna::DLNAControlPointMediaRenderer::last_reply
protected

◆ local_mute

int tiny_dlna::DLNAControlPointMediaRenderer::local_mute = false
protected

◆ local_transport_state

const char* tiny_dlna::DLNAControlPointMediaRenderer::local_transport_state = "STOPPED"
protected

◆ local_url

Str tiny_dlna::DLNAControlPointMediaRenderer::local_url
protected

◆ local_volume

int tiny_dlna::DLNAControlPointMediaRenderer::local_volume = 0
protected

◆ p_http

DLNAHttpRequest* tiny_dlna::DLNAControlPointMediaRenderer::p_http = nullptr
protected

◆ p_mgr

DLNAControlPoint* tiny_dlna::DLNAControlPointMediaRenderer::p_mgr = nullptr
protected

◆ p_udp

IUDPService* tiny_dlna::DLNAControlPointMediaRenderer::p_udp = nullptr
protected

◆ reference

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

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