fidl_fuchsia_media_audio/
fidl_fuchsia_media_audio.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_media_audio_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct EffectsControllerMarker;
16
17impl fidl::endpoints::ProtocolMarker for EffectsControllerMarker {
18    type Proxy = EffectsControllerProxy;
19    type RequestStream = EffectsControllerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = EffectsControllerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.media.audio.EffectsController";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for EffectsControllerMarker {}
26pub type EffectsControllerUpdateEffectResult = Result<(), UpdateEffectError>;
27
28pub trait EffectsControllerProxyInterface: Send + Sync {
29    type UpdateEffectResponseFut: std::future::Future<Output = Result<EffectsControllerUpdateEffectResult, fidl::Error>>
30        + Send;
31    fn r#update_effect(&self, effect_name: &str, config: &str) -> Self::UpdateEffectResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct EffectsControllerSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for EffectsControllerSynchronousProxy {
41    type Proxy = EffectsControllerProxy;
42    type Protocol = EffectsControllerMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl EffectsControllerSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name =
61            <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
62        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
63    }
64
65    pub fn into_channel(self) -> fidl::Channel {
66        self.client.into_channel()
67    }
68
69    /// Waits until an event arrives and returns it. It is safe for other
70    /// threads to make concurrent requests while waiting for an event.
71    pub fn wait_for_event(
72        &self,
73        deadline: zx::MonotonicInstant,
74    ) -> Result<EffectsControllerEvent, fidl::Error> {
75        EffectsControllerEvent::decode(self.client.wait_for_event(deadline)?)
76    }
77
78    /// Sends the `config` message to an audio effect named `effect_name`. If the
79    /// server closes the `EffectsController` connection for any reason, that
80    /// indicates that the effects have been reset and any state associated with
81    /// previous `UpdateEffect` messages have been lost. Clients who wish to re-apply
82    /// state should respond by reconnecting and resending any needed `UpdateEffect`
83    /// messages. If a client closes the connection, no state will be lost but the
84    /// client will also be unable to determine if and when any state associated with
85    /// previous messages have been lost.
86    ///
87    /// Returns success (empty response) if the message was accepted by an
88    /// effect named `effect_name`.
89    ///
90    /// Returns `UpdateEffectError.INVALID_CONFIG` if an effect with the name
91    /// `effect_name` was found, but the `config` message was rejected.
92    ///
93    /// Returns `UpdateEffectError.NOT_FOUND` if no effect with name `effect_name`
94    /// could be located.
95    pub fn r#update_effect(
96        &self,
97        mut effect_name: &str,
98        mut config: &str,
99        ___deadline: zx::MonotonicInstant,
100    ) -> Result<EffectsControllerUpdateEffectResult, fidl::Error> {
101        let _response = self.client.send_query::<
102            EffectsControllerUpdateEffectRequest,
103            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, UpdateEffectError>,
104        >(
105            (effect_name, config,),
106            0x4e39e4b5e6279125,
107            fidl::encoding::DynamicFlags::empty(),
108            ___deadline,
109        )?;
110        Ok(_response.map(|x| x))
111    }
112}
113
114#[derive(Debug, Clone)]
115pub struct EffectsControllerProxy {
116    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
117}
118
119impl fidl::endpoints::Proxy for EffectsControllerProxy {
120    type Protocol = EffectsControllerMarker;
121
122    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
123        Self::new(inner)
124    }
125
126    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
127        self.client.into_channel().map_err(|client| Self { client })
128    }
129
130    fn as_channel(&self) -> &::fidl::AsyncChannel {
131        self.client.as_channel()
132    }
133}
134
135impl EffectsControllerProxy {
136    /// Create a new Proxy for fuchsia.media.audio/EffectsController.
137    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
138        let protocol_name =
139            <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
140        Self { client: fidl::client::Client::new(channel, protocol_name) }
141    }
142
143    /// Get a Stream of events from the remote end of the protocol.
144    ///
145    /// # Panics
146    ///
147    /// Panics if the event stream was already taken.
148    pub fn take_event_stream(&self) -> EffectsControllerEventStream {
149        EffectsControllerEventStream { event_receiver: self.client.take_event_receiver() }
150    }
151
152    /// Sends the `config` message to an audio effect named `effect_name`. If the
153    /// server closes the `EffectsController` connection for any reason, that
154    /// indicates that the effects have been reset and any state associated with
155    /// previous `UpdateEffect` messages have been lost. Clients who wish to re-apply
156    /// state should respond by reconnecting and resending any needed `UpdateEffect`
157    /// messages. If a client closes the connection, no state will be lost but the
158    /// client will also be unable to determine if and when any state associated with
159    /// previous messages have been lost.
160    ///
161    /// Returns success (empty response) if the message was accepted by an
162    /// effect named `effect_name`.
163    ///
164    /// Returns `UpdateEffectError.INVALID_CONFIG` if an effect with the name
165    /// `effect_name` was found, but the `config` message was rejected.
166    ///
167    /// Returns `UpdateEffectError.NOT_FOUND` if no effect with name `effect_name`
168    /// could be located.
169    pub fn r#update_effect(
170        &self,
171        mut effect_name: &str,
172        mut config: &str,
173    ) -> fidl::client::QueryResponseFut<
174        EffectsControllerUpdateEffectResult,
175        fidl::encoding::DefaultFuchsiaResourceDialect,
176    > {
177        EffectsControllerProxyInterface::r#update_effect(self, effect_name, config)
178    }
179}
180
181impl EffectsControllerProxyInterface for EffectsControllerProxy {
182    type UpdateEffectResponseFut = fidl::client::QueryResponseFut<
183        EffectsControllerUpdateEffectResult,
184        fidl::encoding::DefaultFuchsiaResourceDialect,
185    >;
186    fn r#update_effect(
187        &self,
188        mut effect_name: &str,
189        mut config: &str,
190    ) -> Self::UpdateEffectResponseFut {
191        fn _decode(
192            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
193        ) -> Result<EffectsControllerUpdateEffectResult, fidl::Error> {
194            let _response = fidl::client::decode_transaction_body::<
195                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, UpdateEffectError>,
196                fidl::encoding::DefaultFuchsiaResourceDialect,
197                0x4e39e4b5e6279125,
198            >(_buf?)?;
199            Ok(_response.map(|x| x))
200        }
201        self.client.send_query_and_decode::<
202            EffectsControllerUpdateEffectRequest,
203            EffectsControllerUpdateEffectResult,
204        >(
205            (effect_name, config,),
206            0x4e39e4b5e6279125,
207            fidl::encoding::DynamicFlags::empty(),
208            _decode,
209        )
210    }
211}
212
213pub struct EffectsControllerEventStream {
214    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
215}
216
217impl std::marker::Unpin for EffectsControllerEventStream {}
218
219impl futures::stream::FusedStream for EffectsControllerEventStream {
220    fn is_terminated(&self) -> bool {
221        self.event_receiver.is_terminated()
222    }
223}
224
225impl futures::Stream for EffectsControllerEventStream {
226    type Item = Result<EffectsControllerEvent, fidl::Error>;
227
228    fn poll_next(
229        mut self: std::pin::Pin<&mut Self>,
230        cx: &mut std::task::Context<'_>,
231    ) -> std::task::Poll<Option<Self::Item>> {
232        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
233            &mut self.event_receiver,
234            cx
235        )?) {
236            Some(buf) => std::task::Poll::Ready(Some(EffectsControllerEvent::decode(buf))),
237            None => std::task::Poll::Ready(None),
238        }
239    }
240}
241
242#[derive(Debug)]
243pub enum EffectsControllerEvent {}
244
245impl EffectsControllerEvent {
246    /// Decodes a message buffer as a [`EffectsControllerEvent`].
247    fn decode(
248        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
249    ) -> Result<EffectsControllerEvent, fidl::Error> {
250        let (bytes, _handles) = buf.split_mut();
251        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
252        debug_assert_eq!(tx_header.tx_id, 0);
253        match tx_header.ordinal {
254            _ => Err(fidl::Error::UnknownOrdinal {
255                ordinal: tx_header.ordinal,
256                protocol_name:
257                    <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
258            }),
259        }
260    }
261}
262
263/// A Stream of incoming requests for fuchsia.media.audio/EffectsController.
264pub struct EffectsControllerRequestStream {
265    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
266    is_terminated: bool,
267}
268
269impl std::marker::Unpin for EffectsControllerRequestStream {}
270
271impl futures::stream::FusedStream for EffectsControllerRequestStream {
272    fn is_terminated(&self) -> bool {
273        self.is_terminated
274    }
275}
276
277impl fidl::endpoints::RequestStream for EffectsControllerRequestStream {
278    type Protocol = EffectsControllerMarker;
279    type ControlHandle = EffectsControllerControlHandle;
280
281    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
282        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
283    }
284
285    fn control_handle(&self) -> Self::ControlHandle {
286        EffectsControllerControlHandle { inner: self.inner.clone() }
287    }
288
289    fn into_inner(
290        self,
291    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
292    {
293        (self.inner, self.is_terminated)
294    }
295
296    fn from_inner(
297        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
298        is_terminated: bool,
299    ) -> Self {
300        Self { inner, is_terminated }
301    }
302}
303
304impl futures::Stream for EffectsControllerRequestStream {
305    type Item = Result<EffectsControllerRequest, fidl::Error>;
306
307    fn poll_next(
308        mut self: std::pin::Pin<&mut Self>,
309        cx: &mut std::task::Context<'_>,
310    ) -> std::task::Poll<Option<Self::Item>> {
311        let this = &mut *self;
312        if this.inner.check_shutdown(cx) {
313            this.is_terminated = true;
314            return std::task::Poll::Ready(None);
315        }
316        if this.is_terminated {
317            panic!("polled EffectsControllerRequestStream after completion");
318        }
319        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
320            |bytes, handles| {
321                match this.inner.channel().read_etc(cx, bytes, handles) {
322                    std::task::Poll::Ready(Ok(())) => {}
323                    std::task::Poll::Pending => return std::task::Poll::Pending,
324                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
325                        this.is_terminated = true;
326                        return std::task::Poll::Ready(None);
327                    }
328                    std::task::Poll::Ready(Err(e)) => {
329                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
330                            e.into(),
331                        ))))
332                    }
333                }
334
335                // A message has been received from the channel
336                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
337
338                std::task::Poll::Ready(Some(match header.ordinal {
339                    0x4e39e4b5e6279125 => {
340                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
341                        let mut req = fidl::new_empty!(
342                            EffectsControllerUpdateEffectRequest,
343                            fidl::encoding::DefaultFuchsiaResourceDialect
344                        );
345                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EffectsControllerUpdateEffectRequest>(&header, _body_bytes, handles, &mut req)?;
346                        let control_handle =
347                            EffectsControllerControlHandle { inner: this.inner.clone() };
348                        Ok(EffectsControllerRequest::UpdateEffect {
349                            effect_name: req.effect_name,
350                            config: req.config,
351
352                            responder: EffectsControllerUpdateEffectResponder {
353                                control_handle: std::mem::ManuallyDrop::new(control_handle),
354                                tx_id: header.tx_id,
355                            },
356                        })
357                    }
358                    _ => Err(fidl::Error::UnknownOrdinal {
359                        ordinal: header.ordinal,
360                        protocol_name:
361                            <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
362                    }),
363                }))
364            },
365        )
366    }
367}
368
369#[derive(Debug)]
370pub enum EffectsControllerRequest {
371    /// Sends the `config` message to an audio effect named `effect_name`. If the
372    /// server closes the `EffectsController` connection for any reason, that
373    /// indicates that the effects have been reset and any state associated with
374    /// previous `UpdateEffect` messages have been lost. Clients who wish to re-apply
375    /// state should respond by reconnecting and resending any needed `UpdateEffect`
376    /// messages. If a client closes the connection, no state will be lost but the
377    /// client will also be unable to determine if and when any state associated with
378    /// previous messages have been lost.
379    ///
380    /// Returns success (empty response) if the message was accepted by an
381    /// effect named `effect_name`.
382    ///
383    /// Returns `UpdateEffectError.INVALID_CONFIG` if an effect with the name
384    /// `effect_name` was found, but the `config` message was rejected.
385    ///
386    /// Returns `UpdateEffectError.NOT_FOUND` if no effect with name `effect_name`
387    /// could be located.
388    UpdateEffect {
389        effect_name: String,
390        config: String,
391        responder: EffectsControllerUpdateEffectResponder,
392    },
393}
394
395impl EffectsControllerRequest {
396    #[allow(irrefutable_let_patterns)]
397    pub fn into_update_effect(
398        self,
399    ) -> Option<(String, String, EffectsControllerUpdateEffectResponder)> {
400        if let EffectsControllerRequest::UpdateEffect { effect_name, config, responder } = self {
401            Some((effect_name, config, responder))
402        } else {
403            None
404        }
405    }
406
407    /// Name of the method defined in FIDL
408    pub fn method_name(&self) -> &'static str {
409        match *self {
410            EffectsControllerRequest::UpdateEffect { .. } => "update_effect",
411        }
412    }
413}
414
415#[derive(Debug, Clone)]
416pub struct EffectsControllerControlHandle {
417    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
418}
419
420impl fidl::endpoints::ControlHandle for EffectsControllerControlHandle {
421    fn shutdown(&self) {
422        self.inner.shutdown()
423    }
424    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
425        self.inner.shutdown_with_epitaph(status)
426    }
427
428    fn is_closed(&self) -> bool {
429        self.inner.channel().is_closed()
430    }
431    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
432        self.inner.channel().on_closed()
433    }
434
435    #[cfg(target_os = "fuchsia")]
436    fn signal_peer(
437        &self,
438        clear_mask: zx::Signals,
439        set_mask: zx::Signals,
440    ) -> Result<(), zx_status::Status> {
441        use fidl::Peered;
442        self.inner.channel().signal_peer(clear_mask, set_mask)
443    }
444}
445
446impl EffectsControllerControlHandle {}
447
448#[must_use = "FIDL methods require a response to be sent"]
449#[derive(Debug)]
450pub struct EffectsControllerUpdateEffectResponder {
451    control_handle: std::mem::ManuallyDrop<EffectsControllerControlHandle>,
452    tx_id: u32,
453}
454
455/// Set the the channel to be shutdown (see [`EffectsControllerControlHandle::shutdown`])
456/// if the responder is dropped without sending a response, so that the client
457/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
458impl std::ops::Drop for EffectsControllerUpdateEffectResponder {
459    fn drop(&mut self) {
460        self.control_handle.shutdown();
461        // Safety: drops once, never accessed again
462        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
463    }
464}
465
466impl fidl::endpoints::Responder for EffectsControllerUpdateEffectResponder {
467    type ControlHandle = EffectsControllerControlHandle;
468
469    fn control_handle(&self) -> &EffectsControllerControlHandle {
470        &self.control_handle
471    }
472
473    fn drop_without_shutdown(mut self) {
474        // Safety: drops once, never accessed again due to mem::forget
475        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
476        // Prevent Drop from running (which would shut down the channel)
477        std::mem::forget(self);
478    }
479}
480
481impl EffectsControllerUpdateEffectResponder {
482    /// Sends a response to the FIDL transaction.
483    ///
484    /// Sets the channel to shutdown if an error occurs.
485    pub fn send(self, mut result: Result<(), UpdateEffectError>) -> Result<(), fidl::Error> {
486        let _result = self.send_raw(result);
487        if _result.is_err() {
488            self.control_handle.shutdown();
489        }
490        self.drop_without_shutdown();
491        _result
492    }
493
494    /// Similar to "send" but does not shutdown the channel if an error occurs.
495    pub fn send_no_shutdown_on_err(
496        self,
497        mut result: Result<(), UpdateEffectError>,
498    ) -> Result<(), fidl::Error> {
499        let _result = self.send_raw(result);
500        self.drop_without_shutdown();
501        _result
502    }
503
504    fn send_raw(&self, mut result: Result<(), UpdateEffectError>) -> Result<(), fidl::Error> {
505        self.control_handle.inner.send::<fidl::encoding::ResultType<
506            fidl::encoding::EmptyStruct,
507            UpdateEffectError,
508        >>(
509            result,
510            self.tx_id,
511            0x4e39e4b5e6279125,
512            fidl::encoding::DynamicFlags::empty(),
513        )
514    }
515}
516
517#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
518pub struct GainControlMarker;
519
520impl fidl::endpoints::ProtocolMarker for GainControlMarker {
521    type Proxy = GainControlProxy;
522    type RequestStream = GainControlRequestStream;
523    #[cfg(target_os = "fuchsia")]
524    type SynchronousProxy = GainControlSynchronousProxy;
525
526    const DEBUG_NAME: &'static str = "(anonymous) GainControl";
527}
528
529pub trait GainControlProxyInterface: Send + Sync {
530    fn r#set_gain(&self, gain_db: f32) -> Result<(), fidl::Error>;
531    fn r#set_gain_with_ramp(
532        &self,
533        gain_db: f32,
534        duration: i64,
535        ramp_type: RampType,
536    ) -> Result<(), fidl::Error>;
537    fn r#set_mute(&self, muted: bool) -> Result<(), fidl::Error>;
538}
539#[derive(Debug)]
540#[cfg(target_os = "fuchsia")]
541pub struct GainControlSynchronousProxy {
542    client: fidl::client::sync::Client,
543}
544
545#[cfg(target_os = "fuchsia")]
546impl fidl::endpoints::SynchronousProxy for GainControlSynchronousProxy {
547    type Proxy = GainControlProxy;
548    type Protocol = GainControlMarker;
549
550    fn from_channel(inner: fidl::Channel) -> Self {
551        Self::new(inner)
552    }
553
554    fn into_channel(self) -> fidl::Channel {
555        self.client.into_channel()
556    }
557
558    fn as_channel(&self) -> &fidl::Channel {
559        self.client.as_channel()
560    }
561}
562
563#[cfg(target_os = "fuchsia")]
564impl GainControlSynchronousProxy {
565    pub fn new(channel: fidl::Channel) -> Self {
566        let protocol_name = <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
567        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
568    }
569
570    pub fn into_channel(self) -> fidl::Channel {
571        self.client.into_channel()
572    }
573
574    /// Waits until an event arrives and returns it. It is safe for other
575    /// threads to make concurrent requests while waiting for an event.
576    pub fn wait_for_event(
577        &self,
578        deadline: zx::MonotonicInstant,
579    ) -> Result<GainControlEvent, fidl::Error> {
580        GainControlEvent::decode(self.client.wait_for_event(deadline)?)
581    }
582
583    /// Sets the gain in decibels.
584    pub fn r#set_gain(&self, mut gain_db: f32) -> Result<(), fidl::Error> {
585        self.client.send::<GainControlSetGainRequest>(
586            (gain_db,),
587            0x2fc070871d033f64,
588            fidl::encoding::DynamicFlags::empty(),
589        )
590    }
591
592    /// Smoothly changes gain from its current value to specified value, over the
593    /// specified duration (in milliseconds). If 'duration_ns' is 0, gain changes
594    /// immediately. Otherwise, gain changes only while the stream is running.
595    ///
596    /// Any active or pending ramp is cancelled by subsequent call to SetGain.
597    ///
598    /// There can be at most 1 active ramp at any time. Any active or pending
599    /// ramp is replaced by a later call to SetGainWithRamp (even if duration is
600    /// 0). In this case gain would ramps directly from its most recent
601    /// (mid-ramp) value to the newly-specified one, over the new duration,
602    /// using the new easing.
603    ///
604    /// Usage example (using time in seconds):
605    ///  Time 0
606    ///      SetGainWithRamp(`MUTED_GAIN_DB`, 0, SCALE_LINEAR)         // Ramp 1
607    ///      SetGainWithRamp(0.0f, `ZX_SEC`(4), SCALE_LINEAR)          // Ramp 2
608    ///  Time 3
609    ///      PlayNoReply(kNoTimestamp, any_media_time)
610    ///  Time 4
611    ///      PauseNoReply()
612    ///  Time 7
613    ///      PlayNoReply(kNoTimestamp, any_media_time)
614    ///  Time 8
615    ///      SetGainWithRamp(`MUTED_GAIN_DB`, ZX_SEC(1), SCALE_LINEAR) // Ramp 3
616    ///
617    ///
618    /// Time 0: Ramp 1 completes immediately, changing the gain to `MUTED_GAIN_DB`.
619    ///         Ramp 2 is pending, since we are not in playback.
620    /// Time 3, Ramp 2 begins ramping from `MUTED_GAIN_DB` to 0 dB
621    ///         (scale 0.0=>1.0).
622    /// Time 4: Ramp 2 pauses (3s remain). Per `SCALE_LINEAR`, scale is approx.
623    ///         0.25.
624    /// Time 7: Ramp 2 resumes from most recent value toward the target.
625    /// Time 8: Ramp 3 replaces Ramp 2 and starts from current scale
626    ///         (approx 0.5).
627    /// Time 9: Ramp 3 completes; current scale value is now 0.0 (`MUTED_GAIN_DB`).
628    pub fn r#set_gain_with_ramp(
629        &self,
630        mut gain_db: f32,
631        mut duration: i64,
632        mut ramp_type: RampType,
633    ) -> Result<(), fidl::Error> {
634        self.client.send::<GainControlSetGainWithRampRequest>(
635            (gain_db, duration, ramp_type),
636            0x3a175b2d6979e8ea,
637            fidl::encoding::DynamicFlags::empty(),
638        )
639    }
640
641    /// Sets the mute value. Ramping and mute are fully independent, although
642    /// they both affect the scaling that is applied.
643    pub fn r#set_mute(&self, mut muted: bool) -> Result<(), fidl::Error> {
644        self.client.send::<GainControlSetMuteRequest>(
645            (muted,),
646            0x5415723c1e31448,
647            fidl::encoding::DynamicFlags::empty(),
648        )
649    }
650}
651
652#[derive(Debug, Clone)]
653pub struct GainControlProxy {
654    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
655}
656
657impl fidl::endpoints::Proxy for GainControlProxy {
658    type Protocol = GainControlMarker;
659
660    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
661        Self::new(inner)
662    }
663
664    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
665        self.client.into_channel().map_err(|client| Self { client })
666    }
667
668    fn as_channel(&self) -> &::fidl::AsyncChannel {
669        self.client.as_channel()
670    }
671}
672
673impl GainControlProxy {
674    /// Create a new Proxy for fuchsia.media.audio/GainControl.
675    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
676        let protocol_name = <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
677        Self { client: fidl::client::Client::new(channel, protocol_name) }
678    }
679
680    /// Get a Stream of events from the remote end of the protocol.
681    ///
682    /// # Panics
683    ///
684    /// Panics if the event stream was already taken.
685    pub fn take_event_stream(&self) -> GainControlEventStream {
686        GainControlEventStream { event_receiver: self.client.take_event_receiver() }
687    }
688
689    /// Sets the gain in decibels.
690    pub fn r#set_gain(&self, mut gain_db: f32) -> Result<(), fidl::Error> {
691        GainControlProxyInterface::r#set_gain(self, gain_db)
692    }
693
694    /// Smoothly changes gain from its current value to specified value, over the
695    /// specified duration (in milliseconds). If 'duration_ns' is 0, gain changes
696    /// immediately. Otherwise, gain changes only while the stream is running.
697    ///
698    /// Any active or pending ramp is cancelled by subsequent call to SetGain.
699    ///
700    /// There can be at most 1 active ramp at any time. Any active or pending
701    /// ramp is replaced by a later call to SetGainWithRamp (even if duration is
702    /// 0). In this case gain would ramps directly from its most recent
703    /// (mid-ramp) value to the newly-specified one, over the new duration,
704    /// using the new easing.
705    ///
706    /// Usage example (using time in seconds):
707    ///  Time 0
708    ///      SetGainWithRamp(`MUTED_GAIN_DB`, 0, SCALE_LINEAR)         // Ramp 1
709    ///      SetGainWithRamp(0.0f, `ZX_SEC`(4), SCALE_LINEAR)          // Ramp 2
710    ///  Time 3
711    ///      PlayNoReply(kNoTimestamp, any_media_time)
712    ///  Time 4
713    ///      PauseNoReply()
714    ///  Time 7
715    ///      PlayNoReply(kNoTimestamp, any_media_time)
716    ///  Time 8
717    ///      SetGainWithRamp(`MUTED_GAIN_DB`, ZX_SEC(1), SCALE_LINEAR) // Ramp 3
718    ///
719    ///
720    /// Time 0: Ramp 1 completes immediately, changing the gain to `MUTED_GAIN_DB`.
721    ///         Ramp 2 is pending, since we are not in playback.
722    /// Time 3, Ramp 2 begins ramping from `MUTED_GAIN_DB` to 0 dB
723    ///         (scale 0.0=>1.0).
724    /// Time 4: Ramp 2 pauses (3s remain). Per `SCALE_LINEAR`, scale is approx.
725    ///         0.25.
726    /// Time 7: Ramp 2 resumes from most recent value toward the target.
727    /// Time 8: Ramp 3 replaces Ramp 2 and starts from current scale
728    ///         (approx 0.5).
729    /// Time 9: Ramp 3 completes; current scale value is now 0.0 (`MUTED_GAIN_DB`).
730    pub fn r#set_gain_with_ramp(
731        &self,
732        mut gain_db: f32,
733        mut duration: i64,
734        mut ramp_type: RampType,
735    ) -> Result<(), fidl::Error> {
736        GainControlProxyInterface::r#set_gain_with_ramp(self, gain_db, duration, ramp_type)
737    }
738
739    /// Sets the mute value. Ramping and mute are fully independent, although
740    /// they both affect the scaling that is applied.
741    pub fn r#set_mute(&self, mut muted: bool) -> Result<(), fidl::Error> {
742        GainControlProxyInterface::r#set_mute(self, muted)
743    }
744}
745
746impl GainControlProxyInterface for GainControlProxy {
747    fn r#set_gain(&self, mut gain_db: f32) -> Result<(), fidl::Error> {
748        self.client.send::<GainControlSetGainRequest>(
749            (gain_db,),
750            0x2fc070871d033f64,
751            fidl::encoding::DynamicFlags::empty(),
752        )
753    }
754
755    fn r#set_gain_with_ramp(
756        &self,
757        mut gain_db: f32,
758        mut duration: i64,
759        mut ramp_type: RampType,
760    ) -> Result<(), fidl::Error> {
761        self.client.send::<GainControlSetGainWithRampRequest>(
762            (gain_db, duration, ramp_type),
763            0x3a175b2d6979e8ea,
764            fidl::encoding::DynamicFlags::empty(),
765        )
766    }
767
768    fn r#set_mute(&self, mut muted: bool) -> Result<(), fidl::Error> {
769        self.client.send::<GainControlSetMuteRequest>(
770            (muted,),
771            0x5415723c1e31448,
772            fidl::encoding::DynamicFlags::empty(),
773        )
774    }
775}
776
777pub struct GainControlEventStream {
778    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
779}
780
781impl std::marker::Unpin for GainControlEventStream {}
782
783impl futures::stream::FusedStream for GainControlEventStream {
784    fn is_terminated(&self) -> bool {
785        self.event_receiver.is_terminated()
786    }
787}
788
789impl futures::Stream for GainControlEventStream {
790    type Item = Result<GainControlEvent, fidl::Error>;
791
792    fn poll_next(
793        mut self: std::pin::Pin<&mut Self>,
794        cx: &mut std::task::Context<'_>,
795    ) -> std::task::Poll<Option<Self::Item>> {
796        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
797            &mut self.event_receiver,
798            cx
799        )?) {
800            Some(buf) => std::task::Poll::Ready(Some(GainControlEvent::decode(buf))),
801            None => std::task::Poll::Ready(None),
802        }
803    }
804}
805
806#[derive(Debug)]
807pub enum GainControlEvent {
808    OnGainMuteChanged { gain_db: f32, muted: bool },
809}
810
811impl GainControlEvent {
812    #[allow(irrefutable_let_patterns)]
813    pub fn into_on_gain_mute_changed(self) -> Option<(f32, bool)> {
814        if let GainControlEvent::OnGainMuteChanged { gain_db, muted } = self {
815            Some((gain_db, muted))
816        } else {
817            None
818        }
819    }
820
821    /// Decodes a message buffer as a [`GainControlEvent`].
822    fn decode(
823        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
824    ) -> Result<GainControlEvent, fidl::Error> {
825        let (bytes, _handles) = buf.split_mut();
826        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
827        debug_assert_eq!(tx_header.tx_id, 0);
828        match tx_header.ordinal {
829            0x66d528cad4e0d753 => {
830                let mut out = fidl::new_empty!(
831                    GainControlOnGainMuteChangedRequest,
832                    fidl::encoding::DefaultFuchsiaResourceDialect
833                );
834                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlOnGainMuteChangedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
835                Ok((GainControlEvent::OnGainMuteChanged { gain_db: out.gain_db, muted: out.muted }))
836            }
837            _ => Err(fidl::Error::UnknownOrdinal {
838                ordinal: tx_header.ordinal,
839                protocol_name: <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
840            }),
841        }
842    }
843}
844
845/// A Stream of incoming requests for fuchsia.media.audio/GainControl.
846pub struct GainControlRequestStream {
847    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
848    is_terminated: bool,
849}
850
851impl std::marker::Unpin for GainControlRequestStream {}
852
853impl futures::stream::FusedStream for GainControlRequestStream {
854    fn is_terminated(&self) -> bool {
855        self.is_terminated
856    }
857}
858
859impl fidl::endpoints::RequestStream for GainControlRequestStream {
860    type Protocol = GainControlMarker;
861    type ControlHandle = GainControlControlHandle;
862
863    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
864        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
865    }
866
867    fn control_handle(&self) -> Self::ControlHandle {
868        GainControlControlHandle { inner: self.inner.clone() }
869    }
870
871    fn into_inner(
872        self,
873    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
874    {
875        (self.inner, self.is_terminated)
876    }
877
878    fn from_inner(
879        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
880        is_terminated: bool,
881    ) -> Self {
882        Self { inner, is_terminated }
883    }
884}
885
886impl futures::Stream for GainControlRequestStream {
887    type Item = Result<GainControlRequest, fidl::Error>;
888
889    fn poll_next(
890        mut self: std::pin::Pin<&mut Self>,
891        cx: &mut std::task::Context<'_>,
892    ) -> std::task::Poll<Option<Self::Item>> {
893        let this = &mut *self;
894        if this.inner.check_shutdown(cx) {
895            this.is_terminated = true;
896            return std::task::Poll::Ready(None);
897        }
898        if this.is_terminated {
899            panic!("polled GainControlRequestStream after completion");
900        }
901        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
902            |bytes, handles| {
903                match this.inner.channel().read_etc(cx, bytes, handles) {
904                    std::task::Poll::Ready(Ok(())) => {}
905                    std::task::Poll::Pending => return std::task::Poll::Pending,
906                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
907                        this.is_terminated = true;
908                        return std::task::Poll::Ready(None);
909                    }
910                    std::task::Poll::Ready(Err(e)) => {
911                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
912                            e.into(),
913                        ))))
914                    }
915                }
916
917                // A message has been received from the channel
918                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
919
920                std::task::Poll::Ready(Some(match header.ordinal {
921                    0x2fc070871d033f64 => {
922                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
923                        let mut req = fidl::new_empty!(
924                            GainControlSetGainRequest,
925                            fidl::encoding::DefaultFuchsiaResourceDialect
926                        );
927                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetGainRequest>(&header, _body_bytes, handles, &mut req)?;
928                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
929                        Ok(GainControlRequest::SetGain { gain_db: req.gain_db, control_handle })
930                    }
931                    0x3a175b2d6979e8ea => {
932                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
933                        let mut req = fidl::new_empty!(
934                            GainControlSetGainWithRampRequest,
935                            fidl::encoding::DefaultFuchsiaResourceDialect
936                        );
937                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetGainWithRampRequest>(&header, _body_bytes, handles, &mut req)?;
938                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
939                        Ok(GainControlRequest::SetGainWithRamp {
940                            gain_db: req.gain_db,
941                            duration: req.duration,
942                            ramp_type: req.ramp_type,
943
944                            control_handle,
945                        })
946                    }
947                    0x5415723c1e31448 => {
948                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
949                        let mut req = fidl::new_empty!(
950                            GainControlSetMuteRequest,
951                            fidl::encoding::DefaultFuchsiaResourceDialect
952                        );
953                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetMuteRequest>(&header, _body_bytes, handles, &mut req)?;
954                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
955                        Ok(GainControlRequest::SetMute { muted: req.muted, control_handle })
956                    }
957                    _ => Err(fidl::Error::UnknownOrdinal {
958                        ordinal: header.ordinal,
959                        protocol_name:
960                            <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
961                    }),
962                }))
963            },
964        )
965    }
966}
967
968/// Enables control and monitoring of audio gain. This interface is typically
969/// a tear-off of other interfaces. For example, `fuchsia.media.audio.Renderer`
970/// has a `BindGainControl` method that binds to a gain control that controls
971/// gain for the renderer.
972#[derive(Debug)]
973pub enum GainControlRequest {
974    /// Sets the gain in decibels.
975    SetGain { gain_db: f32, control_handle: GainControlControlHandle },
976    /// Smoothly changes gain from its current value to specified value, over the
977    /// specified duration (in milliseconds). If 'duration_ns' is 0, gain changes
978    /// immediately. Otherwise, gain changes only while the stream is running.
979    ///
980    /// Any active or pending ramp is cancelled by subsequent call to SetGain.
981    ///
982    /// There can be at most 1 active ramp at any time. Any active or pending
983    /// ramp is replaced by a later call to SetGainWithRamp (even if duration is
984    /// 0). In this case gain would ramps directly from its most recent
985    /// (mid-ramp) value to the newly-specified one, over the new duration,
986    /// using the new easing.
987    ///
988    /// Usage example (using time in seconds):
989    ///  Time 0
990    ///      SetGainWithRamp(`MUTED_GAIN_DB`, 0, SCALE_LINEAR)         // Ramp 1
991    ///      SetGainWithRamp(0.0f, `ZX_SEC`(4), SCALE_LINEAR)          // Ramp 2
992    ///  Time 3
993    ///      PlayNoReply(kNoTimestamp, any_media_time)
994    ///  Time 4
995    ///      PauseNoReply()
996    ///  Time 7
997    ///      PlayNoReply(kNoTimestamp, any_media_time)
998    ///  Time 8
999    ///      SetGainWithRamp(`MUTED_GAIN_DB`, ZX_SEC(1), SCALE_LINEAR) // Ramp 3
1000    ///
1001    ///
1002    /// Time 0: Ramp 1 completes immediately, changing the gain to `MUTED_GAIN_DB`.
1003    ///         Ramp 2 is pending, since we are not in playback.
1004    /// Time 3, Ramp 2 begins ramping from `MUTED_GAIN_DB` to 0 dB
1005    ///         (scale 0.0=>1.0).
1006    /// Time 4: Ramp 2 pauses (3s remain). Per `SCALE_LINEAR`, scale is approx.
1007    ///         0.25.
1008    /// Time 7: Ramp 2 resumes from most recent value toward the target.
1009    /// Time 8: Ramp 3 replaces Ramp 2 and starts from current scale
1010    ///         (approx 0.5).
1011    /// Time 9: Ramp 3 completes; current scale value is now 0.0 (`MUTED_GAIN_DB`).
1012    SetGainWithRamp {
1013        gain_db: f32,
1014        duration: i64,
1015        ramp_type: RampType,
1016        control_handle: GainControlControlHandle,
1017    },
1018    /// Sets the mute value. Ramping and mute are fully independent, although
1019    /// they both affect the scaling that is applied.
1020    SetMute { muted: bool, control_handle: GainControlControlHandle },
1021}
1022
1023impl GainControlRequest {
1024    #[allow(irrefutable_let_patterns)]
1025    pub fn into_set_gain(self) -> Option<(f32, GainControlControlHandle)> {
1026        if let GainControlRequest::SetGain { gain_db, control_handle } = self {
1027            Some((gain_db, control_handle))
1028        } else {
1029            None
1030        }
1031    }
1032
1033    #[allow(irrefutable_let_patterns)]
1034    pub fn into_set_gain_with_ramp(self) -> Option<(f32, i64, RampType, GainControlControlHandle)> {
1035        if let GainControlRequest::SetGainWithRamp {
1036            gain_db,
1037            duration,
1038            ramp_type,
1039            control_handle,
1040        } = self
1041        {
1042            Some((gain_db, duration, ramp_type, control_handle))
1043        } else {
1044            None
1045        }
1046    }
1047
1048    #[allow(irrefutable_let_patterns)]
1049    pub fn into_set_mute(self) -> Option<(bool, GainControlControlHandle)> {
1050        if let GainControlRequest::SetMute { muted, control_handle } = self {
1051            Some((muted, control_handle))
1052        } else {
1053            None
1054        }
1055    }
1056
1057    /// Name of the method defined in FIDL
1058    pub fn method_name(&self) -> &'static str {
1059        match *self {
1060            GainControlRequest::SetGain { .. } => "set_gain",
1061            GainControlRequest::SetGainWithRamp { .. } => "set_gain_with_ramp",
1062            GainControlRequest::SetMute { .. } => "set_mute",
1063        }
1064    }
1065}
1066
1067#[derive(Debug, Clone)]
1068pub struct GainControlControlHandle {
1069    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1070}
1071
1072impl fidl::endpoints::ControlHandle for GainControlControlHandle {
1073    fn shutdown(&self) {
1074        self.inner.shutdown()
1075    }
1076    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1077        self.inner.shutdown_with_epitaph(status)
1078    }
1079
1080    fn is_closed(&self) -> bool {
1081        self.inner.channel().is_closed()
1082    }
1083    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1084        self.inner.channel().on_closed()
1085    }
1086
1087    #[cfg(target_os = "fuchsia")]
1088    fn signal_peer(
1089        &self,
1090        clear_mask: zx::Signals,
1091        set_mask: zx::Signals,
1092    ) -> Result<(), zx_status::Status> {
1093        use fidl::Peered;
1094        self.inner.channel().signal_peer(clear_mask, set_mask)
1095    }
1096}
1097
1098impl GainControlControlHandle {
1099    pub fn send_on_gain_mute_changed(
1100        &self,
1101        mut gain_db: f32,
1102        mut muted: bool,
1103    ) -> Result<(), fidl::Error> {
1104        self.inner.send::<GainControlOnGainMuteChangedRequest>(
1105            (gain_db, muted),
1106            0,
1107            0x66d528cad4e0d753,
1108            fidl::encoding::DynamicFlags::empty(),
1109        )
1110    }
1111}
1112
1113#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1114pub struct VolumeControlMarker;
1115
1116impl fidl::endpoints::ProtocolMarker for VolumeControlMarker {
1117    type Proxy = VolumeControlProxy;
1118    type RequestStream = VolumeControlRequestStream;
1119    #[cfg(target_os = "fuchsia")]
1120    type SynchronousProxy = VolumeControlSynchronousProxy;
1121
1122    const DEBUG_NAME: &'static str = "(anonymous) VolumeControl";
1123}
1124
1125pub trait VolumeControlProxyInterface: Send + Sync {
1126    fn r#set_volume(&self, volume: f32) -> Result<(), fidl::Error>;
1127    fn r#set_mute(&self, mute: bool) -> Result<(), fidl::Error>;
1128}
1129#[derive(Debug)]
1130#[cfg(target_os = "fuchsia")]
1131pub struct VolumeControlSynchronousProxy {
1132    client: fidl::client::sync::Client,
1133}
1134
1135#[cfg(target_os = "fuchsia")]
1136impl fidl::endpoints::SynchronousProxy for VolumeControlSynchronousProxy {
1137    type Proxy = VolumeControlProxy;
1138    type Protocol = VolumeControlMarker;
1139
1140    fn from_channel(inner: fidl::Channel) -> Self {
1141        Self::new(inner)
1142    }
1143
1144    fn into_channel(self) -> fidl::Channel {
1145        self.client.into_channel()
1146    }
1147
1148    fn as_channel(&self) -> &fidl::Channel {
1149        self.client.as_channel()
1150    }
1151}
1152
1153#[cfg(target_os = "fuchsia")]
1154impl VolumeControlSynchronousProxy {
1155    pub fn new(channel: fidl::Channel) -> Self {
1156        let protocol_name = <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1157        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1158    }
1159
1160    pub fn into_channel(self) -> fidl::Channel {
1161        self.client.into_channel()
1162    }
1163
1164    /// Waits until an event arrives and returns it. It is safe for other
1165    /// threads to make concurrent requests while waiting for an event.
1166    pub fn wait_for_event(
1167        &self,
1168        deadline: zx::MonotonicInstant,
1169    ) -> Result<VolumeControlEvent, fidl::Error> {
1170        VolumeControlEvent::decode(self.client.wait_for_event(deadline)?)
1171    }
1172
1173    /// Sets the volume of the audio element to the given value in
1174    /// [0.0, 1.0]. If the value is provided is outside of [0.0, 1.0],
1175    /// the value is clamped before application.
1176    pub fn r#set_volume(&self, mut volume: f32) -> Result<(), fidl::Error> {
1177        self.client.send::<VolumeControlSetVolumeRequest>(
1178            (volume,),
1179            0x6ff4231809a697da,
1180            fidl::encoding::DynamicFlags::empty(),
1181        )
1182    }
1183
1184    /// Sets whether the controlled element is muted. Mute is not the same
1185    /// as setting volume to 0.0; volume will persist for the duration of
1186    /// a mute. If volume was 0.5 before mute, volume will resume at 0.5
1187    /// following unmute.
1188    pub fn r#set_mute(&self, mut mute: bool) -> Result<(), fidl::Error> {
1189        self.client.send::<VolumeControlSetMuteRequest>(
1190            (mute,),
1191            0x50c10c28bba46425,
1192            fidl::encoding::DynamicFlags::empty(),
1193        )
1194    }
1195}
1196
1197#[derive(Debug, Clone)]
1198pub struct VolumeControlProxy {
1199    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1200}
1201
1202impl fidl::endpoints::Proxy for VolumeControlProxy {
1203    type Protocol = VolumeControlMarker;
1204
1205    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1206        Self::new(inner)
1207    }
1208
1209    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1210        self.client.into_channel().map_err(|client| Self { client })
1211    }
1212
1213    fn as_channel(&self) -> &::fidl::AsyncChannel {
1214        self.client.as_channel()
1215    }
1216}
1217
1218impl VolumeControlProxy {
1219    /// Create a new Proxy for fuchsia.media.audio/VolumeControl.
1220    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1221        let protocol_name = <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1222        Self { client: fidl::client::Client::new(channel, protocol_name) }
1223    }
1224
1225    /// Get a Stream of events from the remote end of the protocol.
1226    ///
1227    /// # Panics
1228    ///
1229    /// Panics if the event stream was already taken.
1230    pub fn take_event_stream(&self) -> VolumeControlEventStream {
1231        VolumeControlEventStream { event_receiver: self.client.take_event_receiver() }
1232    }
1233
1234    /// Sets the volume of the audio element to the given value in
1235    /// [0.0, 1.0]. If the value is provided is outside of [0.0, 1.0],
1236    /// the value is clamped before application.
1237    pub fn r#set_volume(&self, mut volume: f32) -> Result<(), fidl::Error> {
1238        VolumeControlProxyInterface::r#set_volume(self, volume)
1239    }
1240
1241    /// Sets whether the controlled element is muted. Mute is not the same
1242    /// as setting volume to 0.0; volume will persist for the duration of
1243    /// a mute. If volume was 0.5 before mute, volume will resume at 0.5
1244    /// following unmute.
1245    pub fn r#set_mute(&self, mut mute: bool) -> Result<(), fidl::Error> {
1246        VolumeControlProxyInterface::r#set_mute(self, mute)
1247    }
1248}
1249
1250impl VolumeControlProxyInterface for VolumeControlProxy {
1251    fn r#set_volume(&self, mut volume: f32) -> Result<(), fidl::Error> {
1252        self.client.send::<VolumeControlSetVolumeRequest>(
1253            (volume,),
1254            0x6ff4231809a697da,
1255            fidl::encoding::DynamicFlags::empty(),
1256        )
1257    }
1258
1259    fn r#set_mute(&self, mut mute: bool) -> Result<(), fidl::Error> {
1260        self.client.send::<VolumeControlSetMuteRequest>(
1261            (mute,),
1262            0x50c10c28bba46425,
1263            fidl::encoding::DynamicFlags::empty(),
1264        )
1265    }
1266}
1267
1268pub struct VolumeControlEventStream {
1269    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1270}
1271
1272impl std::marker::Unpin for VolumeControlEventStream {}
1273
1274impl futures::stream::FusedStream for VolumeControlEventStream {
1275    fn is_terminated(&self) -> bool {
1276        self.event_receiver.is_terminated()
1277    }
1278}
1279
1280impl futures::Stream for VolumeControlEventStream {
1281    type Item = Result<VolumeControlEvent, fidl::Error>;
1282
1283    fn poll_next(
1284        mut self: std::pin::Pin<&mut Self>,
1285        cx: &mut std::task::Context<'_>,
1286    ) -> std::task::Poll<Option<Self::Item>> {
1287        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1288            &mut self.event_receiver,
1289            cx
1290        )?) {
1291            Some(buf) => std::task::Poll::Ready(Some(VolumeControlEvent::decode(buf))),
1292            None => std::task::Poll::Ready(None),
1293        }
1294    }
1295}
1296
1297#[derive(Debug)]
1298pub enum VolumeControlEvent {
1299    OnVolumeMuteChanged { new_volume: f32, new_muted: bool },
1300}
1301
1302impl VolumeControlEvent {
1303    #[allow(irrefutable_let_patterns)]
1304    pub fn into_on_volume_mute_changed(self) -> Option<(f32, bool)> {
1305        if let VolumeControlEvent::OnVolumeMuteChanged { new_volume, new_muted } = self {
1306            Some((new_volume, new_muted))
1307        } else {
1308            None
1309        }
1310    }
1311
1312    /// Decodes a message buffer as a [`VolumeControlEvent`].
1313    fn decode(
1314        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1315    ) -> Result<VolumeControlEvent, fidl::Error> {
1316        let (bytes, _handles) = buf.split_mut();
1317        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1318        debug_assert_eq!(tx_header.tx_id, 0);
1319        match tx_header.ordinal {
1320            0x9cea352bd86c171 => {
1321                let mut out = fidl::new_empty!(
1322                    VolumeControlOnVolumeMuteChangedRequest,
1323                    fidl::encoding::DefaultFuchsiaResourceDialect
1324                );
1325                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VolumeControlOnVolumeMuteChangedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1326                Ok((VolumeControlEvent::OnVolumeMuteChanged {
1327                    new_volume: out.new_volume,
1328                    new_muted: out.new_muted,
1329                }))
1330            }
1331            _ => Err(fidl::Error::UnknownOrdinal {
1332                ordinal: tx_header.ordinal,
1333                protocol_name: <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1334            }),
1335        }
1336    }
1337}
1338
1339/// A Stream of incoming requests for fuchsia.media.audio/VolumeControl.
1340pub struct VolumeControlRequestStream {
1341    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1342    is_terminated: bool,
1343}
1344
1345impl std::marker::Unpin for VolumeControlRequestStream {}
1346
1347impl futures::stream::FusedStream for VolumeControlRequestStream {
1348    fn is_terminated(&self) -> bool {
1349        self.is_terminated
1350    }
1351}
1352
1353impl fidl::endpoints::RequestStream for VolumeControlRequestStream {
1354    type Protocol = VolumeControlMarker;
1355    type ControlHandle = VolumeControlControlHandle;
1356
1357    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1358        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1359    }
1360
1361    fn control_handle(&self) -> Self::ControlHandle {
1362        VolumeControlControlHandle { inner: self.inner.clone() }
1363    }
1364
1365    fn into_inner(
1366        self,
1367    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1368    {
1369        (self.inner, self.is_terminated)
1370    }
1371
1372    fn from_inner(
1373        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1374        is_terminated: bool,
1375    ) -> Self {
1376        Self { inner, is_terminated }
1377    }
1378}
1379
1380impl futures::Stream for VolumeControlRequestStream {
1381    type Item = Result<VolumeControlRequest, fidl::Error>;
1382
1383    fn poll_next(
1384        mut self: std::pin::Pin<&mut Self>,
1385        cx: &mut std::task::Context<'_>,
1386    ) -> std::task::Poll<Option<Self::Item>> {
1387        let this = &mut *self;
1388        if this.inner.check_shutdown(cx) {
1389            this.is_terminated = true;
1390            return std::task::Poll::Ready(None);
1391        }
1392        if this.is_terminated {
1393            panic!("polled VolumeControlRequestStream after completion");
1394        }
1395        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1396            |bytes, handles| {
1397                match this.inner.channel().read_etc(cx, bytes, handles) {
1398                    std::task::Poll::Ready(Ok(())) => {}
1399                    std::task::Poll::Pending => return std::task::Poll::Pending,
1400                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1401                        this.is_terminated = true;
1402                        return std::task::Poll::Ready(None);
1403                    }
1404                    std::task::Poll::Ready(Err(e)) => {
1405                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1406                            e.into(),
1407                        ))))
1408                    }
1409                }
1410
1411                // A message has been received from the channel
1412                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1413
1414                std::task::Poll::Ready(Some(match header.ordinal {
1415                    0x6ff4231809a697da => {
1416                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1417                        let mut req = fidl::new_empty!(
1418                            VolumeControlSetVolumeRequest,
1419                            fidl::encoding::DefaultFuchsiaResourceDialect
1420                        );
1421                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VolumeControlSetVolumeRequest>(&header, _body_bytes, handles, &mut req)?;
1422                        let control_handle =
1423                            VolumeControlControlHandle { inner: this.inner.clone() };
1424                        Ok(VolumeControlRequest::SetVolume { volume: req.volume, control_handle })
1425                    }
1426                    0x50c10c28bba46425 => {
1427                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1428                        let mut req = fidl::new_empty!(
1429                            VolumeControlSetMuteRequest,
1430                            fidl::encoding::DefaultFuchsiaResourceDialect
1431                        );
1432                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VolumeControlSetMuteRequest>(&header, _body_bytes, handles, &mut req)?;
1433                        let control_handle =
1434                            VolumeControlControlHandle { inner: this.inner.clone() };
1435                        Ok(VolumeControlRequest::SetMute { mute: req.mute, control_handle })
1436                    }
1437                    _ => Err(fidl::Error::UnknownOrdinal {
1438                        ordinal: header.ordinal,
1439                        protocol_name:
1440                            <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1441                    }),
1442                }))
1443            },
1444        )
1445    }
1446}
1447
1448/// A protocol for controlling volume.
1449#[derive(Debug)]
1450pub enum VolumeControlRequest {
1451    /// Sets the volume of the audio element to the given value in
1452    /// [0.0, 1.0]. If the value is provided is outside of [0.0, 1.0],
1453    /// the value is clamped before application.
1454    SetVolume { volume: f32, control_handle: VolumeControlControlHandle },
1455    /// Sets whether the controlled element is muted. Mute is not the same
1456    /// as setting volume to 0.0; volume will persist for the duration of
1457    /// a mute. If volume was 0.5 before mute, volume will resume at 0.5
1458    /// following unmute.
1459    SetMute { mute: bool, control_handle: VolumeControlControlHandle },
1460}
1461
1462impl VolumeControlRequest {
1463    #[allow(irrefutable_let_patterns)]
1464    pub fn into_set_volume(self) -> Option<(f32, VolumeControlControlHandle)> {
1465        if let VolumeControlRequest::SetVolume { volume, control_handle } = self {
1466            Some((volume, control_handle))
1467        } else {
1468            None
1469        }
1470    }
1471
1472    #[allow(irrefutable_let_patterns)]
1473    pub fn into_set_mute(self) -> Option<(bool, VolumeControlControlHandle)> {
1474        if let VolumeControlRequest::SetMute { mute, control_handle } = self {
1475            Some((mute, control_handle))
1476        } else {
1477            None
1478        }
1479    }
1480
1481    /// Name of the method defined in FIDL
1482    pub fn method_name(&self) -> &'static str {
1483        match *self {
1484            VolumeControlRequest::SetVolume { .. } => "set_volume",
1485            VolumeControlRequest::SetMute { .. } => "set_mute",
1486        }
1487    }
1488}
1489
1490#[derive(Debug, Clone)]
1491pub struct VolumeControlControlHandle {
1492    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1493}
1494
1495impl fidl::endpoints::ControlHandle for VolumeControlControlHandle {
1496    fn shutdown(&self) {
1497        self.inner.shutdown()
1498    }
1499    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1500        self.inner.shutdown_with_epitaph(status)
1501    }
1502
1503    fn is_closed(&self) -> bool {
1504        self.inner.channel().is_closed()
1505    }
1506    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1507        self.inner.channel().on_closed()
1508    }
1509
1510    #[cfg(target_os = "fuchsia")]
1511    fn signal_peer(
1512        &self,
1513        clear_mask: zx::Signals,
1514        set_mask: zx::Signals,
1515    ) -> Result<(), zx_status::Status> {
1516        use fidl::Peered;
1517        self.inner.channel().signal_peer(clear_mask, set_mask)
1518    }
1519}
1520
1521impl VolumeControlControlHandle {
1522    pub fn send_on_volume_mute_changed(
1523        &self,
1524        mut new_volume: f32,
1525        mut new_muted: bool,
1526    ) -> Result<(), fidl::Error> {
1527        self.inner.send::<VolumeControlOnVolumeMuteChangedRequest>(
1528            (new_volume, new_muted),
1529            0,
1530            0x9cea352bd86c171,
1531            fidl::encoding::DynamicFlags::empty(),
1532        )
1533    }
1534}
1535
1536mod internal {
1537    use super::*;
1538}