2012-12-04 11:46:07 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AudioChannelService.h"
|
2012-12-05 19:01:58 -08:00
|
|
|
#include "AudioChannelServiceChild.h"
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
|
2014-12-29 02:56:00 -08:00
|
|
|
#include "nsContentUtils.h"
|
2014-10-17 08:29:39 -07:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2012-12-04 11:46:07 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2013-04-25 17:53:26 -07:00
|
|
|
#include "nsHashPropertyBag.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2014-03-11 03:46:55 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2014-09-16 10:15:16 -07:00
|
|
|
#include "mozilla/dom/SettingChangeNotificationBinding.h"
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2012-12-06 02:11:06 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-07-17 22:22:36 -07:00
|
|
|
#include "nsJSUtils.h"
|
2012-12-06 02:11:06 -08:00
|
|
|
#include "nsIAudioManager.h"
|
2013-11-24 15:50:03 -08:00
|
|
|
#include "SpeakerManagerService.h"
|
2013-07-17 22:22:36 -07:00
|
|
|
#define NS_AUDIOMANAGER_CONTRACTID "@mozilla.org/telephony/audiomanager;1"
|
2012-12-06 02:11:06 -08:00
|
|
|
#endif
|
2013-07-17 22:22:36 -07:00
|
|
|
|
2014-03-20 03:45:55 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2013-02-14 12:41:29 -08:00
|
|
|
using namespace mozilla::hal;
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
StaticRefPtr<AudioChannelService> gAudioChannelService;
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
// Mappings from 'mozaudiochannel' attribute strings to an enumeration.
|
|
|
|
static const nsAttrValue::EnumTable kMozAudioChannelAttributeTable[] = {
|
|
|
|
{ "normal", (int16_t)AudioChannel::Normal },
|
|
|
|
{ "content", (int16_t)AudioChannel::Content },
|
|
|
|
{ "notification", (int16_t)AudioChannel::Notification },
|
|
|
|
{ "alarm", (int16_t)AudioChannel::Alarm },
|
|
|
|
{ "telephony", (int16_t)AudioChannel::Telephony },
|
|
|
|
{ "ringer", (int16_t)AudioChannel::Ringer },
|
|
|
|
{ "publicnotification", (int16_t)AudioChannel::Publicnotification },
|
|
|
|
{ nullptr }
|
|
|
|
};
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
// static
|
|
|
|
AudioChannelService*
|
|
|
|
AudioChannelService::GetAudioChannelService()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-12-05 19:01:58 -08:00
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return AudioChannelServiceChild::GetAudioChannelService();
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:10:16 -07:00
|
|
|
return gAudioChannelService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
AudioChannelService*
|
|
|
|
AudioChannelService::GetOrCreateAudioChannelService()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return AudioChannelServiceChild::GetOrCreateAudioChannelService();
|
|
|
|
}
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
// If we already exist, exit early
|
|
|
|
if (gAudioChannelService) {
|
|
|
|
return gAudioChannelService;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new instance, register, return
|
|
|
|
nsRefPtr<AudioChannelService> service = new AudioChannelService();
|
2014-08-28 23:10:16 -07:00
|
|
|
MOZ_ASSERT(service);
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
gAudioChannelService = service;
|
|
|
|
return gAudioChannelService;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioChannelService::Shutdown()
|
|
|
|
{
|
2012-12-05 19:01:58 -08:00
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return AudioChannelServiceChild::Shutdown();
|
|
|
|
}
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
if (gAudioChannelService) {
|
|
|
|
gAudioChannelService = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(AudioChannelService, nsIObserver, nsITimerCallback)
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
AudioChannelService::AudioChannelService()
|
2014-04-25 03:22:17 -07:00
|
|
|
: mCurrentHigherChannel(-1)
|
|
|
|
, mCurrentVisibleHigherChannel(-1)
|
2013-09-17 00:46:06 -07:00
|
|
|
, mPlayableHiddenContentChildID(CONTENT_PROCESS_ID_UNKNOWN)
|
2013-10-07 23:30:04 -07:00
|
|
|
, mDisabled(false)
|
2013-09-12 05:26:03 -07:00
|
|
|
, mDefChannelChildID(CONTENT_PROCESS_ID_UNKNOWN)
|
2012-12-04 11:46:07 -08:00
|
|
|
{
|
2012-12-28 09:57:35 -08:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->AddObserver(this, "ipc:content-shutdown", false);
|
2013-10-07 23:30:04 -07:00
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
2014-10-17 08:29:39 -07:00
|
|
|
obs->AddObserver(this, "inner-window-destroyed", false);
|
2013-07-17 22:22:36 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// To monitor the volume settings based on audio channel.
|
|
|
|
obs->AddObserver(this, "mozsettings-changed", false);
|
|
|
|
#endif
|
2012-12-28 09:57:35 -08:00
|
|
|
}
|
|
|
|
}
|
2012-12-04 11:46:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioChannelService::~AudioChannelService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:25:18 -08:00
|
|
|
AudioChannelService::RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannel aChannel,
|
2013-09-17 20:46:22 -07:00
|
|
|
bool aWithVideo)
|
2012-12-04 11:46:07 -08:00
|
|
|
{
|
2013-10-07 23:30:04 -07:00
|
|
|
if (mDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelAgentData* data = new AudioChannelAgentData(aChannel,
|
2013-09-02 02:45:44 -07:00
|
|
|
true /* aElementHidden */,
|
2013-09-17 20:46:22 -07:00
|
|
|
AUDIO_CHANNEL_STATE_MUTED /* aState */,
|
|
|
|
aWithVideo);
|
2013-01-08 23:18:16 -08:00
|
|
|
mAgents.Put(aAgent, data);
|
2014-04-10 10:39:20 -07:00
|
|
|
RegisterType(aChannel, CONTENT_PROCESS_ID_MAIN, aWithVideo);
|
2014-03-11 03:47:25 -07:00
|
|
|
|
|
|
|
// If this is the first agent for this window, we must notify the observers.
|
|
|
|
uint32_t count = CountWindow(aAgent->Window());
|
|
|
|
if (count == 1) {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->NotifyObservers(ToSupports(aAgent->Window()),
|
|
|
|
"media-playback",
|
|
|
|
NS_LITERAL_STRING("active").get());
|
|
|
|
}
|
|
|
|
}
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::RegisterType(AudioChannel aChannel, uint64_t aChildID,
|
|
|
|
bool aWithVideo)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
2013-10-07 23:30:04 -07:00
|
|
|
if (mDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelInternalType type = GetInternalType(aChannel, true);
|
2013-01-08 23:18:16 -08:00
|
|
|
mChannelCounters[type].AppendElement(aChildID);
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2014-07-10 06:06:23 -07:00
|
|
|
|
|
|
|
// We must keep the childIds in order to decide which app is allowed to play
|
|
|
|
// with then telephony channel.
|
|
|
|
if (aChannel == AudioChannel::Telephony) {
|
|
|
|
RegisterTelephonyChild(aChildID);
|
|
|
|
}
|
|
|
|
|
2013-04-28 19:47:15 -07:00
|
|
|
// Since there is another telephony registered, we can unregister old one
|
|
|
|
// immediately.
|
2014-04-10 10:39:20 -07:00
|
|
|
if (mDeferTelChannelTimer && aChannel == AudioChannel::Telephony) {
|
2013-04-28 19:47:15 -07:00
|
|
|
mDeferTelChannelTimer->Cancel();
|
|
|
|
mDeferTelChannelTimer = nullptr;
|
2014-04-10 10:39:20 -07:00
|
|
|
UnregisterTypeInternal(aChannel, mTimerElementHidden, mTimerChildID,
|
|
|
|
false);
|
2013-09-17 20:46:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aWithVideo) {
|
|
|
|
mWithVideoChildIDs.AppendElement(aChildID);
|
2013-04-28 19:47:15 -07:00
|
|
|
}
|
|
|
|
|
2013-12-15 21:08:03 -08:00
|
|
|
// No hidden content channel can be playable if there is a content channel
|
|
|
|
// in foreground (bug 855208), nor if there is a normal channel with video
|
|
|
|
// in foreground (bug 894249).
|
|
|
|
if (type == AUDIO_CHANNEL_INT_CONTENT ||
|
|
|
|
(type == AUDIO_CHANNEL_INT_NORMAL &&
|
|
|
|
mWithVideoChildIDs.Contains(aChildID))) {
|
|
|
|
mPlayableHiddenContentChildID = CONTENT_PROCESS_ID_UNKNOWN;
|
|
|
|
}
|
2013-09-17 00:46:06 -07:00
|
|
|
// One hidden content channel can be playable only when there is no any
|
2013-12-15 21:08:03 -08:00
|
|
|
// content channel in the foreground, and no normal channel with video in
|
|
|
|
// foreground.
|
|
|
|
else if (type == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
|
2013-09-17 00:46:06 -07:00
|
|
|
mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) {
|
|
|
|
mPlayableHiddenContentChildID = aChildID;
|
|
|
|
}
|
|
|
|
|
2013-04-28 19:47:15 -07:00
|
|
|
// In order to avoid race conditions, it's safer to notify any existing
|
|
|
|
// agent any time a new one is registered.
|
2013-04-25 17:53:26 -07:00
|
|
|
SendAudioChannelChangedNotification(aChildID);
|
2014-06-24 22:15:12 -07:00
|
|
|
SendNotification();
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
2012-12-04 11:46:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:25:18 -08:00
|
|
|
AudioChannelService::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent)
|
2012-12-04 11:46:07 -08:00
|
|
|
{
|
2013-10-07 23:30:04 -07:00
|
|
|
if (mDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-10 14:56:20 -08:00
|
|
|
nsAutoPtr<AudioChannelAgentData> data;
|
|
|
|
mAgents.RemoveAndForget(aAgent, data);
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2013-01-10 14:56:20 -08:00
|
|
|
if (data) {
|
2014-04-10 10:39:20 -07:00
|
|
|
UnregisterType(data->mChannel, data->mElementHidden,
|
2013-09-17 20:46:22 -07:00
|
|
|
CONTENT_PROCESS_ID_MAIN, data->mWithVideo);
|
2013-01-10 14:56:20 -08:00
|
|
|
}
|
2014-10-17 08:29:39 -07:00
|
|
|
|
2013-11-24 15:50:03 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
bool active = AnyAudioChannelIsActive();
|
|
|
|
for (uint32_t i = 0; i < mSpeakerManager.Length(); i++) {
|
|
|
|
mSpeakerManager[i]->SetAudioChannelActive(active);
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-11 03:47:25 -07:00
|
|
|
|
|
|
|
// If this is the last agent for this window, we must notify the observers.
|
|
|
|
uint32_t count = CountWindow(aAgent->Window());
|
|
|
|
if (count == 0) {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->NotifyObservers(ToSupports(aAgent->Window()),
|
|
|
|
"media-playback",
|
|
|
|
NS_LITERAL_STRING("inactive").get());
|
|
|
|
}
|
|
|
|
}
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2012-12-05 19:01:58 -08:00
|
|
|
void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::UnregisterType(AudioChannel aChannel,
|
2013-01-08 23:18:16 -08:00
|
|
|
bool aElementHidden,
|
2013-09-17 20:46:22 -07:00
|
|
|
uint64_t aChildID,
|
|
|
|
bool aWithVideo)
|
2013-04-28 19:47:15 -07:00
|
|
|
{
|
2013-10-07 23:30:04 -07:00
|
|
|
if (mDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-28 19:47:15 -07:00
|
|
|
// There are two reasons to defer the decrease of telephony channel.
|
|
|
|
// 1. User can have time to remove device from his ear before music resuming.
|
|
|
|
// 2. Give BT SCO to be disconnected before starting to connect A2DP.
|
2014-07-10 06:06:23 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
|
|
|
|
if (aChannel == AudioChannel::Telephony) {
|
|
|
|
UnregisterTelephonyChild(aChildID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aChannel == AudioChannel::Telephony &&
|
|
|
|
(mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN].Length() +
|
|
|
|
mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY].Length()) == 1) {
|
|
|
|
mTimerElementHidden = aElementHidden;
|
|
|
|
mTimerChildID = aChildID;
|
|
|
|
mDeferTelChannelTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
mDeferTelChannelTimer->InitWithCallback(this, 1500, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-28 19:47:15 -07:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
UnregisterTypeInternal(aChannel, aElementHidden, aChildID, aWithVideo);
|
2013-04-28 19:47:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::UnregisterTypeInternal(AudioChannel aChannel,
|
2013-04-28 19:47:15 -07:00
|
|
|
bool aElementHidden,
|
2013-09-17 20:46:22 -07:00
|
|
|
uint64_t aChildID,
|
|
|
|
bool aWithVideo)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
2012-12-28 09:57:35 -08:00
|
|
|
// The array may contain multiple occurrence of this appId but
|
|
|
|
// this should remove only the first one.
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelInternalType type = GetInternalType(aChannel, aElementHidden);
|
2013-02-28 11:22:59 -08:00
|
|
|
MOZ_ASSERT(mChannelCounters[type].Contains(aChildID));
|
2013-01-08 23:18:16 -08:00
|
|
|
mChannelCounters[type].RemoveElement(aChildID);
|
2012-12-07 03:46:18 -08:00
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
// In order to avoid race conditions, it's safer to notify any existing
|
2012-12-06 07:25:18 -08:00
|
|
|
// agent any time a new one is registered.
|
2013-01-08 23:18:16 -08:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2013-09-17 00:46:06 -07:00
|
|
|
// No hidden content channel is playable if the original playable hidden
|
|
|
|
// process does not need to play audio from background anymore.
|
2014-04-10 10:39:20 -07:00
|
|
|
if (aChannel == AudioChannel::Content &&
|
2013-09-17 00:46:06 -07:00
|
|
|
mPlayableHiddenContentChildID == aChildID &&
|
|
|
|
!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].Contains(aChildID)) {
|
|
|
|
mPlayableHiddenContentChildID = CONTENT_PROCESS_ID_UNKNOWN;
|
2013-02-25 00:54:07 -08:00
|
|
|
}
|
2013-09-17 20:46:22 -07:00
|
|
|
|
|
|
|
if (aWithVideo) {
|
|
|
|
MOZ_ASSERT(mWithVideoChildIDs.Contains(aChildID));
|
|
|
|
mWithVideoChildIDs.RemoveElement(aChildID);
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
SendAudioChannelChangedNotification(aChildID);
|
2014-06-24 22:15:12 -07:00
|
|
|
SendNotification();
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
2012-12-04 11:46:07 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 09:02:32 -08:00
|
|
|
void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::UpdateChannelType(AudioChannel aChannel,
|
2013-02-26 09:02:32 -08:00
|
|
|
uint64_t aChildID,
|
|
|
|
bool aElementHidden,
|
|
|
|
bool aElementWasHidden)
|
|
|
|
{
|
|
|
|
// Calculate the new and old internal type and update the hashtable if needed.
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelInternalType newType = GetInternalType(aChannel, aElementHidden);
|
|
|
|
AudioChannelInternalType oldType = GetInternalType(aChannel, aElementWasHidden);
|
2013-02-26 09:02:32 -08:00
|
|
|
|
|
|
|
if (newType != oldType) {
|
|
|
|
mChannelCounters[newType].AppendElement(aChildID);
|
2013-02-28 11:22:59 -08:00
|
|
|
MOZ_ASSERT(mChannelCounters[oldType].Contains(aChildID));
|
2013-02-26 09:02:32 -08:00
|
|
|
mChannelCounters[oldType].RemoveElement(aChildID);
|
|
|
|
}
|
2013-09-17 00:46:06 -07:00
|
|
|
|
2013-12-15 21:08:03 -08:00
|
|
|
// No hidden content channel can be playable if there is a content channel
|
|
|
|
// in foreground (bug 855208), nor if there is a normal channel with video
|
|
|
|
// in foreground (bug 894249).
|
|
|
|
if (newType == AUDIO_CHANNEL_INT_CONTENT ||
|
|
|
|
(newType == AUDIO_CHANNEL_INT_NORMAL &&
|
|
|
|
mWithVideoChildIDs.Contains(aChildID))) {
|
|
|
|
mPlayableHiddenContentChildID = CONTENT_PROCESS_ID_UNKNOWN;
|
|
|
|
}
|
|
|
|
// If there is no content channel in foreground and no normal channel with
|
|
|
|
// video in foreground, the last content channel which goes from foreground
|
|
|
|
// to background can be playable.
|
|
|
|
else if (oldType == AUDIO_CHANNEL_INT_CONTENT &&
|
2013-09-17 00:46:06 -07:00
|
|
|
newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
|
|
|
|
mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) {
|
|
|
|
mPlayableHiddenContentChildID = aChildID;
|
|
|
|
}
|
2013-02-26 09:02:32 -08:00
|
|
|
}
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState
|
|
|
|
AudioChannelService::GetState(AudioChannelAgent* aAgent, bool aElementHidden)
|
2012-12-04 11:46:07 -08:00
|
|
|
{
|
2013-01-10 14:56:20 -08:00
|
|
|
AudioChannelAgentData* data;
|
2013-01-08 23:18:16 -08:00
|
|
|
if (!mAgents.Get(aAgent, &data)) {
|
2013-09-02 02:45:44 -07:00
|
|
|
return AUDIO_CHANNEL_STATE_MUTED;
|
2012-12-04 11:46:07 -08:00
|
|
|
}
|
|
|
|
|
2013-01-29 18:54:07 -08:00
|
|
|
bool oldElementHidden = data->mElementHidden;
|
2013-01-08 23:18:16 -08:00
|
|
|
// Update visibility.
|
2013-01-10 14:56:20 -08:00
|
|
|
data->mElementHidden = aElementHidden;
|
2013-01-29 18:54:07 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
data->mState = GetStateInternal(data->mChannel, CONTENT_PROCESS_ID_MAIN,
|
2013-01-29 18:54:07 -08:00
|
|
|
aElementHidden, oldElementHidden);
|
2013-09-02 02:45:44 -07:00
|
|
|
return data->mState;
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::GetStateInternal(AudioChannel aChannel, uint64_t aChildID,
|
|
|
|
bool aElementHidden,
|
|
|
|
bool aElementWasHidden)
|
2013-01-08 23:18:16 -08:00
|
|
|
{
|
2014-04-10 10:39:20 -07:00
|
|
|
UpdateChannelType(aChannel, aChildID, aElementHidden, aElementWasHidden);
|
2013-02-26 09:02:32 -08:00
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
// Calculating the new and old type and update the hashtable if needed.
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelInternalType newType = GetInternalType(aChannel, aElementHidden);
|
|
|
|
AudioChannelInternalType oldType = GetInternalType(aChannel,
|
|
|
|
aElementWasHidden);
|
2012-12-05 19:34:17 -08:00
|
|
|
|
2013-09-17 20:46:22 -07:00
|
|
|
if (newType != oldType &&
|
2014-04-10 10:39:20 -07:00
|
|
|
(aChannel == AudioChannel::Content ||
|
|
|
|
(aChannel == AudioChannel::Normal &&
|
2013-09-17 20:46:22 -07:00
|
|
|
mWithVideoChildIDs.Contains(aChildID)))) {
|
2014-06-24 22:15:12 -07:00
|
|
|
SendNotification();
|
2013-01-29 18:54:07 -08:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
SendAudioChannelChangedNotification(aChildID);
|
|
|
|
|
2013-01-16 05:29:57 -08:00
|
|
|
// Let play any visible audio channel.
|
|
|
|
if (!aElementHidden) {
|
2013-09-02 02:45:44 -07:00
|
|
|
if (CheckVolumeFadedCondition(newType, aElementHidden)) {
|
|
|
|
return AUDIO_CHANNEL_STATE_FADED;
|
|
|
|
}
|
2014-07-10 06:06:23 -07:00
|
|
|
return CheckTelephonyPolicy(aChannel, aChildID);
|
2013-01-16 05:29:57 -08:00
|
|
|
}
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
// We are not visible, maybe we have to mute.
|
|
|
|
if (newType == AUDIO_CHANNEL_INT_NORMAL_HIDDEN ||
|
|
|
|
(newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN &&
|
2013-09-17 00:46:06 -07:00
|
|
|
// One process can have multiple content channels; and during the
|
|
|
|
// transition from foreground to background, its content channels will be
|
|
|
|
// updated with correct visibility status one by one. All its content
|
|
|
|
// channels should remain playable until all of their visibility statuses
|
|
|
|
// have been updated as hidden. After all its content channels have been
|
|
|
|
// updated properly as hidden, mPlayableHiddenContentChildID is used to
|
|
|
|
// check whether this background process is playable or not.
|
|
|
|
!(mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].Contains(aChildID) ||
|
|
|
|
(mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty() &&
|
|
|
|
mPlayableHiddenContentChildID == aChildID)))) {
|
2013-09-02 02:45:44 -07:00
|
|
|
return AUDIO_CHANNEL_STATE_MUTED;
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
2012-12-05 17:20:59 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// After checking the condition on normal & content channel, if the state
|
|
|
|
// is not on muted then checking other higher channels type here.
|
|
|
|
if (ChannelsActiveWithHigherPriorityThan(newType)) {
|
2013-01-08 23:18:16 -08:00
|
|
|
MOZ_ASSERT(newType != AUDIO_CHANNEL_INT_NORMAL_HIDDEN);
|
2013-09-02 02:45:44 -07:00
|
|
|
if (CheckVolumeFadedCondition(newType, aElementHidden)) {
|
|
|
|
return AUDIO_CHANNEL_STATE_FADED;
|
|
|
|
}
|
|
|
|
return AUDIO_CHANNEL_STATE_MUTED;
|
|
|
|
}
|
|
|
|
|
2014-07-10 06:06:23 -07:00
|
|
|
return CheckTelephonyPolicy(aChannel, aChildID);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioChannelState
|
|
|
|
AudioChannelService::CheckTelephonyPolicy(AudioChannel aChannel,
|
|
|
|
uint64_t aChildID)
|
|
|
|
{
|
|
|
|
// Only the latest childID is allowed to play with telephony channel.
|
|
|
|
if (aChannel != AudioChannel::Telephony) {
|
|
|
|
return AUDIO_CHANNEL_STATE_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mTelephonyChildren.IsEmpty());
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
bool found = false;
|
|
|
|
for (uint32_t i = 0, len = mTelephonyChildren.Length(); i < len; ++i) {
|
|
|
|
if (mTelephonyChildren[i].mChildID == aChildID) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(found);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mTelephonyChildren.LastElement().mChildID == aChildID
|
|
|
|
? AUDIO_CHANNEL_STATE_NORMAL : AUDIO_CHANNEL_STATE_MUTED;
|
2013-09-02 02:45:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AudioChannelService::CheckVolumeFadedCondition(AudioChannelInternalType aType,
|
|
|
|
bool aElementHidden)
|
|
|
|
{
|
|
|
|
// Only normal & content channels are considered
|
|
|
|
if (aType > AUDIO_CHANNEL_INT_CONTENT_HIDDEN) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consider that audio from notification is with short duration
|
|
|
|
// so just fade the volume not pause it
|
|
|
|
if (mChannelCounters[AUDIO_CHANNEL_INT_NOTIFICATION].IsEmpty() &&
|
|
|
|
mChannelCounters[AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN].IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since this element is on the foreground, it can be allowed to play always.
|
|
|
|
// So return true directly when there is any notification channel alive.
|
|
|
|
if (aElementHidden == false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If element is on the background, it is possible paused by channels higher
|
|
|
|
// then notification.
|
|
|
|
for (int i = AUDIO_CHANNEL_INT_LAST - 1;
|
|
|
|
i != AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN; --i) {
|
|
|
|
if (!mChannelCounters[i].IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-05 17:20:59 -08:00
|
|
|
}
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
return true;
|
2012-12-04 11:46:07 -08:00
|
|
|
}
|
|
|
|
|
2013-01-04 21:03:51 -08:00
|
|
|
bool
|
2013-01-28 03:47:18 -08:00
|
|
|
AudioChannelService::ContentOrNormalChannelIsActive()
|
2013-01-04 21:03:51 -08:00
|
|
|
{
|
2013-01-08 23:18:16 -08:00
|
|
|
return !mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty() ||
|
2013-01-28 03:47:18 -08:00
|
|
|
!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].IsEmpty() ||
|
|
|
|
!mChannelCounters[AUDIO_CHANNEL_INT_NORMAL].IsEmpty();
|
2013-01-04 21:03:51 -08:00
|
|
|
}
|
|
|
|
|
2014-05-29 00:20:42 -07:00
|
|
|
bool
|
|
|
|
AudioChannelService::TelephonyChannelIsActive()
|
|
|
|
{
|
|
|
|
return !mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY].IsEmpty() ||
|
|
|
|
!mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN].IsEmpty();
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
bool
|
|
|
|
AudioChannelService::ProcessContentOrNormalChannelIsActive(uint64_t aChildID)
|
|
|
|
{
|
|
|
|
return mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].Contains(aChildID) ||
|
|
|
|
mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].Contains(aChildID) ||
|
|
|
|
mChannelCounters[AUDIO_CHANNEL_INT_NORMAL].Contains(aChildID);
|
|
|
|
}
|
|
|
|
|
2013-09-12 05:26:03 -07:00
|
|
|
void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::SetDefaultVolumeControlChannel(int32_t aChannel,
|
2015-02-25 02:46:11 -08:00
|
|
|
bool aVisible)
|
2013-09-12 05:26:03 -07:00
|
|
|
{
|
2015-02-25 02:46:11 -08:00
|
|
|
SetDefaultVolumeControlChannelInternal(aChannel, aVisible,
|
2014-04-10 10:39:20 -07:00
|
|
|
CONTENT_PROCESS_ID_MAIN);
|
2013-09-12 05:26:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::SetDefaultVolumeControlChannelInternal(int32_t aChannel,
|
2015-02-25 02:46:11 -08:00
|
|
|
bool aVisible,
|
2014-04-10 10:39:20 -07:00
|
|
|
uint64_t aChildID)
|
2013-09-12 05:26:03 -07:00
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this child is in the background and mDefChannelChildID is set to
|
|
|
|
// others then it means other child in the foreground already set it's
|
|
|
|
// own default channel already.
|
2015-02-25 02:46:35 -08:00
|
|
|
if (!aVisible && mDefChannelChildID != aChildID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Workaround for the call screen app. The call screen app is running on the
|
|
|
|
// main process, that will results in wrong visible state. Because we use the
|
|
|
|
// docshell's active state as visible state, the main process is always
|
|
|
|
// active. Therefore, we will see the strange situation that the visible
|
|
|
|
// state of the call screen is always true. If the mDefChannelChildID is set
|
|
|
|
// to others then it means other child in the foreground already set it's
|
|
|
|
// own default channel already.
|
|
|
|
// Summary :
|
|
|
|
// Child process : foreground app always can set type.
|
|
|
|
// Parent process : check the mDefChannelChildID.
|
|
|
|
else if (aChildID == CONTENT_PROCESS_ID_MAIN &&
|
|
|
|
mDefChannelChildID != CONTENT_PROCESS_ID_UNKNOWN) {
|
2013-09-12 05:26:03 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-25 02:46:35 -08:00
|
|
|
mDefChannelChildID = aVisible ? aChildID : CONTENT_PROCESS_ID_UNKNOWN;
|
|
|
|
nsAutoString channelName;
|
2014-04-10 10:39:20 -07:00
|
|
|
if (aChannel == -1) {
|
|
|
|
channelName.AssignASCII("unknown");
|
|
|
|
} else {
|
|
|
|
GetAudioChannelString(static_cast<AudioChannel>(aChannel), channelName);
|
|
|
|
}
|
|
|
|
|
2013-09-12 05:26:03 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2013-10-03 11:40:53 -07:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nullptr, "default-volume-channel-changed",
|
|
|
|
channelName.get());
|
|
|
|
}
|
2013-09-12 05:26:03 -07:00
|
|
|
}
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
void
|
2013-04-25 17:53:26 -07:00
|
|
|
AudioChannelService::SendAudioChannelChangedNotification(uint64_t aChildID)
|
2013-01-08 23:18:16 -08:00
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
nsRefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
|
|
|
|
props->SetPropertyAsUint64(NS_LITERAL_STRING("childID"), aChildID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2013-10-03 11:40:53 -07:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(static_cast<nsIWritablePropertyBag*>(props),
|
|
|
|
"audio-channel-process-changed", nullptr);
|
|
|
|
}
|
2013-04-25 17:53:26 -07:00
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
// Calculating the most important active channel.
|
2014-04-10 10:39:20 -07:00
|
|
|
int32_t higher = -1;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2013-01-16 05:38:51 -08:00
|
|
|
// Top-Down in the hierarchy for visible elements
|
2013-01-08 23:18:16 -08:00
|
|
|
if (!mChannelCounters[AUDIO_CHANNEL_INT_PUBLICNOTIFICATION].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Publicnotification);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!mChannelCounters[AUDIO_CHANNEL_INT_RINGER].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Ringer);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Telephony);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!mChannelCounters[AUDIO_CHANNEL_INT_ALARM].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Alarm);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!mChannelCounters[AUDIO_CHANNEL_INT_NOTIFICATION].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Notification);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
2013-01-16 05:38:51 -08:00
|
|
|
else if (!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Content);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!mChannelCounters[AUDIO_CHANNEL_INT_NORMAL].IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = static_cast<int32_t>(AudioChannel::Normal);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
int32_t visibleHigher = higher;
|
2013-01-28 03:47:18 -08:00
|
|
|
|
2013-01-16 05:38:51 -08:00
|
|
|
// Top-Down in the hierarchy for non-visible elements
|
2014-02-17 02:58:12 -08:00
|
|
|
// And we can ignore normal channel because it can't play in the background.
|
2014-04-10 10:39:20 -07:00
|
|
|
int32_t index;
|
|
|
|
for (index = 0; kMozAudioChannelAttributeTable[index].tag; ++index);
|
|
|
|
|
|
|
|
for (--index;
|
|
|
|
kMozAudioChannelAttributeTable[index].value > higher &&
|
|
|
|
kMozAudioChannelAttributeTable[index].value > (int16_t)AudioChannel::Normal;
|
|
|
|
--index) {
|
2014-02-17 02:58:12 -08:00
|
|
|
// Each channel type will be split to fg and bg for recording the state,
|
|
|
|
// so here need to do a translation.
|
2014-07-28 03:55:51 -07:00
|
|
|
if (mChannelCounters[index * 2 + 1].IsEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kMozAudioChannelAttributeTable[index].value == (int16_t)AudioChannel::Content) {
|
|
|
|
if (mPlayableHiddenContentChildID != CONTENT_PROCESS_ID_UNKNOWN) {
|
|
|
|
higher = kMozAudioChannelAttributeTable[index].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-10 10:39:20 -07:00
|
|
|
higher = kMozAudioChannelAttributeTable[index].value;
|
2014-02-17 02:58:12 -08:00
|
|
|
break;
|
2013-01-28 03:47:18 -08:00
|
|
|
}
|
2013-01-16 05:38:51 -08:00
|
|
|
}
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
if (higher != mCurrentHigherChannel) {
|
|
|
|
mCurrentHigherChannel = higher;
|
|
|
|
|
|
|
|
nsString channelName;
|
2014-04-10 10:39:20 -07:00
|
|
|
if (mCurrentHigherChannel != -1) {
|
|
|
|
GetAudioChannelString(static_cast<AudioChannel>(mCurrentHigherChannel),
|
|
|
|
channelName);
|
2013-01-08 23:18:16 -08:00
|
|
|
} else {
|
2013-01-08 23:20:34 -08:00
|
|
|
channelName.AssignLiteral("none");
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
2013-10-07 23:27:23 -07:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nullptr, "audio-channel-changed", channelName.get());
|
|
|
|
}
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
2013-01-28 03:47:18 -08:00
|
|
|
|
|
|
|
if (visibleHigher != mCurrentVisibleHigherChannel) {
|
|
|
|
mCurrentVisibleHigherChannel = visibleHigher;
|
|
|
|
|
|
|
|
nsString channelName;
|
2014-04-10 10:39:20 -07:00
|
|
|
if (mCurrentVisibleHigherChannel != -1) {
|
|
|
|
GetAudioChannelString(static_cast<AudioChannel>(mCurrentVisibleHigherChannel),
|
|
|
|
channelName);
|
2013-01-28 03:47:18 -08:00
|
|
|
} else {
|
|
|
|
channelName.AssignLiteral("none");
|
|
|
|
}
|
|
|
|
|
2013-10-07 23:27:23 -07:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nullptr, "visible-audio-channel-changed", channelName.get());
|
|
|
|
}
|
2013-01-28 03:47:18 -08:00
|
|
|
}
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
AudioChannelService::NotifyEnumerator(AudioChannelAgent* aAgent,
|
2013-01-10 14:56:20 -08:00
|
|
|
AudioChannelAgentData* aData, void* aUnused)
|
2013-01-08 23:18:16 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAgent);
|
|
|
|
aAgent->NotifyAudioChannelStateChanged();
|
2012-12-04 11:46:07 -08:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:15:12 -07:00
|
|
|
class NotifyRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit NotifyRunnable(AudioChannelService* aService)
|
2014-06-24 22:15:12 -07:00
|
|
|
: mService(aService)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
mService->Notify();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<AudioChannelService> mService;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioChannelService::SendNotification()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mRunnable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRunnable = new NotifyRunnable(this);
|
|
|
|
NS_DispatchToCurrentThread(mRunnable);
|
|
|
|
}
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
void
|
|
|
|
AudioChannelService::Notify()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-06-24 22:15:12 -07:00
|
|
|
mRunnable = nullptr;
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2012-12-06 07:25:18 -08:00
|
|
|
// Notify any agent for the main process.
|
|
|
|
mAgents.EnumerateRead(NotifyEnumerator, nullptr);
|
2012-12-05 19:01:58 -08:00
|
|
|
|
|
|
|
// Notify for the child processes.
|
|
|
|
nsTArray<ContentParent*> children;
|
|
|
|
ContentParent::GetAll(children);
|
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
|
|
|
unused << children[i]->SendAudioChannelNotify();
|
|
|
|
}
|
2012-12-04 11:46:07 -08:00
|
|
|
}
|
|
|
|
|
2013-04-28 19:47:15 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
AudioChannelService::Notify(nsITimer* aTimer)
|
|
|
|
{
|
2014-04-10 10:39:20 -07:00
|
|
|
UnregisterTypeInternal(AudioChannel::Telephony, mTimerElementHidden,
|
|
|
|
mTimerChildID, false);
|
2013-04-28 19:47:15 -07:00
|
|
|
mDeferTelChannelTimer = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-24 15:50:03 -08:00
|
|
|
bool
|
|
|
|
AudioChannelService::AnyAudioChannelIsActive()
|
|
|
|
{
|
|
|
|
for (int i = AUDIO_CHANNEL_INT_LAST - 1;
|
|
|
|
i >= AUDIO_CHANNEL_INT_NORMAL; --i) {
|
|
|
|
if (!mChannelCounters[i].IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
bool
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelService::ChannelsActiveWithHigherPriorityThan(
|
|
|
|
AudioChannelInternalType aType)
|
2012-12-04 11:46:07 -08:00
|
|
|
{
|
2013-01-16 05:38:51 -08:00
|
|
|
for (int i = AUDIO_CHANNEL_INT_LAST - 1;
|
2013-01-08 23:18:16 -08:00
|
|
|
i != AUDIO_CHANNEL_INT_CONTENT_HIDDEN; --i) {
|
2012-12-04 11:46:07 -08:00
|
|
|
if (i == aType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:57:35 -08:00
|
|
|
if (!mChannelCounters[i].IsEmpty()) {
|
2012-12-04 11:46:07 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-05 17:20:59 -08:00
|
|
|
|
2014-10-17 08:29:39 -07:00
|
|
|
PLDHashOperator
|
|
|
|
AudioChannelService::WindowDestroyedEnumerator(AudioChannelAgent* aAgent,
|
|
|
|
nsAutoPtr<AudioChannelAgentData>& aData,
|
|
|
|
void* aPtr)
|
|
|
|
{
|
|
|
|
uint64_t* innerID = static_cast<uint64_t*>(aPtr);
|
|
|
|
MOZ_ASSERT(innerID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aAgent->Window());
|
|
|
|
if (!window || window->WindowID() != *innerID) {
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioChannelService* service = AudioChannelService::GetAudioChannelService();
|
|
|
|
MOZ_ASSERT(service);
|
|
|
|
|
|
|
|
service->UnregisterType(aData->mChannel, aData->mElementHidden,
|
|
|
|
CONTENT_PROCESS_ID_MAIN, aData->mWithVideo);
|
|
|
|
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:57:35 -08:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
|
2012-12-28 09:57:35 -08:00
|
|
|
{
|
2013-10-07 23:30:04 -07:00
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
mDisabled = true;
|
|
|
|
}
|
|
|
|
|
2013-07-17 22:22:36 -07:00
|
|
|
if (!strcmp(aTopic, "ipc:content-shutdown")) {
|
|
|
|
nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(aSubject);
|
|
|
|
if (!props) {
|
|
|
|
NS_WARNING("ipc:content-shutdown message without property bag as subject");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-25 07:12:17 -08:00
|
|
|
|
2013-09-17 20:46:22 -07:00
|
|
|
int32_t index;
|
2013-07-17 22:22:36 -07:00
|
|
|
uint64_t childID = 0;
|
|
|
|
nsresult rv = props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"),
|
|
|
|
&childID);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
for (int32_t type = AUDIO_CHANNEL_INT_NORMAL;
|
|
|
|
type < AUDIO_CHANNEL_INT_LAST;
|
|
|
|
++type) {
|
2013-09-17 20:46:22 -07:00
|
|
|
|
2013-07-17 22:22:36 -07:00
|
|
|
while ((index = mChannelCounters[type].IndexOf(childID)) != -1) {
|
|
|
|
mChannelCounters[type].RemoveElementAt(index);
|
|
|
|
}
|
2013-09-17 20:46:22 -07:00
|
|
|
}
|
2013-07-17 22:22:36 -07:00
|
|
|
|
2013-09-17 00:46:06 -07:00
|
|
|
// No hidden content channel is playable if the original playable hidden
|
|
|
|
// process shuts down.
|
|
|
|
if (mPlayableHiddenContentChildID == childID) {
|
|
|
|
mPlayableHiddenContentChildID = CONTENT_PROCESS_ID_UNKNOWN;
|
2013-09-17 20:46:22 -07:00
|
|
|
}
|
2013-09-17 00:46:06 -07:00
|
|
|
|
2013-09-17 20:46:22 -07:00
|
|
|
while ((index = mWithVideoChildIDs.IndexOf(childID)) != -1) {
|
|
|
|
mWithVideoChildIDs.RemoveElementAt(index);
|
2013-01-25 07:12:17 -08:00
|
|
|
}
|
2013-07-17 22:22:36 -07:00
|
|
|
|
|
|
|
// We don't have to remove the agents from the mAgents hashtable because if
|
|
|
|
// that table contains only agents running on the same process.
|
|
|
|
|
|
|
|
SendAudioChannelChangedNotification(childID);
|
2014-06-24 22:15:12 -07:00
|
|
|
SendNotification();
|
2013-09-12 05:26:03 -07:00
|
|
|
|
|
|
|
if (mDefChannelChildID == childID) {
|
2014-04-10 10:39:20 -07:00
|
|
|
SetDefaultVolumeControlChannelInternal(-1, false, childID);
|
2013-09-12 05:26:03 -07:00
|
|
|
mDefChannelChildID = CONTENT_PROCESS_ID_UNKNOWN;
|
|
|
|
}
|
2013-07-17 22:22:36 -07:00
|
|
|
} else {
|
|
|
|
NS_WARNING("ipc:content-shutdown message without childID property");
|
|
|
|
}
|
|
|
|
}
|
2014-10-17 08:29:39 -07:00
|
|
|
|
2013-07-17 22:22:36 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// To process the volume control on each audio channel according to
|
|
|
|
// change of settings
|
|
|
|
else if (!strcmp(aTopic, "mozsettings-changed")) {
|
2014-12-29 02:56:00 -08:00
|
|
|
RootedDictionary<SettingChangeNotification> setting(nsContentUtils::RootingCxForThread());
|
|
|
|
if (!WrappedJSToDictionary(aSubject, setting)) {
|
2013-07-17 22:22:36 -07:00
|
|
|
return NS_OK;
|
2012-12-28 09:57:35 -08:00
|
|
|
}
|
2014-09-16 10:15:16 -07:00
|
|
|
if (!StringBeginsWith(setting.mKey, NS_LITERAL_STRING("audio.volume."))) {
|
2013-07-17 22:22:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-09-16 10:15:16 -07:00
|
|
|
if (!setting.mValue.isNumber()) {
|
2013-07-17 22:22:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-02-03 18:10:22 -08:00
|
|
|
|
2013-07-17 22:22:36 -07:00
|
|
|
nsCOMPtr<nsIAudioManager> audioManager = do_GetService(NS_AUDIOMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(audioManager, NS_OK);
|
|
|
|
|
2014-09-16 10:15:16 -07:00
|
|
|
int32_t index = setting.mValue.toNumber();
|
|
|
|
if (setting.mKey.EqualsLiteral("audio.volume.content")) {
|
2014-04-10 10:39:20 -07:00
|
|
|
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Content, index);
|
2014-09-16 10:15:16 -07:00
|
|
|
} else if (setting.mKey.EqualsLiteral("audio.volume.notification")) {
|
2014-04-10 10:39:20 -07:00
|
|
|
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Notification, index);
|
2014-09-16 10:15:16 -07:00
|
|
|
} else if (setting.mKey.EqualsLiteral("audio.volume.alarm")) {
|
2014-04-10 10:39:20 -07:00
|
|
|
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Alarm, index);
|
2014-09-16 10:15:16 -07:00
|
|
|
} else if (setting.mKey.EqualsLiteral("audio.volume.telephony")) {
|
2014-04-10 10:39:20 -07:00
|
|
|
audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Telephony, index);
|
2014-09-16 10:15:16 -07:00
|
|
|
} else if (!setting.mKey.EqualsLiteral("audio.volume.bt_sco")) {
|
2013-10-14 03:45:35 -07:00
|
|
|
// bt_sco is not a valid audio channel so we manipulate it in
|
|
|
|
// AudioManager.cpp. And the others should not be used.
|
2014-04-20 00:36:40 -07:00
|
|
|
// We didn't use MOZ_CRASH or MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE here
|
|
|
|
// because any web content who has permission of mozSettings can set any
|
|
|
|
// names then it can be easy to crash the B2G.
|
2013-10-14 03:45:35 -07:00
|
|
|
NS_WARNING("unexpected audio channel for volume control");
|
2013-07-17 22:22:36 -07:00
|
|
|
}
|
2012-12-28 09:57:35 -08:00
|
|
|
}
|
2013-07-17 22:22:36 -07:00
|
|
|
#endif
|
2012-12-28 09:57:35 -08:00
|
|
|
|
2014-10-17 08:29:39 -07:00
|
|
|
else if (!strcmp(aTopic, "inner-window-destroyed")) {
|
|
|
|
nsCOMPtr<nsISupportsPRUint64> wrapper = do_QueryInterface(aSubject);
|
|
|
|
NS_ENSURE_TRUE(wrapper, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
uint64_t innerID;
|
|
|
|
nsresult rv = wrapper->GetData(&innerID);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAgents.Enumerate(WindowDestroyedEnumerator, &innerID);
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
bool active = AnyAudioChannelIsActive();
|
|
|
|
for (uint32_t i = 0; i < mSpeakerManager.Length(); i++) {
|
|
|
|
mSpeakerManager[i]->SetAudioChannelActive(active);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:57:35 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-08 23:18:16 -08:00
|
|
|
|
|
|
|
AudioChannelService::AudioChannelInternalType
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::GetInternalType(AudioChannel aChannel,
|
2013-01-08 23:18:16 -08:00
|
|
|
bool aElementHidden)
|
|
|
|
{
|
2014-04-10 10:39:20 -07:00
|
|
|
switch (aChannel) {
|
|
|
|
case AudioChannel::Normal:
|
2013-01-08 23:18:16 -08:00
|
|
|
return aElementHidden
|
2013-01-16 05:38:51 -08:00
|
|
|
? AUDIO_CHANNEL_INT_NORMAL_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_NORMAL;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
case AudioChannel::Content:
|
2013-01-08 23:18:16 -08:00
|
|
|
return aElementHidden
|
2013-01-16 05:38:51 -08:00
|
|
|
? AUDIO_CHANNEL_INT_CONTENT_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_CONTENT;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
case AudioChannel::Notification:
|
2013-01-16 05:38:51 -08:00
|
|
|
return aElementHidden
|
|
|
|
? AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_NOTIFICATION;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
case AudioChannel::Alarm:
|
2013-01-16 05:38:51 -08:00
|
|
|
return aElementHidden
|
|
|
|
? AUDIO_CHANNEL_INT_ALARM_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_ALARM;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
case AudioChannel::Telephony:
|
2013-01-16 05:38:51 -08:00
|
|
|
return aElementHidden
|
|
|
|
? AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_TELEPHONY;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
case AudioChannel::Ringer:
|
2013-01-16 05:38:51 -08:00
|
|
|
return aElementHidden
|
|
|
|
? AUDIO_CHANNEL_INT_RINGER_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_RINGER;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
case AudioChannel::Publicnotification:
|
2013-01-16 05:38:51 -08:00
|
|
|
return aElementHidden
|
|
|
|
? AUDIO_CHANNEL_INT_PUBLICNOTIFICATION_HIDDEN
|
|
|
|
: AUDIO_CHANNEL_INT_PUBLICNOTIFICATION;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
MOZ_CRASH("unexpected audio channel");
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
2014-03-11 03:46:55 -07:00
|
|
|
|
|
|
|
struct RefreshAgentsVolumeData
|
|
|
|
{
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit RefreshAgentsVolumeData(nsPIDOMWindow* aWindow)
|
2014-03-11 03:46:55 -07:00
|
|
|
: mWindow(aWindow)
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsPIDOMWindow* mWindow;
|
|
|
|
nsTArray<nsRefPtr<AudioChannelAgent>> mAgents;
|
|
|
|
};
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
AudioChannelService::RefreshAgentsVolumeEnumerator(AudioChannelAgent* aAgent,
|
|
|
|
AudioChannelAgentData* aUnused,
|
|
|
|
void* aPtr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAgent);
|
|
|
|
RefreshAgentsVolumeData* data = static_cast<RefreshAgentsVolumeData*>(aPtr);
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aAgent->Window());
|
|
|
|
if (window && !window->IsInnerWindow()) {
|
|
|
|
window = window->GetCurrentInnerWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window == data->mWindow) {
|
|
|
|
data->mAgents.AppendElement(aAgent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
AudioChannelService::RefreshAgentsVolume(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
RefreshAgentsVolumeData data(aWindow);
|
|
|
|
mAgents.EnumerateRead(RefreshAgentsVolumeEnumerator, &data);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < data.mAgents.Length(); ++i) {
|
|
|
|
data.mAgents[i]->WindowVolumeChanged();
|
|
|
|
}
|
|
|
|
}
|
2014-03-11 03:47:25 -07:00
|
|
|
|
|
|
|
struct CountWindowData
|
|
|
|
{
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit CountWindowData(nsIDOMWindow* aWindow)
|
2014-03-11 03:47:25 -07:00
|
|
|
: mWindow(aWindow)
|
|
|
|
, mCount(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsIDOMWindow* mWindow;
|
|
|
|
uint32_t mCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
AudioChannelService::CountWindowEnumerator(AudioChannelAgent* aAgent,
|
|
|
|
AudioChannelAgentData* aUnused,
|
|
|
|
void* aPtr)
|
|
|
|
{
|
|
|
|
CountWindowData* data = static_cast<CountWindowData*>(aPtr);
|
|
|
|
MOZ_ASSERT(aAgent);
|
|
|
|
|
|
|
|
if (aAgent->Window() == data->mWindow) {
|
|
|
|
++data->mCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
AudioChannelService::CountWindow(nsIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
CountWindowData data(aWindow);
|
|
|
|
mAgents.EnumerateRead(CountWindowEnumerator, &data);
|
|
|
|
return data.mCount;
|
|
|
|
}
|
2014-03-20 03:45:55 -07:00
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
/* static */ const nsAttrValue::EnumTable*
|
|
|
|
AudioChannelService::GetAudioChannelTable()
|
|
|
|
{
|
|
|
|
return kMozAudioChannelAttributeTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ AudioChannel
|
|
|
|
AudioChannelService::GetAudioChannel(const nsAString& aChannel)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) {
|
|
|
|
if (aChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].tag)) {
|
|
|
|
return static_cast<AudioChannel>(kMozAudioChannelAttributeTable[i].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AudioChannel::Normal;
|
|
|
|
}
|
2014-03-20 03:45:55 -07:00
|
|
|
|
|
|
|
/* static */ AudioChannel
|
|
|
|
AudioChannelService::GetDefaultAudioChannel()
|
|
|
|
{
|
|
|
|
nsString audioChannel = Preferences::GetString("media.defaultAudioChannel");
|
|
|
|
if (audioChannel.IsEmpty()) {
|
|
|
|
return AudioChannel::Normal;
|
|
|
|
}
|
|
|
|
|
2014-04-10 10:39:20 -07:00
|
|
|
for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) {
|
|
|
|
if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].tag)) {
|
|
|
|
return static_cast<AudioChannel>(kMozAudioChannelAttributeTable[i].value);
|
2014-03-20 03:45:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AudioChannel::Normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2014-04-10 10:39:20 -07:00
|
|
|
AudioChannelService::GetAudioChannelString(AudioChannel aChannel,
|
|
|
|
nsAString& aString)
|
|
|
|
{
|
|
|
|
aString.AssignASCII("normal");
|
|
|
|
|
|
|
|
for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) {
|
|
|
|
if (aChannel ==
|
|
|
|
static_cast<AudioChannel>(kMozAudioChannelAttributeTable[i].value)) {
|
|
|
|
aString.AssignASCII(kMozAudioChannelAttributeTable[i].tag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
AudioChannelService::GetDefaultAudioChannelString(nsAString& aString)
|
2014-03-20 03:45:55 -07:00
|
|
|
{
|
|
|
|
aString.AssignASCII("normal");
|
|
|
|
|
|
|
|
nsString audioChannel = Preferences::GetString("media.defaultAudioChannel");
|
|
|
|
if (!audioChannel.IsEmpty()) {
|
2014-04-10 10:39:20 -07:00
|
|
|
for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) {
|
|
|
|
if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].tag)) {
|
2014-03-20 03:45:55 -07:00
|
|
|
aString = audioChannel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 06:06:23 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
AudioChannelService::RegisterTelephonyChild(uint64_t aChildID)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0, len = mTelephonyChildren.Length(); i < len; ++i) {
|
|
|
|
if (mTelephonyChildren[i].mChildID == aChildID) {
|
|
|
|
++mTelephonyChildren[i].mInstances;
|
|
|
|
|
|
|
|
if (i != len - 1) {
|
|
|
|
TelephonyChild child = mTelephonyChildren[i];
|
|
|
|
mTelephonyChildren.RemoveElementAt(i);
|
|
|
|
mTelephonyChildren.AppendElement(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mTelephonyChildren.AppendElement(TelephonyChild(aChildID));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioChannelService::UnregisterTelephonyChild(uint64_t aChildID)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0, len = mTelephonyChildren.Length(); i < len; ++i) {
|
|
|
|
if (mTelephonyChildren[i].mChildID == aChildID) {
|
|
|
|
if (!--mTelephonyChildren[i].mInstances) {
|
|
|
|
mTelephonyChildren.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(false, "This should not happen.");
|
|
|
|
}
|