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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_audiochannelservice_h__
|
|
|
|
#define mozilla_dom_audiochannelservice_h__
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
2012-12-28 09:57:35 -08:00
|
|
|
#include "nsIObserver.h"
|
2013-03-17 00:55:16 -07:00
|
|
|
#include "nsTArray.h"
|
2013-04-28 19:47:15 -07:00
|
|
|
#include "nsITimer.h"
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
#include "AudioChannelCommon.h"
|
2012-12-06 07:25:18 -08:00
|
|
|
#include "AudioChannelAgent.h"
|
2013-01-10 14:56:20 -08:00
|
|
|
#include "nsClassHashtable.h"
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-11-24 15:50:03 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
class SpeakerManagerService;
|
|
|
|
#endif
|
2013-04-28 19:47:15 -07:00
|
|
|
class AudioChannelService
|
|
|
|
: public nsIObserver
|
|
|
|
, public nsITimerCallback
|
2012-12-04 11:46:07 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-12-28 09:57:35 -08:00
|
|
|
NS_DECL_NSIOBSERVER
|
2013-04-28 19:47:15 -07:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
/**
|
2013-09-02 02:45:44 -07:00
|
|
|
* Returns the AudioChannelServce singleton. Only to be called from main
|
|
|
|
* thread.
|
|
|
|
*
|
2012-12-04 11:46:07 -08:00
|
|
|
* @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise.
|
|
|
|
*/
|
2013-09-02 02:45:44 -07:00
|
|
|
static AudioChannelService* GetAudioChannelService();
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown the singleton.
|
|
|
|
*/
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
/**
|
2012-12-06 07:25:18 -08:00
|
|
|
* Any audio channel agent that starts playing should register itself to
|
2012-12-04 11:46:07 -08:00
|
|
|
* this service, sharing the AudioChannelType.
|
|
|
|
*/
|
2012-12-06 07:25:18 -08:00
|
|
|
virtual void RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
|
2013-09-17 20:46:22 -07:00
|
|
|
AudioChannelType aType,
|
|
|
|
bool aWithVideo);
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
/**
|
2013-09-12 05:26:03 -07:00
|
|
|
* Any audio channel agent that stops playing should unregister itself to
|
2012-12-04 11:46:07 -08:00
|
|
|
* this service.
|
|
|
|
*/
|
2012-12-06 07:25:18 -08:00
|
|
|
virtual void UnregisterAudioChannelAgent(AudioChannelAgent* aAgent);
|
2012-12-04 11:46:07 -08:00
|
|
|
|
|
|
|
/**
|
2013-09-02 02:45:44 -07:00
|
|
|
* Return the state to indicate this agent should keep playing/
|
|
|
|
* fading volume/muted.
|
2012-12-04 11:46:07 -08:00
|
|
|
*/
|
2013-09-02 02:45:44 -07:00
|
|
|
virtual AudioChannelState GetState(AudioChannelAgent* aAgent,
|
|
|
|
bool aElementHidden);
|
2012-12-04 11:46:07 -08:00
|
|
|
|
2013-01-04 21:03:51 -08:00
|
|
|
/**
|
|
|
|
* Return true if there is a content channel active in this process
|
|
|
|
* or one of its subprocesses.
|
|
|
|
*/
|
2013-01-28 03:47:18 -08:00
|
|
|
virtual bool ContentOrNormalChannelIsActive();
|
2013-01-04 21:03:51 -08:00
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
/**
|
2013-09-02 02:45:44 -07:00
|
|
|
* Return true if a normal or content channel is active for the given
|
|
|
|
* process ID.
|
2013-04-25 17:53:26 -07:00
|
|
|
*/
|
|
|
|
virtual bool ProcessContentOrNormalChannelIsActive(uint64_t aChildID);
|
|
|
|
|
2013-09-12 05:26:03 -07:00
|
|
|
/***
|
|
|
|
* AudioChannelManager calls this function to notify the default channel used
|
|
|
|
* to adjust volume when there is no any active channel.
|
|
|
|
*/
|
|
|
|
virtual void SetDefaultVolumeControlChannel(AudioChannelType aType,
|
|
|
|
bool aHidden);
|
|
|
|
|
2013-11-24 15:50:03 -08:00
|
|
|
bool AnyAudioChannelIsActive();
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
void RegisterSpeakerManager(SpeakerManagerService* aSpeakerManager)
|
|
|
|
{
|
|
|
|
if (!mSpeakerManager.Contains(aSpeakerManager)) {
|
|
|
|
mSpeakerManager.AppendElement(aSpeakerManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterSpeakerManager(SpeakerManagerService* aSpeakerManager)
|
|
|
|
{
|
|
|
|
mSpeakerManager.RemoveElement(aSpeakerManager);
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-05 19:01:58 -08:00
|
|
|
protected:
|
2012-12-04 11:46:07 -08:00
|
|
|
void Notify();
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
/**
|
2013-04-25 17:53:26 -07:00
|
|
|
* Send the audio-channel-changed notification for the given process ID if
|
|
|
|
* needed.
|
2013-01-08 23:18:16 -08:00
|
|
|
*/
|
2013-04-25 17:53:26 -07:00
|
|
|
void SendAudioChannelChangedNotification(uint64_t aChildID);
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2012-12-05 19:01:58 -08:00
|
|
|
/* Register/Unregister IPC types: */
|
2013-09-17 20:46:22 -07:00
|
|
|
void RegisterType(AudioChannelType aType, uint64_t aChildID, bool aWithVideo);
|
2013-01-08 23:18:16 -08:00
|
|
|
void UnregisterType(AudioChannelType aType, bool aElementHidden,
|
2013-09-17 20:46:22 -07:00
|
|
|
uint64_t aChildID, bool aWithVideo);
|
2013-04-28 19:47:15 -07:00
|
|
|
void UnregisterTypeInternal(AudioChannelType aType, bool aElementHidden,
|
2013-09-17 20:46:22 -07:00
|
|
|
uint64_t aChildID, bool aWithVideo);
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState GetStateInternal(AudioChannelType aType, uint64_t aChildID,
|
|
|
|
bool aElementHidden,
|
|
|
|
bool aElementWasHidden);
|
2012-12-05 19:01:58 -08:00
|
|
|
|
2013-02-26 09:02:32 -08:00
|
|
|
/* Update the internal type value following the visibility changes */
|
|
|
|
void UpdateChannelType(AudioChannelType aType, uint64_t aChildID,
|
|
|
|
bool aElementHidden, bool aElementWasHidden);
|
|
|
|
|
2013-09-12 05:26:03 -07:00
|
|
|
/* Send the default-volume-channel-changed notification */
|
|
|
|
void SetDefaultVolumeControlChannelInternal(AudioChannelType aType,
|
|
|
|
bool aHidden, uint64_t aChildID);
|
|
|
|
|
2012-12-04 11:46:07 -08:00
|
|
|
AudioChannelService();
|
|
|
|
virtual ~AudioChannelService();
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
enum AudioChannelInternalType {
|
|
|
|
AUDIO_CHANNEL_INT_NORMAL = 0,
|
|
|
|
AUDIO_CHANNEL_INT_NORMAL_HIDDEN,
|
|
|
|
AUDIO_CHANNEL_INT_CONTENT,
|
|
|
|
AUDIO_CHANNEL_INT_CONTENT_HIDDEN,
|
|
|
|
AUDIO_CHANNEL_INT_NOTIFICATION,
|
2013-01-16 05:38:51 -08:00
|
|
|
AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN,
|
2013-01-08 23:18:16 -08:00
|
|
|
AUDIO_CHANNEL_INT_ALARM,
|
2013-01-16 05:38:51 -08:00
|
|
|
AUDIO_CHANNEL_INT_ALARM_HIDDEN,
|
2013-01-08 23:18:16 -08:00
|
|
|
AUDIO_CHANNEL_INT_TELEPHONY,
|
2013-01-16 05:38:51 -08:00
|
|
|
AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN,
|
2013-01-08 23:18:16 -08:00
|
|
|
AUDIO_CHANNEL_INT_RINGER,
|
2013-01-16 05:38:51 -08:00
|
|
|
AUDIO_CHANNEL_INT_RINGER_HIDDEN,
|
2013-01-08 23:18:16 -08:00
|
|
|
AUDIO_CHANNEL_INT_PUBLICNOTIFICATION,
|
2013-01-16 05:38:51 -08:00
|
|
|
AUDIO_CHANNEL_INT_PUBLICNOTIFICATION_HIDDEN,
|
2013-01-08 23:18:16 -08:00
|
|
|
AUDIO_CHANNEL_INT_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
bool ChannelsActiveWithHigherPriorityThan(AudioChannelInternalType aType);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
bool CheckVolumeFadedCondition(AudioChannelInternalType aType,
|
|
|
|
bool aElementHidden);
|
|
|
|
|
2012-12-05 17:20:59 -08:00
|
|
|
const char* ChannelName(AudioChannelType aType);
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
AudioChannelInternalType GetInternalType(AudioChannelType aType,
|
|
|
|
bool aElementHidden);
|
|
|
|
|
2013-01-10 14:56:20 -08:00
|
|
|
class AudioChannelAgentData {
|
|
|
|
public:
|
|
|
|
AudioChannelAgentData(AudioChannelType aType,
|
|
|
|
bool aElementHidden,
|
2013-09-17 20:46:22 -07:00
|
|
|
AudioChannelState aState,
|
|
|
|
bool aWithVideo)
|
2013-01-10 14:56:20 -08:00
|
|
|
: mType(aType)
|
|
|
|
, mElementHidden(aElementHidden)
|
2013-09-02 02:45:44 -07:00
|
|
|
, mState(aState)
|
2013-09-17 20:46:22 -07:00
|
|
|
, mWithVideo(aWithVideo)
|
2013-01-10 14:56:20 -08:00
|
|
|
{}
|
|
|
|
|
2013-01-08 23:18:16 -08:00
|
|
|
AudioChannelType mType;
|
|
|
|
bool mElementHidden;
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState mState;
|
2013-09-17 20:46:22 -07:00
|
|
|
const bool mWithVideo;
|
2013-01-08 23:18:16 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
NotifyEnumerator(AudioChannelAgent* aAgent,
|
2013-01-10 14:56:20 -08:00
|
|
|
AudioChannelAgentData* aData, void *aUnused);
|
2013-01-08 23:18:16 -08:00
|
|
|
|
2013-01-10 14:56:20 -08:00
|
|
|
nsClassHashtable< nsPtrHashKey<AudioChannelAgent>, AudioChannelAgentData > mAgents;
|
2013-11-24 15:50:03 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsTArray<SpeakerManagerService*> mSpeakerManager;
|
|
|
|
#endif
|
2013-01-08 23:18:16 -08:00
|
|
|
nsTArray<uint64_t> mChannelCounters[AUDIO_CHANNEL_INT_LAST];
|
2012-12-05 17:20:59 -08:00
|
|
|
|
|
|
|
AudioChannelType mCurrentHigherChannel;
|
2013-01-28 03:47:18 -08:00
|
|
|
AudioChannelType mCurrentVisibleHigherChannel;
|
2012-12-05 19:01:58 -08:00
|
|
|
|
2013-09-17 20:46:22 -07:00
|
|
|
nsTArray<uint64_t> mWithVideoChildIDs;
|
2013-09-17 00:46:06 -07:00
|
|
|
|
|
|
|
// mPlayableHiddenContentChildID stores the ChildID of the process which can
|
|
|
|
// play content channel(s) in the background.
|
|
|
|
// A background process contained content channel(s) will become playable:
|
|
|
|
// 1. When this background process registers its content channel(s) in
|
|
|
|
// AudioChannelService and there is no foreground process with registered
|
|
|
|
// content channel(s).
|
|
|
|
// 2. When this process goes from foreground into background and there is
|
|
|
|
// no foreground process with registered content channel(s).
|
|
|
|
// A background process contained content channel(s) will become non-playable:
|
|
|
|
// 1. When there is a foreground process registering its content channel(s)
|
|
|
|
// in AudioChannelService.
|
|
|
|
// ps. Currently this condition is never satisfied because the default value
|
|
|
|
// of visibility status of each channel during registering is hidden = true.
|
|
|
|
// 2. When there is a process with registered content channel(s) goes from
|
|
|
|
// background into foreground.
|
|
|
|
// 3. When this process unregisters all hidden content channels.
|
|
|
|
// 4. When this process shuts down.
|
|
|
|
uint64_t mPlayableHiddenContentChildID;
|
2013-01-25 07:12:17 -08:00
|
|
|
|
2013-10-07 23:30:04 -07:00
|
|
|
bool mDisabled;
|
|
|
|
|
2013-04-28 19:47:15 -07:00
|
|
|
nsCOMPtr<nsITimer> mDeferTelChannelTimer;
|
|
|
|
bool mTimerElementHidden;
|
|
|
|
uint64_t mTimerChildID;
|
|
|
|
|
2013-09-12 05:26:03 -07:00
|
|
|
uint64_t mDefChannelChildID;
|
|
|
|
|
2012-12-05 19:01:58 -08:00
|
|
|
// This is needed for IPC comunication between
|
|
|
|
// AudioChannelServiceChild and this class.
|
|
|
|
friend class ContentParent;
|
|
|
|
friend class ContentChild;
|
2012-12-04 11:46:07 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|