|
YAACC - UPNP Client and Server
|
Feeds raw PCM into the tcp source of a Snapcast server in real time. More...


Classes | |
| class | Config |
| The settings; the defaults are the ones of the design. | |
| enum | Failure |
| Why a feeder failed. More... | |
| interface | Listener |
| Told once when the feeder fails (not when it is closed). More... | |
| enum | State |
| The state of a feeder. More... | |
Public Member Functions | |
| boolean | write (byte[] data, int offset, int length) |
| Copies PCM into the queue. | |
| void | discard () |
| Drops what is queued (a seek or a stop); the writer keeps its clock and writes silence if nothing follows. | |
| void | close () |
| Stops the threads, closes the socket and drops the queue. | |
| State | getState () |
| Failure | getFailure () |
| Why the feeder failed; null unless the state is FAILED (or CLOSED after a failure). | |
| int | getChunkBytes () |
| The size of a chunk in bytes. | |
| int | getQueuedBytes () |
| Bytes in the queue now. | |
| int | getQueueCapacity () |
| The most bytes the queue can hold. | |
| long | getChunksWritten () |
| Chunks handed to the connection (including silence). | |
| long | getBytesWritten () |
| Bytes handed to the connection (including silence). | |
| long | getSilenceChunks () |
| Chunks of silence written because the producer had nothing. | |
| long | getDroppedBytes () |
Bytes that write had to drop. | |
| long | getLeadNanos () |
| How far the written audio is ahead of real time now (negative: behind). | |
| long | getMaxLeadNanos () |
| The largest lead seen right after a write. | |
| long | getLateChunks () |
| Chunks that were written more than one chunk after they were due. | |
| long | getReanchors () |
| How often the pacer re-anchored after a stall. | |
Public Member Functions inherited from de.yaacc.multiroom.feed.PcmSink | |
Static Public Member Functions | |
| static PcmFeeder | connect (InetAddress address, int port, PcmFormat format, Config config, FeedConnection.Factory factory, FeedClock clock, Listener listener) throws IOException |
| Connects and starts the threads. | |
Static Public Attributes | |
| static final int | MAX_QUEUE_CHUNKS = 8 |
| The most chunks the queue between the producer and the writer thread can hold. | |
Feeds raw PCM into the tcp source of a Snapcast server in real time.
Where it connects. connect takes an InetAddress and a port and connects to exactly that: the address of the control connection's peer (SnapcastRpc.getPeerAddress()) and the port that YAACC itself asked for in Stream.AddStream. A host, port or URI that a server reply contains is never a connect target (the server reports 0.0.0.0:<port>; connecting to that would reach the phone itself, so the wildcard and multicast addresses are refused). The address is not logged here and not put into an exception.
How it writes. The producer thread calls write, which copies the bytes into a queue of at most {@value MAX_QUEUE_CHUNKS} chunks. A writer thread of its own takes one chunk at a time and writes it at the deadline given by a RealTimePacer (absolute deadlines, a look-ahead of 3 chunks, a re-anchor instead of a burst after a stall). The socket gets a small send buffer and TCP_NODELAY, so what is in flight stays a few chunks and a pause or stop is heard soon. The server reads one chunk per chunk_ms and resyncs when a read is late, so the writer never underruns: when the queue is empty at the time a chunk is due it writes silence (an all-zero chunk, which the server counts as silent), for at most silenceFillChunks chunks; after that it waits without writing until audio arrives and anchors the clock again. A chunk that is only partly queued is waited for (it is padded with zeros only when it is due and its first bytes have been waiting for half a chunk), and the writer wakes when audio arrives, so zeros never land in the middle of audio that is being handed over.
Back pressure. write waits up to writeWaitMillis for room in the queue and then reports failure (and counts the dropped bytes); the queue never grows.
A stalled peer. Java sockets have no write timeout. A watchdog thread closes the connection when one write has not finished after stallTimeoutMillis (default 10 s); the feeder is then FAILED with Failure#STALLED and the listener is told once.
close() stops both threads and closes the socket. Everything is safe to call from any thread.
| void de.yaacc.snapcast.feed.PcmFeeder.close | ( | ) |
Stops the threads, closes the socket and drops the queue.
Safe to call twice and from the listener.
Referenced by de.yaacc.snapcast.feed.PcmFeederOutput.close().


|
static |
Connects and starts the threads.
Blocking (up to the connect timeout): never call it on the main thread.
| address | the peer address of the control connection, nothing else |
| port | the port that YAACC asked for in Stream.AddStream |
| format | the sample format of the stream |
| config | the settings, or null for the defaults |
| factory | opens the connection, see SocketFeedConnection#FACTORY |
| clock | the time source, FeedClock#SYSTEM in the app |
| listener | told once if the feeder fails; may be null |
| IllegalArgumentException | for no address, the wildcard or a multicast address, or a port outside 1 to 65535 |
| IOException | when the connection can not be made (a fixed text: no address, no cause) |

| void de.yaacc.snapcast.feed.PcmFeeder.discard | ( | ) |
Drops what is queued (a seek or a stop); the writer keeps its clock and writes silence if nothing follows.
Implements de.yaacc.multiroom.feed.PcmSink.
Referenced by de.yaacc.snapcast.feed.PcmFeeder.close(), and de.yaacc.snapcast.feed.PcmFeederOutput.discard().

| boolean de.yaacc.snapcast.feed.PcmFeeder.write | ( | byte[] | data, |
| int | offset, | ||
| int | length ) |
Copies PCM into the queue.
Waits up to writeWaitMillis for room; what does not fit by then is dropped and counted.
| IllegalArgumentException | for a range outside the array or a length that is not whole frames (an odd number of bytes would shift the channels for the rest of the stream) |
Implements de.yaacc.multiroom.feed.PcmSink.
Referenced by de.yaacc.snapcast.feed.PcmFeederOutput.write().
