class CodecBuffer

Defined at line 92 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

This object is a buffer both known to CodecImpl and exposed to the

CodecAdapter with the buffer mapped (as appropriate) and pinned (as

appropriate).

The CodecAdapter can choose to use the mapping or pin that the CodecBuffer

provides, but this only lasts as long as the CodecBuffer instance.

The CodecBuffer instance remains allocated until CoreCodecRemoveBuffer

specifying the instance or CoreCodecEnsureBuffersNotConfigured (impliciatly

specifying all configured CodecBuffer(s)) is called, and the CodecAdapter has

closed all handles and mappings derived from GetChildVmo().

The CodecAdapter should not make any handles, mappings, or pins derived from

vmo() (including duplicates and child VMOs). These won't keep the CodecBuffer

allocated. Instead, the CodecAdapter can use GetChildVmo(); the returned

handle (and handles/mappings/pins derived from that) will keep the

CodecBuffer allocated. Ensuring that the CodecBuffer pointer remains valid

until the CodecAdapter has fully closed/unmapped/unpinned all its

buffer-derived stuff reduces the chance of a CodecAdapter accessing a

no-longer-allocated CodecBuffer.

The const-ness of a CodecBuffer refers to the fields of the CodecBuffer

instance, not to the data pointed at by buffer_base(). The context accessors

re. VideoFrame, CodecAdapterFrameBase, CodecAdapterBufferContextBase are

marked mutable, as those are for use by the CodecAdapter whenever is

convenient to the CodecAdapter (as long as CodecBuffer is known still

allocated).

Public Methods

std::unique_ptr<CodecBuffer> CreateFromVmo (uint32_t buffer_index, zx::vmo vmo, uint32_t vmo_usable_start, uint32_t vmo_usable_size, bool need_write, bool is_physically_contiguous)

Defined at line 61 of file ../../src/media/lib/test/codec_buffer.cc

bool GetDupVmo (bool is_for_write, zx::vmo * out_vmo)

Each successful call to this method dups the VMO handle, with basic rights

+ read + optional write depending on is_for_write.

Defined at line 26 of file ../../src/media/lib/test/codec_buffer.cc

uint32_t buffer_index ()

In buffer-per-packet mode this is equal to the corresponding packet index,

for purposes of mapping from packet_index to buffer_index.

Defined at line 14 of file ../../src/media/lib/test/codec_buffer.cc

uint8_t * base ()

The vaddr of the start of the mapped VMO for this buffer.

This will return nullptr if there's no VMO mapping because CPU access isn't

possible. In that case the vaddr data pointer passed around regarding a

packet will be an offset into the buffer / VMO, and is only meaningful

with respect to a CodecBuffer that's also passed alongside.

Defined at line 32 of file ../../src/media/lib/test/include/lib/media/test/codec_buffer.h

void SetCodecAdapterBufferContext (std::weak_ptr<CodecAdapterBufferContextBase> buffer_context)

The CodecAdapter can set a CodecAdapterBufferContextBase to avoid needing

to look up a CodecBuffer* later to find the relevant "buffer context" (from

the CodecAdapter's point of view).

std::weak_ptr<CodecAdapterBufferContextBase> codec_adapter_buffer_context ()
uint64_t lifetime_ordinal ()

This is the same value as buffer_lifetime_ordinal in StreamProcessor FIDL.

Defined at line 95 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

uint32_t index ()

This matches the buffer_index field of fuchsia::media::Packet when the packet refers to this

buffer.

Defined at line 99 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

CodecPort port ()

Defined at line 101 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

bool is_secure ()

Defined at line 103 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

fuchsia_sysmem2::CoherencyDomain coherency_domain ()

Defined at line 104 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

bool is_known_contiguous ()

Defined at line 112 of file ../../src/media/lib/codec_impl/codec_buffer.cc

zx_paddr_t physical_base ()

This will ZX_PANIC() if the buffer hasn't been pinned yet, or if !is_known_contiguous().

Defined at line 114 of file ../../src/media/lib/codec_impl/codec_buffer.cc

size_t size ()

The max size in bytes of meaningful/valid content starting at vmo_offset()

(from sysmem BufferMemorySettings.size_bytes). Producers must fit all

valid image/packet data within size().

Defined at line 123 of file ../../src/media/lib/codec_impl/codec_buffer.cc

size_t raw_vmo_size ()

The total VMO size in bytes (from sysmem BufferMemorySettings.raw_vmo_size /

zx_vmo_get_size). When sysmem pad_* constraints are used, raw_vmo_size()

includes trailing padding space beyond vmo_offset() + size() that is mapped

and accessible for padding/over-read/over-write, but must not hold

meaningful content.

Defined at line 125 of file ../../src/media/lib/codec_impl/codec_buffer.cc

const zx::vmo & vmo ()

This VMO is owned by CodecBuffer, but can be used temporarily (in a

non-owned fashion) to get VMO info or similar.

If the CodecAdapter wants to hold a VMO handle, a mapping, or a pin of its

own, the CodecAdapter should start with GetChildVmo() instead of vmo().

Holding a handle, mapping, or pin based on vmo() won't keep the CodecBuffer

instance allocated (but it will prevent the underlying memory from being

reused). Instead, by using GetChildVmo(), the CodecBuffer instance stays

allocated until the CodecAdapter has closed all its GetChildVmo-derived

handles to the buffer and unmapped all its GetChildVmo-derived mappings to

the buffer (and all pins). This helps avoid potential use-after-free of the

CodecBuffer and can make debugging / diagnosing simpler.

Defined at line 35 of file ../../src/media/lib/test/include/lib/media/test/codec_buffer.h

zx::vmo GetChildVmo ()

Up until the first buffer-relevant call to CoreCodecRemoveBuffer or

CoreCodecEnsureBuffersNotConfigured, the CodecBuffer will remain allocated

even if the CodecAdapter is not holding a handle obtained from

GetChildVmo() or anything derived from such a handle. If the CodecAdapter

wants/needs the CodecBuffer to remain allocated beyond said call, the

CodecAdapter must hold at least one handle obtained from GetChildVmo(), or

something derived from such a handle that keeps the VMO alive.

If a CodecAdapter does not keep any vmo(s) from GetChildVmo(), including

duplicates, mappings, or pins, that CodecAdapter must ensure that no buffer

usage of any form will occur beyond the first relevant

CoreCodecRemoveBuffer or CoreCodecEnsureBuffersNotConfigured.

If a CodecAdapter makes a separate pin of its own using GetChildVmo() (or a

duplicate and/or descendent), the CodecAdapter can continue doing DMA

to/from the buffer until its own unpin.

Calling GetChildVmo() (directly or indirectly via CodecPacket::SetBuffer())

after the first buffer-relevant CoreCodecRemoveBuffer or

CoreCodecEnsureBuffersNotConfigured is only valid while the CodecAdapter

still holds at least one open handle derived from an earlier GetChildVmo()

call.

The CodecAdapter should not rely on the returned VMO to be derived from

vmo(), though the returned vmo does refer to the same underlying buffer.

Defined at line 129 of file ../../src/media/lib/codec_impl/codec_buffer.cc

uint64_t vmo_offset ()

The offset within the main VMO where data of this CodecBuffer starts. The vmo_offset() is not

required to be divisible by page size.

Defined at line 36 of file ../../src/media/lib/test/include/lib/media/test/codec_buffer.h

void SetVideoFrame (std::weak_ptr<VideoFrame> video_frame)

Deprecated. See SetCodecAdapterFrame and/or

SetCodecAdapterBufferContext instead.

Defined at line 171 of file ../../src/media/lib/codec_impl/codec_buffer.cc

std::weak_ptr<VideoFrame> video_frame ()

Defined at line 175 of file ../../src/media/lib/codec_impl/codec_buffer.cc

void SetCodecAdapterFrame (std::weak_ptr<CodecAdapterFrameBase> video_frame)

The CodecAdapter can set a CodecAdapterFrameBase to avoid needing to

look up a CodecBuffer* later to find the relevant "frame" (from the

CodecAdapter's point of view).

std::weak_ptr<CodecAdapterFrameBase> codec_adapter_frame ()
zx_status_t Pin ()

Unpin is automatic during ~CodecBuffer.

Defined at line 177 of file ../../src/media/lib/codec_impl/codec_buffer.cc

bool is_pinned ()

Defined at line 220 of file ../../src/media/lib/codec_impl/codec_buffer.cc

void CacheFlush (uint32_t flush_offset, uint32_t length)

Defined at line 222 of file ../../src/media/lib/codec_impl/codec_buffer.cc

size_t size_bytes ()

Defined at line 33 of file ../../src/media/lib/test/include/lib/media/test/codec_buffer.h

bool is_physically_contiguous ()

For testing.

Defined at line 39 of file ../../src/media/lib/test/include/lib/media/test/codec_buffer.h

bool is_remove_pending ()

This returns true from just before CoreCodecRemoveBuffer or CoreCodecEnsureBuffersNotConfigured

is called, until destruction.

A CodecAdapter may choose to ignore this accessor (relying only on CoreCodecRemoveBuffer and/or

CoreCodecEnsureBuffersNotConfigured).

If a CodecAdapter does not support dynamic buffers, this bool isn't particularly interesting

other than possibly for some debug asserts.

If a CodecAdapter does support dynamic buffers, this bool being true means it's appropriate to

close all handles derived from GetChildVmo() (and any derived from vmo(), though creating those

isn't recommended in the first place). Upon parent_vmo_ seeing ZX_VMO_ZERO_CHILDREN, the

CodecBuffer will be deleted, so the CodecAdapter should take care to remove all dependence on

the CodecBuffer* before closing the last handle.

For output buffers, the CodecAdapter can look at is_remove_pending() just before it would

otherwise be putting an output buffer back on its free list, for buffers that weren't already

free when CoreCodecRemoveBuffer or mid-stream CoreCodecEnsureBuffersNotConfigured was called.

For input buffers, this will only become true if the buffer is not with the CodecAdapter and

won't be referenced by any subsequent input packet sent to the CodecAdapter. So for most

CodecAdapter(s), input buffer removal can happen during the call to CoreCodecRemoveBuffer or

CoreCodecEnsureBuffersNotConfigured, without needing to call is_remove_pending() (may still be

useful for asserts).

This is public to avoid the CodecAdapter needing to keep a redundant bool in VideoFrame,

CodecAdapterFrame, or CodecAdapterBufferContext.

Defined at line 226 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

void CacheFlushAndInvalidate (uint32_t flush_offset, uint32_t length)

Defined at line 226 of file ../../src/media/lib/codec_impl/codec_buffer.cc

bool was_ever_added_to_core_codec ()

Defined at line 228 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

void SetWasEverAddedToCoreCodec ()

Defined at line 229 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

void AssertMagic ()

Defined at line 234 of file ../../src/media/lib/codec_impl/include/lib/media/codec_impl/codec_buffer.h

Protected Methods

void CodecBuffer (CodecImpl * parent, Info buffer_info, CodecVmoRange vmo_range)

Defined at line 15 of file ../../src/media/lib/codec_impl/codec_buffer.cc

void ~CodecBuffer ()

Defined at line 41 of file ../../src/media/lib/codec_impl/codec_buffer.cc

bool Map ()

Maps a page-aligned portion of the VMO including vmo_usable_start to vmo_usable_start +

vmo_usable_size.

Defined at line 75 of file ../../src/media/lib/codec_impl/codec_buffer.cc

Records

Friends

class CodecPacket
class CodecBufferForTest
class default_delete
class unique_ptr
class CodecImpl