No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
darkwater 1ba59ff853
All checks were successful
Check and publish Arch package / check (push) Successful in 1m16s
Check and publish Arch package / Package for x86_64 (push) Successful in 39s
Check and publish Arch package / Package for aarch64 (push) Successful in 40s
Pin packaging action revision with registry owner support
2026-11-08 18:44:15 +01:00
.forgejo/workflows Pin packaging action revision with registry owner support 2026-11-08 18:44:15 +01:00
packaging Extract Tizen provider with configurable namespaces and Arch package CI 2026-11-08 18:14:48 +01:00
src Extract Tizen provider with configurable namespaces and Arch package CI 2026-11-08 18:14:48 +01:00
tests Extract Tizen provider with configurable namespaces and Arch package CI 2026-11-08 18:14:48 +01:00
.gitignore Extract Tizen provider with configurable namespaces and Arch package CI 2026-11-08 18:14:48 +01:00
Cargo.lock Fetch Tanuki dependencies from git.dark.red 2026-11-08 18:21:26 +01:00
Cargo.toml Fetch Tanuki dependencies from git.dark.red 2026-11-08 18:21:26 +01:00
README.md Publish provider packages in the shared Fubuki Arch registry 2026-11-08 18:40:47 +01:00
rust-toolchain.toml Extract Tizen provider with configurable namespaces and Arch package CI 2026-11-08 18:14:48 +01:00

Tanuki Tizen provider

A standalone native Rust provider that publishes UPnP RenderingControl volume and mute state to Tanuki and accepts volume/mute requests through Tanuki. It uses GENA notifications, without volume polling. Developed from the user's ~/tv-volume.sh Samsung SetVolume script; tested against a simulated TV and the real Tanuki server. Read-only SSDP discovery and volume notification parsing were verified on the user's LAN with a receive-only probe on 2026-11-01. Physical-TV volume/mute controls and complete provider deployment remain unverified.

Topic Kind Value
/tv/volume retained output observed integer 0–100, instance 0, Master channel
/tv/desired-volume retained input requested integer 0–100
/tv/mute retained output observed boolean: true means muted
/tv/desired-mute retained input requested boolean: true mutes, false unmutes

The default topic prefix is /tv. Set TANUKI_TOPIC_PREFIX or --topic-prefix to choose your own namespace; Tanuki imposes no global device naming standard. All four paths above are relative to that prefix. With several TVs on the same Tanuki server, configure distinct prefixes yourself, for example /tv/living-room and /tv/bedroom.

The managed client name defaults to tizen <device UDN> for discovery-selected TVs, or tizen <host>:<port> with an explicit description URL. Override it with TANUKI_CLIENT_NAME or --client-name if needed. No schema is installed automatically: the provider validates control values and logs invalid requests. Tanuki acceptance does not guarantee TV execution. SOAP success never publishes invented observed volume or mute state. Mute is not inferred from a zero volume value.

Extracted from examples/tv-volume in Tanuki at commit 6b437f1028bbdf293795fc10439937297d9f036a. This provider currently exposes volume and mute through UPnP RenderingControl; other Tizen controls are outside its current scope. Compatible non-Tizen renderers may also work.

Run

Start Tanuki in its own checkout, then discover available devices from this provider checkout:

# In the Tanuki checkout:
cargo run -p tanuki
# In this provider checkout, in another terminal: read-only listing; never connects to Tanuki or sends SOAP.
cargo run -p tanuki-provider-tizen -- --discover

Discovery sends two SSDP M-SEARCH requests to 239.255.255.250:1900, waits four seconds for replies, then fetches their advertised description URLs using HTTP GET. It keeps devices with a supported RenderingControl service and deduplicates repeated advertisements/URLs by device UDN. The listing includes friendly name, stable UDN and current description URL. Routers and other unrelated UPnP devices are excluded.

Run without arguments if exactly one renderer is present, or choose one by its exact name or stable UDN. Selecting by UDN survives DHCP address changes and renaming. If multiple renderers match, startup lists the choices and exits instead of choosing one arbitrarily.

cargo run -p tanuki-provider-tizen
# Or choose the user's TV discovered on 2026-11-01:
cargo run -p tanuki-provider-tizen -- --device uuid:b79e314d-c9c0-4dc1-8ac3-1c46fee17138
# Friendly names also work:
cargo run -p tanuki-provider-tizen -- --device '[TV] Samsung TV'

These provider commands enable the existing control behavior, including applying unexpired retained desired volume or mute at startup. Use --discover for read-only checks while media is playing. It returns before listener setup, Tanuki connection, input claiming or control code. Automated control tests use isolated loopback simulated TVs.

The callback address is chosen automatically from this machine's route to the selected TV, using the actual bound listener port and /notify. No UDP datagram is sent to determine that local address. Defaults are listener 0.0.0.0:0 (an automatically assigned port) and Tanuki ws://127.0.0.1:5167/v1/ws. Override these when necessary:

cargo run -p tanuki-provider-tizen -- --device '[TV] Samsung TV' \
  --listen 0.0.0.0:9198 --tanuki-url ws://127.0.0.1:5167/v1/ws
# Routed/NAT setups can supply --callback-url http://REACHABLE_HOST:9198/notify.

Discovery uses the default IPv4 multicast route; it does not enumerate every network interface or search across VLANs. An offline TV or blocked multicast produces no match. Every supervised restart discovers again. Explicit device and callback URLs remain supported for networks where discovery is unavailable:

cargo run -p tanuki-provider-tizen -- \
  http://192.168.1.50:9197/description.xml \
  http://192.168.1.20:9198/notify \
  0.0.0.0:9198 ws://127.0.0.1:5167/v1/ws

These explicit addresses are placeholders. The user's actual read-only discovery found [TV] Samsung TV at http://192.168.0.152:9197/dmr on 2026-11-01, alongside Sinon Satellite and Tetsuya. The UUID selector above avoids depending on that TV IP. No live provider, subscription or volume command was run during this check.

The provider reads the first RenderingControl v1/v2/v3 service's controlURL and eventSubURL, resolving relative paths and optional URLBase. It does not guess ports or event paths. Both TV URLs and the callback must use HTTP. The callback path must be /notify, without a query, and its advertised port must route to the listener. HTTP requests bypass proxy environment variables. Description fetches during discovery have three-second timeouts, eight concurrent requests, and the existing 64 KiB body limit; at most 512 SSDP responses and 64 description URLs are processed.

Observe changes with the inspector or SSE, and submit requested audio settings:

# In the Tanuki checkout:
cargo run -p tanuki-ui
curl -N 'http://127.0.0.1:5167/v1/sse?select=/tv/**'
curl -sS -H 'Tanuki-Client: TV remote' -H 'Content-Type: application/json' \
  --data '{"operations":[{"op":"submit_desired","topic":"/tv/desired-volume","value":25,"expiry":{"mode":"set","duration":"PT30S"}}]}' \
  http://127.0.0.1:5167/v1/write
# Mute (send false instead of true to unmute):
curl -sS -H 'Tanuki-Client: TV remote' -H 'Content-Type: application/json' \
  --data '{"operations":[{"op":"submit_desired","topic":"/tv/desired-mute","value":true,"expiry":{"mode":"set","duration":"PT30S"}}]}' \
  http://127.0.0.1:5167/v1/write

Desired mute requires a JSON boolean, not a numeric or string value. The provider calls SetMute with instance 0, Master channel and DesiredMute 1/0. Its SOAP response confirms only action acceptance; observed /tv/mute changes only when a TV notification reports it. Mute-only events leave volume unchanged. An event containing volume and mute publishes both in one Tanuki batch, and reordered event coalescing preserves the latest value of each field independently.

An unexpired retained request is applied once when the provider starts/restarts. Subsequent submissions are applied once per observed write provenance; rapid requests can coalesce to the latest value. Metadata changes do not repeat a request. It does not continually fight physical-remote changes to maintain the old desired value. Clearing/expiring intent does not undo the TV setting. SOAP failure is logged without an immediate retry; a later service restart can apply still-retained intent again. Give short-lived requests an expiry as above.

Lifetime and failure behavior

Startup discovers/selects a device (unless explicitly configured), chooses the callback, fetches the description, connects to Tanuki, removes old observed state, and defines/claims both desired inputs. The callback listener starts before SUBSCRIBE, so an initial notification arriving before the subscribe response can queue safely. The provider waits for real subscription events and requires a Master volume within ten seconds. TVs that omit it are currently unsupported; there is no silent polling fallback or GetVolume bootstrap. Mute is optional in the initial report: /tv/mute remains absent until reported and is never defaulted to false. TV support for mute notifications and SetMute is required to use those features; unsupported SOAP actions are logged without retry.

Subscriptions request 60 seconds and renew at half the granted interval, capped at 30 seconds. Only the current SID is processed. Empty LastChange values (including whitespace or empty CDATA) are accepted as no-op notifications: they advance the subscription sequence without changing observed audio state. Duplicate or late sequence numbers are ignored. Out-of-order notifications wait in a buffer of at most 64 events for up to one second, then apply in sequence order; contiguous buffered audio changes can coalesce to the latest value per field. An unresolved gap or full reorder buffer ends the service so restarting gets a fresh initial state. A bounded 64-message callback queue returns HTTP 503 when full; malformed events return 400. HTTP bodies are limited to 64 KiB and outgoing requests have ten-second timeouts. Callback replies use UPnP HTTP status codes, not Tanuki JSON envelopes.

Observed volume and mute have 90-second expiries, refreshed when each field is reported and together on successful subscription renewal (for known fields). A renewal refresh repeats the last observed values; their Tanuki timestamps indicate provider/subscription health, not a new measurement. A TV that silently stops delivering events while accepting renewals cannot be detected without additional device-specific checks. This is an explicit limit of this notification-only provider.

Renewal failure, event gaps, Tanuki disconnection, or observed claim takeover end the service with an error. Ctrl-C/SIGTERM ends it normally. Cleanup attempts UNSUBSCRIBE, stops the callback task, removes both observed topics in one batch and closes the session, releasing both claims. Desired intent remains. If cleanup cannot reach Tanuki, the published audio states expire. The provider stores nothing on disk; Tanuki owns any persistence. Callback and control operations are serialized in the provider loop; a slow SOAP request can delay processing/renewal until timeout.

Arch package and system service

CI follows the Fubuki packaging convention: the sinon runner builds x86_64 and aarch64 binaries, assembles the executable, this guide and the systemd template, and calls actions/build-arch-package. The shared action builds a pacman package and publishes it to the fubuki Forgejo Arch registry, group extras, alongside the other Fubuki packages. The source repository stays under tanuki; hosts can use their existing Fubuki pacman repository. The runner must supply the pinned Rust toolchain, both targets and /cross-aarch64.sh, as in Fubuki. Configure the repository/organization PACKAGE_TOKEN secret with package write permission for fubuki. Pushes to master and manual workflow runs publish after formatting, Clippy, debug and release tests pass. Pull requests run checks without publishing. Packages use a UTC timestamp version; installing a package does not start a TV provider automatically.

The package installs /usr/bin/tanuki-provider-tizen and /usr/lib/systemd/system/tanuki-provider-tizen@.service. Discover the TV's UDN:

tanuki-provider-tizen --discover

Use its bare UUID, without the uuid: prefix, as the instance name:

sudo systemctl enable --now tanuki-provider-tizen@b79e314d-c9c0-4dc1-8ac3-1c46fee17138.service
journalctl -u tanuki-provider-tizen@b79e314d-c9c0-4dc1-8ac3-1c46fee17138.service -f

The template adds uuid: and uses systemd's %i to preserve literal UUID hyphens (%I would unescape them into slashes). It runs as an unprivileged dynamic user, needs no home directory or persistent files, and rediscovers the TV after each failure. It retries failures every five seconds indefinitely, including TV-off or Tanuki-down startup. Normal shutdown is not restarted. System startup waits for network-online.target; Tanuki may run locally or remotely and does not need a particular systemd unit name.

Edit configuration for one TV through an upgrade-safe drop-in:

sudo systemctl edit tanuki-provider-tizen@b79e314d-c9c0-4dc1-8ac3-1c46fee17138.service
[Service]
Environment="TANUKI_URL=ws://127.0.0.1:5167/v1/ws"
Environment="TANUKI_TOPIC_PREFIX=/tv/living-room"

Then restart that instance. systemctl edit tanuki-provider-tizen@.service changes defaults for all instances. Each instance defaults to /tv; choose separate prefixes yourself when exposing multiple TVs to the same server. Instance client names contain their UUID, and automatic callback ports avoid listener collisions.

Environment variable CLI override Default
TIZEN_DEVICE --device discover exactly one renderer; unit sets uuid:%i
TANUKI_URL --tanuki-url ws://127.0.0.1:5167/v1/ws
TANUKI_TOPIC_PREFIX --topic-prefix /tv
TANUKI_CLIENT_NAME --client-name derived from TV identity; unit sets tizen uuid:%i
TIZEN_LISTEN --listen 0.0.0.0:0 (automatically assigned port)
TIZEN_CALLBACK_URL --callback-url automatically selected address and actual bound port

CLI options override environment values. Topic prefixes must be valid ordinary Tanuki paths, without wildcards or a reserved system namespace. For a firewall, set TIZEN_LISTEN=0.0.0.0:9198 and permit the TV to reach that TCP port. Assign a different port per instance. Set TIZEN_CALLBACK_URL=http://HOST:9198/notify only when the automatic address is unsuitable; its advertised port must reach the listener. Discovery also needs outbound IPv4 SSDP multicast and its replies.

Migration: disable the old tanuki-tv-volume user service before starting this system service. It uses the same /tv topics by default and can apply still-retained desired intent. The new client identity differs from the old tv-volume bridge; no topic or input-value migration is required.

Build and verify

The SDK and production test server are pinned Git dependencies from Tanuki; no sibling checkout or published crates are needed. Cargo.lock is committed. The nightly toolchain pin matches the source project.

cargo fmt --all -- --check
cargo clippy --locked --all-targets -- -D warnings
cargo test --locked
cargo test --locked --release
cargo build --locked --release

Unit tests cover XML channel/instance selection, malformed/range checks, URL resolution and granted subscription duration. Discovery tests use a loopback SSDP responder and HTTP descriptions to verify duplicate suppression, device filtering, GET-only access, unique name/UDN selection and callback route/port selection. CLI tests cover environment configuration, option precedence, namespace validation, read-only listing and existing explicit-address syntax. Integration tests use actual HTTP callbacks, SOAP requests, WebSockets and production Tanuki server logic: initial/event publication, atomic volume/mute updates, mute-only and reordered audio changes, SetMute for true/false without optimistic output, invalid intent, foreign subscriptions, renewal, a 130-event empty-notification burst followed by a valid volume update, reordered updates, duplicate/wraparound handling, missing-event recovery boundary, claim takeover, shutdown and stale-state removal. Additional scenarios cover custom-prefix state/control/cleanup and two independent providers on one Tanuki server. Hardware acceptance remains manual: subscribe, press the physical remote, submit Tanuki intent, switch the TV off/on and confirm recovery through the configured supervisor.

References: UPnP event subscriptions and RenderingControl LastChange.