fn negotiate_codec_settings(
        stream: &'a avdtp::StreamEndpoint,
    ) -> Result<avdtp::ServiceCapability, Error> {
        match stream.codec_type() {
            Some(&avdtp::MediaCodecType::AUDIO_AAC) => {
                let codec_extra =
                    Self::lookup_codec_extra(stream).ok_or(format_err!("no codec extra found"))?;
                let remote_codec_info = AacCodecInfo::try_from(&codec_extra[..])?;
                let negotiated_bitrate =
                    std::cmp::min(remote_codec_info.bitrate(), PREFERRED_BITRATE_AAC);

                // Remote peers have to support these options
                let aac_codec_info = AacCodecInfo::new(
                    AacObjectType::MPEG2_AAC_LC,
                    AacSamplingFrequency::FREQ48000HZ,
                    AacChannels::TWO,
                    true,
                    negotiated_bitrate,
                )?;
                Ok(avdtp::ServiceCapability::MediaCodec {
                    media_type: avdtp::MediaType::Audio,
                    codec_type: avdtp::MediaCodecType::AUDIO_AAC,
                    codec_extra: aac_codec_info.to_bytes().to_vec(),
                })
            }
            Some(&avdtp::MediaCodecType::AUDIO_SBC) => {
                // TODO(39321): Choose codec options based on availability and quality.
                let sbc_codec_info = SbcCodecInfo::new(
                    SbcSamplingFrequency::FREQ48000HZ,
                    SbcChannelMode::JOINT_STEREO,
                    SbcBlockCount::SIXTEEN,
                    SbcSubBands::EIGHT,
                    SbcAllocation::LOUDNESS,
                    /* min_bpv= */ 53,
                    /* max_bpv= */ 53,
                )?;

                Ok(avdtp::ServiceCapability::MediaCodec {
                    media_type: avdtp::MediaType::Audio,
                    codec_type: avdtp::MediaCodecType::AUDIO_SBC,
                    codec_extra: sbc_codec_info.to_bytes().to_vec(),
                })
            }
            Some(t) => Err(format_err!("Unsupported codec {:?}", t)),
            None => Err(format_err!("No codec type")),
        }
    }
/// From `stream` remote options, select our preferred and supported encoding options
From `stream` remote options, select our preferred and supported encoding options
From ` stream ` remote options select our preferred and supported encoding options
fn negotiate_codec_settings(
        stream: &'a avdtp::StreamEndpoint,
    ) -> Result<avdtp::ServiceCapability, Error> {
        match stream.codec_type() {
            Some(&avdtp::MediaCodecType::AUDIO_AAC) => {
                let codec_extra =
                    Self::lookup_codec_extra(stream).ok_or(format_err!("no codec extra found"))?;
                let remote_codec_info = AacCodecInfo::try_from(&codec_extra[..])?;
                let negotiated_bitrate =
                    std::cmp::min(remote_codec_info.bitrate(), PREFERRED_BITRATE_AAC);
                // Remote peers have to support these options
                let aac_codec_info = AacCodecInfo::new(
                    AacObjectType::MPEG2_AAC_LC,
                    AacSamplingFrequency::FREQ48000HZ,
                    AacChannels::TWO,
                    true,
                    negotiated_bitrate,
                )?;
                Ok(avdtp::ServiceCapability::MediaCodec {
                    media_type: avdtp::MediaType::Audio,
                    codec_type: avdtp::MediaCodecType::AUDIO_AAC,
                    codec_extra: aac_codec_info.to_bytes().to_vec(),
                })
            }
            Some(&avdtp::MediaCodecType::AUDIO_SBC) => {
                // TODO(39321): Choose codec options based on availability and quality.
                let sbc_codec_info = SbcCodecInfo::new(
                    SbcSamplingFrequency::FREQ48000HZ,
                    SbcChannelMode::JOINT_STEREO,
                    SbcBlockCount::SIXTEEN,
                    SbcSubBands::EIGHT,
                    SbcAllocation::LOUDNESS,
                    /* min_bpv= */ 53,
                    /* max_bpv= */ 53,
                )?;
                Ok(avdtp::ServiceCapability::MediaCodec {
                    media_type: avdtp::MediaType::Audio,
                    codec_type: avdtp::MediaCodecType::AUDIO_SBC,
                    codec_extra: sbc_codec_info.to_bytes().to_vec(),
                })
            }
            Some(t) => Err(format_err!("Unsupported codec {:?}", t)),
            None => Err(format_err!("No codec type")),
        }
    }
fn negotiate_codec_settings ( stream : & ' a avdtp :: StreamEndpoint , ) -> Result < avdtp :: ServiceCapability , Error > { match stream . codec_type ( ) { Some ( & avdtp :: MediaCodecType :: AUDIO_AAC ) => { let codec_extra = Self :: lookup_codec_extra ( stream ) . ok_or ( format_err ! ( " " ) ) ? ; let remote_codec_info = AacCodecInfo :: try_from ( & codec_extra [ .. ] ) ? ; let negotiated_bitrate = std :: cmp :: min ( remote_codec_info . bitrate ( ) , PREFERRED_BITRATE_AAC ) ; // Remote peers have to support these options let aac_codec_info = AacCodecInfo :: new ( AacObjectType :: MPEG2_AAC_LC , AacSamplingFrequency :: FREQ48000HZ , AacChannels :: TWO , true , negotiated_bitrate , ) ? ; Ok ( avdtp :: ServiceCapability :: MediaCodec { media_type : avdtp :: MediaType :: Audio , codec_type : avdtp :: MediaCodecType :: AUDIO_AAC , codec_extra : aac_codec_info . to_bytes ( ) . to_vec ( ) , } ) } Some ( & avdtp :: MediaCodecType :: AUDIO_SBC ) => { // TODO(39321): Choose codec options based on availability and quality. let sbc_codec_info = SbcCodecInfo :: new ( SbcSamplingFrequency :: FREQ48000HZ , SbcChannelMode :: JOINT_STEREO , SbcBlockCount :: SIXTEEN , SbcSubBands :: EIGHT , SbcAllocation :: LOUDNESS , /* min_bpv= */ 53 , /* max_bpv= */ 53 , ) ? ; Ok ( avdtp :: ServiceCapability :: MediaCodec { media_type : avdtp :: MediaType :: Audio , codec_type : avdtp :: MediaCodecType :: AUDIO_SBC , codec_extra : sbc_codec_info . to_bytes ( ) . to_vec ( ) , } ) } Some ( t ) => Err ( format_err ! ( " " t ) ) , None => Err ( format_err ! ( " " ) ) , } }
From `stream` remote options, select our preferred and supported encoding options
From ` stream ` remote options select our preferred and supported encoding options
stream
&'a avdtp::StreamEndpoint
stream
&'a avdtp::StreamEndpoint