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        let protocol_name = <CodecFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
104        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
105    }
106
107    pub fn into_channel(self) -> fidl::Channel {
108        self.client.into_channel()
109    }
110
111    /// Waits until an event arrives and returns it. It is safe for other
112    /// threads to make concurrent requests while waiting for an event.
113    pub fn wait_for_event(
114        &self,
115        deadline: zx::MonotonicInstant,
116    ) -> Result<CodecFactoryEvent, fidl::Error> {
117        CodecFactoryEvent::decode(self.client.wait_for_event(deadline)?)
118    }
119
120    /// A client should call |GetDetailedCodecDescriptions()| to get a list of
121    /// codecs supported either by software implementations or by underlying hardware.
122    pub fn r#get_detailed_codec_descriptions(
123        &self,
124        ___deadline: zx::MonotonicInstant,
125    ) -> Result<CodecFactoryGetDetailedCodecDescriptionsResponse, fidl::Error> {
126        let _response = self.client.send_query::<
127            fidl::encoding::EmptyPayload,
128            CodecFactoryGetDetailedCodecDescriptionsResponse,
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::Handle {
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 { codecs: Vec<CodecDescription> },
522}
523
524impl CodecFactoryEvent {
525    #[allow(irrefutable_let_patterns)]
526    pub fn into_on_codec_list(self) -> Option<Vec<CodecDescription>> {
527        if let CodecFactoryEvent::OnCodecList { codecs } = self {
528            Some((codecs))
529        } else {
530            None
531        }
532    }
533
534    /// Decodes a message buffer as a [`CodecFactoryEvent`].
535    fn decode(
536        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
537    ) -> Result<CodecFactoryEvent, fidl::Error> {
538        let (bytes, _handles) = buf.split_mut();
539        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
540        debug_assert_eq!(tx_header.tx_id, 0);
541        match tx_header.ordinal {
542            0x2f93e3d51ff1ace0 => {
543                let mut out = fidl::new_empty!(
544                    CodecFactoryOnCodecListRequest,
545                    fidl::encoding::DefaultFuchsiaResourceDialect
546                );
547                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryOnCodecListRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
548                Ok((CodecFactoryEvent::OnCodecList { codecs: out.codecs }))
549            }
550            _ => Err(fidl::Error::UnknownOrdinal {
551                ordinal: tx_header.ordinal,
552                protocol_name: <CodecFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
553            }),
554        }
555    }
556}
557
558/// A Stream of incoming requests for fuchsia.mediacodec/CodecFactory.
559pub struct CodecFactoryRequestStream {
560    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
561    is_terminated: bool,
562}
563
564impl std::marker::Unpin for CodecFactoryRequestStream {}
565
566impl futures::stream::FusedStream for CodecFactoryRequestStream {
567    fn is_terminated(&self) -> bool {
568        self.is_terminated
569    }
570}
571
572impl fidl::endpoints::RequestStream for CodecFactoryRequestStream {
573    type Protocol = CodecFactoryMarker;
574    type ControlHandle = CodecFactoryControlHandle;
575
576    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
577        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
578    }
579
580    fn control_handle(&self) -> Self::ControlHandle {
581        CodecFactoryControlHandle { inner: self.inner.clone() }
582    }
583
584    fn into_inner(
585        self,
586    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
587    {
588        (self.inner, self.is_terminated)
589    }
590
591    fn from_inner(
592        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
593        is_terminated: bool,
594    ) -> Self {
595        Self { inner, is_terminated }
596    }
597}
598
599impl futures::Stream for CodecFactoryRequestStream {
600    type Item = Result<CodecFactoryRequest, fidl::Error>;
601
602    fn poll_next(
603        mut self: std::pin::Pin<&mut Self>,
604        cx: &mut std::task::Context<'_>,
605    ) -> std::task::Poll<Option<Self::Item>> {
606        let this = &mut *self;
607        if this.inner.check_shutdown(cx) {
608            this.is_terminated = true;
609            return std::task::Poll::Ready(None);
610        }
611        if this.is_terminated {
612            panic!("polled CodecFactoryRequestStream after completion");
613        }
614        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
615            |bytes, handles| {
616                match this.inner.channel().read_etc(cx, bytes, handles) {
617                    std::task::Poll::Ready(Ok(())) => {}
618                    std::task::Poll::Pending => return std::task::Poll::Pending,
619                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
620                        this.is_terminated = true;
621                        return std::task::Poll::Ready(None);
622                    }
623                    std::task::Poll::Ready(Err(e)) => {
624                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
625                            e.into(),
626                        ))))
627                    }
628                }
629
630                // A message has been received from the channel
631                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
632
633                std::task::Poll::Ready(Some(match header.ordinal {
634                    0x7a3a1c956352d49a => {
635                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
636                        let mut req = fidl::new_empty!(
637                            fidl::encoding::EmptyPayload,
638                            fidl::encoding::DefaultFuchsiaResourceDialect
639                        );
640                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
641                        let control_handle =
642                            CodecFactoryControlHandle { inner: this.inner.clone() };
643                        Ok(CodecFactoryRequest::GetDetailedCodecDescriptions {
644                            responder: CodecFactoryGetDetailedCodecDescriptionsResponder {
645                                control_handle: std::mem::ManuallyDrop::new(control_handle),
646                                tx_id: header.tx_id,
647                            },
648                        })
649                    }
650                    0x72a3c2035a1e94f0 => {
651                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
652                        let mut req = fidl::new_empty!(
653                            CodecFactoryCreateDecoderRequest,
654                            fidl::encoding::DefaultFuchsiaResourceDialect
655                        );
656                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryCreateDecoderRequest>(&header, _body_bytes, handles, &mut req)?;
657                        let control_handle =
658                            CodecFactoryControlHandle { inner: this.inner.clone() };
659                        Ok(CodecFactoryRequest::CreateDecoder {
660                            decoder_params: req.decoder_params,
661                            decoder: req.decoder,
662
663                            control_handle,
664                        })
665                    }
666                    0x20c3a235602eed0f => {
667                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
668                        let mut req = fidl::new_empty!(
669                            CodecFactoryCreateEncoderRequest,
670                            fidl::encoding::DefaultFuchsiaResourceDialect
671                        );
672                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryCreateEncoderRequest>(&header, _body_bytes, handles, &mut req)?;
673                        let control_handle =
674                            CodecFactoryControlHandle { inner: this.inner.clone() };
675                        Ok(CodecFactoryRequest::CreateEncoder {
676                            encoder_params: req.encoder_params,
677                            encoder: req.encoder,
678
679                            control_handle,
680                        })
681                    }
682                    0x1086674ad2568498 => {
683                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
684                        let mut req = fidl::new_empty!(
685                            CodecFactoryAttachLifetimeTrackingRequest,
686                            fidl::encoding::DefaultFuchsiaResourceDialect
687                        );
688                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecFactoryAttachLifetimeTrackingRequest>(&header, _body_bytes, handles, &mut req)?;
689                        let control_handle =
690                            CodecFactoryControlHandle { inner: this.inner.clone() };
691                        Ok(CodecFactoryRequest::AttachLifetimeTracking {
692                            codec_end: req.codec_end,
693
694                            control_handle,
695                        })
696                    }
697                    _ => Err(fidl::Error::UnknownOrdinal {
698                        ordinal: header.ordinal,
699                        protocol_name:
700                            <CodecFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
701                    }),
702                }))
703            },
704        )
705    }
706}
707
708/// The purpose of the media::CodecFactory interface is to create
709/// media::StreamProcessor instances for decoders and encoders.
710///
711/// The interface methods don't attempt to homogenize all codec types,
712/// preferring to have a separate dedicated message for decoders.
713#[derive(Debug)]
714pub enum CodecFactoryRequest {
715    /// A client should call |GetDetailedCodecDescriptions()| to get a list of
716    /// codecs supported either by software implementations or by underlying hardware.
717    GetDetailedCodecDescriptions { responder: CodecFactoryGetDetailedCodecDescriptionsResponder },
718    /// CreateDecoder:
719    ///
720    /// decoder_params - See CreateDecoder_Params comments for required
721    /// and optional parameters for creating a decoder.
722    ///
723    /// decoder - a Codec.NewRequest() which will hopefully be connected to
724    /// a Codec server, or the Codec channel will get closed if no suitable
725    /// codec can be found.  We don't return any additional Codec-specific
726    /// status here because finding the Codec is allowed to be fully async, so
727    /// we don't necessarily yet know on return from this method which Codec
728    /// will be selected, if any.
729    ///
730    /// Rough sequence to create a decoder:
731    ///
732    /// factory = ConnectToEnvironmentService(CodecFactory);
733    /// CreateDecoder_Params params;
734    /// [fill out params]
735    /// CreateDecoder(params, decoder_request);
736    ///
737    /// See use_media_decoder code for more detail.
738    CreateDecoder {
739        decoder_params: CreateDecoderParams,
740        decoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
741        control_handle: CodecFactoryControlHandle,
742    },
743    /// CreateEncoder:
744    ///
745    /// encoder_params - See CreateEncoder_Params comments for required
746    /// and optional parameters for creating a decoder.
747    ///
748    /// encoder - a Codec.NewRequest() which will hopefully be connected to
749    /// a Codec server, or the Codec channel will get closed if no suitable
750    /// codec can be found.  We don't return any additional Codec-specific
751    /// status here because finding the Codec is allowed to be fully async, so
752    /// we don't necessarily yet know on return from this method which Codec
753    /// will be selected, if any.
754    CreateEncoder {
755        encoder_params: CreateEncoderParams,
756        encoder: fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
757        control_handle: CodecFactoryControlHandle,
758    },
759    /// AttachLifetimeTracking:
760    ///
761    /// Attach an eventpair endpoint to the next Create{X}(), so that the
762    /// codec_end will be closed when the number of buffers allocated reaches
763    /// 'buffers_remaining'.  Multiple eventpair endpoints can be attached per
764    /// create, with an enforced limit of
765    /// CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX.
766    ///
767    /// The lifetime signalled by this event is intended to track all resources
768    /// used by the codec, including sysmem-allocated buffers created internally
769    /// by the codec.  The sysmem buffer collections visible to the client, for
770    /// input and output buffers, are not included in the resources tracked
771    /// here, because those can be tracked separately via
772    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().  It is
773    /// permitted to send a duplicate of codec_end to both this
774    /// AttachLifetimeTracking() and also to
775    /// fuchsia.sysmem.BufferCollection.AttachLifetimeTracking().
776    /// The ZX_EVENTPAIR_PEER_CLOSED will happen when both/all lifetimes are
777    /// fully over.  This conveniently avoids needing multiple separate async
778    /// waits by the client.
779    ///
780    /// In the case of server process crashes, or failure of a codec to plumb
781    /// codec_end to sysmem, ZX_EVENTPAIR_PEER_CLOSED signalled on the peer of
782    /// codec_end may occur shortly before all resources are freed.
783    ///
784    /// A maximum of CODEC_FACTORY_LIFETIME_TRACKING_EVENTPAIR_PER_CREATE_MAX
785    /// calls to AttachLifetimeTracking() are allowed
786    /// before any Create{X}().  There is no way to cancel an attach short of
787    /// closing the CodecFactory channel.  Closing the client end of the
788    /// eventpair doesn't subtract from the number of pending attach(es).  For
789    /// this reason, it can be good to only send attach message(s) immediately
790    /// before the relevant Create{X}(), when it's known by the client that both
791    /// the attach message(s) and the Create{X}() messages will be sent.
792    ///
793    /// Closing the client's end doesn't result in any action by the server.
794    /// If the server listens to events from the client end at all, it is for
795    /// debug logging only.
796    ///
797    /// The server intentionally doesn't "trust" any bits signalled by the
798    /// client.  This mechanism intentionally uses only ZX_EVENTPAIR_PEER_CLOSED
799    /// which can't be triggered early, and is only triggered when all handles
800    /// to codec_end are closed.  No meaning is associated with any of the other
801    /// signal bits, and clients should functionally ignore any other signal
802    /// bits on either end of the eventpair or its peer.
803    ///
804    /// The codec_end may lack ZX_RIGHT_SIGNAL or ZX_RIGHT_SIGNAL_PEER, but must
805    /// have ZX_RIGHT_DUPLICATE (and must have ZX_RIGHT_TRANSFER to transfer
806    /// without causing CodecFactory channel failure).
807    AttachLifetimeTracking { codec_end: fidl::EventPair, control_handle: CodecFactoryControlHandle },
808}
809
810impl CodecFactoryRequest {
811    #[allow(irrefutable_let_patterns)]
812    pub fn into_get_detailed_codec_descriptions(
813        self,
814    ) -> Option<(CodecFactoryGetDetailedCodecDescriptionsResponder)> {
815        if let CodecFactoryRequest::GetDetailedCodecDescriptions { responder } = self {
816            Some((responder))
817        } else {
818            None
819        }
820    }
821
822    #[allow(irrefutable_let_patterns)]
823    pub fn into_create_decoder(
824        self,
825    ) -> Option<(
826        CreateDecoderParams,
827        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
828        CodecFactoryControlHandle,
829    )> {
830        if let CodecFactoryRequest::CreateDecoder { decoder_params, decoder, control_handle } = self
831        {
832            Some((decoder_params, decoder, control_handle))
833        } else {
834            None
835        }
836    }
837
838    #[allow(irrefutable_let_patterns)]
839    pub fn into_create_encoder(
840        self,
841    ) -> Option<(
842        CreateEncoderParams,
843        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
844        CodecFactoryControlHandle,
845    )> {
846        if let CodecFactoryRequest::CreateEncoder { encoder_params, encoder, control_handle } = self
847        {
848            Some((encoder_params, encoder, control_handle))
849        } else {
850            None
851        }
852    }
853
854    #[allow(irrefutable_let_patterns)]
855    pub fn into_attach_lifetime_tracking(
856        self,
857    ) -> Option<(fidl::EventPair, CodecFactoryControlHandle)> {
858        if let CodecFactoryRequest::AttachLifetimeTracking { codec_end, control_handle } = self {
859            Some((codec_end, control_handle))
860        } else {
861            None
862        }
863    }
864
865    /// Name of the method defined in FIDL
866    pub fn method_name(&self) -> &'static str {
867        match *self {
868            CodecFactoryRequest::GetDetailedCodecDescriptions { .. } => {
869                "get_detailed_codec_descriptions"
870            }
871            CodecFactoryRequest::CreateDecoder { .. } => "create_decoder",
872            CodecFactoryRequest::CreateEncoder { .. } => "create_encoder",
873            CodecFactoryRequest::AttachLifetimeTracking { .. } => "attach_lifetime_tracking",
874        }
875    }
876}
877
878#[derive(Debug, Clone)]
879pub struct CodecFactoryControlHandle {
880    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
881}
882
883impl fidl::endpoints::ControlHandle for CodecFactoryControlHandle {
884    fn shutdown(&self) {
885        self.inner.shutdown()
886    }
887    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
888        self.inner.shutdown_with_epitaph(status)
889    }
890
891    fn is_closed(&self) -> bool {
892        self.inner.channel().is_closed()
893    }
894    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
895        self.inner.channel().on_closed()
896    }
897
898    #[cfg(target_os = "fuchsia")]
899    fn signal_peer(
900        &self,
901        clear_mask: zx::Signals,
902        set_mask: zx::Signals,
903    ) -> Result<(), zx_status::Status> {
904        use fidl::Peered;
905        self.inner.channel().signal_peer(clear_mask, set_mask)
906    }
907}
908
909impl CodecFactoryControlHandle {
910    pub fn send_on_codec_list(&self, mut codecs: &[CodecDescription]) -> Result<(), fidl::Error> {
911        self.inner.send::<CodecFactoryOnCodecListRequest>(
912            (codecs,),
913            0,
914            0x2f93e3d51ff1ace0,
915            fidl::encoding::DynamicFlags::empty(),
916        )
917    }
918}
919
920#[must_use = "FIDL methods require a response to be sent"]
921#[derive(Debug)]
922pub struct CodecFactoryGetDetailedCodecDescriptionsResponder {
923    control_handle: std::mem::ManuallyDrop<CodecFactoryControlHandle>,
924    tx_id: u32,
925}
926
927/// Set the the channel to be shutdown (see [`CodecFactoryControlHandle::shutdown`])
928/// if the responder is dropped without sending a response, so that the client
929/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
930impl std::ops::Drop for CodecFactoryGetDetailedCodecDescriptionsResponder {
931    fn drop(&mut self) {
932        self.control_handle.shutdown();
933        // Safety: drops once, never accessed again
934        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
935    }
936}
937
938impl fidl::endpoints::Responder for CodecFactoryGetDetailedCodecDescriptionsResponder {
939    type ControlHandle = CodecFactoryControlHandle;
940
941    fn control_handle(&self) -> &CodecFactoryControlHandle {
942        &self.control_handle
943    }
944
945    fn drop_without_shutdown(mut self) {
946        // Safety: drops once, never accessed again due to mem::forget
947        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
948        // Prevent Drop from running (which would shut down the channel)
949        std::mem::forget(self);
950    }
951}
952
953impl CodecFactoryGetDetailedCodecDescriptionsResponder {
954    /// Sends a response to the FIDL transaction.
955    ///
956    /// Sets the channel to shutdown if an error occurs.
957    pub fn send(
958        self,
959        mut payload: &CodecFactoryGetDetailedCodecDescriptionsResponse,
960    ) -> Result<(), fidl::Error> {
961        let _result = self.send_raw(payload);
962        if _result.is_err() {
963            self.control_handle.shutdown();
964        }
965        self.drop_without_shutdown();
966        _result
967    }
968
969    /// Similar to "send" but does not shutdown the channel if an error occurs.
970    pub fn send_no_shutdown_on_err(
971        self,
972        mut payload: &CodecFactoryGetDetailedCodecDescriptionsResponse,
973    ) -> Result<(), fidl::Error> {
974        let _result = self.send_raw(payload);
975        self.drop_without_shutdown();
976        _result
977    }
978
979    fn send_raw(
980        &self,
981        mut payload: &CodecFactoryGetDetailedCodecDescriptionsResponse,
982    ) -> Result<(), fidl::Error> {
983        self.control_handle.inner.send::<CodecFactoryGetDetailedCodecDescriptionsResponse>(
984            payload,
985            self.tx_id,
986            0x7a3a1c956352d49a,
987            fidl::encoding::DynamicFlags::empty(),
988        )
989    }
990}
991
992mod internal {
993    use super::*;
994
995    impl fidl::encoding::ResourceTypeMarker for CodecFactoryAttachLifetimeTrackingRequest {
996        type Borrowed<'a> = &'a mut Self;
997        fn take_or_borrow<'a>(
998            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
999        ) -> Self::Borrowed<'a> {
1000            value
1001        }
1002    }
1003
1004    unsafe impl fidl::encoding::TypeMarker for CodecFactoryAttachLifetimeTrackingRequest {
1005        type Owned = Self;
1006
1007        #[inline(always)]
1008        fn inline_align(_context: fidl::encoding::Context) -> usize {
1009            4
1010        }
1011
1012        #[inline(always)]
1013        fn inline_size(_context: fidl::encoding::Context) -> usize {
1014            4
1015        }
1016    }
1017
1018    unsafe impl
1019        fidl::encoding::Encode<
1020            CodecFactoryAttachLifetimeTrackingRequest,
1021            fidl::encoding::DefaultFuchsiaResourceDialect,
1022        > for &mut CodecFactoryAttachLifetimeTrackingRequest
1023    {
1024        #[inline]
1025        unsafe fn encode(
1026            self,
1027            encoder: &mut fidl::encoding::Encoder<
1028                '_,
1029                fidl::encoding::DefaultFuchsiaResourceDialect,
1030            >,
1031            offset: usize,
1032            _depth: fidl::encoding::Depth,
1033        ) -> fidl::Result<()> {
1034            encoder.debug_check_bounds::<CodecFactoryAttachLifetimeTrackingRequest>(offset);
1035            // Delegate to tuple encoding.
1036            fidl::encoding::Encode::<
1037                CodecFactoryAttachLifetimeTrackingRequest,
1038                fidl::encoding::DefaultFuchsiaResourceDialect,
1039            >::encode(
1040                (<fidl::encoding::HandleType<
1041                    fidl::EventPair,
1042                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1043                    2147483648,
1044                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1045                    &mut self.codec_end
1046                ),),
1047                encoder,
1048                offset,
1049                _depth,
1050            )
1051        }
1052    }
1053    unsafe impl<
1054            T0: fidl::encoding::Encode<
1055                fidl::encoding::HandleType<
1056                    fidl::EventPair,
1057                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1058                    2147483648,
1059                >,
1060                fidl::encoding::DefaultFuchsiaResourceDialect,
1061            >,
1062        >
1063        fidl::encoding::Encode<
1064            CodecFactoryAttachLifetimeTrackingRequest,
1065            fidl::encoding::DefaultFuchsiaResourceDialect,
1066        > for (T0,)
1067    {
1068        #[inline]
1069        unsafe fn encode(
1070            self,
1071            encoder: &mut fidl::encoding::Encoder<
1072                '_,
1073                fidl::encoding::DefaultFuchsiaResourceDialect,
1074            >,
1075            offset: usize,
1076            depth: fidl::encoding::Depth,
1077        ) -> fidl::Result<()> {
1078            encoder.debug_check_bounds::<CodecFactoryAttachLifetimeTrackingRequest>(offset);
1079            // Zero out padding regions. There's no need to apply masks
1080            // because the unmasked parts will be overwritten by fields.
1081            // Write the fields.
1082            self.0.encode(encoder, offset + 0, depth)?;
1083            Ok(())
1084        }
1085    }
1086
1087    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1088        for CodecFactoryAttachLifetimeTrackingRequest
1089    {
1090        #[inline(always)]
1091        fn new_empty() -> Self {
1092            Self {
1093                codec_end: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
1094            }
1095        }
1096
1097        #[inline]
1098        unsafe fn decode(
1099            &mut self,
1100            decoder: &mut fidl::encoding::Decoder<
1101                '_,
1102                fidl::encoding::DefaultFuchsiaResourceDialect,
1103            >,
1104            offset: usize,
1105            _depth: fidl::encoding::Depth,
1106        ) -> fidl::Result<()> {
1107            decoder.debug_check_bounds::<Self>(offset);
1108            // Verify that padding bytes are zero.
1109            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.codec_end, decoder, offset + 0, _depth)?;
1110            Ok(())
1111        }
1112    }
1113
1114    impl fidl::encoding::ResourceTypeMarker for CodecFactoryCreateDecoderRequest {
1115        type Borrowed<'a> = &'a mut Self;
1116        fn take_or_borrow<'a>(
1117            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1118        ) -> Self::Borrowed<'a> {
1119            value
1120        }
1121    }
1122
1123    unsafe impl fidl::encoding::TypeMarker for CodecFactoryCreateDecoderRequest {
1124        type Owned = Self;
1125
1126        #[inline(always)]
1127        fn inline_align(_context: fidl::encoding::Context) -> usize {
1128            8
1129        }
1130
1131        #[inline(always)]
1132        fn inline_size(_context: fidl::encoding::Context) -> usize {
1133            24
1134        }
1135    }
1136
1137    unsafe impl
1138        fidl::encoding::Encode<
1139            CodecFactoryCreateDecoderRequest,
1140            fidl::encoding::DefaultFuchsiaResourceDialect,
1141        > for &mut CodecFactoryCreateDecoderRequest
1142    {
1143        #[inline]
1144        unsafe fn encode(
1145            self,
1146            encoder: &mut fidl::encoding::Encoder<
1147                '_,
1148                fidl::encoding::DefaultFuchsiaResourceDialect,
1149            >,
1150            offset: usize,
1151            _depth: fidl::encoding::Depth,
1152        ) -> fidl::Result<()> {
1153            encoder.debug_check_bounds::<CodecFactoryCreateDecoderRequest>(offset);
1154            // Delegate to tuple encoding.
1155            fidl::encoding::Encode::<
1156                CodecFactoryCreateDecoderRequest,
1157                fidl::encoding::DefaultFuchsiaResourceDialect,
1158            >::encode(
1159                (
1160                    <CreateDecoderParams as fidl::encoding::ValueTypeMarker>::borrow(
1161                        &self.decoder_params,
1162                    ),
1163                    <fidl::encoding::Endpoint<
1164                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1165                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1166                        &mut self.decoder
1167                    ),
1168                ),
1169                encoder,
1170                offset,
1171                _depth,
1172            )
1173        }
1174    }
1175    unsafe impl<
1176            T0: fidl::encoding::Encode<
1177                CreateDecoderParams,
1178                fidl::encoding::DefaultFuchsiaResourceDialect,
1179            >,
1180            T1: fidl::encoding::Encode<
1181                fidl::encoding::Endpoint<
1182                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1183                >,
1184                fidl::encoding::DefaultFuchsiaResourceDialect,
1185            >,
1186        >
1187        fidl::encoding::Encode<
1188            CodecFactoryCreateDecoderRequest,
1189            fidl::encoding::DefaultFuchsiaResourceDialect,
1190        > for (T0, T1)
1191    {
1192        #[inline]
1193        unsafe fn encode(
1194            self,
1195            encoder: &mut fidl::encoding::Encoder<
1196                '_,
1197                fidl::encoding::DefaultFuchsiaResourceDialect,
1198            >,
1199            offset: usize,
1200            depth: fidl::encoding::Depth,
1201        ) -> fidl::Result<()> {
1202            encoder.debug_check_bounds::<CodecFactoryCreateDecoderRequest>(offset);
1203            // Zero out padding regions. There's no need to apply masks
1204            // because the unmasked parts will be overwritten by fields.
1205            unsafe {
1206                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1207                (ptr as *mut u64).write_unaligned(0);
1208            }
1209            // Write the fields.
1210            self.0.encode(encoder, offset + 0, depth)?;
1211            self.1.encode(encoder, offset + 16, depth)?;
1212            Ok(())
1213        }
1214    }
1215
1216    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1217        for CodecFactoryCreateDecoderRequest
1218    {
1219        #[inline(always)]
1220        fn new_empty() -> Self {
1221            Self {
1222                decoder_params: fidl::new_empty!(
1223                    CreateDecoderParams,
1224                    fidl::encoding::DefaultFuchsiaResourceDialect
1225                ),
1226                decoder: fidl::new_empty!(
1227                    fidl::encoding::Endpoint<
1228                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1229                    >,
1230                    fidl::encoding::DefaultFuchsiaResourceDialect
1231                ),
1232            }
1233        }
1234
1235        #[inline]
1236        unsafe fn decode(
1237            &mut self,
1238            decoder: &mut fidl::encoding::Decoder<
1239                '_,
1240                fidl::encoding::DefaultFuchsiaResourceDialect,
1241            >,
1242            offset: usize,
1243            _depth: fidl::encoding::Depth,
1244        ) -> fidl::Result<()> {
1245            decoder.debug_check_bounds::<Self>(offset);
1246            // Verify that padding bytes are zero.
1247            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1248            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1249            let mask = 0xffffffff00000000u64;
1250            let maskedval = padval & mask;
1251            if maskedval != 0 {
1252                return Err(fidl::Error::NonZeroPadding {
1253                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1254                });
1255            }
1256            fidl::decode!(
1257                CreateDecoderParams,
1258                fidl::encoding::DefaultFuchsiaResourceDialect,
1259                &mut self.decoder_params,
1260                decoder,
1261                offset + 0,
1262                _depth
1263            )?;
1264            fidl::decode!(
1265                fidl::encoding::Endpoint<
1266                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1267                >,
1268                fidl::encoding::DefaultFuchsiaResourceDialect,
1269                &mut self.decoder,
1270                decoder,
1271                offset + 16,
1272                _depth
1273            )?;
1274            Ok(())
1275        }
1276    }
1277
1278    impl fidl::encoding::ResourceTypeMarker for CodecFactoryCreateEncoderRequest {
1279        type Borrowed<'a> = &'a mut Self;
1280        fn take_or_borrow<'a>(
1281            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1282        ) -> Self::Borrowed<'a> {
1283            value
1284        }
1285    }
1286
1287    unsafe impl fidl::encoding::TypeMarker for CodecFactoryCreateEncoderRequest {
1288        type Owned = Self;
1289
1290        #[inline(always)]
1291        fn inline_align(_context: fidl::encoding::Context) -> usize {
1292            8
1293        }
1294
1295        #[inline(always)]
1296        fn inline_size(_context: fidl::encoding::Context) -> usize {
1297            24
1298        }
1299    }
1300
1301    unsafe impl
1302        fidl::encoding::Encode<
1303            CodecFactoryCreateEncoderRequest,
1304            fidl::encoding::DefaultFuchsiaResourceDialect,
1305        > for &mut CodecFactoryCreateEncoderRequest
1306    {
1307        #[inline]
1308        unsafe fn encode(
1309            self,
1310            encoder: &mut fidl::encoding::Encoder<
1311                '_,
1312                fidl::encoding::DefaultFuchsiaResourceDialect,
1313            >,
1314            offset: usize,
1315            _depth: fidl::encoding::Depth,
1316        ) -> fidl::Result<()> {
1317            encoder.debug_check_bounds::<CodecFactoryCreateEncoderRequest>(offset);
1318            // Delegate to tuple encoding.
1319            fidl::encoding::Encode::<
1320                CodecFactoryCreateEncoderRequest,
1321                fidl::encoding::DefaultFuchsiaResourceDialect,
1322            >::encode(
1323                (
1324                    <CreateEncoderParams as fidl::encoding::ValueTypeMarker>::borrow(
1325                        &self.encoder_params,
1326                    ),
1327                    <fidl::encoding::Endpoint<
1328                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1329                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1330                        &mut self.encoder
1331                    ),
1332                ),
1333                encoder,
1334                offset,
1335                _depth,
1336            )
1337        }
1338    }
1339    unsafe impl<
1340            T0: fidl::encoding::Encode<
1341                CreateEncoderParams,
1342                fidl::encoding::DefaultFuchsiaResourceDialect,
1343            >,
1344            T1: fidl::encoding::Encode<
1345                fidl::encoding::Endpoint<
1346                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1347                >,
1348                fidl::encoding::DefaultFuchsiaResourceDialect,
1349            >,
1350        >
1351        fidl::encoding::Encode<
1352            CodecFactoryCreateEncoderRequest,
1353            fidl::encoding::DefaultFuchsiaResourceDialect,
1354        > for (T0, T1)
1355    {
1356        #[inline]
1357        unsafe fn encode(
1358            self,
1359            encoder: &mut fidl::encoding::Encoder<
1360                '_,
1361                fidl::encoding::DefaultFuchsiaResourceDialect,
1362            >,
1363            offset: usize,
1364            depth: fidl::encoding::Depth,
1365        ) -> fidl::Result<()> {
1366            encoder.debug_check_bounds::<CodecFactoryCreateEncoderRequest>(offset);
1367            // Zero out padding regions. There's no need to apply masks
1368            // because the unmasked parts will be overwritten by fields.
1369            unsafe {
1370                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1371                (ptr as *mut u64).write_unaligned(0);
1372            }
1373            // Write the fields.
1374            self.0.encode(encoder, offset + 0, depth)?;
1375            self.1.encode(encoder, offset + 16, depth)?;
1376            Ok(())
1377        }
1378    }
1379
1380    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1381        for CodecFactoryCreateEncoderRequest
1382    {
1383        #[inline(always)]
1384        fn new_empty() -> Self {
1385            Self {
1386                encoder_params: fidl::new_empty!(
1387                    CreateEncoderParams,
1388                    fidl::encoding::DefaultFuchsiaResourceDialect
1389                ),
1390                encoder: fidl::new_empty!(
1391                    fidl::encoding::Endpoint<
1392                        fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1393                    >,
1394                    fidl::encoding::DefaultFuchsiaResourceDialect
1395                ),
1396            }
1397        }
1398
1399        #[inline]
1400        unsafe fn decode(
1401            &mut self,
1402            decoder: &mut fidl::encoding::Decoder<
1403                '_,
1404                fidl::encoding::DefaultFuchsiaResourceDialect,
1405            >,
1406            offset: usize,
1407            _depth: fidl::encoding::Depth,
1408        ) -> fidl::Result<()> {
1409            decoder.debug_check_bounds::<Self>(offset);
1410            // Verify that padding bytes are zero.
1411            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1412            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1413            let mask = 0xffffffff00000000u64;
1414            let maskedval = padval & mask;
1415            if maskedval != 0 {
1416                return Err(fidl::Error::NonZeroPadding {
1417                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1418                });
1419            }
1420            fidl::decode!(
1421                CreateEncoderParams,
1422                fidl::encoding::DefaultFuchsiaResourceDialect,
1423                &mut self.encoder_params,
1424                decoder,
1425                offset + 0,
1426                _depth
1427            )?;
1428            fidl::decode!(
1429                fidl::encoding::Endpoint<
1430                    fidl::endpoints::ServerEnd<fidl_fuchsia_media::StreamProcessorMarker>,
1431                >,
1432                fidl::encoding::DefaultFuchsiaResourceDialect,
1433                &mut self.encoder,
1434                decoder,
1435                offset + 16,
1436                _depth
1437            )?;
1438            Ok(())
1439        }
1440    }
1441}