Bug 836655 - [Audio] To remove ChildID if there is no content channel playing in foreground. And only send audio-channel-changed with normal when ChildID in the background has content channel in playing state. r=baku
authorMarco Chen <mchen@mozilla.com>
Mon, 25 Feb 2013 16:54:07 +0800
changeset 122918 1c8ec52deaf4d12ea1e1ee03d886a95d3d4e2698
parent 122917 e9e4dab21e795d989964c091125b065ed137e318
child 122919 ec88008d44986873831a4f1de46e9ba73e6ff859
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs836655
milestone22.0a1
Bug 836655 - [Audio] To remove ChildID if there is no content channel playing in foreground. And only send audio-channel-changed with normal when ChildID in the background has content channel in playing state. r=baku
dom/audiochannel/AudioChannelService.cpp
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -130,16 +130,24 @@ AudioChannelService::UnregisterType(Audi
   // The array may contain multiple occurrence of this appId but
   // this should remove only the first one.
   AudioChannelInternalType type = GetInternalType(aType, aElementHidden);
   mChannelCounters[type].RemoveElement(aChildID);
 
   // In order to avoid race conditions, it's safer to notify any existing
   // agent any time a new one is registered.
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
+    // We only remove ChildID when it is in the foreground.
+    // If in the background, we kept ChildID for allowing it to play next song.
+    if (aType == AUDIO_CHANNEL_CONTENT &&
+        mActiveContentChildIDs.Contains(aChildID) &&
+        (!aElementHidden &&
+         !mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].Contains(aChildID))) {
+      mActiveContentChildIDs.RemoveElement(aChildID);
+    }
     SendAudioChannelChangedNotification();
     Notify();
   }
 }
 
 bool
 AudioChannelService::GetMuted(AudioChannelAgent* aAgent, bool aElementHidden)
 {
@@ -170,33 +178,41 @@ AudioChannelService::GetMutedInternal(Au
 
   if (newType != oldType) {
     mChannelCounters[newType].AppendElement(aChildID);
     mChannelCounters[oldType].RemoveElement(aChildID);
   }
 
   // If the audio content channel is visible, let's remember this ChildID.
   if (newType == AUDIO_CHANNEL_INT_CONTENT &&
-      oldType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
-      !mActiveContentChildIDs.Contains(aChildID)) {
+      oldType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN) {
 
     if (mActiveContentChildIDsFrozen) {
       mActiveContentChildIDsFrozen = false;
       mActiveContentChildIDs.Clear();
     }
 
-    mActiveContentChildIDs.AppendElement(aChildID);
+    if (!mActiveContentChildIDs.Contains(aChildID)) {
+      mActiveContentChildIDs.AppendElement(aChildID);
+    }
   }
 
-  // If nothing is visible, the list has to been frozen.
   else if (newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
            oldType == AUDIO_CHANNEL_INT_CONTENT &&
-           !mActiveContentChildIDsFrozen &&
-           mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) {
-    mActiveContentChildIDsFrozen = true;
+           !mActiveContentChildIDsFrozen) {
+    // If nothing is visible, the list has to been frozen.
+    // Or if there is still any one with other ChildID in foreground then
+    // it should be removed from list and left other ChildIDs in the foreground
+    // to keep playing. Finally only last one childID which go to background
+    // will be in list.
+    if (mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) {
+      mActiveContentChildIDsFrozen = true;
+    } else if (!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].Contains(aChildID)) {
+      mActiveContentChildIDs.RemoveElement(aChildID);
+    }
   }
 
   if (newType != oldType && aType == AUDIO_CHANNEL_CONTENT) {
     Notify();
   }
 
   // Let play any visible audio channel.
   if (!aElementHidden) {
@@ -286,18 +302,22 @@ AudioChannelService::SendAudioChannelCha
     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;
     }
 
-    // Content channels play in background if just one is active.
-    else if (!mActiveContentChildIDs.IsEmpty()) {
+    // There is only one Child can play content channel in the background.
+    // And need to check whether there is any content channels under playing
+    // now.
+    else if (!mActiveContentChildIDs.IsEmpty() &&
+             mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].Contains(
+             mActiveContentChildIDs[0])) {
       higher = AUDIO_CHANNEL_CONTENT;
     }
   }
 
   if (higher != mCurrentHigherChannel) {
     mCurrentHigherChannel = higher;
 
     nsString channelName;