class CapturePacketQueue

Defined at line 45 of file ../../src/media/audio/audio_core/capture_packet_queue.h

This queue has two states:

Initially, a packet is pushed onto a "pending" queue. The mixer will write to the first

packet in the pending queue, and once the mixer is done, it will move that packet to the

"ready" queue, meaning the packet is now ready to be sent to the client. The FIDL loop

will pop packets from the ready queue as they become available.

Packets are pushed onto the pending queue in one of two ways:

1. For preallocated queues, the pending queue is prepopulated automatically. After

a packet is popped from the ready queue, it can be added back to the pending queue

by Recycle().

2. For dynamically allocated queues, packets must be explicitly pushed onto the

pending queue, and once the packet is popped from the ready queue, the caller

takes permanent ownership.

This class is thread safe.

Public Methods

fpromise::result<std::shared_ptr<CapturePacketQueue>, std::string> CreatePreallocated (const fzl::VmoMapper & payload_buffer, const Format & format, size_t frames_per_packet)

Create a packet queue where all available packets are preallocated. To use payload_buffer

as a ring buffer, ensure that packets are recycled in the same order they are popped.

It is illegal to call Push on the returned packet queue.

Defined at line 34 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

std::shared_ptr<CapturePacketQueue> CreateDynamicallyAllocated (const fzl::VmoMapper & payload_buffer, const Format & format)

Create a packet queue where all packets will be dynamically allocated by Push.

It is illegal to call Recycle on packets returned from this queue.

Defined at line 72 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

bool empty ()

Report whether the pending and ready queues are both empty.

Defined at line 84 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

size_t PendingSize ()

Report the number of pending and ready packets.

Defined at line 89 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

size_t ReadySize ()

Defined at line 94 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

std::optional<PacketMixState> NextMixerJob ()

Defined at line 99 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

PacketMixStatus FinishMixerJob (const PacketMixState & state)

Defined at line 115 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

void DiscardPendingPackets ()

Atomically move all packets from the pending queue to the ready queue.

Defined at line 133 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

fbl::RefPtr<Packet> PopReady ()

Pop a packet from the ready queue. Returns nullptr if the ready queue is empty.

Defined at line 160 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

fpromise::result<void, std::string> PushPending (size_t offset_frames, size_t num_frames, CaptureAtCallback callback)

Push a packet onto the the end of the pending queue.

The queue must have been created with CreateDynamicallyAllocated.

Returns an error if the packet is malformed.

Defined at line 175 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

fpromise::result<void, std::string> Recycle (const StreamPacket & stream_packet)

Recycle a packet back onto the queue. The packet must have been previously

returned by Pop and the queue must have been created with CreatePreallocated.

Returns an error if stream_packet was not in flight.

Defined at line 205 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

void Shutdown ()

Stop accepting packets. All further calls to PushPending and Recycle will be

ignored, and NextMixerJob will return nullopt.

Defined at line 239 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

void WaitForPendingPacket ()

Block until the pending queue is non-empty or the queue has been shut down.

Defined at line 257 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

void CapturePacketQueue (Mode mode, const fzl::VmoMapper & payload_buffer, const Format & format)

This needs to be public for std::make_unique.

Defined at line 26 of file ../../src/media/audio/audio_core/capture_packet_queue.cc

Enumerations

enum PacketMixStatus
Name Value
Done 0
Partial 1
Discarded 2

Complete the job started by the last call to NextMixerJob().

Defined at line 150 of file ../../src/media/audio/audio_core/capture_packet_queue.h

Records