class RingBuffer
Defined at line 52 of file ../../src/media/audio/services/mixer/mix/ring_buffer.h
Represents a single-producer multi-consumer ring buffer of audio data. A ring buffer represents a
window into an infinite stream. Frame numbers are specified relative to this infinite stream --
the translation into ring buffer offsets happens internally.
## Concurrency
Code in this directory (`mix/`) is supposed to be single-threaded, but ring buffers are unusual.
Ring buffers are concurrent by their very nature: the producer and consumer may be running in
different threads, or even in different HW domains. Hence, all public methods in this class are
safe to call from any thread, except `PrepareToWrite`, which must be called by the producer.
The actual data in a ring buffer is synchronized by time, using one of two protocols, as
described below.
### External producer or consumer
If the ring buffer is shared with an external producer or consumer, such as a hardware device,
then we divide the ring buffer into two adjacent regions: a "safe write" region, which the
producer can write, and a "safe read" region, which the consumers can read. These regions meet at
the current time: the "safe write" region is in the future while the "safe read" region is in the
past. The producer and consumers must agree on these regions using some out-of-band mechanism.
More information about this protocol can be found at the documentation for the
`fuchsia.audio.RingBuffer` FIDL type.
### Splitters
Each SplitterNode uses a RingBuffer to connect a source stream (which writes to the buffer) with
one or more destination streams (which read from the buffer). SplitterNodes don't have a clean
separation into "safe read" and "safe write" regions. In some cases, consumers are allowed to
read from the same region the producer is writing to. See ../docs/splitters.h for a detailed
description of this protocol.
Public Methods
void RingBuffer (const Format & format, UnreadableClock reference_clock, std::shared_ptr<MemoryMappedBuffer> buffer)
Defined at line 28 of file ../../src/media/audio/services/mixer/mix/ring_buffer.cc
PacketView Read (int64_t start_frame, int64_t frame_count)
Returns a packet representing the given range of frames. If the range wraps around the buffer,
only the first part of the range is returned. Handles cache invalidation.
Defined at line 35 of file ../../src/media/audio/services/mixer/mix/ring_buffer.cc
WritablePacketView PrepareToWrite (int64_t start_frame, int64_t frame_count)
Like Read, but returns a wrapper around a PacketView that handles cache flushing. The caller
should hold onto the returned object until they are done with the write. Cannot be called
concurrently -- see class comments for more discussion.
Defined at line 54 of file ../../src/media/audio/services/mixer/mix/ring_buffer.cc
const Format & format ()
Returns the format of this buffer.
Defined at line 79 of file ../../src/media/audio/services/mixer/mix/ring_buffer.h
UnreadableClock reference_clock ()
Returns the clock used by this buffer.
Defined at line 82 of file ../../src/media/audio/services/mixer/mix/ring_buffer.h
void SetBufferAsync (std::shared_ptr<MemoryMappedBuffer> new_buffer)
Changes the underlying buffer. This change happens asynchronously during the next call to
`PrepareToWrite`. If this is called multiple times before the next `PrepareToWrite`, only the
most recent call has any effect.
Defined at line 89 of file ../../src/media/audio/services/mixer/mix/ring_buffer.cc