Bug 1249437 - Remove workaround of volume control r=alwu
authorSotaro Ikeda <sotaro.ikeda.g@gmail.com>
Wed, 09 Mar 2016 15:34:07 -0800
changeset 287973 170566dce920857ca11e0c264781c1226d379fb5
parent 287972 e83b73ce4d1ac60a7b6d7c70b5c75ee54ef20a6a
child 287974 a1c6dad1153682c6c9fcafe85157bc2b9e02b419
push id30071
push usercbook@mozilla.com
push dateThu, 10 Mar 2016 10:51:55 +0000
treeherdermozilla-central@dd1abe874252 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalwu
bugs1249437
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1249437 - Remove workaround of volume control r=alwu
dom/system/gonk/AudioManager.cpp
dom/system/gonk/AudioManager.h
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -1356,49 +1356,37 @@ AudioManager::VolumeStreamState::SetVolu
   bool exist = mVolumeIndexes.Get(device, &oldVolumeIndex);
   if (exist && aIndex == oldVolumeIndex) {
     // No update
     return NS_OK;
   }
 
   // AudioPolicyManager::setStreamVolumeIndex() set volumes of all active
   // devices for stream.
-  nsresult rv = SetVolumeIndex(aIndex, device);
+  nsresult rv;
+  rv = SetVolumeIndexToConsistentDeviceIfNeeded(aIndex, device);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  // Workaround to make audio volume control consisitent.
-  // Active devices of AUDIO_STREAM_NOTIFICATION are affected by
-  // AUDIO_STREAM_MUSIC's activity. It makes audio volume control inconsistent.
-  // See Bug 1196724
-  if (device != AUDIO_DEVICE_OUT_SPEAKER &&
-      mStreamType == AUDIO_STREAM_NOTIFICATION) {
-      // Rescaling of index is not necessary.
-      rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_SPEAKER);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-  }
-
   return NS_OK;
 }
 
 nsresult
 AudioManager::VolumeStreamState::SetVolumeIndexToAliasStreams(uint32_t aIndex,
                                                               uint32_t aDevice)
 {
   uint32_t oldVolumeIndex = 0;
   bool exist = mVolumeIndexes.Get(aDevice, &oldVolumeIndex);
   if (exist && aIndex == oldVolumeIndex) {
     // No update
     return NS_OK;
   }
 
-  nsresult rv = SetVolumeIndex(aIndex, aDevice);
+  nsresult rv = SetVolumeIndexToConsistentDeviceIfNeeded(aIndex, aDevice);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   for (int32_t streamType = 0; streamType < AUDIO_STREAM_MAX; streamType++) {
     if ((streamType != mStreamType) &&
          sStreamVolumeAliasTbl[streamType] == mStreamType) {
       // Rescaling of index is not necessary.
@@ -1409,16 +1397,37 @@ AudioManager::VolumeStreamState::SetVolu
       }
     }
   }
 
   return NS_OK;
 }
 
 nsresult
+AudioManager::VolumeStreamState::SetVolumeIndexToConsistentDeviceIfNeeded(uint32_t aIndex, uint32_t aDevice)
+{
+  nsresult rv;
+  if (aDevice == AUDIO_DEVICE_OUT_SPEAKER || aDevice == AUDIO_DEVICE_OUT_EARPIECE) {
+    // Set AUDIO_DEVICE_OUT_SPEAKER and AUDIO_DEVICE_OUT_EARPIECE to same volume.
+    rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_SPEAKER);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+    rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_EARPIECE);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  } else {
+    // No alias device
+    rv = SetVolumeIndex(aIndex, aDevice);
+  }
+  return rv;  
+}
+
+nsresult
 AudioManager::VolumeStreamState::SetVolumeIndex(uint32_t aIndex,
                                                 uint32_t aDevice,
                                                 bool aUpdateCache)
 {
   status_t rv;
 #if ANDROID_VERSION >= 17
   if (aUpdateCache) {
     mVolumeIndexes.Put(aDevice, aIndex);
--- a/dom/system/gonk/AudioManager.h
+++ b/dom/system/gonk/AudioManager.h
@@ -82,16 +82,17 @@ public:
     uint32_t GetVolumeIndex();
     uint32_t GetVolumeIndex(uint32_t aDevice);
     void ClearCurrentVolumeUpdated();
     // Set volume index to all active devices.
     // Active devices are chosen by android AudioPolicyManager.
     nsresult SetVolumeIndexToActiveDevices(uint32_t aIndex);
     // Set volume index to all alias streams for device. Alias streams have same volume.
     nsresult SetVolumeIndexToAliasStreams(uint32_t aIndex, uint32_t aDevice);
+    nsresult SetVolumeIndexToConsistentDeviceIfNeeded(uint32_t aIndex, uint32_t aDevice);
     nsresult SetVolumeIndex(uint32_t aIndex, uint32_t aDevice, bool aUpdateCache = true);
     // Restore volume index to all devices. Called when AudioFlinger is restarted.
     void RestoreVolumeIndexToAllDevices();
   private:
     AudioManager& mManager;
     const int32_t mStreamType;
     uint32_t mLastDevices;
     bool mIsDevicesChanged;