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

Minimal Digital Media Server implementation. More...

#include <MediaServer.h>

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

Public Types

typedef void(* PrepareDataCallback) (const char *objectID, const char *browseFlag, const char *filter, int startingIndex, int requestedCount, const char *sortCriteria, int &numberReturned, int &totalMatches, int &updateID, void *reference)
 
typedef bool(* GetDataCallback) (int index, MediaItem &item, void *reference)
 

Public Member Functions

 MediaServer ()
 
 ~MediaServer ()
 
void end ()
 
void setupServices (HttpServer &server, IUDPService &udp)
 to be implemented by subclasses
 
void setPrepareDataCallback (PrepareDataCallback cb)
 Sets the PrepareData callback.
 
void setGetDataCallback (GetDataCallback cb)
 Sets the GetData callback.
 
void setReference (void *ref)
 Sets a user reference pointer, available in callbacks.
 
HttpServergetHttpServer ()
 Provides access to the http server.
 
- 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 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 * replyTemplate ()
 
static void contentDirectoryControlCB (HttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 
static void writeEscapedText (Print &out, const char *s)
 
static void streamReplyCallback (Print &out)
 
static void buildEscapedDIDL (Print &out, GetDataCallback get_data_cb, int count)
 
static void connmgrControlCB (HttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 

Protected Attributes

const char * st = "urn:schemas-upnp-org:device:MediaServer:1"
 
const char * usn = "uuid:media-server-0000-0000-0000-000000000001"
 
PrepareDataCallback prepare_data_cb = nullptr
 
GetDataCallback get_data_cb = nullptr
 
HttpServerp_server = nullptr
 
void * reference_ = nullptr
 
- 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
 

Static Protected Attributes

static GetDataCallback g_stream_get_data_cb = nullptr
 
static int g_stream_numberReturned = 0
 
static int g_stream_totalMatches = 0
 
static int g_stream_updateID = 0
 
static void * g_stream_reference = nullptr
 

Detailed Description

Minimal Digital Media Server implementation.

This class implements a lightweight DLNA MediaServer device with a ContentDirectory service (Browse) and a ConnectionManager service.

The API is designed for embedding custom content lists and streaming logic. Instead of a single browse callback, the API now uses two callbacks:

A user reference pointer can be set with setReference(void*), and is passed to both callbacks for custom context or data.

Example usage:

The implementation is intentionally compact and suitable as a starting point for embedded or test DLNA servers.

Member Typedef Documentation

◆ GetDataCallback

typedef bool(* tiny_dlna::MediaServer::GetDataCallback) (int index, MediaItem &item, void *reference)

◆ PrepareDataCallback

typedef void(* tiny_dlna::MediaServer::PrepareDataCallback) (const char *objectID, const char *browseFlag, const char *filter, int startingIndex, int requestedCount, const char *sortCriteria, int &numberReturned, int &totalMatches, int &updateID, void *reference)

Constructor & Destructor Documentation

◆ MediaServer()

tiny_dlna::MediaServer::MediaServer ( )
inline

◆ ~MediaServer()

tiny_dlna::MediaServer::~MediaServer ( )
inline

Member Function Documentation

◆ buildEscapedDIDL()

static void tiny_dlna::MediaServer::buildEscapedDIDL ( Print &  out,
GetDataCallback  get_data_cb,
int  count 
)
inlinestaticprotected

◆ connmgrControlCB()

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

◆ contentDirectoryControlCB()

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

◆ end()

void tiny_dlna::MediaServer::end ( )
inline

◆ getHttpServer()

HttpServer * tiny_dlna::MediaServer::getHttpServer ( )
inline

Provides access to the http server.

◆ replyTemplate()

static const char * tiny_dlna::MediaServer::replyTemplate ( )
inlinestaticprotected

generic SOAP reply template with placeholders: %1 = ActionResponse, %2 = ServiceName, %3 = inner payload

◆ setGetDataCallback()

void tiny_dlna::MediaServer::setGetDataCallback ( GetDataCallback  cb)
inline

Sets the GetData callback.

◆ setPrepareDataCallback()

void tiny_dlna::MediaServer::setPrepareDataCallback ( PrepareDataCallback  cb)
inline

Sets the PrepareData callback.

◆ setReference()

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

Sets a user reference pointer, available in callbacks.

◆ setupServices()

void tiny_dlna::MediaServer::setupServices ( HttpServer server,
IUDPService udp 
)
inlinevirtual

to be implemented by subclasses

Reimplemented from tiny_dlna::DLNADeviceInfo.

◆ setupServicesImpl()

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

◆ streamReplyCallback()

static void tiny_dlna::MediaServer::streamReplyCallback ( Print &  out)
inlinestaticprotected

◆ writeEscapedText()

static void tiny_dlna::MediaServer::writeEscapedText ( Print &  out,
const char *  s 
)
inlinestaticprotected

Member Data Documentation

◆ g_stream_get_data_cb

GetDataCallback tiny_dlna::MediaServer::g_stream_get_data_cb = nullptr
inlinestaticprotected

◆ g_stream_numberReturned

int tiny_dlna::MediaServer::g_stream_numberReturned = 0
inlinestaticprotected

◆ g_stream_reference

void* tiny_dlna::MediaServer::g_stream_reference = nullptr
inlinestaticprotected

◆ g_stream_totalMatches

int tiny_dlna::MediaServer::g_stream_totalMatches = 0
inlinestaticprotected

◆ g_stream_updateID

int tiny_dlna::MediaServer::g_stream_updateID = 0
inlinestaticprotected

◆ get_data_cb

GetDataCallback tiny_dlna::MediaServer::get_data_cb = nullptr
protected

◆ p_server

HttpServer* tiny_dlna::MediaServer::p_server = nullptr
protected

◆ prepare_data_cb

PrepareDataCallback tiny_dlna::MediaServer::prepare_data_cb = nullptr
protected

◆ reference_

void* tiny_dlna::MediaServer::reference_ = nullptr
protected

◆ st

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

◆ usn

const char* tiny_dlna::MediaServer::usn = "uuid:media-server-0000-0000-0000-000000000001"
protected

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