|
YAACC - UPNP Client and Server
|
The stream that YAACC creates on a snapserver to play into: one tcp source in server mode per phone, the group that plays on it, and the cleanup. More...


Classes | |
| class | EnsureResult |
The result of ensure(); never carries an exception. | |
| interface | MarkerStore |
| Keeps the per-install marker. More... | |
| enum | ReleaseResult |
The outcome of release. More... | |
| enum | Status |
The outcome of ensure(). More... | |
| enum | UseResult |
The outcome of useFor. More... | |
Public Member Functions | |
| SnapcastStreams (SnapcastOperations operations, String phoneName, MarkerStore markerStore) | |
The real clock, the default idle timeout and a SecureRandom for the marker; the stream is made in FLAC. | |
| SnapcastStreams (SnapcastOperations operations, String phoneName, MarkerStore markerStore, java.util.function.Supplier< String > codec) | |
| String | getMarker () |
| The per-install marker (8 lower-case hex characters). | |
| String | getStreamName () |
The name, and with it the id, of our stream: YAACC <phone name> <marker>. | |
| synchronized EnsureResult | ensure () |
| Makes sure the stream exists: adopts our own, or adds one (see the class comment). | |
| synchronized UseResult | useFor (String groupId) |
| Lets a group play our stream and remembers the stream it played before. | |
| synchronized ReleaseResult | release (String groupId) |
Puts a group back on the stream it played before useFor, but only if it is still on our stream and the previous stream still exists. | |
| void | noteAudio () |
| Tells that audio was written: restarts the idle timer. | |
| synchronized boolean | removeIfIdle () |
| Removes the stream (after giving the groups their previous streams back) if no audio was noted for the idle timeout. | |
| synchronized boolean | shutdown () |
| Gives every group that YAACC moved its previous stream back and removes our stream (on user request, or when the last player ended). | |
| synchronized int | removeLeftovers () |
Removes streams that carry our marker, are tcp and are used by no group, other than the one we hold: the leftovers of a crash. | |
Public Member Functions inherited from de.yaacc.snapcast.feed.FeedStreams | |
Static Public Attributes | |
| static final int | FIRST_PORT = 4953 |
| The first port YAACC asks for. | |
| static final int | PORT_COUNT = 10 |
How many ports from FIRST_PORT on YAACC may use (and the most tries of one ensure()). | |
| static final long | DEFAULT_IDLE_TIMEOUT_MILLIS = 10 * 60 * 1000L |
The default time without audio after which removeIfIdle() removes the stream: 10 minutes. | |
| static final int | MAX_PHONE_NAME_LENGTH = 32 |
| The longest phone name in the stream name, in characters. | |
| static final String | NAME_PREFIX = "YAACC " |
| The start of every stream name of ours. | |
| static final String | DEFAULT_PHONE_NAME = "Phone" |
| Used when a phone name has no letter or digit. | |
| static final PcmFormat | FORMAT = PcmFormat.SNAPCAST_DEFAULT |
| The sample format of the stream. | |
| static final String | HINT_STATIC_SOURCE = "snapcast_feed_static_source_hint" |
| Resource key of the hint text for a server that refuses the stream: use a static source (see the README). | |
| static final String | HINT_AUTHORIZATION = "snapcast_feed_authorization_hint" |
| Resource key of the hint text for a server that wants a login (authorization is not supported). | |
The stream that YAACC creates on a snapserver to play into: one tcp source in server mode per phone, the group that plays on it, and the cleanup.
All calls block (they make control calls): use them from a worker, never from the main thread or from inside a delivery of SnapcastRpc listeners.
The stream. Its name is YAACC <phone name> <marker>. The phone name is cut down to letters, digits, space, - and _ (32 characters at most). The marker is 8 random hex characters made once per install and kept by the MarkerStore; it is what makes a stream ours. The URI is tcp://0.0.0.0:<port>?name=<name>&mode=server&sampleformat=48000:16:2&codec=flac, the name percent-encoded in full, so that nothing in it can become a query parameter of its own. The port is chosen by YAACC from {@value FIRST_PORT} to FIRST_PORT + PORT_COUNT - 1, leaving out every port that a stream URI of the status names; a port that the server can not bind (answer -32603) makes it try the next, at most {@value PORT_COUNT} times.
What is trusted. Everything in a status is untrusted. A stream is adopted only if its id is our exact name (with the marker) and it is tcp, mode=server, has the expected sample format, is bound to 0.0.0.0 and uses a port of our range. A stream that only looks like ours is never touched. YAACC removes a stream only if it carries our marker (and is tcp) and no group uses it, or if it is the one it recorded itself and still looks like ours; it restores a group's previous stream only if the group is still on our stream and the previous stream still exists. The port that ensure() reports is the one YAACC asked for (or, for an adopted stream, one of our own range); the caller connects the PcmFeeder to it at the control connection's peer address, never to a host from the status.
Idle cleanup. removeIfIdle() removes the stream after idleTimeoutMillis without a call of noteAudio(). The server's own stream status idle plays no part: digital silence between tracks turns it idle while data flows.
Instances are thread safe; the control calls run one at a time.
| de.yaacc.snapcast.feed.SnapcastStreams.SnapcastStreams | ( | SnapcastOperations | operations, |
| String | phoneName, | ||
| MarkerStore | markerStore, | ||
| java.util.function.Supplier< String > | codec ) |
| codec | the codec that the server sends the stream to its clients in (pcm, flac or opus), asked for each time |
| synchronized EnsureResult de.yaacc.snapcast.feed.SnapcastStreams.ensure | ( | ) |
Makes sure the stream exists: adopts our own, or adds one (see the class comment).
Also removes leftovers of ours that no group uses (crash recovery). Never throws for what a server does.
Implements de.yaacc.snapcast.feed.FeedStreams.
Referenced by de.yaacc.snapcast.feed.LinkBoundStreams.ensure().


| void de.yaacc.snapcast.feed.SnapcastStreams.noteAudio | ( | ) |
Tells that audio was written: restarts the idle timer.
Cheap, never blocks, callable from any thread.
Implements de.yaacc.snapcast.feed.FeedStreams.
Referenced by de.yaacc.snapcast.feed.LinkBoundStreams.noteAudio().

| synchronized ReleaseResult de.yaacc.snapcast.feed.SnapcastStreams.release | ( | String | groupId | ) |
Puts a group back on the stream it played before useFor, but only if it is still on our stream and the previous stream still exists.
A group that someone moved elsewhere in the meantime is left alone.
Implements de.yaacc.snapcast.feed.FeedStreams.
Referenced by de.yaacc.snapcast.feed.LinkBoundStreams.release().


| synchronized boolean de.yaacc.snapcast.feed.SnapcastStreams.removeIfIdle | ( | ) |
Removes the stream (after giving the groups their previous streams back) if no audio was noted for the idle timeout.
Call it from a timer of the owner. The caller closes its PcmFeeder first or has none.
shutdown()) Implements de.yaacc.snapcast.feed.FeedStreams.
Referenced by de.yaacc.snapcast.feed.LinkBoundStreams.removeIfIdle().


| synchronized int de.yaacc.snapcast.feed.SnapcastStreams.removeLeftovers | ( | ) |
Removes streams that carry our marker, are tcp and are used by no group, other than the one we hold: the leftovers of a crash.
At most 8 per call.
Referenced by de.yaacc.snapcast.feed.SnapcastStreams.ensure().


| synchronized boolean de.yaacc.snapcast.feed.SnapcastStreams.shutdown | ( | ) |
Gives every group that YAACC moved its previous stream back and removes our stream (on user request, or when the last player ended).
The stream stays while a restore failed, and while any group still plays it (also one that somebody else moved there: it would be left on a stream that is gone); the status is read again before the removal. Only a stream that still looks like ours is removed.
Implements de.yaacc.snapcast.feed.FeedStreams.
Referenced by de.yaacc.snapcast.feed.SnapcastStreams.removeIfIdle(), and de.yaacc.snapcast.feed.LinkBoundStreams.shutdown().


| synchronized UseResult de.yaacc.snapcast.feed.SnapcastStreams.useFor | ( | String | groupId | ) |
Lets a group play our stream and remembers the stream it played before.
A group that is on our stream already is left as it is (and its remembered previous stream is kept). When the move fails the record of the previous stream is kept as well (the server may have applied the move before the answer was lost).
Implements de.yaacc.snapcast.feed.FeedStreams.
Referenced by de.yaacc.snapcast.feed.LinkBoundStreams.useFor().

