Skip to main content

fidl_fuchsia_mediacodec/
fidl_fuchsia_mediacodec.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_mediacodec_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct CodecFactoryAttachLifetimeTrackingRequest {
16    pub codec_end: fidl::EventPair,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for CodecFactoryAttachLifetimeTrackingRequest
21{
22}
23
24#[derive(Debug, PartialEq)]
25pub struct CodecFactoryCreateDecoderRequest {
26    pub decoder_params: CreateDecoderParams,
27    pub decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
28}
29
30impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
31    for CodecFactoryCreateDecoderRequest
32{
33}
34
35#[derive(Debug, PartialEq)]
36pub struct CodecFactoryCreateEncoderRequest {
37    pub encoder_params: CreateEncoderParams,
38    pub encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
39}
40
41impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
42    for CodecFactoryCreateEncoderRequest
43{
44}
45
46#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
47pub struct CodecFactoryMarker;
48
49impl fidl::endpoints::ProtocolMarker for CodecFactoryMarker {
50    type Proxy = CodecFactoryProxy;
51    type RequestStream = CodecFactoryRequestStream;
52    #[cfg(target_os = "fuchsia")]
53    type SynchronousProxy = CodecFactorySynchronousProxy;
54
55    const DEBUG_NAME: &'static str = "fuchsia.mediacodec.CodecFactory";
56}
57impl fidl::endpoints::DiscoverableProtocolMarker for CodecFactoryMarker {}
58
59pub trait CodecFactoryProxyInterface: Send + Sync {
60    type GetDetailedCodecDescriptionsResponseFut: std::future::Future<
61            Output = Result<CodecFactoryGetDetailedCodecDescriptionsResponse, fidl::Error>,
62        > + Send;
63    fn r#get_detailed_codec_descriptions(&self) -> Self::GetDetailedCodecDescriptionsResponseFut;
64    fn r#create_decoder(
65        &self,
66        decoder_params: &CreateDecoderParams,
67        decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
68    ) -> Result<(), fidl::Error>;
69    fn r#create_encoder(
70        &self,
71        encoder_params: &CreateEncoderParams,
72        encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
73    ) -> Result<(), fidl::Error>;
74    fn r#attach_lifetime_tracking(&self, codec_end: fidl::EventPair) -> Result<(), fidl::Error>;
75}
76#[derive(Debug)]
77#[cfg(target_os = "fuchsia")]
78pub struct CodecFactorySynchronousProxy {
79    client: fidl::client::sync::Client,
80}
81
82#[cfg(target_os = "fuchsia")]
83impl fidl::endpoints::SynchronousProxy for CodecFactorySynchronousProxy {
84    type Proxy = CodecFactoryProxy;
85    type Protocol = CodecFactoryMarker;
86
87    fn from_channel(inner: fidl::Channel) -> Self {
88        Self::new(inner)
89    }
90
91    fn into_channel(self) -> fidl::Channel {
92        self.client.into_channel()
93    }
94
95    fn as_channel(&self) -> &fidl::Channel {
96        self.client.as_channel()
97    }
98}
99
100#[cfg(target_os = "fuchsia")]
101impl CodecFactorySynchronousProxy {
102    pub fn new(channel: fidl::Channel) -> Self {
103        Self { client: fidl::client::sync::Client::new(channel) }
104    }
105
106    pub fn into_channel(self) -> fidl::Channel {
107        self.client.into_channel()
108    }
109
110    /// Waits until an event arrives and returns it. It is safe for other
111    /// threads to make concurrent requests while waiting for an event.
112    pub fn wait_for_event(
113        &self,
114        deadline: zx::MonotonicInstant,
115    ) -> Result<CodecFactoryEvent, fidl::Error> {
116        CodecFactoryEvent::decode(self.client.wait_for_event::<CodecFactoryMarker>(deadline)?)
117    }
118
119    /// A client should call |GetDetailedCodecDescriptions()| to get a list of
120    /// codecs supported either by software implementations or by underlying hardware.
121    pub fn r#get_detailed_codec_descriptions(
122        &self,
123        ___deadline: zx::MonotonicInstant,
124    ) -> Result<CodecFactoryGetDetailedCodecDescriptionsResponse, fidl::Error> {
125        let _response = self.client.send_query::<
126            fidl::encoding::EmptyPayload,
127            CodecFactoryGetDetailedCodecDescriptionsResponse,
128            CodecFactoryMarker,
129        >(
130            (),
131            0x7a3a1c956352d49a,
132            fidl::encoding::DynamicFlags::empty(),
133            ___deadline,
134        )?;
135        Ok(_response)
136    }
137
138    /// CreateDecoder:
139    ///
140    /// decoder_params - See CreateDecoder_Params comments for required
141    /// and optional parameters for creating a decoder.
142    ///
143    /// decoder - a Codec.NewRequest() which will hopefully be connected to
144    /// a Codec server, or the Codec channel will get closed if no suitable
145    /// codec can be found.  We don't return any additional Codec-specific
146    /// status here because finding the Codec is allowed to be fully async, so
147    /// we don't necessarily yet know on return from this method which Codec
148    /// will be selected, if any.
149    ///
150    /// Rough sequence to create a decoder:
151    ///
152    /// factory = ConnectToEnvironmentService(CodecFactory);
153    /// CreateDecoder_Params params;
154    /// [fill out params]
155    /// CreateDecoder(params, decoder_request);
156    ///
157    /// See use_media_decoder code for more detail.
158    pub fn r#create_decoder(
159        &self,
160        mut decoder_params: &CreateDecoderParams,
161        mut decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
162    ) -> Result<(), fidl::Error> {
163        self.client.send::<CodecFactoryCreateDecoderRequest>(
164            (decoder_params, decoder),
165            0x72a3c2035a1e94f0,
166            fidl::encoding::DynamicFlags::empty(),
167        )
168    }
169
170    /// CreateEncoder:
171    ///
172    /// encoder_params - See CreateEncoder_Params comments for required
173    /// and optional parameters for creating a decoder.
174    ///
175    /// encoder - a Codec.NewRequest() which will hopefully be connected to
176    /// a Codec server, or the Codec channel will get closed if no suitable
177    /// codec can be found.  We don't return any additional Codec-specific
178    /// status here because finding the Codec is allowed to be fully async, so
179    /// we don't necessarily yet know on return from this method which Codec
180    /// will be selected, if any.
181    pub fn r#create_encoder(
182        &self,
183        mut encoder_params: &CreateEncoderParams,
184        mut encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
185    ) -> Result<(), fidl::Error> {
186        self.client.send::<CodecFactoryCreateEncoderRequest>(
187            (encoder_params, encoder),
188            0x20c3a235602eed0f,
189            fidl::encoding::DynamicFlags::empty(),
190        )
191    }
192
193    /// AttachLifetimeTracking:
194    ///
195    /// Attach an eventpair endpoint to the next Create{X}(), so that the
196    /// codec_end will be closed when the number of buffers allocated reaches
197    /// 'buffers_remaining'.  Multiple eventpair endpoints can be attached per
198    /// create, with an enforced limit of
199    /// CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX.
200    ///
201    /// The lifetime signalled by this event is intended to track all resources
202    /// used by the codec, including sysmem-allocated buffers created internally
203    /// by the codec.  The sysmem buffer collections visible to the client, for
204    /// input and output buffers, are not included in the resources tracked
205    /// here, because those can be tracked separately via
206    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().  It is
207    /// permitted to send a duplicate of codec_end to both this
208    /// AttachLifetimeTracking() and also to
209    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().
210    /// The ZX_EVENTPAIR_PEER_CLOSED will happen when both/all lifetimes are
211    /// fully over.  This conveniently avoids needing multiple separate async
212    /// waits by the client.
213    ///
214    /// In the case of server process crashes, or failure of a codec to plumb
215    /// codec_end to sysmem, ZX_EVENTPAIR_PEER_CLOSED signalled on the peer of
216    /// codec_end may occur shortly before all resources are freed.
217    ///
218    /// A maximum of CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX
219    /// calls to AttachLifetimeTracking() are allowed
220    /// before any Create{X}().  There is no way to cancel an attach short of
221    /// closing the CodecFactory channel.  Closing the client end of the
222    /// eventpair doesn't subtract from the number of pending attach(es).  For
223    /// this reason, it can be good to only send attach message(s) immediately
224    /// before the relevant Create{X}(), when it's known by the client that both
225    /// the attach message(s) and the Create{X}() messages will be sent.
226    ///
227    /// Closing the client's end doesn't result in any action by the server.
228    /// If the server listens to events from the client end at all, it is for
229    /// debug logging only.
230    ///
231    /// The server intentionally doesn't "trust" any bits signalled by the
232    /// client.  This mechanism intentionally uses only ZX_EVENTPAIR_PEER_CLOSED
233    /// which can't be triggered early, and is only triggered when all handles
234    /// to codec_end are closed.  No meaning is associated with any of the other
235    /// signal bits, and clients should functionally ignore any other signal
236    /// bits on either end of the eventpair or its peer.
237    ///
238    /// The codec_end may lack ZX_RIGHT_SIGNAL or ZX_RIGHT_SIGNAL_PEER, but must
239    /// have ZX_RIGHT_DUPLICATE (and must have ZX_RIGHT_TRANSFER to transfer
240    /// without causing CodecFactory channel failure).
241    pub fn r#attach_lifetime_tracking(
242        &self,
243        mut codec_end: fidl::EventPair,
244    ) -> Result<(), fidl::Error> {
245        self.client.send::<CodecFactoryAttachLifetimeTrackingRequest>(
246            (codec_end,),
247            0x1086674ad2568498,
248            fidl::encoding::DynamicFlags::empty(),
249        )
250    }
251}
252
253#[cfg(target_os = "fuchsia")]
254impl From<CodecFactorySynchronousProxy> for zx::NullableHandle {
255    fn from(value: CodecFactorySynchronousProxy) -> Self {
256        value.into_channel().into()
257    }
258}
259
260#[cfg(target_os = "fuchsia")]
261impl From<fidl::Channel> for CodecFactorySynchronousProxy {
262    fn from(value: fidl::Channel) -> Self {
263        Self::new(value)
264    }
265}
266
267#[cfg(target_os = "fuchsia")]
268impl fidl::endpoints::FromClient for CodecFactorySynchronousProxy {
269    type Protocol = CodecFactoryMarker;
270
271    fn from_client(value: fidl::endpoints::ClientEnd<CodecFactoryMarker>) -> Self {
272        Self::new(value.into_channel())
273    }
274}
275
276#[derive(Debug, Clone)]
277pub struct CodecFactoryProxy {
278    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
279}
280
281impl fidl::endpoints::Proxy for CodecFactoryProxy {
282    type Protocol = CodecFactoryMarker;
283
284    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
285        Self::new(inner)
286    }
287
288    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
289        self.client.into_channel().map_err(|client| Self { client })
290    }
291
292    fn as_channel(&self) -> &::fidl::AsyncChannel {
293        self.client.as_channel()
294    }
295}
296
297impl CodecFactoryProxy {
298    /// Create a new Proxy for fuchsia.mediacodec/CodecFactory.
299    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
300        let protocol_name = <CodecFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
301        Self { client: fidl::client::Client::new(channel, protocol_name) }
302    }
303
304    /// Get a Stream of events from the remote end of the protocol.
305    ///
306    /// # Panics
307    ///
308    /// Panics if the event stream was already taken.
309    pub fn take_event_stream(&self) -> CodecFactoryEventStream {
310        CodecFactoryEventStream { event_receiver: self.client.take_event_receiver() }
311    }
312
313    /// A client should call |GetDetailedCodecDescriptions()| to get a list of
314    /// codecs supported either by software implementations or by underlying hardware.
315    pub fn r#get_detailed_codec_descriptions(
316        &self,
317    ) -> fidl::client::QueryResponseFut<
318        CodecFactoryGetDetailedCodecDescriptionsResponse,
319        fidl::encoding::DefaultFuchsiaResourceDialect,
320    > {
321        CodecFactoryProxyInterface::r#get_detailed_codec_descriptions(self)
322    }
323
324    /// CreateDecoder:
325    ///
326    /// decoder_params - See CreateDecoder_Params comments for required
327    /// and optional parameters for creating a decoder.
328    ///
329    /// decoder - a Codec.NewRequest() which will hopefully be connected to
330    /// a Codec server, or the Codec channel will get closed if no suitable
331    /// codec can be found.  We don't return any additional Codec-specific
332    /// status here because finding the Codec is allowed to be fully async, so
333    /// we don't necessarily yet know on return from this method which Codec
334    /// will be selected, if any.
335    ///
336    /// Rough sequence to create a decoder:
337    ///
338    /// factory = ConnectToEnvironmentService(CodecFactory);
339    /// CreateDecoder_Params params;
340    /// [fill out params]
341    /// CreateDecoder(params, decoder_request);
342    ///
343    /// See use_media_decoder code for more detail.
344    pub fn r#create_decoder(
345        &self,
346        mut decoder_params: &CreateDecoderParams,
347        mut decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
348    ) -> Result<(), fidl::Error> {
349        CodecFactoryProxyInterface::r#create_decoder(self, decoder_params, decoder)
350    }
351
352    /// CreateEncoder:
353    ///
354    /// encoder_params - See CreateEncoder_Params comments for required
355    /// and optional parameters for creating a decoder.
356    ///
357    /// encoder - a Codec.NewRequest() which will hopefully be connected to
358    /// a Codec server, or the Codec channel will get closed if no suitable
359    /// codec can be found.  We don't return any additional Codec-specific
360    /// status here because finding the Codec is allowed to be fully async, so
361    /// we don't necessarily yet know on return from this method which Codec
362    /// will be selected, if any.
363    pub fn r#create_encoder(
364        &self,
365        mut encoder_params: &CreateEncoderParams,
366        mut encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
367    ) -> Result<(), fidl::Error> {
368        CodecFactoryProxyInterface::r#create_encoder(self, encoder_params, encoder)
369    }
370
371    /// AttachLifetimeTracking:
372    ///
373    /// Attach an eventpair endpoint to the next Create{X}(), so that the
374    /// codec_end will be closed when the number of buffers allocated reaches
375    /// 'buffers_remaining'.  Multiple eventpair endpoints can be attached per
376    /// create, with an enforced limit of
377    /// CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX.
378    ///
379    /// The lifetime signalled by this event is intended to track all resources
380    /// used by the codec, including sysmem-allocated buffers created internally
381    /// by the codec.  The sysmem buffer collections visible to the client, for
382    /// input and output buffers, are not included in the resources tracked
383    /// here, because those can be tracked separately via
384    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().  It is
385    /// permitted to send a duplicate of codec_end to both this
386    /// AttachLifetimeTracking() and also to
387    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().
388    /// The ZX_EVENTPAIR_PEER_CLOSED will happen when both/all lifetimes are
389    /// fully over.  This conveniently avoids needing multiple separate async
390    /// waits by the client.
391    ///
392    /// In the case of server process crashes, or failure of a codec to plumb
393    /// codec_end to sysmem, ZX_EVENTPAIR_PEER_CLOSED signalled on the peer of
394    /// codec_end may occur shortly before all resources are freed.
395    ///
396    /// A maximum of CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX
397    /// calls to AttachLifetimeTracking() are allowed
398    /// before any Create{X}().  There is no way to cancel an attach short of
399    /// closing the CodecFactory channel.  Closing the client end of the
400    /// eventpair doesn't subtract from the number of pending attach(es).  For
401    /// this reason, it can be good to only send attach message(s) immediately
402    /// before the relevant Create{X}(), when it's known by the client that both
403    /// the attach message(s) and the Create{X}() messages will be sent.
404    ///
405    /// Closing the client's end doesn't result in any action by the server.
406    /// If the server listens to events from the client end at all, it is for
407    /// debug logging only.
408    ///
409    /// The server intentionally doesn't "trust" any bits signalled by the
410    /// client.  This mechanism intentionally uses only ZX_EVENTPAIR_PEER_CLOSED
411    /// which can't be triggered early, and is only triggered when all handles
412    /// to codec_end are closed.  No meaning is associated with any of the other
413    /// signal bits, and clients should functionally ignore any other signal
414    /// bits on either end of the eventpair or its peer.
415    ///
416    /// The codec_end may lack ZX_RIGHT_SIGNAL or ZX_RIGHT_SIGNAL_PEER, but must
417    /// have ZX_RIGHT_DUPLICATE (and must have ZX_RIGHT_TRANSFER to transfer
418    /// without causing CodecFactory channel failure).
419    pub fn r#attach_lifetime_tracking(
420        &self,
421        mut codec_end: fidl::EventPair,
422    ) -> Result<(), fidl::Error> {
423        CodecFactoryProxyInterface::r#attach_lifetime_tracking(self, codec_end)
424    }
425}
426
427impl CodecFactoryProxyInterface for CodecFactoryProxy {
428    type GetDetailedCodecDescriptionsResponseFut = fidl::client::QueryResponseFut<
429        CodecFactoryGetDetailedCodecDescriptionsResponse,
430        fidl::encoding::DefaultFuchsiaResourceDialect,
431    >;
432    fn r#get_detailed_codec_descriptions(&self) -> Self::GetDetailedCodecDescriptionsResponseFut {
433        fn _decode(
434            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
435        ) -> Result<CodecFactoryGetDetailedCodecDescriptionsResponse, fidl::Error> {
436            let _response = fidl::client::decode_transaction_body::<
437                CodecFactoryGetDetailedCodecDescriptionsResponse,
438                fidl::encoding::DefaultFuchsiaResourceDialect,
439                0x7a3a1c956352d49a,
440            >(_buf?)?;
441            Ok(_response)
442        }
443        self.client.send_query_and_decode::<
444            fidl::encoding::EmptyPayload,
445            CodecFactoryGetDetailedCodecDescriptionsResponse,
446        >(
447            (),
448            0x7a3a1c956352d49a,
449            fidl::encoding::DynamicFlags::empty(),
450            _decode,
451        )
452    }
453
454    fn r#create_decoder(
455        &self,
456        mut decoder_params: &CreateDecoderParams,
457        mut decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
458    ) -> Result<(), fidl::Error> {
459        self.client.send::<CodecFactoryCreateDecoderRequest>(
460            (decoder_params, decoder),
461            0x72a3c2035a1e94f0,
462            fidl::encoding::DynamicFlags::empty(),
463        )
464    }
465
466    fn r#create_encoder(
467        &self,
468        mut encoder_params: &CreateEncoderParams,
469        mut encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
470    ) -> Result<(), fidl::Error> {
471        self.client.send::<CodecFactoryCreateEncoderRequest>(
472            (encoder_params, encoder),
473            0x20c3a235602eed0f,
474            fidl::encoding::DynamicFlags::empty(),
475        )
476    }
477
478    fn r#attach_lifetime_tracking(
479        &self,
480        mut codec_end: fidl::EventPair,
481    ) -> Result<(), fidl::Error> {
482        self.client.send::<CodecFactoryAttachLifetimeTrackingRequest>(
483            (codec_end,),
484            0x1086674ad2568498,
485            fidl::encoding::DynamicFlags::empty(),
486        )
487    }
488}
489
490pub struct CodecFactoryEventStream {
491    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
492}
493
494impl std::marker::Unpin for CodecFactoryEventStream {}
495
496impl futures::stream::FusedStream for CodecFactoryEventStream {
497    fn is_terminated(&self) -> bool {
498        self.event_receiver.is_terminated()
499    }
500}
501
502impl futures::Stream for CodecFactoryEventStream {
503    type Item = Result<CodecFactoryEvent, fidl::Error>;
504
505    fn poll_next(
506        mut self: std::pin::Pin<&mut Self>,
507        cx: &mut std::task::Context<'_>,
508    ) -> std::task::Poll<Option<Self::Item>> {
509        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
510            &mut self.event_receiver,
511            cx
512        )?) {
513            Some(buf) => std::task::Poll::Ready(Some(CodecFactoryEvent::decode(buf))),
514            None => std::task::Poll::Ready(None),
515        }
516    }
517}
518
519#[derive(Debug)]
520pub enum CodecFactoryEvent {
521    OnCodecList {
522        codecs: Vec<CodecDescription>,
523    },
524    #[non_exhaustive]
525    _UnknownEvent {
526        /// Ordinal of the event that was sent.
527        ordinal: u64,
528    },
529}
530
531impl CodecFactoryEvent {
532    #[allow(irrefutable_let_patterns)]
533    pub fn into_on_codec_list(self) -> Option<Vec<CodecDescription>> {
534        if let CodecFactoryEvent::OnCodecList { codecs } = self { Some((codecs)) } else { None }
535    }
536
537    /// Decodes a message buffer as a [`CodecFactoryEvent`].
538    fn decode(
539        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
540    ) -> Result<CodecFactoryEvent, fidl::Error> {
541        let (bytes, _handles) = buf.split_mut();
542        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
543        debug_assert_eq!(tx_header.tx_id, 0);
544        match tx_header.ordinal {
545            0x2f93e3d51ff1ace0 => {
546                let mut out = fidl::new_empty!(
547                    CodecFactoryOnCodecListRequest,
548                    fidl::encoding::DefaultFuchsiaResourceDialect
549                );
550                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryOnCodecListRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
551                Ok((CodecFactoryEvent::OnCodecList { codecs: out.codecs }))
552            }
553            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
554                Ok(CodecFactoryEvent::_UnknownEvent { ordinal: tx_header.ordinal })
555            }
556            _ => Err(fidl::Error::UnknownOrdinal {
557                ordinal: tx_header.ordinal,
558                protocol_name: <CodecFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
559            }),
560        }
561    }
562}
563
564/// A Stream of incoming requests for fuchsia.mediacodec/CodecFactory.
565pub struct CodecFactoryRequestStream {
566    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
567    is_terminated: bool,
568}
569
570impl std::marker::Unpin for CodecFactoryRequestStream {}
571
572impl futures::stream::FusedStream for CodecFactoryRequestStream {
573    fn is_terminated(&self) -> bool {
574        self.is_terminated
575    }
576}
577
578impl fidl::endpoints::RequestStream for CodecFactoryRequestStream {
579    type Protocol = CodecFactoryMarker;
580    type ControlHandle = CodecFactoryControlHandle;
581
582    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
583        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
584    }
585
586    fn control_handle(&self) -> Self::ControlHandle {
587        CodecFactoryControlHandle { inner: self.inner.clone() }
588    }
589
590    fn into_inner(
591        self,
592    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
593    {
594        (self.inner, self.is_terminated)
595    }
596
597    fn from_inner(
598        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
599        is_terminated: bool,
600    ) -> Self {
601        Self { inner, is_terminated }
602    }
603}
604
605impl futures::Stream for CodecFactoryRequestStream {
606    type Item = Result<CodecFactoryRequest, fidl::Error>;
607
608    fn poll_next(
609        mut self: std::pin::Pin<&mut Self>,
610        cx: &mut std::task::Context<'_>,
611    ) -> std::task::Poll<Option<Self::Item>> {
612        let this = &mut *self;
613        if this.inner.check_shutdown(cx) {
614            this.is_terminated = true;
615            return std::task::Poll::Ready(None);
616        }
617        if this.is_terminated {
618            panic!("polled CodecFactoryRequestStream after completion");
619        }
620        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
621            |bytes, handles| {
622                match this.inner.channel().read_etc(cx, bytes, handles) {
623                    std::task::Poll::Ready(Ok(())) => {}
624                    std::task::Poll::Pending => return std::task::Poll::Pending,
625                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
626                        this.is_terminated = true;
627                        return std::task::Poll::Ready(None);
628                    }
629                    std::task::Poll::Ready(Err(e)) => {
630                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
631                            e.into(),
632                        ))));
633                    }
634                }
635
636                // A message has been received from the channel
637                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
638
639                std::task::Poll::Ready(Some(match header.ordinal {
640                    0x7a3a1c956352d49a => {
641                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
642                        let mut req = fidl::new_empty!(
643                            fidl::encoding::EmptyPayload,
644                            fidl::encoding::DefaultFuchsiaResourceDialect
645                        );
646                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
647                        let control_handle =
648                            CodecFactoryControlHandle { inner: this.inner.clone() };
649                        Ok(CodecFactoryRequest::GetDetailedCodecDescriptions {
650                            responder: CodecFactoryGetDetailedCodecDescriptionsResponder {
651                                control_handle: std::mem::ManuallyDrop::new(control_handle),
652                                tx_id: header.tx_id,
653                            },
654                        })
655                    }
656                    0x72a3c2035a1e94f0 => {
657                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
658                        let mut req = fidl::new_empty!(
659                            CodecFactoryCreateDecoderRequest,
660                            fidl::encoding::DefaultFuchsiaResourceDialect
661                        );
662                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryCreateDecoderRequest>(&header, _body_bytes, handles, &mut req)?;
663                        let control_handle =
664                            CodecFactoryControlHandle { inner: this.inner.clone() };
665                        Ok(CodecFactoryRequest::CreateDecoder {
666                            decoder_params: req.decoder_params,
667                            decoder: req.decoder,
668
669                            control_handle,
670                        })
671                    }
672                    0x20c3a235602eed0f => {
673                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
674                        let mut req = fidl::new_empty!(
675                            CodecFactoryCreateEncoderRequest,
676                            fidl::encoding::DefaultFuchsiaResourceDialect
677                        );
678                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryCreateEncoderRequest>(&header, _body_bytes, handles, &mut req)?;
679                        let control_handle =
680                            CodecFactoryControlHandle { inner: this.inner.clone() };
681                        Ok(CodecFactoryRequest::CreateEncoder {
682                            encoder_params: req.encoder_params,
683                            encoder: req.encoder,
684
685                            control_handle,
686                        })
687                    }
688                    0x1086674ad2568498 => {
689                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
690                        let mut req = fidl::new_empty!(
691                            CodecFactoryAttachLifetimeTrackingRequest,
692                            fidl::encoding::DefaultFuchsiaResourceDialect
693                        );
694                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryAttachLifetimeTrackingRequest>(&header, _body_bytes, handles, &mut req)?;
695                        let control_handle =
696                            CodecFactoryControlHandle { inner: this.inner.clone() };
697                        Ok(CodecFactoryRequest::AttachLifetimeTracking {
698                            codec_end: req.codec_end,
699
700                            control_handle,
701                        })
702                    }
703                    _ if header.tx_id == 0
704                        && header
705                            .dynamic_flags()
706                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
707                    {
708                        Ok(CodecFactoryRequest::_UnknownMethod {
709                            ordinal: header.ordinal,
710                            control_handle: CodecFactoryControlHandle { inner: this.inner.clone() },
711                            method_type: fidl::MethodType::OneWay,
712                        })
713                    }
714                    _ if header
715                        .dynamic_flags()
716                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
717                    {
718                        this.inner.send_framework_err(
719                            fidl::encoding::FrameworkErr::UnknownMethod,
720                            header.tx_id,
721                            header.ordinal,
722                            header.dynamic_flags(),
723                            (bytes, handles),
724                        )?;
725                        Ok(CodecFactoryRequest::_UnknownMethod {
726                            ordinal: header.ordinal,
727                            control_handle: CodecFactoryControlHandle { inner: this.inner.clone() },
728                            method_type: fidl::MethodType::TwoWay,
729                        })
730                    }
731                    _ => Err(fidl::Error::UnknownOrdinal {
732                        ordinal: header.ordinal,
733                        protocol_name:
734                            <CodecFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
735                    }),
736                }))
737            },
738        )
739    }
740}
741
742/// The purpose of the media::CodecFactory interface is to create
743/// media::StreamProcessor instances for decoders and encoders.
744///
745/// The interface methods don't attempt to homogenize all codec types,
746/// preferring to have a separate dedicated message for decoders.
747#[derive(Debug)]
748pub enum CodecFactoryRequest {
749    /// A client should call |GetDetailedCodecDescriptions()| to get a list of
750    /// codecs supported either by software implementations or by underlying hardware.
751    GetDetailedCodecDescriptions { responder: CodecFactoryGetDetailedCodecDescriptionsResponder },
752    /// CreateDecoder:
753    ///
754    /// decoder_params - See CreateDecoder_Params comments for required
755    /// and optional parameters for creating a decoder.
756    ///
757    /// decoder - a Codec.NewRequest() which will hopefully be connected to
758    /// a Codec server, or the Codec channel will get closed if no suitable
759    /// codec can be found.  We don't return any additional Codec-specific
760    /// status here because finding the Codec is allowed to be fully async, so
761    /// we don't necessarily yet know on return from this method which Codec
762    /// will be selected, if any.
763    ///
764    /// Rough sequence to create a decoder:
765    ///
766    /// factory = ConnectToEnvironmentService(CodecFactory);
767    /// CreateDecoder_Params params;
768    /// [fill out params]
769    /// CreateDecoder(params, decoder_request);
770    ///
771    /// See use_media_decoder code for more detail.
772    CreateDecoder {
773        decoder_params: CreateDecoderParams,
774        decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
775        control_handle: CodecFactoryControlHandle,
776    },
777    /// CreateEncoder:
778    ///
779    /// encoder_params - See CreateEncoder_Params comments for required
780    /// and optional parameters for creating a decoder.
781    ///
782    /// encoder - a Codec.NewRequest() which will hopefully be connected to
783    /// a Codec server, or the Codec channel will get closed if no suitable
784    /// codec can be found.  We don't return any additional Codec-specific
785    /// status here because finding the Codec is allowed to be fully async, so
786    /// we don't necessarily yet know on return from this method which Codec
787    /// will be selected, if any.
788    CreateEncoder {
789        encoder_params: CreateEncoderParams,
790        encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
791        control_handle: CodecFactoryControlHandle,
792    },
793    /// AttachLifetimeTracking:
794    ///
795    /// Attach an eventpair endpoint to the next Create{X}(), so that the
796    /// codec_end will be closed when the number of buffers allocated reaches
797    /// 'buffers_remaining'.  Multiple eventpair endpoints can be attached per
798    /// create, with an enforced limit of
799    /// CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX.
800    ///
801    /// The lifetime signalled by this event is intended to track all resources
802    /// used by the codec, including sysmem-allocated buffers created internally
803    /// by the codec.  The sysmem buffer collections visible to the client, for
804    /// input and output buffers, are not included in the resources tracked
805    /// here, because those can be tracked separately via
806    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().  It is
807    /// permitted to send a duplicate of codec_end to both this
808    /// AttachLifetimeTracking() and also to
809    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().
810    /// The ZX_EVENTPAIR_PEER_CLOSED will happen when both/all lifetimes are
811    /// fully over.  This conveniently avoids needing multiple separate async
812    /// waits by the client.
813    ///
814    /// In the case of server process crashes, or failure of a codec to plumb
815    /// codec_end to sysmem, ZX_EVENTPAIR_PEER_CLOSED signalled on the peer of
816    /// codec_end may occur shortly before all resources are freed.
817    ///
818    /// A maximum of CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX
819    /// calls to AttachLifetimeTracking() are allowed
820    /// before any Create{X}().  There is no way to cancel an attach short of
821    /// closing the CodecFactory channel.  Closing the client end of the
822    /// eventpair doesn't subtract from the number of pending attach(es).  For
823    /// this reason, it can be good to only send attach message(s) immediately
824    /// before the relevant Create{X}(), when it's known by the client that both
825    /// the attach message(s) and the Create{X}() messages will be sent.
826    ///
827    /// Closing the client's end doesn't result in any action by the server.
828    /// If the server listens to events from the client end at all, it is for
829    /// debug logging only.
830    ///
831    /// The server intentionally doesn't "trust" any bits signalled by the
832    /// client.  This mechanism intentionally uses only ZX_EVENTPAIR_PEER_CLOSED
833    /// which can't be triggered early, and is only triggered when all handles
834    /// to codec_end are closed.  No meaning is associated with any of the other
835    /// signal bits, and clients should functionally ignore any other signal
836    /// bits on either end of the eventpair or its peer.
837    ///
838    /// The codec_end may lack ZX_RIGHT_SIGNAL or ZX_RIGHT_SIGNAL_PEER, but must
839    /// have ZX_RIGHT_DUPLICATE (and must have ZX_RIGHT_TRANSFER to transfer
840    /// without causing CodecFactory channel failure).
841    AttachLifetimeTracking { codec_end: fidl::EventPair, control_handle: CodecFactoryControlHandle },
842    /// An interaction was received which does not match any known method.
843    #[non_exhaustive]
844    _UnknownMethod {
845        /// Ordinal of the method that was called.
846        ordinal: u64,
847        control_handle: CodecFactoryControlHandle,
848        method_type: fidl::MethodType,
849    },
850}
851
852impl CodecFactoryRequest {
853    #[allow(irrefutable_let_patterns)]
854    pub fn into_get_detailed_codec_descriptions(
855        self,
856    ) -> Option<(CodecFactoryGetDetailedCodecDescriptionsResponder)> {
857        if let CodecFactoryRequest::GetDetailedCodecDescriptions { responder } = self {
858            Some((responder))
859        } else {
860            None
861        }
862    }
863
864    #[allow(irrefutable_let_patterns)]
865    pub fn into_create_decoder(
866        self,
867    ) -> Option<(
868        CreateDecoderParams,
869        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
870        CodecFactoryControlHandle,
871    )> {
872        if let CodecFactoryRequest::CreateDecoder { decoder_params, decoder, control_handle } = self
873        {
874            Some((decoder_params, decoder, control_handle))
875        } else {
876            None
877        }
878    }
879
880    #[allow(irrefutable_let_patterns)]
881    pub fn into_create_encoder(
882        self,
883    ) -> Option<(
884        CreateEncoderParams,
885        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
886        CodecFactoryControlHandle,
887    )> {
888        if let CodecFactoryRequest::CreateEncoder { encoder_params, encoder, control_handle } = self
889        {
890            Some((encoder_params, encoder, control_handle))
891        } else {
892            None
893        }
894    }
895
896    #[allow(irrefutable_let_patterns)]
897    pub fn into_attach_lifetime_tracking(
898        self,
899    ) -> Option<(fidl::EventPair, CodecFactoryControlHandle)> {
900        if let CodecFactoryRequest::AttachLifetimeTracking { codec_end, control_handle } = self {
901            Some((codec_end, control_handle))
902        } else {
903            None
904        }
905    }
906
907    /// Name of the method defined in FIDL
908    pub fn method_name(&self) -> &'static str {
909        match *self {
910            CodecFactoryRequest::GetDetailedCodecDescriptions { .. } => {
911                "get_detailed_codec_descriptions"
912            }
913            CodecFactoryRequest::CreateDecoder { .. } => "create_decoder",
914            CodecFactoryRequest::CreateEncoder { .. } => "create_encoder",
915            CodecFactoryRequest::AttachLifetimeTracking { .. } => "attach_lifetime_tracking",
916            CodecFactoryRequest::_UnknownMethod {
917                method_type: fidl::MethodType::OneWay, ..
918            } => "unknown one-way method",
919            CodecFactoryRequest::_UnknownMethod {
920                method_type: fidl::MethodType::TwoWay, ..
921            } => "unknown two-way method",
922        }
923    }
924}
925
926#[derive(Debug, Clone)]
927pub struct CodecFactoryControlHandle {
928    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
929}
930
931impl CodecFactoryControlHandle {
932    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
933        self.inner.shutdown_with_epitaph(status.into())
934    }
935}
936
937impl fidl::endpoints::ControlHandle for CodecFactoryControlHandle {
938    fn shutdown(&self) {
939        self.inner.shutdown()
940    }
941
942    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
943        self.inner.shutdown_with_epitaph(status)
944    }
945
946    fn is_closed(&self) -> bool {
947        self.inner.channel().is_closed()
948    }
949    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
950        self.inner.channel().on_closed()
951    }
952
953    #[cfg(target_os = "fuchsia")]
954    fn signal_peer(
955        &self,
956        clear_mask: zx::Signals,
957        set_mask: zx::Signals,
958    ) -> Result<(), zx_status::Status> {
959        use fidl::Peered;
960        self.inner.channel().signal_peer(clear_mask, set_mask)
961    }
962}
963
964impl CodecFactoryControlHandle {
965    pub fn send_on_codec_list(&self, mut codecs: &[CodecDescription]) -> Result<(), fidl::Error> {
966        self.inner.send::<CodecFactoryOnCodecListRequest>(
967            (codecs,),
968            0,
969            0x2f93e3d51ff1ace0,
970            fidl::encoding::DynamicFlags::empty(),
971        )
972    }
973}
974
975#[must_use = "FIDL methods require a response to be sent"]
976#[derive(Debug)]
977pub struct CodecFactoryGetDetailedCodecDescriptionsResponder {
978    control_handle: std::mem::ManuallyDrop<CodecFactoryControlHandle>,
979    tx_id: u32,
980}
981
982/// Set the the channel to be shutdown (see [`CodecFactoryControlHandle::shutdown`])
983/// if the responder is dropped without sending a response, so that the client
984/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
985impl std::ops::Drop for CodecFactoryGetDetailedCodecDescriptionsResponder {
986    fn drop(&mut self) {
987        self.control_handle.shutdown();
988        // Safety: drops once, never accessed again
989        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
990    }
991}
992
993impl fidl::endpoints::Responder for CodecFactoryGetDetailedCodecDescriptionsResponder {
994    type ControlHandle = CodecFactoryControlHandle;
995
996    fn control_handle(&self) -> &CodecFactoryControlHandle {
997        &self.control_handle
998    }
999
1000    fn drop_without_shutdown(mut self) {
1001        // Safety: drops once, never accessed again due to mem::forget
1002        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1003        // Prevent Drop from running (which would shut down the channel)
1004        std::mem::forget(self);
1005    }
1006}
1007
1008impl CodecFactoryGetDetailedCodecDescriptionsResponder {
1009    /// Sends a response to the FIDL transaction.
1010    ///
1011    /// Sets the channel to shutdown if an error occurs.
1012    pub fn send(
1013        self,
1014        mut payload: &CodecFactoryGetDetailedCodecDescriptionsResponse,
1015    ) -> Result<(), fidl::Error> {
1016        let _result = self.send_raw(payload);
1017        if _result.is_err() {
1018            self.control_handle.shutdown();
1019        }
1020        self.drop_without_shutdown();
1021        _result
1022    }
1023
1024    /// Similar to "send" but does not shutdown the channel if an error occurs.
1025    pub fn send_no_shutdown_on_err(
1026        self,
1027        mut payload: &CodecFactoryGetDetailedCodecDescriptionsResponse,
1028    ) -> Result<(), fidl::Error> {
1029        let _result = self.send_raw(payload);
1030        self.drop_without_shutdown();
1031        _result
1032    }
1033
1034    fn send_raw(
1035        &self,
1036        mut payload: &CodecFactoryGetDetailedCodecDescriptionsResponse,
1037    ) -> Result<(), fidl::Error> {
1038        self.control_handle.inner.send::<CodecFactoryGetDetailedCodecDescriptionsResponse>(
1039            payload,
1040            self.tx_id,
1041            0x7a3a1c956352d49a,
1042            fidl::encoding::DynamicFlags::empty(),
1043        )
1044    }
1045}
1046
1047mod internal {
1048    use super::*;
1049
1050    impl fidl::encoding::ResourceTypeMarker for CodecFactoryAttachLifetimeTrackingRequest {
1051        type Borrowed<'a> = &'a mut Self;
1052        fn take_or_borrow<'a>(
1053            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1054        ) -> Self::Borrowed<'a> {
1055            value
1056        }
1057    }
1058
1059    unsafe impl fidl::encoding::TypeMarker for CodecFactoryAttachLifetimeTrackingRequest {
1060        type Owned = Self;
1061
1062        #[inline(always)]
1063        fn inline_align(_context: fidl::encoding::Context) -> usize {
1064            4
1065        }
1066
1067        #[inline(always)]
1068        fn inline_size(_context: fidl::encoding::Context) -> usize {
1069            4
1070        }
1071    }
1072
1073    unsafe impl
1074        fidl::encoding::Encode<
1075            CodecFactoryAttachLifetimeTrackingRequest,
1076            fidl::encoding::DefaultFuchsiaResourceDialect,
1077        > for &mut CodecFactoryAttachLifetimeTrackingRequest
1078    {
1079        #[inline]
1080        unsafe fn encode(
1081            self,
1082            encoder: &mut fidl::encoding::Encoder<
1083                '_,
1084                fidl::encoding::DefaultFuchsiaResourceDialect,
1085            >,
1086            offset: usize,
1087            _depth: fidl::encoding::Depth,
1088        ) -> fidl::Result<()> {
1089            encoder.debug_check_bounds::<CodecFactoryAttachLifetimeTrackingRequest>(offset);
1090            // Delegate to tuple encoding.
1091            fidl::encoding::Encode::<
1092                CodecFactoryAttachLifetimeTrackingRequest,
1093                fidl::encoding::DefaultFuchsiaResourceDialect,
1094            >::encode(
1095                (<fidl::encoding::HandleType<
1096                    fidl::EventPair,
1097                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1098                    2147483648,
1099                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1100                    &mut self.codec_end
1101                ),),
1102                encoder,
1103                offset,
1104                _depth,
1105            )
1106        }
1107    }
1108    unsafe impl<
1109        T0: fidl::encoding::Encode<
1110                fidl::encoding::HandleType<
1111                    fidl::EventPair,
1112                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1113                    2147483648,
1114                >,
1115                fidl::encoding::DefaultFuchsiaResourceDialect,
1116            >,
1117    >
1118        fidl::encoding::Encode<
1119            CodecFactoryAttachLifetimeTrackingRequest,
1120            fidl::encoding::DefaultFuchsiaResourceDialect,
1121        > for (T0,)
1122    {
1123        #[inline]
1124        unsafe fn encode(
1125            self,
1126            encoder: &mut fidl::encoding::Encoder<
1127                '_,
1128                fidl::encoding::DefaultFuchsiaResourceDialect,
1129            >,
1130            offset: usize,
1131            depth: fidl::encoding::Depth,
1132        ) -> fidl::Result<()> {
1133            encoder.debug_check_bounds::<CodecFactoryAttachLifetimeTrackingRequest>(offset);
1134            // Zero out padding regions. There's no need to apply masks
1135            // because the unmasked parts will be overwritten by fields.
1136            // Write the fields.
1137            self.0.encode(encoder, offset + 0, depth)?;
1138            Ok(())
1139        }
1140    }
1141
1142    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1143        for CodecFactoryAttachLifetimeTrackingRequest
1144    {
1145        #[inline(always)]
1146        fn new_empty() -> Self {
1147            Self {
1148                codec_end: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
1149            }
1150        }
1151
1152        #[inline]
1153        unsafe fn decode(
1154            &mut self,
1155            decoder: &mut fidl::encoding::Decoder<
1156                '_,
1157                fidl::encoding::DefaultFuchsiaResourceDialect,
1158            >,
1159            offset: usize,
1160            _depth: fidl::encoding::Depth,
1161        ) -> fidl::Result<()> {
1162            decoder.debug_check_bounds::<Self>(offset);
1163            // Verify that padding bytes are zero.
1164            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.codec_end, decoder, offset + 0, _depth)?;
1165            Ok(())
1166        }
1167    }
1168
1169    impl fidl::encoding::ResourceTypeMarker for CodecFactoryCreateDecoderRequest {
1170        type Borrowed<'a> = &'a mut Self;
1171        fn take_or_borrow<'a>(
1172            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1173        ) -> Self::Borrowed<'a> {
1174            value
1175        }
1176    }
1177
1178    unsafe impl fidl::encoding::TypeMarker for CodecFactoryCreateDecoderRequest {
1179        type Owned = Self;
1180
1181        #[inline(always)]
1182        fn inline_align(_context: fidl::encoding::Context) -> usize {
1183            8
1184        }
1185
1186        #[inline(always)]
1187        fn inline_size(_context: fidl::encoding::Context) -> usize {
1188            24
1189        }
1190    }
1191
1192    unsafe impl
1193        fidl::encoding::Encode<
1194            CodecFactoryCreateDecoderRequest,
1195            fidl::encoding::DefaultFuchsiaResourceDialect,
1196        > for &mut CodecFactoryCreateDecoderRequest
1197    {
1198        #[inline]
1199        unsafe fn encode(
1200            self,
1201            encoder: &mut fidl::encoding::Encoder<
1202                '_,
1203                fidl::encoding::DefaultFuchsiaResourceDialect,
1204            >,
1205            offset: usize,
1206            _depth: fidl::encoding::Depth,
1207        ) -> fidl::Result<()> {
1208            encoder.debug_check_bounds::<CodecFactoryCreateDecoderRequest>(offset);
1209            // Delegate to tuple encoding.
1210            fidl::encoding::Encode::<
1211                CodecFactoryCreateDecoderRequest,
1212                fidl::encoding::DefaultFuchsiaResourceDialect,
1213            >::encode(
1214                (
1215                    <CreateDecoderParams as fidl::encoding::ValueTypeMarker>::borrow(
1216                        &self.decoder_params,
1217                    ),
1218                    <fidl::encoding::Endpoint<
1219                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1220                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1221                        &mut self.decoder
1222                    ),
1223                ),
1224                encoder,
1225                offset,
1226                _depth,
1227            )
1228        }
1229    }
1230    unsafe impl<
1231        T0: fidl::encoding::Encode<CreateDecoderParams, fidl::encoding::DefaultFuchsiaResourceDialect>,
1232        T1: fidl::encoding::Encode<
1233                fidl::encoding::Endpoint<
1234                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1235                >,
1236                fidl::encoding::DefaultFuchsiaResourceDialect,
1237            >,
1238    >
1239        fidl::encoding::Encode<
1240            CodecFactoryCreateDecoderRequest,
1241            fidl::encoding::DefaultFuchsiaResourceDialect,
1242        > for (T0, T1)
1243    {
1244        #[inline]
1245        unsafe fn encode(
1246            self,
1247            encoder: &mut fidl::encoding::Encoder<
1248                '_,
1249                fidl::encoding::DefaultFuchsiaResourceDialect,
1250            >,
1251            offset: usize,
1252            depth: fidl::encoding::Depth,
1253        ) -> fidl::Result<()> {
1254            encoder.debug_check_bounds::<CodecFactoryCreateDecoderRequest>(offset);
1255            // Zero out padding regions. There's no need to apply masks
1256            // because the unmasked parts will be overwritten by fields.
1257            unsafe {
1258                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1259                (ptr as *mut u64).write_unaligned(0);
1260            }
1261            // Write the fields.
1262            self.0.encode(encoder, offset + 0, depth)?;
1263            self.1.encode(encoder, offset + 16, depth)?;
1264            Ok(())
1265        }
1266    }
1267
1268    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1269        for CodecFactoryCreateDecoderRequest
1270    {
1271        #[inline(always)]
1272        fn new_empty() -> Self {
1273            Self {
1274                decoder_params: fidl::new_empty!(
1275                    CreateDecoderParams,
1276                    fidl::encoding::DefaultFuchsiaResourceDialect
1277                ),
1278                decoder: fidl::new_empty!(
1279                    fidl::encoding::Endpoint<
1280                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1281                    >,
1282                    fidl::encoding::DefaultFuchsiaResourceDialect
1283                ),
1284            }
1285        }
1286
1287        #[inline]
1288        unsafe fn decode(
1289            &mut self,
1290            decoder: &mut fidl::encoding::Decoder<
1291                '_,
1292                fidl::encoding::DefaultFuchsiaResourceDialect,
1293            >,
1294            offset: usize,
1295            _depth: fidl::encoding::Depth,
1296        ) -> fidl::Result<()> {
1297            decoder.debug_check_bounds::<Self>(offset);
1298            // Verify that padding bytes are zero.
1299            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1300            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1301            let mask = 0xffffffff00000000u64;
1302            let maskedval = padval & mask;
1303            if maskedval != 0 {
1304                return Err(fidl::Error::NonZeroPadding {
1305                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1306                });
1307            }
1308            fidl::decode!(
1309                CreateDecoderParams,
1310                fidl::encoding::DefaultFuchsiaResourceDialect,
1311                &mut self.decoder_params,
1312                decoder,
1313                offset + 0,
1314                _depth
1315            )?;
1316            fidl::decode!(
1317                fidl::encoding::Endpoint<
1318                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1319                >,
1320                fidl::encoding::DefaultFuchsiaResourceDialect,
1321                &mut self.decoder,
1322                decoder,
1323                offset + 16,
1324                _depth
1325            )?;
1326            Ok(())
1327        }
1328    }
1329
1330    impl fidl::encoding::ResourceTypeMarker for CodecFactoryCreateEncoderRequest {
1331        type Borrowed<'a> = &'a mut Self;
1332        fn take_or_borrow<'a>(
1333            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1334        ) -> Self::Borrowed<'a> {
1335            value
1336        }
1337    }
1338
1339    unsafe impl fidl::encoding::TypeMarker for CodecFactoryCreateEncoderRequest {
1340        type Owned = Self;
1341
1342        #[inline(always)]
1343        fn inline_align(_context: fidl::encoding::Context) -> usize {
1344            8
1345        }
1346
1347        #[inline(always)]
1348        fn inline_size(_context: fidl::encoding::Context) -> usize {
1349            24
1350        }
1351    }
1352
1353    unsafe impl
1354        fidl::encoding::Encode<
1355            CodecFactoryCreateEncoderRequest,
1356            fidl::encoding::DefaultFuchsiaResourceDialect,
1357        > for &mut CodecFactoryCreateEncoderRequest
1358    {
1359        #[inline]
1360        unsafe fn encode(
1361            self,
1362            encoder: &mut fidl::encoding::Encoder<
1363                '_,
1364                fidl::encoding::DefaultFuchsiaResourceDialect,
1365            >,
1366            offset: usize,
1367            _depth: fidl::encoding::Depth,
1368        ) -> fidl::Result<()> {
1369            encoder.debug_check_bounds::<CodecFactoryCreateEncoderRequest>(offset);
1370            // Delegate to tuple encoding.
1371            fidl::encoding::Encode::<
1372                CodecFactoryCreateEncoderRequest,
1373                fidl::encoding::DefaultFuchsiaResourceDialect,
1374            >::encode(
1375                (
1376                    <CreateEncoderParams as fidl::encoding::ValueTypeMarker>::borrow(
1377                        &self.encoder_params,
1378                    ),
1379                    <fidl::encoding::Endpoint<
1380                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1381                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1382                        &mut self.encoder
1383                    ),
1384                ),
1385                encoder,
1386                offset,
1387                _depth,
1388            )
1389        }
1390    }
1391    unsafe impl<
1392        T0: fidl::encoding::Encode<CreateEncoderParams, fidl::encoding::DefaultFuchsiaResourceDialect>,
1393        T1: fidl::encoding::Encode<
1394                fidl::encoding::Endpoint<
1395                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1396                >,
1397                fidl::encoding::DefaultFuchsiaResourceDialect,
1398            >,
1399    >
1400        fidl::encoding::Encode<
1401            CodecFactoryCreateEncoderRequest,
1402            fidl::encoding::DefaultFuchsiaResourceDialect,
1403        > for (T0, T1)
1404    {
1405        #[inline]
1406        unsafe fn encode(
1407            self,
1408            encoder: &mut fidl::encoding::Encoder<
1409                '_,
1410                fidl::encoding::DefaultFuchsiaResourceDialect,
1411            >,
1412            offset: usize,
1413            depth: fidl::encoding::Depth,
1414        ) -> fidl::Result<()> {
1415            encoder.debug_check_bounds::<CodecFactoryCreateEncoderRequest>(offset);
1416            // Zero out padding regions. There's no need to apply masks
1417            // because the unmasked parts will be overwritten by fields.
1418            unsafe {
1419                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1420                (ptr as *mut u64).write_unaligned(0);
1421            }
1422            // Write the fields.
1423            self.0.encode(encoder, offset + 0, depth)?;
1424            self.1.encode(encoder, offset + 16, depth)?;
1425            Ok(())
1426        }
1427    }
1428
1429    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1430        for CodecFactoryCreateEncoderRequest
1431    {
1432        #[inline(always)]
1433        fn new_empty() -> Self {
1434            Self {
1435                encoder_params: fidl::new_empty!(
1436                    CreateEncoderParams,
1437                    fidl::encoding::DefaultFuchsiaResourceDialect
1438                ),
1439                encoder: fidl::new_empty!(
1440                    fidl::encoding::Endpoint<
1441                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1442                    >,
1443                    fidl::encoding::DefaultFuchsiaResourceDialect
1444                ),
1445            }
1446        }
1447
1448        #[inline]
1449        unsafe fn decode(
1450            &mut self,
1451            decoder: &mut fidl::encoding::Decoder<
1452                '_,
1453                fidl::encoding::DefaultFuchsiaResourceDialect,
1454            >,
1455            offset: usize,
1456            _depth: fidl::encoding::Depth,
1457        ) -> fidl::Result<()> {
1458            decoder.debug_check_bounds::<Self>(offset);
1459            // Verify that padding bytes are zero.
1460            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1461            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1462            let mask = 0xffffffff00000000u64;
1463            let maskedval = padval & mask;
1464            if maskedval != 0 {
1465                return Err(fidl::Error::NonZeroPadding {
1466                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1467                });
1468            }
1469            fidl::decode!(
1470                CreateEncoderParams,
1471                fidl::encoding::DefaultFuchsiaResourceDialect,
1472                &mut self.encoder_params,
1473                decoder,
1474                offset + 0,
1475                _depth
1476            )?;
1477            fidl::decode!(
1478                fidl::encoding::Endpoint<
1479                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1480                >,
1481                fidl::encoding::DefaultFuchsiaResourceDialect,
1482                &mut self.encoder,
1483                decoder,
1484                offset + 16,
1485                _depth
1486            )?;
1487            Ok(())
1488        }
1489    }
1490}