зеркало из https://github.com/mozilla/gecko-dev.git
Bug 811222 - Enable system app to get currently used audio channel. r=sicking a=blocking-basecamp
This commit is contained in:
Родитель
0cdc6d4fd2
Коммит
1eb86723d4
|
@ -928,6 +928,15 @@ window.addEventListener('ContentStart', function update_onContentStart() {
|
|||
}, "headphones-status-changed", false);
|
||||
})();
|
||||
|
||||
(function audioChannelChangedTracker() {
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
shell.sendChromeEvent({
|
||||
type: 'audio-channel-changed',
|
||||
channel: aData
|
||||
});
|
||||
}, "audio-channel-changed", false);
|
||||
})();
|
||||
|
||||
(function recordingStatusTracker() {
|
||||
let gRecordingActiveCount = 0;
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ AudioChannelService::Shutdown()
|
|||
NS_IMPL_ISUPPORTS0(AudioChannelService)
|
||||
|
||||
AudioChannelService::AudioChannelService()
|
||||
: mCurrentHigherChannel(AUDIO_CHANNEL_NORMAL)
|
||||
{
|
||||
mChannelCounters = new int32_t[AUDIO_CHANNEL_PUBLICNOTIFICATION+1];
|
||||
|
||||
|
@ -127,25 +128,51 @@ AudioChannelService::GetMuted(AudioChannelType aType, bool aElementHidden)
|
|||
}
|
||||
}
|
||||
|
||||
bool muted = false;
|
||||
|
||||
// Priorities:
|
||||
switch (aType) {
|
||||
case AUDIO_CHANNEL_NORMAL:
|
||||
case AUDIO_CHANNEL_CONTENT:
|
||||
return !!mChannelCounters[AUDIO_CHANNEL_NOTIFICATION] ||
|
||||
!!mChannelCounters[AUDIO_CHANNEL_ALARM] ||
|
||||
!!mChannelCounters[AUDIO_CHANNEL_TELEPHONY] ||
|
||||
!!mChannelCounters[AUDIO_CHANNEL_PUBLICNOTIFICATION];
|
||||
muted = !!mChannelCounters[AUDIO_CHANNEL_NOTIFICATION] ||
|
||||
!!mChannelCounters[AUDIO_CHANNEL_ALARM] ||
|
||||
!!mChannelCounters[AUDIO_CHANNEL_TELEPHONY] ||
|
||||
!!mChannelCounters[AUDIO_CHANNEL_PUBLICNOTIFICATION];
|
||||
|
||||
case AUDIO_CHANNEL_NOTIFICATION:
|
||||
case AUDIO_CHANNEL_ALARM:
|
||||
case AUDIO_CHANNEL_TELEPHONY:
|
||||
return ChannelsActiveWithHigherPriorityThan(aType);
|
||||
muted = ChannelsActiveWithHigherPriorityThan(aType);
|
||||
|
||||
case AUDIO_CHANNEL_PUBLICNOTIFICATION:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
// Notification if needed.
|
||||
if (!muted) {
|
||||
|
||||
// Calculating the most important unmuted channel:
|
||||
AudioChannelType higher = AUDIO_CHANNEL_NORMAL;
|
||||
for (int32_t type = AUDIO_CHANNEL_NORMAL;
|
||||
type <= AUDIO_CHANNEL_PUBLICNOTIFICATION;
|
||||
++type) {
|
||||
if (mChannelCounters[type]) {
|
||||
higher = (AudioChannelType)type;
|
||||
}
|
||||
}
|
||||
|
||||
if (higher != mCurrentHigherChannel) {
|
||||
mCurrentHigherChannel = higher;
|
||||
|
||||
nsString channelName;
|
||||
channelName.AssignASCII(ChannelName(mCurrentHigherChannel));
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
obs->NotifyObservers(nullptr, "audio-channel-changed", channelName.get());
|
||||
}
|
||||
}
|
||||
|
||||
return muted;
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,3 +211,30 @@ AudioChannelService::ChannelsActiveWithHigherPriorityThan(AudioChannelType aType
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char*
|
||||
AudioChannelService::ChannelName(AudioChannelType aType)
|
||||
{
|
||||
static struct {
|
||||
int32_t type;
|
||||
const char* value;
|
||||
} ChannelNameTable[] = {
|
||||
{ AUDIO_CHANNEL_NORMAL, "normal" },
|
||||
{ AUDIO_CHANNEL_CONTENT, "normal" },
|
||||
{ AUDIO_CHANNEL_NOTIFICATION, "notification" },
|
||||
{ AUDIO_CHANNEL_ALARM, "alarm" },
|
||||
{ AUDIO_CHANNEL_TELEPHONY, "telephony" },
|
||||
{ AUDIO_CHANNEL_PUBLICNOTIFICATION, "publicnotification" },
|
||||
{ -1, "unknown" }
|
||||
};
|
||||
|
||||
for (int i = AUDIO_CHANNEL_NORMAL; ; ++i) {
|
||||
if (ChannelNameTable[i].type == aType ||
|
||||
ChannelNameTable[i].type == -1) {
|
||||
return ChannelNameTable[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
NS_NOTREACHED("Execution should not reach here!");
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -59,9 +59,13 @@ protected:
|
|||
|
||||
bool ChannelsActiveWithHigherPriorityThan(AudioChannelType aType);
|
||||
|
||||
const char* ChannelName(AudioChannelType aType);
|
||||
|
||||
nsDataHashtable< nsPtrHashKey<nsHTMLMediaElement>, AudioChannelType > mMediaElements;
|
||||
|
||||
int32_t* mChannelCounters;
|
||||
|
||||
AudioChannelType mCurrentHigherChannel;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
Загрузка…
Ссылка в новой задаче