perchco / perchrtc

An iOS WebRTC demo using XirSys servers
MIT License
135 stars 34 forks source link

"Machine Gun" Noise When Bluetooth Device Is Connected #42

Open toiye opened 8 years ago

toiye commented 8 years ago

I'm not exactly sure how to explain this problem, but when a bluetooth headphone or car stereo is connected when we start the connection and enable the audio stream, we get a really terrible repeated noise, like a video game machine gun, instead of normal audio coming through. Totally independent of any audio coming from the sending device.

Switching to the speakerphone and then back to the earpiece resolves the issue, but takes a long time for iOS to make the switch, so it's not a very usable solution. (See weird 1 second delay and toggle below. That's our current hack.) Starting with bluetooth disconnected and then connecting it does not exhibit the issue.

I don't have very many devices to test on, but I've been able to replicate it with both an iPad Mini (gen 1) and an iPhone 6S while using JayBird BlueBudX headphones.

Have you ever heard of anything like this? We're stumped as to how to proceed. Here's our start connection code.

RTCMediaStream *remoteStream = [self.connectionManager.remoteStreams firstObject];
if (remoteStream) {

    RTCAudioTrack *audioTrack = [remoteStream.audioTracks firstObject];
    if (audioTrack) {

        [audioTrack setEnabled:YES];
    }
}

[self.connectionManager activateSpeakers];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {

    [self.connectionManager activateEarpiece];
});

Any help you can provide would be greatly appreciated.