Bluetooth not working on IPhone. Suggestions for fix?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying to implement support for bluetooth on IPhone. Although pjmedia has support for bluetooth, it seems to me it may not have been tested? After a lot of testing I've found out the following:

1. Initializing bluetooth via pjsip

To initialize bluetooth, I run the following code while in call (AudioCategory is AVAudioSessionCategoryPlayAndRecord):

[snippet#1]
	pjmedia_aud_dev_route route = PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH;
	pjsua_snd_set_setting(PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE, &route, PJ_TRUE);

This triggers the function ca_stream_set_cap in 'coreaudio_dev.c'

[snippet#2]
	ostatus = AudioSessionSetProperty (
	    kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
	    sizeof(btooth), &btooth);

Where 'btooth' equals 1. The request fails. 'ostatus' returns kAudioSessionUnsupportedPropertyError ("The audio session property is not supported.").


2. Initializing bluetooth from outside pjsip

To test further, I removed snippet#2 (AudioSessionSetProperty) from 'coreaudio_dev.c' (so it only sets 'strm->param.input_route' and returns PJ_SUCCESS). Then I included the same code in the app after calling snippet#1, so bluetooth-support was turned on in the application, and not in pjsip. Now the call to AudioSessionSetProperty succeeds, but another error occurs.

kAudioSessionProperty_AudioRouteChange is triggered which calls propListener (in coreaudio_dev.c). propListener stops the stream and creates and sets up a new audio unit. This includes resetting the AudioCategory to PlayAndRecord which also resets the audio route from HeadsetBT to ReceiverAndMicrophone (turns off bluetooth!).

The user experiences this as follows: The bluetooth headphone device beeps to indicate it is turned on, followed by 1-2 seconds of sound, then it is turned off. To go around this issue, I simply added "return;" in propListener before the call to 'ca_stream_stop', to prevent it from resetting the stream.


3. Initializing bluetooth outside pjsip with modified propListener

This works in 50% of the cases. When successful, AudioSessionSetProperty returns kAudioSessionNoError, and kAudioSessionProperty_AudioRoute is correctly set to 'HeadsetBT'. Audio is working fine both ways.

However, it fails seemingly randomly. Sometimes five times in a row, and sometimes it works five times in a row, with no obvious pattern. What happens is AudioCategory is set to <null>, which again triggers kAudioSessionProperty_AudioRouteChange with routeChangeReason CategoryChange. After the callback has returned, the AudioCategory has suddenly changed to AVAudioSessionCategorySoloAmbient.

Resetting or changing category before it changes to AVAudioSessionCategorySoloAmbient does not work. No audio is working. There are no clues on the Apple Developer forum to similar errors. Reinitializing the AudioSession does not work. Changing category or enabling bluetooth after this moment returns success in code, but no audio is playing on any device. However, hanging up the call and starting a new call, seems to reset the audio-device, and audio is working again.

I'm pulling my hair out on this. Has anyone got a clue to *anything* of what is going on? All help is appreciated.


Thanks,
Magnus Gal?en.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20101019/fcf67956/attachment.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux