|
YAACC - UPNP Client and Server
|
The pacing math of the feed: when may the next bytes of a real-time PCM stream be written? More...

Public Member Functions | |
| RealTimePacer (FeedClock clock, int bytesPerSecond, int chunkBytes, int lookAheadChunks, int stallChunks) | |
| RealTimePacer (FeedClock clock, PcmFormat format, int chunkMillis) | |
The default look-ahead and stall limit, chunks of chunkMillis milliseconds (whole frames). | |
| int | getChunkBytes () |
| int | getBytesPerSecond () |
| synchronized long | nanosUntilWritable (int bytes) |
How long to wait before bytes more may be written so that the audio sent so far ends no more than the look-ahead after now. | |
| synchronized long | nanosUntilDue () |
| How long until the audio sent so far has been played, that is until the next byte is due. | |
| synchronized void | onWritten (int bytes) |
Records that bytes were written now. | |
| synchronized void | reset () |
| Forgets the anchor: the next write is due at once and anchors the clock again (after a pause in the feed). | |
| synchronized long | leadNanos () |
| The audio sent so far minus the time since the anchor: how far the producer is ahead of real time. | |
| synchronized long | getMaxLeadNanos () |
| The largest lead seen right after a write. | |
| synchronized long | getLateChunks () |
| Writes that came more than one chunk after their audio was due. | |
| synchronized long | getReanchors () |
| Stalls that made the pacer re-anchor. | |
Static Public Member Functions | |
| static int | chunkBytesFor (PcmFormat format, int chunkMillis) |
The size of a chunk of chunkMillis ms in whole frames, at least one frame. | |
The pacing math of the feed: when may the next bytes of a real-time PCM stream be written?
The server reads its tcp source in real time, one chunk per chunk_ms, and a late read makes it resync (an audible break). So the feeder writes at absolute deadlines derived from one anchor time and the number of bytes sent since: a late wake-up does not push the following writes back, and a slow loop does not accumulate a delay. Two rules keep the producer from running away:
lookAheadChunks chunks (default 3, 60 ms) after "now". Everything in socket buffers beyond that would delay a pause or a stop. stallChunks chunks (default 2) after the time its audio was due, the pacer re-anchors to now instead of writing the missing chunks as a burst: the gap is lost (the server resyncs once), there is never an accumulating debt, and the stream is never faster than real time. A write that is late by up to the limit is caught up by the next writes, which are due at once. Writes of any size are accounted by their bytes, so partial chunks are fine. The pacer only calculates; the caller sleeps and writes. It is thread safe and has no thread of its own.
| de.yaacc.multiroom.feed.RealTimePacer.RealTimePacer | ( | FeedClock | clock, |
| int | bytesPerSecond, | ||
| int | chunkBytes, | ||
| int | lookAheadChunks, | ||
| int | stallChunks ) |
| chunkBytes | the size of one chunk of the stream (whole frames); look-ahead and stall limit are counted in these |
| synchronized long de.yaacc.multiroom.feed.RealTimePacer.leadNanos | ( | ) |
The audio sent so far minus the time since the anchor: how far the producer is ahead of real time.
Negative when the audio has been played already (the stream is behind). Zero before the first write.

| synchronized long de.yaacc.multiroom.feed.RealTimePacer.nanosUntilDue | ( | ) |
How long until the audio sent so far has been played, that is until the next byte is due.
Zero when it is due or overdue (also before the first write). Silence to avoid an underrun is written when this is zero.

| synchronized long de.yaacc.multiroom.feed.RealTimePacer.nanosUntilWritable | ( | int | bytes | ) |
How long to wait before bytes more may be written so that the audio sent so far ends no more than the look-ahead after now.
Zero when it may be written at once (also before the first write).

| synchronized void de.yaacc.multiroom.feed.RealTimePacer.onWritten | ( | int | bytes | ) |
Records that bytes were written now.
The first write sets the anchor; a write that is more than the stall limit late re-anchors (see the class comment).
