YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.multiroom.codec.FlacFrameHeader Class Reference

The header of one FLAC frame, read from the first bytes of a chunk of the flac codec: where in the stream (in frames, per channel) the chunk starts. More...

Collaboration diagram for de.yaacc.multiroom.codec.FlacFrameHeader:
Collaboration graph

Classes

enum  Refusal
 Why a header was not accepted. More...
 

Public Member Functions

boolean isValid ()
 
Refusal getRefusal ()
 Null for a valid header.
 
boolean isVariableBlockSize ()
 
int getBlockSize ()
 Frames (samples per channel) in this block.
 
int getSampleRate ()
 Hz; 0 when the frame says "see STREAMINFO".
 
int getChannels ()
 
int getBitsPerSample ()
 0 when the frame says "see STREAMINFO".
 
long getCodedNumber ()
 The frame number (fixed block size) or the sample number (variable block size), as coded.
 
long getFirstSample ()
 The stream position of the first frame (sample per channel) of this block.
 
int getLength ()
 Bytes of the header including the CRC; the frame's subframes follow.
 

Static Public Member Functions

static FlacFrameHeader parse (byte[] data, int offset, int length)
 Reads the header at offset; length bytes from there are available.
 

Detailed Description

The header of one FLAC frame, read from the first bytes of a chunk of the flac codec: where in the stream (in frames, per channel) the chunk starts.

The server's encoder (libFLAC, see flac_encoder.cpp of Snapcast) cuts its output at frame boundaries: every chunk starts with a frame header, and the number coded in it is the position of the audio that the server's encoder was given, whatever the client's decoder does with it later (a platform codec may hold a block back). That every chunk of a real server starts this way is read from the source of Snapcast 0.35.0, not captured from a real server; a chunk that does not is refused here and the engine counts frames instead (the guard is then off).

Layout (FLAC format specification, "frame header"; RFC 9639 section 9.1; checked here against frames made by a conforming encoder, see FlacFrameHeaderTest):

  14 bits sync 0b11111111111110, 1 bit reserved (0), 1 bit blocking strategy (0 fixed, 1 variable block size)
  4 bits block size code, 4 bits sample rate code
  4 bits channel assignment, 3 bits sample size code, 1 bit reserved (0)
  the coded number: UTF-8 style, 1 to 7 bytes (fixed: the frame number, variable: the sample number)
  0, 1 or 2 bytes of "uncommon" block size (codes 0110 and 0111: value - 1)
  0, 1 or 2 bytes of "uncommon" sample rate (codes 1100, 1101, 1110)
  1 byte CRC-8 (polynomial x^8 + x^2 + x + 1, initial value 0) over all bytes of the header before it

Pure and total: parse never throws and never allocates by a number of the data; a header that is not valid comes back with a Refusal. The position of a fixed block size stream is the frame number times the block size of this frame (the block size of the stream; only the last frame of a stream may be shorter, and the server does not end its stream).


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