/// Update the SCO connection state to reflect the call state, creating a
/// a future to wait for incoming SCO connections if necessary.
Update the SCO connection state to reflect the call state, creating a
a future to wait for incoming SCO connections if necessary.
Update the SCO connection state to reflect the call state creating a a future to wait for incoming SCO connections if necessary .
async fn update_sco_state(&mut self) -> Result<(), ()> {
        let call_active = self.calls.is_call_active();
        let call_transferred = self.calls.is_call_transferred_to_ag();
        if call_active && call_transferred {
            error!("Call both active and transferred for peer {}", self.id);
            return Err(());
        }
        let previous_sco_state = &self.sco_state;
        info!("Updating SCO state for peer {}.  Call active: {}, Call transferred: {}, Previous SCO state: {:?}", self.id, call_active, call_transferred, previous_sco_state);
        if call_active {
            match previous_sco_state {
                // A call just started, so set up SCO.
                ScoState::Inactive
                // A call was just transferred to the HF, so set up SCO.
                | ScoState::AwaitingRemote(_)
                => {
                    self.initiate_codec_negotiation().await;
                    self.sco_state = ScoState::SettingUp;
                },
                // We are negotiating codecs; wait for that to finish before starting the SCO
                // connection, so do nothing.
                ScoState::SettingUp
                // The SCO connection was closed by the peer and we requested the call manager set
                // that call as transferred to AG,  but we are waiting on the call manager to do
                // so, so do nothing.
                | ScoState::TearingDown
                // A call is active and we have a SCO connection, so do nothing.
                | ScoState::Active(_) => {},
            }
        } else if call_transferred {
            match previous_sco_state {
            // A call was just started transferred to the AG, so wait for SCO to be set up by the
            // HF.
            ScoState::Inactive
            // A call was in codec negotiation when transferred to the AG, so wait for SCO to be 
            // set up by the HF.
            | ScoState::SettingUp
            // The HF tore down the SCO connection so a call was transferred to the HF and the call
            // manager has acknowledged that, so wait for SCO to be set up by the HF.
            | ScoState::TearingDown
            // A call was active and has just been transferred to the HF, so wait for the SCO
            // connection to be set up by the HF.
            | ScoState::Active(_) => {
               let codecs = self.connection.get_selected_codec().map_or(vec![CodecId::CVSD], |c| vec![c]);
               let sco_connector = self.sco_connector.clone();
               let id = self.id.clone();
               let fut = async move {
                sco_connector.accept(id, codecs).await
               };
               self.sco_state = ScoState::AwaitingRemote(Box::pin(fut));
            }
            // A call is transferred to the HF and we are waiting for SCO to be set up by the HF,
            // so do nothing.
            ScoState::AwaitingRemote(_) => {}
        }
        } else {
            /* No call in progress */
            self.sco_state = ScoState::Inactive
        };
        info!(
            "Finished updating SCO state for peer {}; SCO state is now {:?}",
            self.id, self.sco_state
        );
        Ok(())
    }
async fn update_sco_state ( & mut self ) -> Result < ( ) , ( ) > { let call_active = self . calls . is_call_active ( ) ; let call_transferred = self . calls . is_call_transferred_to_ag ( ) ; if call_active && call_transferred { error ! ( " " self id ) ; return Err ( ( ) ) ; } let previous_sco_state = & self . sco_state ; info ! ( " " self id call_active call_transferred previous_sco_state ) ; if call_active { match previous_sco_state { // A call just started, so set up SCO. ScoState :: Inactive // A call was just transferred to the HF, so set up SCO. | ScoState :: AwaitingRemote ( _ ) => { self . initiate_codec_negotiation ( ) . await ; self . sco_state = ScoState :: SettingUp ; } , // We are negotiating codecs; wait for that to finish before starting the SCO // connection, so do nothing. ScoState :: SettingUp // The SCO connection was closed by the peer and we requested the call manager set // that call as transferred to AG,  but we are waiting on the call manager to do // so, so do nothing. | ScoState :: TearingDown // A call is active and we have a SCO connection, so do nothing. | ScoState :: Active ( _ ) => { } , } } else if call_transferred { match previous_sco_state { // A call was just started transferred to the AG, so wait for SCO to be set up by the // HF. ScoState :: Inactive // A call was in codec negotiation when transferred to the AG, so wait for SCO to be  // set up by the HF. | ScoState :: SettingUp // The HF tore down the SCO connection so a call was transferred to the HF and the call // manager has acknowledged that, so wait for SCO to be set up by the HF. | ScoState :: TearingDown // A call was active and has just been transferred to the HF, so wait for the SCO // connection to be set up by the HF. | ScoState :: Active ( _ ) => { let codecs = self . connection . get_selected_codec ( ) . map_or ( vec ! [ CodecId CVSD ] , | c | vec ! [ c ] ) ; let sco_connector = self . sco_connector . clone ( ) ; let id = self . id . clone ( ) ; let fut = async move { sco_connector . accept ( id , codecs ) . await } ; self . sco_state = ScoState :: AwaitingRemote ( Box :: pin ( fut ) ) ; } // A call is transferred to the HF and we are waiting for SCO to be set up by the HF, // so do nothing. ScoState :: AwaitingRemote ( _ ) => { } } } else { /* No call in progress */ self . sco_state = ScoState :: Inactive } ; info ! ( " " self id self sco_state ) ; Ok ( ( ) ) }
Update the SCO connection state to reflect the call state, creating a
a future to wait for incoming SCO connections if necessary.
Update the SCO connection state to reflect the call state creating a a future to wait for incoming SCO connections if necessary .
&mut self