/* spdmc.h — scorpiox-scorpioplayer-dlna-upnp-media-client * * SCORPIO PLAYER 2027 engine. DLNA/UPnP control point: SSDP discovery of MediaServer + * MediaRenderer devices, bounded description + DIDL parsing, ContentDirectory:1 Browse * (paged), AVTransport:1 / RenderingControl:1 casting, a #26 spffa backend and a * sprch_handler for RuntimeType "DLNA". * * Pure C99, zero external deps (vendored yyjson only). See SPEC.md for every decision * (D1..D22) referenced below. * * Process singleton. One global lock guards the device cache + the listing. The string * returns point at static buffers: valid until the next call of the same function, so copy * them immediately. Transport is scorpiox_io (libcurl desktop / fake tests / iOS URLSession). */ #ifndef SPDMC_H #define SPDMC_H #include "scorpiox-io.h" #include "sprch.h" #ifdef _WIN32 # if defined(SPDMC_BUILD) # define SPDMC_API __declspec(dllexport) # elif defined(SPDMC_STATIC) # define SPDMC_API /* linked into the consumer: no dllimport stubs */ # else # define SPDMC_API __declspec(dllimport) # endif #else # define SPDMC_API __attribute__((visibility("default"))) #endif #ifdef __cplusplus extern "C" { #endif #define SPDMC_OK 0 #define SPDMC_E_ARG (-1) #define SPDMC_E_STATE (-2) #define SPDMC_E_NET (-3) #define SPDMC_E_NOENT (-4) #define SPDMC_E_NOMEM (-5) #define SPDMC_E_UPNP (-6) #define SPDMC_E_REFUSED (-7) #define SPDMC_E_LIMIT (-8) #define SPDMC_E_PROTOCOL (-9) #define SPDMC_E_CONFIG (-10) #define SPDMC_E_NOTSUPPORTED (-11) #define SPDMC_E_AUTH (-12) /* HTTP 401/403: the server refused us */ #define SPDMC_VERSION "1.0.0" #define SPDMC_KIND_SERVER 1 #define SPDMC_KIND_RENDERER 2 #define SPDMC_KIND_BOTH 3 /* ---- cast state = the legacy CastingConnectionState names (Casting.cs:91-110) ---- */ #define SPDMC_CAST_DISCONNECTED 0 #define SPDMC_CAST_CONNECTED 1 #define SPDMC_CAST_RENDERING 2 #define SPDMC_CAST_DISCONNECTING 3 /* ---- version / errors ---- */ SPDMC_API const char *spdmc_version(void); SPDMC_API const char *spdmc_last_error(void); /* message for the last failing call */ SPDMC_API int spdmc_last_code(void); /* 0 ok, else UPnP errorCode or HTTP code */ SPDMC_API int spdmc_config(const char *key, const char *value); /* ---- transport selection (D3, D21) ---- */ SPDMC_API int spdmc_set_io(const scorpiox_io *io); /* NULL = default (libcurl) */ SPDMC_API int spdmc_use_curl(void); /* E_NOTSUPPORTED when built without */ SPDMC_API int spdmc_use_fake(void); /* fake io + SSDP disabled */ SPDMC_API int spdmc_fake_set(const char *url, int http_code, const char *body); SPDMC_API int spdmc_fake_fail(const char *url, const char *transport_error); SPDMC_API int spdmc_fake_calls(const char *url); /* NULL = total */ SPDMC_API void spdmc_fake_reset(void); SPDMC_API int spdmc_fake_ssdp(const char *packet, const char *from_ip); /* inject a packet */ SPDMC_API const char *spdmc_fake_ssdp_sent(int i); /* the M-SEARCHes the client sent */ /* ---- discovery (D4, D5) ---- */ /* kind: 1 server, 2 renderer, 3 both. Sends M-SEARCH, collects replies + NOTIFYs, fetches * descriptions through the installed io, keeps devices whose deviceType matches. * Returns the number of matching devices now cached, or <0. */ SPDMC_API int spdmc_discover(int kind, int timeout_ms); SPDMC_API int spdmc_device_count(void); SPDMC_API const char *spdmc_device_json(int i); /* udn, kind, name, model, location, services… */ SPDMC_API int spdmc_find_device(const char *udn); /* index or -1 */ SPDMC_API int spdmc_forget(const char *udn); /* 0 ok (byebye / explicit) */ SPDMC_API void spdmc_devices_clear(void); SPDMC_API const char *spdmc_resolve_url(const char *base, const char *ref); /* RFC 3986 §5.3 */ /* ---- pure parsers (no io, no sockets) ---- */ SPDMC_API int spdmc_parse_ssdp(const char *packet); /* then *_json: last reply as device */ SPDMC_API int spdmc_parse_description(const char *xml, const char *location); SPDMC_API int spdmc_parse_didl(const char *didl); SPDMC_API const char *spdmc_last_json(void); /* parse result of the last *_parse_* */ /* ---- browse (D8, D9, D10, D11) ---- */ /* flag 0 = BrowseDirectChildren (paged until TotalMatches), 1 = BrowseMetadata (one item). */ SPDMC_API int spdmc_browse(const char *udn, const char *object_id, int start, int count, int flag); SPDMC_API int spdmc_item_count(void); SPDMC_API const char *spdmc_item_json(int i); SPDMC_API int spdmc_total_matches(void); SPDMC_API int spdmc_update_id(void); SPDMC_API const char *spdmc_best_res_url(int i); /* the chosen best res, "" if none */ SPDMC_API void spdmc_cache_clear(void); /* ---- cast (D13, D14) — every mutating export is allow-listed ---- */ SPDMC_API int spdmc_cast_allow(const char *udn); /* allow-list add (the caller's own device) */ SPDMC_API void spdmc_cast_clear(void); /* forget the allow-list */ SPDMC_API int spdmc_cast_allowed(const char *udn); /* predicate */ SPDMC_API int spdmc_cast_set_uri(const char *udn, const char *url, const char *mime, const char *title); SPDMC_API int spdmc_cast_play(const char *udn); SPDMC_API int spdmc_cast_pause(const char *udn); SPDMC_API int spdmc_cast_stop(const char *udn); SPDMC_API int spdmc_cast_seek(const char *udn, int seconds); SPDMC_API int spdmc_cast_state(const char *udn); /* 0 disc 1 conn 2 rendering 3 disconnecting */ SPDMC_API int spdmc_cast_position(const char *udn, int *pos_s, int *dur_s); SPDMC_API int spdmc_cast_volume(const char *udn, int set); /* -1 = get, 0..100 = set */ SPDMC_API int spdmc_cast_mute(const char *udn, int set); /* -1 = get, 0/1 = set */ SPDMC_API int spdmc_sink_check(const char *udn, const char *mime); /* 1 sinks it, 0 not, <0 err */ /* ---- #26 spffa backend (D19) ---- */ SPDMC_API int spdmc_spffa_register(void); /* register the "dlna" backend once */ /* ---- sprch handler (D20) ---- */ SPDMC_API const sprch_handler *spdmc_sprch(void); /* RuntimeType "DLNA" */ #ifdef __cplusplus } #endif #endif /* SPDMC_H */