class OutputSink

Defined at line 33 of file ../../src/media/codec/codecs/output_sink.h

A sink for blocks of output data that manages output packets and output

buffers.

An example use case:

while (input

<

input_end) {

auto [output_block, status] = output_sink.NextOutputBlock(output_size);

if (status != OutputSink::kOk) {

// handle error

}

encoder.EncodeInto(

&input

, output_block.data);

}

This class is expected to be used on two or more threads: a writer thread

that calls `NextOutputBlock` and `Flush`, and then any other thread(s), which

can also be the writer thread. See comments on each method for thread safety

guidance.

Public Methods

void OutputSink (Sender sender, thrd_t writer_thread)

Constructs a new output sink that will use `sender` to emit complete or

flushed output packets.

Defined at line 9 of file ../../src/media/codec/codecs/output_sink.cc

void AddOutputPacket (CodecPacket * output_packet)

Adds an output packet to vend output blocks with. Packets must be added

when they are new and when they are recycled.

This call is allowed from any thread at any time.

Defined at line 14 of file ../../src/media/codec/codecs/output_sink.cc

void AddOutputBuffer (const CodecBuffer * output_buffer)

Adds an output buffer to vend output blocks with. Buffers need only be

added once.

This call is allowed from any thread at any time.

Defined at line 24 of file ../../src/media/codec/codecs/output_sink.cc

Status NextOutputBlock (size_t write_size, std::optional<uint64_t> timestamp_ish, Writer output_block_writer)

Runs the given function, passing in the next output block of at least

`write_size` bytes.

The function should return the amount of bytes actually written to the

block.

OutputBlocks are valid for their lifetime as an argument and should not be

stashed.

The containing packet will be sent when flushed or when it has no room for

the next write.

When there are not enough output packets or output buffers to satisfy a

request, this call will block until the needed resources are added or a

call to `StopAllWaits()` terminates the wait.

This should only be called on the writer thread.

Defined at line 31 of file ../../src/media/codec/codecs/output_sink.cc

Status Flush ()

Flushes the current output packet even if it isn't full.

This should only be called on the writer thread.

Defined at line 74 of file ../../src/media/codec/codecs/output_sink.cc

void StopAllWaits ()

Stops all blocking calls from waiting. They will return a

`kUserTerminatedWait` status. This class will continue to

return `kUserTerminatedWait` instead of blocking until

`Reset` is called.

This call is allowed from any thread.

Defined at line 133 of file ../../src/media/codec/codecs/output_sink.cc

void Reset (bool keep_data)

Resets the stream, re-arming it for waits.

If `keep_data` is true, the free buffers and packets will not be discarded.

This call is allowed from any thread.

Defined at line 138 of file ../../src/media/codec/codecs/output_sink.cc

bool HasPendingPacket ()

Returns whether any packet data has been queued but not sent

Defined at line 104 of file ../../src/media/codec/codecs/output_sink.cc

uint32_t OutputBufferCount ()

Returns the count of added output buffers

Defined at line 106 of file ../../src/media/codec/codecs/output_sink.cc

Enumerations

enum UserStatus
Name Value
kSuccess 0
kError 1

Defined at line 35 of file ../../src/media/codec/codecs/output_sink.h

enum Status
Name Value
kOk 0
kUserTerminatedWait 1
kBuffersTooSmall 2
kUserError 3

Defined at line 61 of file ../../src/media/codec/codecs/output_sink.h

Records