Closed Bug 1168279 Opened 9 years ago Closed 8 years ago

[FFOS7715 v2.1][audio][dophin]FM play in background in headset, Dial a number then open speaker in dialer, Hang up and dial agian, the sound come from speaker not in headset.

Categories

(Firefox OS Graveyard :: AudioChannel, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: jinchao.wang, Assigned: alwu)

Details

Description:
FM play in background in headset, Dial a number then open speaker in dialer,  Hang up and dial agian, the sound come from speaker not in headset.

Device: SPRD 7715ea(dophin)

Steps to Reproduce:
1) FM play in background in headset,
2) Open dialer app, dialing a number ,after call connect, open speaker in dialer,
3) In dialer app, hang up,
4) In dialer app, dial agian,

Actual Result:
the sound come from speaker.

Expected Result:
the sound should come from headset.

Repro frequency:10/10,100%

Analysis:
(1)Flame can't reproduce but dophin can in clean version(mozilla prime code, don't apply sprd patch).
(2)FM in background, the issue can reproduce
(3)Music in background,the issue can't reproduce
(4)Music and FM both not in background,the issue can't reproduce
Dear Alastor:
   Sorry to trouble you. We has a audio problem on Dophin platform, but jingmei has left office from SPRD. So we did't has engineer who has a better understanding of audio. Our engineer just start to study audio and can't analyze this problem now. Can you help me analyze this problem?

   SPRD clean version pac : http://pan.baidu.com/s/1mgh5yg4
Flags: needinfo?(vchen)
Flags: needinfo?(alwu)
I will check it later,
Keep ni for tracking.
Assignee: nobody → alwu
Flags: needinfo?(alwu)
Hi, JinChao,
You mean that "the sound come from speaker", is the dialing sound, FM or Telephony?
Thanks!
Flags: needinfo?(jinchao.wang)
Clear NI, I can reproduce this issue on local.
Flags: needinfo?(vchen)
Flags: needinfo?(jinchao.wang)
(In reply to Alastor Wu [:alwu] from comment #4)
> Clear NI, I can reproduce this issue on local.
Hi Alastor -

My further investigation:

When FM in background and be in playing state, audio policy manager out put logs:
> 05-26 18:23:00.893 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0
> 05-26 18:23:00.893 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0 
> mAvailableOutputDevices 0x8000b
> 05-26 18:23:01.293 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0
> 05-26 18:23:01.293 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0 
> mAvailableOutputDevices 0x8000b
> 05-26 18:23:01.313 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0
> 05-26 18:23:01.313 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0 
> mAvailableOutputDevices 0x8000b

Then make a call:
> 05-26 18:24:53.723 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 0, mPhoneState 2
> 05-26 18:24:53.723 W/AudioPolicyManagerBase(  125): setForceUse() invalid config for 
> FOR_COMMUNICATION in the FM interface.

Open the speaker:
> 05-26 18:25:11.373 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2
> 05-26 18:25:11.373 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2 
> mAvailableOutputDevices 0xb

Disconnected the call:
> 05-26 18:25:24.953 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0
> 05-26 18:25:24.953 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0 
> mAvailableOutputDevices 0xb
> 05-26 18:25:26.953 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0
> 05-26 18:25:26.953 V/AudioPolicyManagerBase(  125): setForceUse() usage 1, config 0, mPhoneState 0 
> mAvailableOutputDevices 0x8000b

Make a call again:
05-26 18:27:02.613 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 0, mPhoneState 0
05-26 18:27:02.613 W/AudioPolicyManagerBase(  125): setForceUse() invalid config for FOR_COMMUNICATION in the FM interface.
05-26 18:27:02.713 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2
05-26 18:27:02.713 W/AudioPolicyManagerBase(  125): setForceUse() invalid config for FOR_COMMUNICATION in the FM interface.
05-26 18:27:03.913 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 0, mPhoneState 2
05-26 18:27:03.913 W/AudioPolicyManagerBase(  125): setForceUse() invalid config for FOR_COMMUNICATION in the FM interface.

Once the call connected:
> 05-26 18:27:07.683 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2
> 05-26 18:27:07.683 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2 
> mAvailableOutputDevices 0xb
> 05-26 18:27:07.783 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2
> 05-26 18:27:07.783 V/AudioPolicyManagerBase(  125): setForceUse() usage 0, config 1, mPhoneState 2 
> mAvailableOutputDevices 0xb

the config's value set to 1, so the sound coming out in speaker.

The issue occurs only at even number when I make a call, but the odd number call is normal.

Maybe this discovery has some help for your further investigation.

Thanks.
Flags: needinfo?(alwu)
I found that when we start the second call, the AudioManager would unexpectedly set the speaker on by some unknown reason. 
I am still finding what is the actually root cause.
Flags: needinfo?(alwu)
(In reply to Alastor Wu [:alwu] from comment #6)
> I found that when we start the second call, the AudioManager would
> unexpectedly set the speaker on by some unknown reason. 
> I am still finding what is the actually root cause.
Hi Alastor -

So sorry to trouble you again and again. 

we find this issue occurs is due to the following modification:

http://bugzilla.spreadtrum.com/bugzilla/show_bug.cgi?id=320757: Bluetooth phone to open the FM, voice out of the receiver

diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp
index 5726832..de7af88 100644
--- a/audio/AudioPolicyManagerBase.cpp
+++ b/audio/AudioPolicyManagerBase.cpp
@@ -243,9 +243,6 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device
             }
 
             ALOGV("setDeviceConnectionState() disconnecting device %x", device);
-            if ((device & FFOS_AUDIO_DEVICE_OUT_FM) && (mAvailableOutputDevices & AUDIO_DEVICE_OUT_FM_SPEAKER)) {
-                setForceUse(AudioSystem::FOR_MEDIA, AudioSystem::FORCE_NONE);
-            }
             // remove device from available output devices
             mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
 
@@ -529,6 +526,16 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
             ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
             return;
         }
+        if (mAvailableOutputDevices & FFOS_AUDIO_DEVICE_OUT_FM) {
+            if (AudioSystem::FORCE_SPEAKER == config) {
+                mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | AUDIO_DEVICE_OUT_FM_SPEAKER);
+            } else {
+                mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~AUDIO_DEVICE_OUT_FM_SPEAKER);
+            }
+            mForceUse[AudioSystem::FOR_MEDIA] = config;
+            ALOGW("setForceUse() invalid config for FOR_COMMUNICATION in the FM interface.");
+            return;
+        }
         forceVolumeReeval = true;
         mForceUse[usage] = config;
         break;
@@ -545,13 +552,12 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
         mForceUse[usage] = config;
         if (mAvailableOutputDevices & FFOS_AUDIO_DEVICE_OUT_FM) {
             if (AudioSystem::FORCE_SPEAKER == config) {
-                setDeviceConnectionState(AUDIO_DEVICE_OUT_FM_SPEAKER,
-                        AudioSystem::DEVICE_STATE_AVAILABLE, FFOS_AUDIO_FM_DEVICE_ADDRESS);
+                mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | AUDIO_DEVICE_OUT_FM_SPEAKER);
             } else {
-                setDeviceConnectionState(AUDIO_DEVICE_OUT_FM_SPEAKER,
-                        AudioSystem::DEVICE_STATE_UNAVAILABLE, FFOS_AUDIO_FM_DEVICE_ADDRESS);
+                mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~AUDIO_DEVICE_OUT_FM_SPEAKER);
             }
         }
+
         break;
     case AudioSystem::FOR_RECORD:
         if (config != AudioSystem::FORCE_BT_SCO && config != AudioSystem::FORCE_WIRED_ACCESSORY &&
@@ -585,6 +591,8 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
         break;
     }
 
+    ALOGV("setForceUse() usage %d, config %d, mPhoneState %d mAvailableOutputDevices 0x%x", usage, config, mPhoneState,mAvailableOut
+
     // check for device and output changes triggered by new force usage
     checkA2dpSuspend();
     checkOutputForAllStrategies();
@@ -2696,9 +2704,6 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st
             device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_FM_HEADSET;
         }
 
-        if (device == AUDIO_DEVICE_NONE) {
-            device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_FM_SPEAKER;
-        }
         } break;
     /* @} */
     default:

After revert that modification, this issue has gone, maybe you could add some comment about this modification and give us some better suggestion.

Thank you.
Flags: needinfo?(alwu)
Hi, LinHui,
According my observation, the root cause might be the wrong config value in SPRDAudioPolicyManager. 
If the issue can be solved by reverting the modification, I think you can do it. (and close the bug)

---

Here is the log from my local,
1) Open the speaker during the first call
> In this step, we set the usage=COMMUNICATION, force=SPEAKER.
> 05-27 17:06:41.561  3634  3634 I GeckoDump: DD | gaia, switchToSpeaker1, open
> 05-27 17:06:41.561  3634  3634 I Gecko   : DD | Telephony, speakerEnabled, force = 1
> 05-27 17:06:41.561  3634  3634 I Gecko   : DD | AudioManager::SetForceForUse, usage = 0, force = 1 <- SPEAKER

2) Start second call
> We would reset the config when the new call start. Notice, the config of COMMUNICATION should be set to NONE.
> 05-27 17:06:50.641  3634  3634 I GeckoDump: DD | gaia, switchToSpeaker2, close
> 05-27 17:06:50.641  3634  3634 I Gecko   : DD | Telephony, speakerEnabled, force = 0
> 05-27 17:06:50.641  3634  3634 I Gecko   : DD | AudioManager::SetForceForUse, usage = 0, force = 0 <- NONE

3) Error here
> Although we set the NONE in step2, the config value is still SPEAKER. 
> If the config value is SPEAKER, the TelephonyService would enable the speaker again by SetForceForUse().
> 05-27 17:06:50.781  3634  3634 I Gecko   : DD | TelephonyService, _updateAudioState
> 05-27 17:06:50.781  3634  3634 I Gecko   : DD | AudioManager::SetForceForUse, usage = 0, force = 1
Flags: needinfo?(alwu)
Close this bug because we wouldn't land the code for v2.1.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.