YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.feed.SnapcastFeedController Class Reference

The coordination of playing into one Snapcast group (task 4.4), without Android: it joins FeedStreams (the stream and the group on the server), FeedServer (the control connection), a FeedOutputFactory (the connection to the stream port) and the clock. More...

Collaboration diagram for de.yaacc.snapcast.feed.SnapcastFeedController:
Collaboration graph

Classes

class  Config
 The settings; the defaults are those of the design.
 
interface  Listener
 Hears what the controller does on its own. More...
 
interface  StartCallback
 The answer to start. More...
 
enum  State
 The state, for tests and the player. More...
 

Public Member Functions

 SnapcastFeedController (FeedStreams streams, FeedServer server, FeedOutputFactory outputs, FeedSlot slot, String groupId, FeedClock clock, RetryScheduler scheduler, Executor worker, Listener listener, Config config, Runnable onReleased)
 
PcmSink sink ()
 The sink for the audio tap: it hands the PCM to the open feed, and refuses (returns false) while there is none.
 
State getState ()
 The state; READY means a feed is open.
 
boolean isFeeding ()
 True while a feed is open and running.
 
void start (final StartCallback callback)
 Opens the feed (or confirms that it is open).
 
void pause ()
 The player paused: what is queued is stale.
 
void stop ()
 The player stopped (also the end of the playlist): drain, close the feed, give the group its previous stream back.
 
void release ()
 The player is gone: like stop(), and the stream is removed and the worker ended.
 
void controlLost ()
 The control connection went down.
 
int getVolume ()
 The group's volume (the average of its connected members) from the model; 0 if unknown.
 
boolean isMuted ()
 True if the group is muted on the server, from the model.
 
void setVolume (int percent)
 Sets the group's volume, 0 to 100.
 
void setMuted (final boolean muted)
 Mutes or unmutes the group on the server.
 

Detailed Description

The coordination of playing into one Snapcast group (task 4.4), without Android: it joins FeedStreams (the stream and the group on the server), FeedServer (the control connection), a FeedOutputFactory (the connection to the stream port) and the clock.

The player is thin glue around it: it asks for a start before ExoPlayer plays, calls pause() / stop() / release(), and hands sink() to the audio tap.

Threads. Every call that blocks (control calls, connecting, closing the feed, the drain) runs on the injected single-thread worker, in the order of the calls; the public methods only queue work or touch volatile state, so they are safe to call from the main thread. sink() is called on ExoPlayer's playback thread; its write waits at most what the FeedOutput waits.

Start (start): take the feed slot of the server (one feed per server), wait for the control connection, ensure() the stream, useFor(group) (remembers the group's previous stream), then read the peer address of the control connection and connect the feed to exactly that address and the port that ensure() reported. The address is read after the last control call and handed on; it is never logged or kept longer than the call. The callback hears onReady on the worker; ExoPlayer starts only then, so no audio is lost to a feed that is not there yet. A stop() / release() that comes while a start is in progress cancels it: the callback hears nothing and the cleanup of the stop runs after the start.

Pause discards what is queued in the feed (the player's pause does not flush the audio processors); the feed stays open. Seek needs nothing: ExoPlayer flushes the processors, and the tap discards. Stop waits about one chunk for the queue to drain (bounded), closes the feed on the worker (closing may block for seconds), gives the group its previous stream back and frees the slot; the stream stays for a start soon after. Release does the same and also removes the stream (shutdown()) and ends the worker.

Failures. A start that does not succeed is reported once as a typed FeedError (never an exception), after everything it did was undone (the group is back, the slot is free). A feed that breaks while playing, or a control connection that is lost (controlLost()), closes the feed and tells the Listener once; the player stops cleanly. After a lost control connection the group may stay on the stream until the next stop or idle check can reach the server.

Idle. While a stream is held a timer (the injected scheduler) looks every minute whether the feed has had no audio for idleTimeoutMillis (a long pause); then it closes the feed and calls FeedStreams#removeIfIdle(). If that does not remove the stream (a restore failed, a group still plays it, the server is not reachable) the next attempt comes later, the delay doubles up to ten minutes, and it starts again after the next audio.

Volume. setVolume / setMuted are the group's volume and mute on the server (the phone's own volume is never touched): levels are changed relative to the levels at the start of a gesture (calls closer than volumeGestureGapMillis belong to one), and only the latest wanted value is sent.

Nothing here logs an address or a name; Listener#onLog gets lines with states and counters only.

Constructor & Destructor Documentation

◆ SnapcastFeedController()

de.yaacc.snapcast.feed.SnapcastFeedController.SnapcastFeedController ( FeedStreams streams,
FeedServer server,
FeedOutputFactory outputs,
FeedSlot slot,
String groupId,
FeedClock clock,
RetryScheduler scheduler,
Executor worker,
Listener listener,
Config config,
Runnable onReleased )
Parameters
groupIdthe group of the server this controller plays into
workera single-thread executor; the controller never blocks the thread that calls it
onReleasedruns on the worker at the end of release(); the owner ends the worker there. May be null.

Member Function Documentation

◆ controlLost()

void de.yaacc.snapcast.feed.SnapcastFeedController.controlLost ( )

The control connection went down.

Returns at once.

Here is the call graph for this function:

◆ getVolume()

int de.yaacc.snapcast.feed.SnapcastFeedController.getVolume ( )

The group's volume (the average of its connected members) from the model; 0 if unknown.

No network.

Here is the call graph for this function:

◆ pause()

void de.yaacc.snapcast.feed.SnapcastFeedController.pause ( )

The player paused: what is queued is stale.

The feed stays open.

Here is the call graph for this function:

◆ release()

void de.yaacc.snapcast.feed.SnapcastFeedController.release ( )

The player is gone: like stop(), and the stream is removed and the worker ended.

Returns at once.

Referenced by de.yaacc.player.SnapcastPlayer.onDestroy().

Here is the caller graph for this function:

◆ setMuted()

void de.yaacc.snapcast.feed.SnapcastFeedController.setMuted ( final boolean muted)

Mutes or unmutes the group on the server.

Returns at once.

Here is the call graph for this function:

◆ setVolume()

void de.yaacc.snapcast.feed.SnapcastFeedController.setVolume ( int percent)

Sets the group's volume, 0 to 100.

Returns at once; only the latest value of a quick series is sent.

◆ sink()

PcmSink de.yaacc.snapcast.feed.SnapcastFeedController.sink ( )

The sink for the audio tap: it hands the PCM to the open feed, and refuses (returns false) while there is none.

The same object for the whole life of the controller, so the tap can be built before the first start.

◆ start()

void de.yaacc.snapcast.feed.SnapcastFeedController.start ( final StartCallback callback)

Opens the feed (or confirms that it is open).

Returns at once; the callback comes on the worker, unless a stop() or release() was called in the meantime, in which case it does not come at all.

◆ stop()

void de.yaacc.snapcast.feed.SnapcastFeedController.stop ( )

The player stopped (also the end of the playlist): drain, close the feed, give the group its previous stream back.

Returns at once. A start that has not finished is cancelled.


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