2012-12-05 19:01:58 -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 "AudioChannelServiceChild.h"
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "mozilla/Util.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-02-26 09:02:32 -08:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2013-01-04 21:03:51 -08:00
|
|
|
#include "nsIObserverService.h"
|
2012-12-05 19:01:58 -08:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2013-02-26 09:02:32 -08:00
|
|
|
using namespace mozilla::hal;
|
2012-12-05 19:01:58 -08:00
|
|
|
|
|
|
|
StaticRefPtr<AudioChannelServiceChild> gAudioChannelServiceChild;
|
|
|
|
|
|
|
|
// static
|
|
|
|
AudioChannelService*
|
|
|
|
AudioChannelServiceChild::GetAudioChannelService()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// If we already exist, exit early
|
|
|
|
if (gAudioChannelServiceChild) {
|
|
|
|
return gAudioChannelServiceChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new instance, register, return
|
|
|
|
nsRefPtr<AudioChannelServiceChild> service = new AudioChannelServiceChild();
|
|
|
|
NS_ENSURE_TRUE(service, nullptr);
|
|
|
|
|
|
|
|
gAudioChannelServiceChild = service;
|
|
|
|
return gAudioChannelServiceChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioChannelServiceChild::Shutdown()
|
|
|
|
{
|
|
|
|
if (gAudioChannelServiceChild) {
|
|
|
|
gAudioChannelServiceChild = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioChannelServiceChild::AudioChannelServiceChild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioChannelServiceChild::~AudioChannelServiceChild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-08 23:18:16 -08:00
|
|
|
AudioChannelServiceChild::GetMuted(AudioChannelAgent* aAgent, bool aElementHidden)
|
2012-12-05 19:01:58 -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)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-05 19:01:58 -08:00
|
|
|
ContentChild *cc = ContentChild::GetSingleton();
|
2013-01-08 23:18:16 -08:00
|
|
|
bool muted = true;
|
2013-01-29 18:54:07 -08:00
|
|
|
bool oldElementHidden = data->mElementHidden;
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2013-02-26 09:02:32 -08:00
|
|
|
UpdateChannelType(data->mType, CONTENT_PROCESS_ID_MAIN, aElementHidden, oldElementHidden);
|
|
|
|
|
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
|
|
|
|
|
|
|
if (cc) {
|
|
|
|
cc->SendAudioChannelGetMuted(data->mType, aElementHidden, oldElementHidden, &muted);
|
|
|
|
}
|
2013-01-10 14:56:20 -08:00
|
|
|
data->mMuted = muted;
|
2012-12-05 19:01:58 -08:00
|
|
|
|
|
|
|
if (cc) {
|
2013-01-08 23:18:16 -08:00
|
|
|
cc->SendAudioChannelChangedNotification();
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return muted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:25:18 -08:00
|
|
|
AudioChannelServiceChild::RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
|
2012-12-28 09:57:35 -08:00
|
|
|
AudioChannelType aType)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
2012-12-06 07:25:18 -08:00
|
|
|
AudioChannelService::RegisterAudioChannelAgent(aAgent, aType);
|
2012-12-05 19:01:58 -08:00
|
|
|
|
|
|
|
ContentChild *cc = ContentChild::GetSingleton();
|
|
|
|
if (cc) {
|
|
|
|
cc->SendAudioChannelRegisterType(aType);
|
|
|
|
}
|
2013-01-04 21:03:51 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
|
|
|
|
}
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:25:18 -08:00
|
|
|
AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
2013-01-10 14:56:20 -08:00
|
|
|
AudioChannelAgentData *pData;
|
|
|
|
if (!mAgents.Get(aAgent, &pData)) {
|
2012-12-05 19:01:58 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-10 14:56:20 -08:00
|
|
|
// We need to keep a copy because unregister will remove the
|
|
|
|
// AudioChannelAgentData object from the hashtable.
|
|
|
|
AudioChannelAgentData data(*pData);
|
|
|
|
|
2012-12-06 07:25:18 -08:00
|
|
|
AudioChannelService::UnregisterAudioChannelAgent(aAgent);
|
2012-12-05 19:01:58 -08:00
|
|
|
|
|
|
|
ContentChild *cc = ContentChild::GetSingleton();
|
|
|
|
if (cc) {
|
2013-01-08 23:18:16 -08:00
|
|
|
cc->SendAudioChannelUnregisterType(data.mType, data.mElementHidden);
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
|
2013-01-04 21:03:51 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
|
|
|
|
}
|
|
|
|
}
|