class CodecImpl

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

CodecImpl is final; CodecAdapter interface is not final and get sub-classed by CodecImpl client

code to implement a specific codec. See also CodecAdapter.

Public Methods

void CodecImpl (fidl::ClientEnd<fuchsia_sysmem2::Allocator> sysmem, std::unique_ptr<CodecAdmission> codec_admission, async_dispatcher_t * shared_fidl_dispatcher, thrd_t shared_fidl_thread, StreamProcessorParams params, fidl::InterfaceRequest<fuchsia::media::StreamProcessor> request)

The CodecImpl will take care of doing set_error_handler() on the sysmem

connection. The sysmem connection should be set up to use the

shared_fidl_dispatcher.

The shared_fidl_thread parameter is deprecated and ignored and may be

thrd_t{} or just {} at the call site.

The shared_fidl_dispatcher must be a single-threaded dispatcher (such as

async::Loop::dispatcher()) or a synchronized dispatcher (such as

fdf::SynchronizedDispatcher::async_dispatcher()), meaning it will only run

one task at a time, in the same order as tasks are posted. CodecImpl does

support synchronized dispatchers that don't always call using the same

thread, just the same sequence/ordering domain. Fwiw, this is why we called

them "ordering domain"s in the first place. Ideally all

async_dispatcher_t(s) would be updated to support "sequence" ops so we

could just call it "sequence" instead of sequence/ordering domain/thread,

but anyway.

The calling thread must be running under the shared_fidl_dispatcher

(sequence/thread).

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

void ~CodecImpl ()

If the client code calls SetSharingFidlDomainForCoreCodec or returns true from

IsSupportsDynamicBuffers, ~CodecImpl must not be called until CodecImpl has called the

error_handler passed to BindAsync (during is fine, a bit later async is fine).

The client code of CodecImpl can cause the error handler to be called asap async by calling

UnbindAsync.

For drivers, the above requirements also implicitly require the driver framework to support

async stop, which DFv2 PrepareStop does support. In contrast, DFv1 initially didn't have async

stop which necessitated supporting ~CodecImpl at any time from the fidl thread, and we still

currently support ~CodecImpl at any time for the existing DFv1 drivers (despite DFv1's current

support for async DdkUnbind), but only when/while SetSharingFidlDomainForCoreCodec isn't used

and !IsSupportsDynamicBuffers.

DFv2 is strongly recommended for any driver wanting to call SetSharingFidlDomainForCoreCodec or

return true from IsSupportsDynamicBuffers, but it may be technically possible to use DFv1 if

DFv1 can/does (now) fully support async stop in all cases short of driver process abort().

Client code which doesn't call SetSharingFidlDomainForCoreCodec and doesn't return true from

IsSupportsDynamicBuffers may call ~CodecImpl on the fidl thread at any time, but support for

this is only retained for legacy reasons, so support for this may be removed at some point. New

or updated client code should strongly prefer to use UnbindAsync and only run ~CodecImpl in

response to the BindAsync error_handler (even if the new client code doesn't call

SetSharingFidlDomainForCoreCodec and doesn't return true from IsSupportsDynamicBuffers).

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

void SetSharingFidlDomainForCoreCodec ()

If called, must be called during setup shortly after construction. This informs CodecImpl that

the shared_fidl_dispatcher thread will also be used as the core codec processing thread / input

domain.

In ~CodecImpl (called on fidl thread), we enforce that if this method was called, we've already

completed the UnbindAsync sequence, so that during ~CodecImpl the fidl thread won't need to

wait on the StreamControl thread which in turn is allowed to wait on core codec processing

which would be a potential deadlock if core codec processing is also on the fidl thread (fidl

thread could end up waiting for itself).

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

bool is_supports_dynamic_buffers ()

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

void CaptureCoreCodecOrderingDomain (async_dispatcher_t * calling_core_codec_dispatcher)

Callers that call SetSharingFidlDomainForCoreCodec must not call this method.

Callers that don't call SetSharingFidlDomainForCoreCodec() _should_ call this method to set the

core codec dispatcher, if available. If called, this must be called on the core codec sequence

or thread, and should be called asap after CodecImpl construction (async is fine; just be aware

that fully robust checking in CodecImpl won't happen until this is called).

The calling_core_codec_dispatcher must be both (a) the core codec ordering domain dispatcher

and (b) the dispatcher managing the current calling thread.

The calling_core_codec_dispatcher must remain valid until ~CodecAdapter. CodecImpl won't post

any tasks to the calling_core_codec_dispatcher; this is only used for checking synchronization

of inbound calls (on CodecImpl directly as appropriate and via CodecAdapterEvents).

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

void UnbindAsync ()

When either SetSharingFidlDomainForCoreCodec is called or IsSupportsDynamicBuffers() returns

true, this is the only valid way for client code to head toward ~CodecImpl. Just calling

~CodecImpl from the FIDL thread without the BindAsync error handler having been called is not

allowed unless SetSharingFidlDomainForCoreCodec was never called and

!IsSupportsDynamicBuffers() (and only for legacy reasons).

After calling this, the caller can later run ~CodecImpl safely in the error_handler passed to

BindAsync or shortly after async. This is only valid to call after calling BindAsync. The

error_handler may run because BindAsync failed async, or because UnbindAsync sequence is

calling the error_handler, but the caller doesn't need to care which. If called, must be called

on the fidl thread.

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

std::mutex & lock ()

This is only intended for use by LocalCodecFactory in creating the appropriate CodecAdapter.

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

void SetLifetimeTracking (std::vector<zx::eventpair> lifetime_tracking_eventpair)

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

void SetCodecMetrics (CodecMetrics * codec_metrics)

The LocalCodecFactory optionally calls this method between construction and

SetCoreCodecAdapter(). If this method is not called, CodecImpl will treat

any call to onCoreCodecLogEvent() as a nop, and will not require that the

CodecAdapter sub-class implement CoreCodecMetricsImplementation().

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

void SetCoreCodecAdapter (std::unique_ptr<CodecAdapter> codec_adapter)

The LocalCodecFactory calls this method once just after CodecImpl

construction and just before BindAsync().

There's only one CodecAdapter for the lifetime of the CodecImpl. This

mechanism intentionally doesn't permit switching input format to a

completely different format, and a CodecAdapter is free to reject any

format change it wants to reject. Before giving up, a client that uses

per-stream input format overrides should go around one more time with a

freshly created Codec created directly with the new format if the client

gets a Codec failure having overridden the input format on a stream of a

Codec such that the stream's input format doesn't exactly match the Codec's

input format (at least for now).

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

void SetCodecDiagnostics (CodecDiagnostics * codec_diagnostics)

The LocalCodecFactory optionally calls this method after SetCoreCodecAdapter() and before

CoreCodecInit(). This method is a passthrough to the underlying

CodecAdapter::SetCodecDiagnostics() method. Note that the codec does not retain any ownership

of the CodecDiagnostics. The pointer is guaranteed to live longer than the codec_impl and if

this method is called, the pointer will not be nullptr.

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

void BindAsync (fit::closure error_handler)

BindAsync()

This enables serving Codec (soon).

Must be called on shared_fidl_thread.

It remains permitted to cause ~CodecImpl (on shared_fidl_thread) after this call.

The core codec initialization and actual binding occur shortly later async after the start of

this call, possibly after this call has returned. This is to avoid core codec initialization

slowing down the shared_fidl_thread() which may be handling other stream data for a different

CodecImpl instance.

Any error, including those encountered before binding is fully complete, will call

error_handler on a clean stack on shared_fidl_thread(), after this call (also on

shared_fidl_thread()) returns. If the client code runs ~CodecImpl on shared_fidl_thread

instead (before error_handler has run on shared_fidl_thread), the error_handler will be deleted

without being run.

The error_handler runs on the fidl dispatcher (see CodecImpl constructor) and is expected to

trigger ~CodecImpl to run, either synchronously during error_handler(), or shortly after async.

In other words it's the responsibility of client code to delete the CodecImpl in a timely

manner during or soon after error_handler(). Until ~CodecImpl, the CodecAdmission won't be

released, and the channel itself won't be closed (intentionally, to ensure the old instance is

cleaned up before a new instance is created based on a client retry triggered by server channel

closure).

When either SetSharingFidlDomainForCoreCodec is called or IsSupportsDynamicBuffers() returns

true, client code must not run ~CodecImpl until error_handler is called. See also UnbindAsync

and ~CodecImpl.

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

void EnableOnStreamFailed ()

Codec interface

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

void SetInputBufferPartialSettings (fuchsia::media::StreamBufferPartialSettings input_settings)

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

void SetOutputBufferPartialSettings (fuchsia::media::StreamBufferPartialSettings output_settings)

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

void CompleteOutputBufferPartialSettings (uint64_t buffer_lifetime_ordinal)

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

void FlushEndOfStreamAndCloseStream (uint64_t stream_lifetime_ordinal)

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

void CloseCurrentStream (uint64_t stream_lifetime_ordinal, bool release_input_buffers, bool release_output_buffers)

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

void Sync (SyncCallback callback)

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

void RecycleOutputPacket (fuchsia::media::PacketHeader available_output_packet)

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

void QueueInputFormatDetails (uint64_t stream_lifetime_ordinal, fuchsia::media::FormatDetails format_details)

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

void QueueInputPacket (fuchsia::media::Packet packet)

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

void QueueInputEndOfStream (uint64_t stream_lifetime_ordinal)

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

void ParticipateInBufferAllocation (fuchsia::media::StreamProcessorParticipateInBufferAllocationRequest request)

These are not sent by correctly-operating clients unless

fuchsia.mediacodec/DetailedCodecDescription.supports_dynamic_buffers is set

to true. See codec_factory.fidl and stream_processor.fidl.

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

void AddBuffer (fuchsia::media::StreamProcessorAddBufferRequest request)

A correctly-operating client will only send this message if

DetailedCodecDescription.supports_dynamic_buffers was set to true.

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

void RemoveBuffer (fuchsia::media::StreamProcessorRemoveBufferRequest request, RemoveBufferCallback callback)

A correctly-operating client will only send this message if

DetailedCodecDescription.supports_dynamic_buffers was set to true.

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

void EnableOldOutputBuffers ()

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

void EnableSameOutputBufferConcurrentlyInFlight ()

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

void EnableForceOutputBuffersFixedImageSize ()

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

void handle_unknown_method (uint64_t ordinal, bool method_has_response)

Currently this will log and close the channel, because currently for a

protocol whose clients and servers are both "platform" and "external", the

abi_compat tool prevents adding a strict message, forcing all new

StreamProcessor messages to be added as "flexible". So currently we have to

assume every unrecognized message is logically strict despite not being

"strict" in FIDL.

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

zx_status_t Pin (uint32_t options, const zx::vmo & vmo, uint64_t offset, uint64_t size, zx_paddr_t * addrs, size_t addrs_count, zx::pmt * pmt)

This way CodecBuffer doesn't use the core_codec_bti_ directly.

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

void Fail (const char * format)

Complain sync, then Unbind() async. Even if more than one caller

complains, the async Unbind() work will only run once (but in such cases it

can be nice to see all the complaining in case multiple things fail at

once). While more than one source of failure can complain, only one will

actually trigger Unbind() work, and the rest will just return knowing that

Unbind() work is started. The Unbind() work itself will synchronize such

that other-thread sources of failure are no longer possible (can no longer

even complain) before deallocating "this".

Callers to Fail() must not be holding lock_. On return from Fail(), "this"

must not be touched as it can already be deallocated.

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

void FailLocked (const char * format)

Callers to FailLocked() must hold lock_ during the call. On return from

FailLocked(), the caller can know that "this" is still allocated only up

to the point where the caller releases lock_. Callers are encouraged not

to touch "this" after the call to FailLocked() besides releasing lock_,

for consistency with how Fail() is used; that said, the unlock itself is

safe.

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

void FailFatal (const char * format)

Report a devhost-fatal error. This method never returns - instead we

fault the whole process. This should only be used in cases where we

don't really expect an error, and where a client can't unilaterally induce

the error - but in case the error happens despite not being expected, we

want nice output that's easy to debug.

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

Protected Methods

bool IsFidl ()

Returns true iff the caller is running on the fidl sequence / ordering domain / thread.

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

bool IsStreamControl ()

Returns true iff the caller is running on the stream control sequence / ordering domain /

thread.

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

bool IsCoreCodec ()

When is_sharing_fidl_domain_for_core_codec_ or CaptureCoreCodecOrderingDomain has been called:

* Returns true iff the caller is running on the core codec sequence / ordering domain /

thread.

When !is_sharing_fidl_domain_for_core_codec_ and CaptureCoreCodecOrderingDomain hasn't been

called so far:

* Returns true iff the caller is not running on any other known sequences / ordering domains

/ threads.

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

Records