Bug 968921 - "audio-channel-change" event should consider the audio channels in the background even there is an one on the foreground. r=baku
authorMarco Chen <mchen@mozilla.com>
Mon, 17 Feb 2014 18:58:12 +0800
changeset 169288 686c461c61aabfb9c3adc7a28642973e251c8c12
parent 169287 3d0a2dd0b4384530490ce725eb18a00b30c65c8f
child 169289 b1a1ebc98ef65e9f809d0ac269931a268e653f25
push id4807
push userryanvm@gmail.com
push dateTue, 18 Feb 2014 13:50:21 +0000
treeherderb2g-inbound@b1a1ebc98ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs968921
milestone30.0a1
Bug 968921 - "audio-channel-change" event should consider the audio channels in the background even there is an one on the foreground. r=baku
dom/audiochannel/AudioChannelService.cpp
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -443,17 +443,17 @@ AudioChannelService::SendAudioChannelCha
 
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   if (obs) {
     obs->NotifyObservers(static_cast<nsIWritablePropertyBag*>(props),
                          "audio-channel-process-changed", nullptr);
   }
 
   // Calculating the most important active channel.
-  AudioChannelType higher = AUDIO_CHANNEL_LAST;
+  AudioChannelType higher = AUDIO_CHANNEL_DEFAULT;
 
   // Top-Down in the hierarchy for visible elements
   if (!mChannelCounters[AUDIO_CHANNEL_INT_PUBLICNOTIFICATION].IsEmpty()) {
     higher = AUDIO_CHANNEL_PUBLICNOTIFICATION;
   }
 
   else if (!mChannelCounters[AUDIO_CHANNEL_INT_RINGER].IsEmpty()) {
     higher = AUDIO_CHANNEL_RINGER;
@@ -477,63 +477,52 @@ AudioChannelService::SendAudioChannelCha
 
   else if (!mChannelCounters[AUDIO_CHANNEL_INT_NORMAL].IsEmpty()) {
     higher = AUDIO_CHANNEL_NORMAL;
   }
 
   AudioChannelType visibleHigher = higher;
 
   // Top-Down in the hierarchy for non-visible elements
-  if (higher == AUDIO_CHANNEL_LAST) {
-    if (!mChannelCounters[AUDIO_CHANNEL_INT_PUBLICNOTIFICATION_HIDDEN].IsEmpty()) {
-      higher = AUDIO_CHANNEL_PUBLICNOTIFICATION;
-    }
-
-    else if (!mChannelCounters[AUDIO_CHANNEL_INT_RINGER_HIDDEN].IsEmpty()) {
-      higher = AUDIO_CHANNEL_RINGER;
+  // And we can ignore normal channel because it can't play in the background.
+  for (int i = AUDIO_CHANNEL_LAST - 1;
+       i > higher && i > AUDIO_CHANNEL_NORMAL; i--) {
+    if (i == AUDIO_CHANNEL_CONTENT &&
+      mPlayableHiddenContentChildID != CONTENT_PROCESS_ID_UNKNOWN) {
+      higher = static_cast<AudioChannelType>(i);
     }
 
-    else if (!mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN].IsEmpty()) {
-      higher = AUDIO_CHANNEL_TELEPHONY;
-    }
-
-    else if (!mChannelCounters[AUDIO_CHANNEL_INT_ALARM_HIDDEN].IsEmpty()) {
-      higher = AUDIO_CHANNEL_ALARM;
-    }
-
-    else if (!mChannelCounters[AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN].IsEmpty()) {
-      higher = AUDIO_CHANNEL_NOTIFICATION;
-    }
-
-    // Check whether there is any playable hidden content channel or not.
-    else if (mPlayableHiddenContentChildID != CONTENT_PROCESS_ID_UNKNOWN) {
-      higher = AUDIO_CHANNEL_CONTENT;
+    // Each channel type will be split to fg and bg for recording the state,
+    // so here need to do a translation.
+    if (!mChannelCounters[i * 2 + 1].IsEmpty()) {
+      higher = static_cast<AudioChannelType>(i);
+      break;
     }
   }
 
   if (higher != mCurrentHigherChannel) {
     mCurrentHigherChannel = higher;
 
     nsString channelName;
-    if (mCurrentHigherChannel != AUDIO_CHANNEL_LAST) {
+    if (mCurrentHigherChannel != AUDIO_CHANNEL_DEFAULT) {
       channelName.AssignASCII(ChannelName(mCurrentHigherChannel));
     } else {
       channelName.AssignLiteral("none");
     }
 
     if (obs) {
       obs->NotifyObservers(nullptr, "audio-channel-changed", channelName.get());
     }
   }
 
   if (visibleHigher != mCurrentVisibleHigherChannel) {
     mCurrentVisibleHigherChannel = visibleHigher;
 
     nsString channelName;
-    if (mCurrentVisibleHigherChannel != AUDIO_CHANNEL_LAST) {
+    if (mCurrentVisibleHigherChannel != AUDIO_CHANNEL_DEFAULT) {
       channelName.AssignASCII(ChannelName(mCurrentVisibleHigherChannel));
     } else {
       channelName.AssignLiteral("none");
     }
 
     if (obs) {
       obs->NotifyObservers(nullptr, "visible-audio-channel-changed", channelName.get());
     }