async fn check_and_bind_volume_controls(
    service_connected: Arc<RwLock<bool>>,
    service_context_handle: ServiceContextHandle,
    stream_volume_controls: &mut HashMap<AudioStreamType, StreamVolumeControl>,
) -> Result<(), Error> {
    if *service_connected.read() {
        return Ok(());
    }

    let service_result =
        service_context_handle.lock().await.connect::<fidl_fuchsia_media::AudioCoreMarker>();

    let audio_service = match service_result {
        Ok(service) => {
            *service_connected.write() = true;
            service
        }
        Err(err) => {
            fx_log_err!("failed to connect to audio core, {}", err);
            return Err(err);
        }
    };

    for stream in default_audio_info().streams.iter() {
        stream_volume_controls.insert(
            stream.stream_type.clone(),
            StreamVolumeControl::create(&audio_service, stream.clone()),
        );
    }
    Ok(())
}
// Checks to see if |service_connected| contains true. If it is not, then
// connect to the audio core service. If the service connects successfully,
// set |service_connected| to true and create a StreamVolumeControl for each
// stream type.
Checks to see if |service_connected| contains true. If it is not, then
connect to the audio core service. If the service connects successfully,
set |service_connected| to true and create a StreamVolumeControl for each
stream type.
Checks to see if |service_connected| contains true . If it is not then connect to the audio core service . If the service connects successfully set |service_connected| to true and create a StreamVolumeControl for each stream type .
async fn check_and_bind_volume_controls(
    service_connected: Arc<RwLock<bool>>,
    service_context_handle: ServiceContextHandle,
    stream_volume_controls: &mut HashMap<AudioStreamType, StreamVolumeControl>,
) -> Result<(), Error> {
    if *service_connected.read() {
        return Ok(());
    }
    let service_result =
        service_context_handle.lock().await.connect::<fidl_fuchsia_media::AudioCoreMarker>();
    let audio_service = match service_result {
        Ok(service) => {
            *service_connected.write() = true;
            service
        }
        Err(err) => {
            fx_log_err!("failed to connect to audio core, {}", err);
            return Err(err);
        }
    };
    for stream in default_audio_info().streams.iter() {
        stream_volume_controls.insert(
            stream.stream_type.clone(),
            StreamVolumeControl::create(&audio_service, stream.clone()),
        );
    }
    Ok(())
}
async fn check_and_bind_volume_controls ( service_connected : Arc < RwLock < bool > > , service_context_handle : ServiceContextHandle , stream_volume_controls : & mut HashMap < AudioStreamType , StreamVolumeControl > , ) -> Result < ( ) , Error > { if * service_connected . read ( ) { return Ok ( ( ) ) ; } let service_result = service_context_handle . lock ( ) . await . connect :: < fidl_fuchsia_media :: AudioCoreMarker > ( ) ; let audio_service = match service_result { Ok ( service ) => { * service_connected . write ( ) = true ; service } Err ( err ) => { fx_log_err ! ( " " err ) ; return Err ( err ) ; } } ; for stream in default_audio_info ( ) . streams . iter ( ) { stream_volume_controls . insert ( stream . stream_type . clone ( ) , StreamVolumeControl :: create ( & audio_service , stream . clone ( ) ) , ) ; } Ok ( ( ) ) }
Checks to see if |service_connected| contains true.
Checks to see if |service_connected| contains true .
service_connected
Arc<RwLock<bool>>
service_context_handle
ServiceContextHandle
stream_volume_controls
&mut HashMap<AudioStreamType, StreamVolumeControl>
service_connected
Arc<RwLock<bool>>
service_context_handle
ServiceContextHandle
stream_volume_controls
&mut HashMap<AudioStreamType, StreamVolumeControl>