diff --git a/content/base/src/nsAttrValue.h b/content/base/src/nsAttrValue.h index 89f0ce2c51c6..8a85e701130d 100644 --- a/content/base/src/nsAttrValue.h +++ b/content/base/src/nsAttrValue.h @@ -12,7 +12,7 @@ #define nsAttrValue_h___ #include "nscore.h" -#include "nsStringGlue.h" +#include "nsString.h" #include "nsStringBuffer.h" #include "nsColor.h" #include "nsCaseTreatment.h" diff --git a/content/html/content/public/HTMLMediaElement.h b/content/html/content/public/HTMLMediaElement.h index ca0db56aee51..961092910408 100644 --- a/content/html/content/public/HTMLMediaElement.h +++ b/content/html/content/public/HTMLMediaElement.h @@ -496,11 +496,7 @@ public: double MozFragmentEnd(); - AudioChannel MozAudioChannelType() const - { - return mAudioChannel; - } - + AudioChannel MozAudioChannelType() const; void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv); TextTrackList* TextTracks(); @@ -1126,8 +1122,8 @@ protected: // True if the media's channel's download has been suspended. bool mDownloadSuspendedByCache; - // Audio Channel. - AudioChannel mAudioChannel; + // Audio Channel Type. + AudioChannelType mAudioChannelType; // The audio channel has been faded. bool mAudioChannelFaded; diff --git a/content/html/content/src/HTMLMediaElement.cpp b/content/html/content/src/HTMLMediaElement.cpp index 52fe49931598..453e1dc570ff 100644 --- a/content/html/content/src/HTMLMediaElement.cpp +++ b/content/html/content/src/HTMLMediaElement.cpp @@ -2004,6 +2004,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNodeInfo) mCORSMode(CORS_NONE), mHasAudio(false), mDownloadSuspendedByCache(false), + mAudioChannelType(AUDIO_CHANNEL_NORMAL), mAudioChannelFaded(false), mPlayingThroughTheAudioChannel(false) { @@ -2016,8 +2017,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNodeInfo) } #endif - mAudioChannel = AudioChannelService::GetDefaultAudioChannel(); - mPaused.SetOuter(this); RegisterFreezableElement(); @@ -2283,6 +2282,18 @@ bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID, { 0 } }; + // Mappings from 'mozaudiochannel' attribute strings to an enumeration. + static const nsAttrValue::EnumTable kMozAudioChannelAttributeTable[] = { + { "normal", AUDIO_CHANNEL_NORMAL }, + { "content", AUDIO_CHANNEL_CONTENT }, + { "notification", AUDIO_CHANNEL_NOTIFICATION }, + { "alarm", AUDIO_CHANNEL_ALARM }, + { "telephony", AUDIO_CHANNEL_TELEPHONY }, + { "ringer", AUDIO_CHANNEL_RINGER }, + { "publicnotification", AUDIO_CHANNEL_PUBLICNOTIFICATION }, + { 0 } + }; + if (aNamespaceID == kNameSpaceID_None) { if (ParseImageAttribute(aAttribute, aValue, aResult)) { return true; @@ -2296,21 +2307,18 @@ bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID, } if (aAttribute == nsGkAtoms::mozaudiochannel) { - const nsAttrValue::EnumTable* table = - AudioChannelService::GetAudioChannelTable(); - MOZ_ASSERT(table); - - bool parsed = aResult.ParseEnumValue(aValue, table, false, &table[0]); + bool parsed = aResult.ParseEnumValue(aValue, kMozAudioChannelAttributeTable, false, + &kMozAudioChannelAttributeTable[0]); if (!parsed) { return false; } - AudioChannel audioChannel = static_cast(aResult.GetEnumValue()); + AudioChannelType audioChannelType = static_cast(aResult.GetEnumValue()); - if (audioChannel != mAudioChannel && + if (audioChannelType != mAudioChannelType && !mDecoder && CheckAudioChannelPermissions(aValue)) { - mAudioChannel = audioChannel; + mAudioChannelType = audioChannelType; } return true; @@ -2596,7 +2604,7 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder, // Tell the decoder about its MediaResource now so things like principals are // available immediately. mDecoder->SetResource(aStream); - aDecoder->SetAudioChannel(mAudioChannel); + mDecoder->SetAudioChannelType(mAudioChannelType); mDecoder->SetAudioCaptured(mAudioCaptured); mDecoder->SetVolume(mMuted ? 0.0 : mVolume); mDecoder->SetPreservesPitch(mPreservesPitch); @@ -3838,14 +3846,12 @@ void HTMLMediaElement::UpdateAudioChannelPlayingState() } nsCOMPtr video = do_QueryObject(this); // Use a weak ref so the audio channel agent can't leak |this|. - if (AudioChannel::Normal == mAudioChannel && video) { + if (AUDIO_CHANNEL_NORMAL == mAudioChannelType && video) { mAudioChannelAgent->InitWithVideo(OwnerDoc()->GetWindow(), - static_cast(mAudioChannel), - this, true); + mAudioChannelType, this, true); } else { mAudioChannelAgent->InitWithWeakCallback(OwnerDoc()->GetWindow(), - static_cast(mAudioChannel), - this); + mAudioChannelType, this); } mAudioChannelAgent->SetVisibilityState(!OwnerDoc()->Hidden()); } @@ -3925,6 +3931,33 @@ HTMLMediaElement::GetOrCreateTextTrackManager() return mTextTrackManager; } +AudioChannel +HTMLMediaElement::MozAudioChannelType() const +{ + switch (mAudioChannelType) { + case AUDIO_CHANNEL_CONTENT: + return AudioChannel::Content; + + case AUDIO_CHANNEL_NOTIFICATION: + return AudioChannel::Notification; + + case AUDIO_CHANNEL_ALARM: + return AudioChannel::Alarm; + + case AUDIO_CHANNEL_TELEPHONY: + return AudioChannel::Telephony; + + case AUDIO_CHANNEL_RINGER: + return AudioChannel::Ringer; + + case AUDIO_CHANNEL_PUBLICNOTIFICATION: + return AudioChannel::Publicnotification; + + default: + return AudioChannelService::GetDefaultAudioChannel(); + } +} + void HTMLMediaElement::SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv) { diff --git a/content/media/AudioStream.cpp b/content/media/AudioStream.cpp index 6053a89457e1..d21acf79dfa4 100644 --- a/content/media/AudioStream.cpp +++ b/content/media/AudioStream.cpp @@ -110,25 +110,25 @@ bool AudioStream::sCubebLatencyPrefSet; } #if defined(__ANDROID__) && defined(MOZ_B2G) -static cubeb_stream_type ConvertChannelToCubebType(dom::AudioChannel aChannel) +static cubeb_stream_type ConvertChannelToCubebType(dom::AudioChannelType aType) { - switch(aChannel) { - case dom::AudioChannel::Normal: + switch(aType) { + case dom::AUDIO_CHANNEL_NORMAL: return CUBEB_STREAM_TYPE_SYSTEM; - case dom::AudioChannel::Content: + case dom::AUDIO_CHANNEL_CONTENT: return CUBEB_STREAM_TYPE_MUSIC; - case dom::AudioChannel::Notification: + case dom::AUDIO_CHANNEL_NOTIFICATION: return CUBEB_STREAM_TYPE_NOTIFICATION; - case dom::AudioChannel::Alarm: + case dom::AUDIO_CHANNEL_ALARM: return CUBEB_STREAM_TYPE_ALARM; - case dom::AudioChannel::Telephony: + case dom::AUDIO_CHANNEL_TELEPHONY: return CUBEB_STREAM_TYPE_VOICE_CALL; - case dom::AudioChannel::Ringer: + case dom::AUDIO_CHANNEL_RINGER: return CUBEB_STREAM_TYPE_RING; // Currently Android openSLES library doesn't support FORCE_AUDIBLE yet. - case dom::AudioChannel::Publicnotification: + case dom::AUDIO_CHANNEL_PUBLICNOTIFICATION: default: - NS_ERROR("The value of AudioChannel is invalid"); + NS_ERROR("The value of AudioChannelType is invalid"); return CUBEB_STREAM_TYPE_MAX; } } @@ -349,7 +349,7 @@ WriteDumpFile(FILE* aDumpFile, AudioStream* aStream, uint32_t aFrames, nsresult AudioStream::Init(int32_t aNumChannels, int32_t aRate, - const dom::AudioChannel aAudioChannel, + const dom::AudioChannelType aAudioChannelType, LatencyRequest aLatencyRequest) { cubeb* cubebContext = GetCubebContext(); @@ -372,7 +372,7 @@ AudioStream::Init(int32_t aNumChannels, int32_t aRate, params.channels = mOutChannels; #if defined(__ANDROID__) #if defined(MOZ_B2G) - params.stream_type = ConvertChannelToCubebType(aAudioChannel); + params.stream_type = ConvertChannelToCubebType(aAudioChannelType); #else params.stream_type = CUBEB_STREAM_TYPE_MUSIC; #endif diff --git a/content/media/AudioStream.h b/content/media/AudioStream.h index 717accf20b3f..085676d782b9 100644 --- a/content/media/AudioStream.h +++ b/content/media/AudioStream.h @@ -7,11 +7,11 @@ #define AudioStream_h_ #include "AudioSampleFormat.h" +#include "AudioChannelCommon.h" #include "nsAutoPtr.h" #include "nsAutoRef.h" #include "nsCOMPtr.h" #include "Latency.h" -#include "mozilla/dom/AudioChannelBinding.h" #include "mozilla/StaticMutex.h" #include "cubeb/cubeb.h" @@ -198,7 +198,7 @@ public: // channels (1 for mono, 2 for stereo, etc) and aRate is the sample rate // (22050Hz, 44100Hz, etc). nsresult Init(int32_t aNumChannels, int32_t aRate, - const dom::AudioChannel aAudioStreamChannel, + const dom::AudioChannelType aAudioStreamType, LatencyRequest aLatencyRequest); // Closes the stream. All future use of the stream is an error. diff --git a/content/media/MediaDecoder.cpp b/content/media/MediaDecoder.cpp index ae56d4a76dcd..e1822cb6a9ae 100644 --- a/content/media/MediaDecoder.cpp +++ b/content/media/MediaDecoder.cpp @@ -23,7 +23,6 @@ #include "nsITimer.h" #include #include "MediaShutdownManager.h" -#include "AudioChannelService.h" #ifdef MOZ_WMF #include "WMFDecoder.h" @@ -428,6 +427,7 @@ MediaDecoder::MediaDecoder() : mPinnedForSeek(false), mShuttingDown(false), mPausedForPlaybackRateNull(false), + mAudioChannelType(AUDIO_CHANNEL_NORMAL), mMinimizePreroll(false) { MOZ_COUNT_CTOR(MediaDecoder); @@ -438,8 +438,6 @@ MediaDecoder::MediaDecoder() : gMediaDecoderLog = PR_NewLogModule("MediaDecoder"); } #endif - - mAudioChannel = AudioChannelService::GetDefaultAudioChannel(); } bool MediaDecoder::Init(MediaDecoderOwner* aOwner) diff --git a/content/media/MediaDecoder.h b/content/media/MediaDecoder.h index 3a981f697359..f09ab12a6d49 100755 --- a/content/media/MediaDecoder.h +++ b/content/media/MediaDecoder.h @@ -183,11 +183,11 @@ destroying the MediaDecoder object. #include "nsIObserver.h" #include "nsAutoPtr.h" #include "MediaResource.h" -#include "mozilla/dom/AudioChannelBinding.h" #include "mozilla/gfx/Rect.h" #include "mozilla/ReentrantMonitor.h" #include "mozilla/TimeStamp.h" #include "MediaStreamGraph.h" +#include "AudioChannelCommon.h" #include "AbstractMediaDecoder.h" #include "necko-config.h" @@ -739,8 +739,8 @@ public: // held. void UpdatePlaybackPosition(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE; - void SetAudioChannel(dom::AudioChannel aChannel) { mAudioChannel = aChannel; } - dom::AudioChannel GetAudioChannel() { return mAudioChannel; } + void SetAudioChannelType(dom::AudioChannelType aType) { mAudioChannelType = aType; } + dom::AudioChannelType GetAudioChannelType() { return mAudioChannelType; } // Send a new set of metadata to the state machine, to be dispatched to the // main thread to be presented when the |currentTime| of the media is greater @@ -1205,7 +1205,7 @@ protected: // Be assigned from media element during the initialization and pass to // AudioStream Class. - dom::AudioChannel mAudioChannel; + dom::AudioChannelType mAudioChannelType; // True if the decoder has been directed to minimize its preroll before // playback starts. After the first time playback starts, we don't attempt diff --git a/content/media/MediaDecoderStateMachine.cpp b/content/media/MediaDecoderStateMachine.cpp index 71282a8455f4..acacc2425035 100644 --- a/content/media/MediaDecoderStateMachine.cpp +++ b/content/media/MediaDecoderStateMachine.cpp @@ -763,7 +763,7 @@ void MediaDecoderStateMachine::AudioLoop() bool setPlaybackRate; bool preservesPitch; bool setPreservesPitch; - AudioChannel audioChannel; + AudioChannelType audioChannelType; { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); @@ -773,7 +773,7 @@ void MediaDecoderStateMachine::AudioLoop() channels = mInfo.mAudio.mChannels; rate = mInfo.mAudio.mRate; - audioChannel = mDecoder->GetAudioChannel(); + audioChannelType = mDecoder->GetAudioChannelType(); volume = mVolume; preservesPitch = mPreservesPitch; playbackRate = mPlaybackRate; @@ -784,7 +784,7 @@ void MediaDecoderStateMachine::AudioLoop() // circumstances, so we take care to drop the decoder monitor while // initializing. nsAutoPtr audioStream(new AudioStream()); - audioStream->Init(channels, rate, audioChannel, AudioStream::HighLatency); + audioStream->Init(channels, rate, audioChannelType, AudioStream::HighLatency); audioStream->SetVolume(volume); if (audioStream->SetPreservesPitch(preservesPitch) != NS_OK) { NS_WARNING("Setting the pitch preservation failed at AudioLoop start."); diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index 7edb2aad9361..a494b8522f81 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -18,7 +18,7 @@ #include "mozilla/Attributes.h" #include "TrackUnionStream.h" #include "ImageContainer.h" -#include "AudioChannelService.h" +#include "AudioChannelCommon.h" #include "AudioNodeEngine.h" #include "AudioNodeStream.h" #include "AudioNodeExternalInputStream.h" @@ -811,9 +811,7 @@ MediaStreamGraphImpl::CreateOrDestroyAudioStreams(GraphTime aAudioOutputStartTim audioOutputStream->mStream = new AudioStream(); // XXX for now, allocate stereo output. But we need to fix this to // match the system's ideal channel configuration. - audioOutputStream->mStream->Init(2, tracks->GetRate(), - AudioChannel::Normal, - AudioStream::LowLatency); + audioOutputStream->mStream->Init(2, tracks->GetRate(), AUDIO_CHANNEL_NORMAL, AudioStream::LowLatency); audioOutputStream->mTrackID = tracks->GetID(); LogLatency(AsyncLatencyLogger::AudioStreamCreate, diff --git a/content/media/webaudio/AudioDestinationNode.cpp b/content/media/webaudio/AudioDestinationNode.cpp index 377be9211484..297893b75121 100644 --- a/content/media/webaudio/AudioDestinationNode.cpp +++ b/content/media/webaudio/AudioDestinationNode.cpp @@ -477,10 +477,40 @@ AudioDestinationNode::CreateAudioChannelAgent() mAudioChannelAgent->StopPlaying(); } + AudioChannelType type = AUDIO_CHANNEL_NORMAL; + switch(mAudioChannel) { + case AudioChannel::Normal: + type = AUDIO_CHANNEL_NORMAL; + break; + + case AudioChannel::Content: + type = AUDIO_CHANNEL_CONTENT; + break; + + case AudioChannel::Notification: + type = AUDIO_CHANNEL_NOTIFICATION; + break; + + case AudioChannel::Alarm: + type = AUDIO_CHANNEL_ALARM; + break; + + case AudioChannel::Telephony: + type = AUDIO_CHANNEL_TELEPHONY; + break; + + case AudioChannel::Ringer: + type = AUDIO_CHANNEL_RINGER; + break; + + case AudioChannel::Publicnotification: + type = AUDIO_CHANNEL_PUBLICNOTIFICATION; + break; + + } + mAudioChannelAgent = new AudioChannelAgent(); - mAudioChannelAgent->InitWithWeakCallback(GetOwner(), - static_cast(mAudioChannel), - this); + mAudioChannelAgent->InitWithWeakCallback(GetOwner(), type, this); nsCOMPtr docshell = do_GetInterface(GetOwner()); if (docshell) { diff --git a/content/svg/content/src/SVGAttrValueWrapper.h b/content/svg/content/src/SVGAttrValueWrapper.h index 8c02b73a5bb0..9a890a5bf9d9 100644 --- a/content/svg/content/src/SVGAttrValueWrapper.h +++ b/content/svg/content/src/SVGAttrValueWrapper.h @@ -12,7 +12,7 @@ * types don't need to be exported outside the SVG module. */ -#include "nsStringGlue.h" +#include "nsString.h" class nsSVGAngle; class nsSVGIntegerPair; diff --git a/dom/audiochannel/AudioChannelAgent.cpp b/dom/audiochannel/AudioChannelAgent.cpp index e88a5ba8e105..af8f8a306fd1 100644 --- a/dom/audiochannel/AudioChannelAgent.cpp +++ b/dom/audiochannel/AudioChannelAgent.cpp @@ -84,22 +84,22 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType, MOZ_ASSERT(aWindow || XRE_GetProcessType() == GeckoProcessType_Default); // We syncd the enum of channel type between nsIAudioChannelAgent.idl and - // AudioChannelBinding.h the same. - MOZ_ASSERT(static_cast(AUDIO_AGENT_CHANNEL_NORMAL) == - AudioChannel::Normal && - static_cast(AUDIO_AGENT_CHANNEL_CONTENT) == - AudioChannel::Content && - static_cast(AUDIO_AGENT_CHANNEL_NOTIFICATION) == - AudioChannel::Notification && - static_cast(AUDIO_AGENT_CHANNEL_ALARM) == - AudioChannel::Alarm && - static_cast(AUDIO_AGENT_CHANNEL_TELEPHONY) == - AudioChannel::Telephony && - static_cast(AUDIO_AGENT_CHANNEL_RINGER) == - AudioChannel::Ringer && - static_cast(AUDIO_AGENT_CHANNEL_PUBLICNOTIFICATION) == - AudioChannel::Publicnotification, - "Enum of channel on nsIAudioChannelAgent.idl should be the same with AudioChannelBinding.h"); + // AudioChannelCommon.h the same. + static_assert(static_cast(AUDIO_AGENT_CHANNEL_NORMAL) == + AUDIO_CHANNEL_NORMAL && + static_cast(AUDIO_AGENT_CHANNEL_CONTENT) == + AUDIO_CHANNEL_CONTENT && + static_cast(AUDIO_AGENT_CHANNEL_NOTIFICATION) == + AUDIO_CHANNEL_NOTIFICATION && + static_cast(AUDIO_AGENT_CHANNEL_ALARM) == + AUDIO_CHANNEL_ALARM && + static_cast(AUDIO_AGENT_CHANNEL_TELEPHONY) == + AUDIO_CHANNEL_TELEPHONY && + static_cast(AUDIO_AGENT_CHANNEL_RINGER) == + AUDIO_CHANNEL_RINGER && + static_cast(AUDIO_AGENT_CHANNEL_PUBLICNOTIFICATION) == + AUDIO_CHANNEL_PUBLICNOTIFICATION, + "Enum of channel on nsIAudioChannelAgent.idl should be the same with AudioChannelCommon.h"); if (mAudioChannelType != AUDIO_AGENT_CHANNEL_ERROR || aChannelType > AUDIO_AGENT_CHANNEL_PUBLICNOTIFICATION || @@ -131,7 +131,7 @@ NS_IMETHODIMP AudioChannelAgent::StartPlaying(int32_t *_retval) } service->RegisterAudioChannelAgent(this, - static_cast(mAudioChannelType), mWithVideo); + static_cast(mAudioChannelType), mWithVideo); *_retval = service->GetState(this, !mVisible); mIsRegToService = true; return NS_OK; diff --git a/dom/audiochannel/AudioChannelCommon.h b/dom/audiochannel/AudioChannelCommon.h index 79d791d447ff..322271881507 100644 --- a/dom/audiochannel/AudioChannelCommon.h +++ b/dom/audiochannel/AudioChannelCommon.h @@ -10,6 +10,20 @@ namespace mozilla { namespace dom { +// The audio channel. Read the nsIHTMLMediaElement.idl for a description +// about this attribute. +enum AudioChannelType { + AUDIO_CHANNEL_DEFAULT = -1, + AUDIO_CHANNEL_NORMAL = 0, + AUDIO_CHANNEL_CONTENT, + AUDIO_CHANNEL_NOTIFICATION, + AUDIO_CHANNEL_ALARM, + AUDIO_CHANNEL_TELEPHONY, + AUDIO_CHANNEL_RINGER, + AUDIO_CHANNEL_PUBLICNOTIFICATION, + AUDIO_CHANNEL_LAST +}; + enum AudioChannelState { AUDIO_CHANNEL_STATE_NORMAL = 0, AUDIO_CHANNEL_STATE_MUTED, diff --git a/dom/audiochannel/AudioChannelService.cpp b/dom/audiochannel/AudioChannelService.cpp index add65d2bb4b3..1887c82514e0 100644 --- a/dom/audiochannel/AudioChannelService.cpp +++ b/dom/audiochannel/AudioChannelService.cpp @@ -37,18 +37,6 @@ using namespace mozilla::hal; StaticRefPtr gAudioChannelService; -// 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 } -}; - // static AudioChannelService* AudioChannelService::GetAudioChannelService() @@ -87,8 +75,8 @@ AudioChannelService::Shutdown() NS_IMPL_ISUPPORTS2(AudioChannelService, nsIObserver, nsITimerCallback) AudioChannelService::AudioChannelService() -: mCurrentHigherChannel(INT32_MAX) -, mCurrentVisibleHigherChannel(INT32_MAX) +: mCurrentHigherChannel(AUDIO_CHANNEL_LAST) +, mCurrentVisibleHigherChannel(AUDIO_CHANNEL_LAST) , mPlayableHiddenContentChildID(CONTENT_PROCESS_ID_UNKNOWN) , mDisabled(false) , mDefChannelChildID(CONTENT_PROCESS_ID_UNKNOWN) @@ -112,19 +100,21 @@ AudioChannelService::~AudioChannelService() void AudioChannelService::RegisterAudioChannelAgent(AudioChannelAgent* aAgent, - AudioChannel aChannel, + AudioChannelType aType, bool aWithVideo) { if (mDisabled) { return; } - AudioChannelAgentData* data = new AudioChannelAgentData(aChannel, + MOZ_ASSERT(aType != AUDIO_CHANNEL_DEFAULT); + + AudioChannelAgentData* data = new AudioChannelAgentData(aType, true /* aElementHidden */, AUDIO_CHANNEL_STATE_MUTED /* aState */, aWithVideo); mAgents.Put(aAgent, data); - RegisterType(aChannel, CONTENT_PROCESS_ID_MAIN, aWithVideo); + RegisterType(aType, CONTENT_PROCESS_ID_MAIN, aWithVideo); // If this is the first agent for this window, we must notify the observers. uint32_t count = CountWindow(aAgent->Window()); @@ -140,24 +130,22 @@ AudioChannelService::RegisterAudioChannelAgent(AudioChannelAgent* aAgent, } void -AudioChannelService::RegisterType(AudioChannel aChannel, uint64_t aChildID, - bool aWithVideo) +AudioChannelService::RegisterType(AudioChannelType aType, uint64_t aChildID, bool aWithVideo) { if (mDisabled) { return; } - AudioChannelInternalType type = GetInternalType(aChannel, true); + AudioChannelInternalType type = GetInternalType(aType, true); mChannelCounters[type].AppendElement(aChildID); if (XRE_GetProcessType() == GeckoProcessType_Default) { // Since there is another telephony registered, we can unregister old one // immediately. - if (mDeferTelChannelTimer && aChannel == AudioChannel::Telephony) { + if (mDeferTelChannelTimer && aType == AUDIO_CHANNEL_TELEPHONY) { mDeferTelChannelTimer->Cancel(); mDeferTelChannelTimer = nullptr; - UnregisterTypeInternal(aChannel, mTimerElementHidden, mTimerChildID, - false); + UnregisterTypeInternal(aType, mTimerElementHidden, mTimerChildID, false); } if (aWithVideo) { @@ -198,7 +186,7 @@ AudioChannelService::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent) mAgents.RemoveAndForget(aAgent, data); if (data) { - UnregisterType(data->mChannel, data->mElementHidden, + UnregisterType(data->mType, data->mElementHidden, CONTENT_PROCESS_ID_MAIN, data->mWithVideo); } #ifdef MOZ_WIDGET_GONK @@ -222,7 +210,7 @@ AudioChannelService::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent) } void -AudioChannelService::UnregisterType(AudioChannel aChannel, +AudioChannelService::UnregisterType(AudioChannelType aType, bool aElementHidden, uint64_t aChildID, bool aWithVideo) @@ -235,7 +223,7 @@ AudioChannelService::UnregisterType(AudioChannel aChannel, // 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. if (XRE_GetProcessType() == GeckoProcessType_Default && - aChannel == AudioChannel::Telephony && + aType == AUDIO_CHANNEL_TELEPHONY && (mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN].Length() + mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY].Length()) == 1) { mTimerElementHidden = aElementHidden; @@ -245,18 +233,18 @@ AudioChannelService::UnregisterType(AudioChannel aChannel, return; } - UnregisterTypeInternal(aChannel, aElementHidden, aChildID, aWithVideo); + UnregisterTypeInternal(aType, aElementHidden, aChildID, aWithVideo); } void -AudioChannelService::UnregisterTypeInternal(AudioChannel aChannel, +AudioChannelService::UnregisterTypeInternal(AudioChannelType aType, bool aElementHidden, uint64_t aChildID, bool aWithVideo) { // The array may contain multiple occurrence of this appId but // this should remove only the first one. - AudioChannelInternalType type = GetInternalType(aChannel, aElementHidden); + AudioChannelInternalType type = GetInternalType(aType, aElementHidden); MOZ_ASSERT(mChannelCounters[type].Contains(aChildID)); mChannelCounters[type].RemoveElement(aChildID); @@ -265,7 +253,7 @@ AudioChannelService::UnregisterTypeInternal(AudioChannel aChannel, if (XRE_GetProcessType() == GeckoProcessType_Default) { // No hidden content channel is playable if the original playable hidden // process does not need to play audio from background anymore. - if (aChannel == AudioChannel::Content && + if (aType == AUDIO_CHANNEL_CONTENT && mPlayableHiddenContentChildID == aChildID && !mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].Contains(aChildID)) { mPlayableHiddenContentChildID = CONTENT_PROCESS_ID_UNKNOWN; @@ -282,14 +270,14 @@ AudioChannelService::UnregisterTypeInternal(AudioChannel aChannel, } void -AudioChannelService::UpdateChannelType(AudioChannel aChannel, +AudioChannelService::UpdateChannelType(AudioChannelType aType, uint64_t aChildID, bool aElementHidden, bool aElementWasHidden) { // Calculate the new and old internal type and update the hashtable if needed. - AudioChannelInternalType newType = GetInternalType(aChannel, aElementHidden); - AudioChannelInternalType oldType = GetInternalType(aChannel, aElementWasHidden); + AudioChannelInternalType newType = GetInternalType(aType, aElementHidden); + AudioChannelInternalType oldType = GetInternalType(aType, aElementWasHidden); if (newType != oldType) { mChannelCounters[newType].AppendElement(aChildID); @@ -327,26 +315,24 @@ AudioChannelService::GetState(AudioChannelAgent* aAgent, bool aElementHidden) // Update visibility. data->mElementHidden = aElementHidden; - data->mState = GetStateInternal(data->mChannel, CONTENT_PROCESS_ID_MAIN, + data->mState = GetStateInternal(data->mType, CONTENT_PROCESS_ID_MAIN, aElementHidden, oldElementHidden); return data->mState; } AudioChannelState -AudioChannelService::GetStateInternal(AudioChannel aChannel, uint64_t aChildID, - bool aElementHidden, - bool aElementWasHidden) +AudioChannelService::GetStateInternal(AudioChannelType aType, uint64_t aChildID, + bool aElementHidden, bool aElementWasHidden) { - UpdateChannelType(aChannel, aChildID, aElementHidden, aElementWasHidden); + UpdateChannelType(aType, aChildID, aElementHidden, aElementWasHidden); // Calculating the new and old type and update the hashtable if needed. - AudioChannelInternalType newType = GetInternalType(aChannel, aElementHidden); - AudioChannelInternalType oldType = GetInternalType(aChannel, - aElementWasHidden); + AudioChannelInternalType newType = GetInternalType(aType, aElementHidden); + AudioChannelInternalType oldType = GetInternalType(aType, aElementWasHidden); if (newType != oldType && - (aChannel == AudioChannel::Content || - (aChannel == AudioChannel::Normal && + (aType == AUDIO_CHANNEL_CONTENT || + (aType == AUDIO_CHANNEL_NORMAL && mWithVideoChildIDs.Contains(aChildID)))) { Notify(); } @@ -441,17 +427,15 @@ AudioChannelService::ProcessContentOrNormalChannelIsActive(uint64_t aChildID) } void -AudioChannelService::SetDefaultVolumeControlChannel(int32_t aChannel, +AudioChannelService::SetDefaultVolumeControlChannel(AudioChannelType aType, bool aHidden) { - SetDefaultVolumeControlChannelInternal(aChannel, aHidden, - CONTENT_PROCESS_ID_MAIN); + SetDefaultVolumeControlChannelInternal(aType, aHidden, CONTENT_PROCESS_ID_MAIN); } void -AudioChannelService::SetDefaultVolumeControlChannelInternal(int32_t aChannel, - bool aHidden, - uint64_t aChildID) +AudioChannelService::SetDefaultVolumeControlChannelInternal( + AudioChannelType aType, bool aHidden, uint64_t aChildID) { if (XRE_GetProcessType() != GeckoProcessType_Default) { return; @@ -466,13 +450,7 @@ AudioChannelService::SetDefaultVolumeControlChannelInternal(int32_t aChannel, mDefChannelChildID = aChildID; nsString channelName; - - if (aChannel == -1) { - channelName.AssignASCII("unknown"); - } else { - GetAudioChannelString(static_cast(aChannel), channelName); - } - + channelName.AssignASCII(ChannelName(aType)); nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { obs->NotifyObservers(nullptr, "default-volume-channel-changed", @@ -497,57 +475,52 @@ AudioChannelService::SendAudioChannelChangedNotification(uint64_t aChildID) } // Calculating the most important active channel. - int32_t higher = -1; + AudioChannelType higher = AUDIO_CHANNEL_DEFAULT; // Top-Down in the hierarchy for visible elements if (!mChannelCounters[AUDIO_CHANNEL_INT_PUBLICNOTIFICATION].IsEmpty()) { - higher = static_cast(AudioChannel::Publicnotification); + higher = AUDIO_CHANNEL_PUBLICNOTIFICATION; } else if (!mChannelCounters[AUDIO_CHANNEL_INT_RINGER].IsEmpty()) { - higher = static_cast(AudioChannel::Ringer); + higher = AUDIO_CHANNEL_RINGER; } else if (!mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY].IsEmpty()) { - higher = static_cast(AudioChannel::Telephony); + higher = AUDIO_CHANNEL_TELEPHONY; } else if (!mChannelCounters[AUDIO_CHANNEL_INT_ALARM].IsEmpty()) { - higher = static_cast(AudioChannel::Alarm); + higher = AUDIO_CHANNEL_ALARM; } else if (!mChannelCounters[AUDIO_CHANNEL_INT_NOTIFICATION].IsEmpty()) { - higher = static_cast(AudioChannel::Notification); + higher = AUDIO_CHANNEL_NOTIFICATION; } else if (!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) { - higher = static_cast(AudioChannel::Content); + higher = AUDIO_CHANNEL_CONTENT; } else if (!mChannelCounters[AUDIO_CHANNEL_INT_NORMAL].IsEmpty()) { - higher = static_cast(AudioChannel::Normal); + higher = AUDIO_CHANNEL_NORMAL; } - int32_t visibleHigher = higher; + AudioChannelType visibleHigher = higher; // Top-Down in the hierarchy for non-visible elements // And we can ignore normal channel because it can't play in the background. - int32_t index; - for (index = 0; kMozAudioChannelAttributeTable[index].tag; ++index); - - for (--index; - kMozAudioChannelAttributeTable[index].value > higher && - kMozAudioChannelAttributeTable[index].value > (int16_t)AudioChannel::Normal; - --index) { - if (kMozAudioChannelAttributeTable[index].value == (int16_t)AudioChannel::Content && + for (int i = AUDIO_CHANNEL_LAST - 1; + i > higher && i > AUDIO_CHANNEL_NORMAL; i--) { + if (i == AUDIO_CHANNEL_CONTENT && mPlayableHiddenContentChildID != CONTENT_PROCESS_ID_UNKNOWN) { - higher = kMozAudioChannelAttributeTable[index].value; + higher = static_cast(i); } // Each channel type will be split to fg and bg for recording the state, // so here need to do a translation. - if (!mChannelCounters[index * 2 + 1].IsEmpty()) { - higher = kMozAudioChannelAttributeTable[index].value; + if (!mChannelCounters[i * 2 + 1].IsEmpty()) { + higher = static_cast(i); break; } } @@ -556,9 +529,8 @@ AudioChannelService::SendAudioChannelChangedNotification(uint64_t aChildID) mCurrentHigherChannel = higher; nsString channelName; - if (mCurrentHigherChannel != -1) { - GetAudioChannelString(static_cast(mCurrentHigherChannel), - channelName); + if (mCurrentHigherChannel != AUDIO_CHANNEL_DEFAULT) { + channelName.AssignASCII(ChannelName(mCurrentHigherChannel)); } else { channelName.AssignLiteral("none"); } @@ -572,9 +544,8 @@ AudioChannelService::SendAudioChannelChangedNotification(uint64_t aChildID) mCurrentVisibleHigherChannel = visibleHigher; nsString channelName; - if (mCurrentVisibleHigherChannel != -1) { - GetAudioChannelString(static_cast(mCurrentVisibleHigherChannel), - channelName); + if (mCurrentVisibleHigherChannel != AUDIO_CHANNEL_DEFAULT) { + channelName.AssignASCII(ChannelName(mCurrentVisibleHigherChannel)); } else { channelName.AssignLiteral("none"); } @@ -613,8 +584,7 @@ AudioChannelService::Notify() NS_IMETHODIMP AudioChannelService::Notify(nsITimer* aTimer) { - UnregisterTypeInternal(AudioChannel::Telephony, mTimerElementHidden, - mTimerChildID, false); + UnregisterTypeInternal(AUDIO_CHANNEL_TELEPHONY, mTimerElementHidden, mTimerChildID, false); mDeferTelChannelTimer = nullptr; return NS_OK; } @@ -650,6 +620,34 @@ AudioChannelService::ChannelsActiveWithHigherPriorityThan( return false; } +const char* +AudioChannelService::ChannelName(AudioChannelType aType) +{ + static struct { + int32_t type; + const char* value; + } ChannelNameTable[] = { + { AUDIO_CHANNEL_NORMAL, "normal" }, + { AUDIO_CHANNEL_CONTENT, "content" }, + { AUDIO_CHANNEL_NOTIFICATION, "notification" }, + { AUDIO_CHANNEL_ALARM, "alarm" }, + { AUDIO_CHANNEL_TELEPHONY, "telephony" }, + { AUDIO_CHANNEL_RINGER, "ringer" }, + { 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; +} + NS_IMETHODIMP AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { @@ -695,7 +693,8 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const ch Notify(); if (mDefChannelChildID == childID) { - SetDefaultVolumeControlChannelInternal(-1, false, childID); + SetDefaultVolumeControlChannelInternal(AUDIO_CHANNEL_DEFAULT, + false, childID); mDefChannelChildID = CONTENT_PROCESS_ID_UNKNOWN; } } else { @@ -740,13 +739,13 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const ch int32_t index = value.toInt32(); if (keyStr.EqualsLiteral("audio.volume.content")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Content, index); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_CONTENT, index); } else if (keyStr.EqualsLiteral("audio.volume.notification")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Notification, index); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_NOTIFICATION, index); } else if (keyStr.EqualsLiteral("audio.volume.alarm")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Alarm, index); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_ALARM, index); } else if (keyStr.EqualsLiteral("audio.volume.telephony")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Telephony, index); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_TELEPHONY, index); } else if (!keyStr.EqualsLiteral("audio.volume.bt_sco")) { // bt_sco is not a valid audio channel so we manipulate it in // AudioManager.cpp. And the others should not be used. @@ -762,50 +761,51 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const ch } AudioChannelService::AudioChannelInternalType -AudioChannelService::GetInternalType(AudioChannel aChannel, +AudioChannelService::GetInternalType(AudioChannelType aType, bool aElementHidden) { - switch (aChannel) { - case AudioChannel::Normal: + switch (aType) { + case AUDIO_CHANNEL_NORMAL: return aElementHidden ? AUDIO_CHANNEL_INT_NORMAL_HIDDEN : AUDIO_CHANNEL_INT_NORMAL; - case AudioChannel::Content: + case AUDIO_CHANNEL_CONTENT: return aElementHidden ? AUDIO_CHANNEL_INT_CONTENT_HIDDEN : AUDIO_CHANNEL_INT_CONTENT; - case AudioChannel::Notification: + case AUDIO_CHANNEL_NOTIFICATION: return aElementHidden ? AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN : AUDIO_CHANNEL_INT_NOTIFICATION; - case AudioChannel::Alarm: + case AUDIO_CHANNEL_ALARM: return aElementHidden ? AUDIO_CHANNEL_INT_ALARM_HIDDEN : AUDIO_CHANNEL_INT_ALARM; - case AudioChannel::Telephony: + case AUDIO_CHANNEL_TELEPHONY: return aElementHidden ? AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN : AUDIO_CHANNEL_INT_TELEPHONY; - case AudioChannel::Ringer: + case AUDIO_CHANNEL_RINGER: return aElementHidden ? AUDIO_CHANNEL_INT_RINGER_HIDDEN : AUDIO_CHANNEL_INT_RINGER; - case AudioChannel::Publicnotification: + case AUDIO_CHANNEL_PUBLICNOTIFICATION: return aElementHidden ? AUDIO_CHANNEL_INT_PUBLICNOTIFICATION_HIDDEN : AUDIO_CHANNEL_INT_PUBLICNOTIFICATION; + case AUDIO_CHANNEL_LAST: default: break; } - MOZ_CRASH("unexpected audio channel"); + MOZ_CRASH("unexpected audio channel type"); } struct RefreshAgentsVolumeData @@ -883,23 +883,21 @@ AudioChannelService::CountWindow(nsIDOMWindow* aWindow) return data.mCount; } -/* static */ const nsAttrValue::EnumTable* -AudioChannelService::GetAudioChannelTable() +// Mappings from 'mozaudiochannel' attribute strings to an enumeration. +static const struct AudioChannelTable { - 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(kMozAudioChannelAttributeTable[i].value); - } - } - - return AudioChannel::Normal; -} + const char* string; + AudioChannel value; +} kMozAudioChannelAttributeTable[] = { + { "normal", AudioChannel::Normal }, + { "content", AudioChannel::Content }, + { "notification", AudioChannel::Notification }, + { "alarm", AudioChannel::Alarm }, + { "telephony", AudioChannel::Telephony }, + { "ringer", AudioChannel::Ringer }, + { "publicnotification", AudioChannel::Publicnotification }, + { nullptr } +}; /* static */ AudioChannel AudioChannelService::GetDefaultAudioChannel() @@ -909,9 +907,9 @@ AudioChannelService::GetDefaultAudioChannel() return AudioChannel::Normal; } - for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) { - if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].tag)) { - return static_cast(kMozAudioChannelAttributeTable[i].value); + for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].string; ++i) { + if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].string)) { + return kMozAudioChannelAttributeTable[i].value; } } @@ -919,29 +917,14 @@ AudioChannelService::GetDefaultAudioChannel() } /* static */ void -AudioChannelService::GetAudioChannelString(AudioChannel aChannel, - nsAString& aString) -{ - aString.AssignASCII("normal"); - - for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) { - if (aChannel == - static_cast(kMozAudioChannelAttributeTable[i].value)) { - aString.AssignASCII(kMozAudioChannelAttributeTable[i].tag); - break; - } - } -} - -/* static */ void -AudioChannelService::GetDefaultAudioChannelString(nsAString& aString) +AudioChannelService::GetDefaultAudioChannelString(nsString& aString) { aString.AssignASCII("normal"); nsString audioChannel = Preferences::GetString("media.defaultAudioChannel"); if (!audioChannel.IsEmpty()) { - for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) { - if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].tag)) { + for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].string; ++i) { + if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].string)) { aString = audioChannel; break; } diff --git a/dom/audiochannel/AudioChannelService.h b/dom/audiochannel/AudioChannelService.h index cf19683365ad..89e0da3095e0 100644 --- a/dom/audiochannel/AudioChannelService.h +++ b/dom/audiochannel/AudioChannelService.h @@ -14,7 +14,6 @@ #include "AudioChannelCommon.h" #include "AudioChannelAgent.h" -#include "nsAttrValue.h" #include "nsClassHashtable.h" #include "mozilla/dom/AudioChannelBinding.h" @@ -49,10 +48,10 @@ public: /** * Any audio channel agent that starts playing should register itself to - * this service, sharing the AudioChannel. + * this service, sharing the AudioChannelType. */ virtual void RegisterAudioChannelAgent(AudioChannelAgent* aAgent, - AudioChannel aChannel, + AudioChannelType aType, bool aWithVideo); /** @@ -82,11 +81,9 @@ public: /*** * AudioChannelManager calls this function to notify the default channel used - * to adjust volume when there is no any active channel. if aChannel is -1, - * the default audio channel will be used. Otherwise aChannel is casted to - * AudioChannel enum. + * to adjust volume when there is no any active channel. */ - virtual void SetDefaultVolumeControlChannel(int32_t aChannel, + virtual void SetDefaultVolumeControlChannel(AudioChannelType aType, bool aHidden); bool AnyAudioChannelIsActive(); @@ -107,11 +104,8 @@ public: } #endif - static const nsAttrValue::EnumTable* GetAudioChannelTable(); - static AudioChannel GetAudioChannel(const nsAString& aString); static AudioChannel GetDefaultAudioChannel(); - static void GetAudioChannelString(AudioChannel aChannel, nsAString& aString); - static void GetDefaultAudioChannelString(nsAString& aString); + static void GetDefaultAudioChannelString(nsString& aString); protected: void Notify(); @@ -123,22 +117,22 @@ protected: void SendAudioChannelChangedNotification(uint64_t aChildID); /* Register/Unregister IPC types: */ - void RegisterType(AudioChannel aChannel, uint64_t aChildID, bool aWithVideo); - void UnregisterType(AudioChannel aChannel, bool aElementHidden, + void RegisterType(AudioChannelType aType, uint64_t aChildID, bool aWithVideo); + void UnregisterType(AudioChannelType aType, bool aElementHidden, uint64_t aChildID, bool aWithVideo); - void UnregisterTypeInternal(AudioChannel aChannel, bool aElementHidden, + void UnregisterTypeInternal(AudioChannelType aType, bool aElementHidden, uint64_t aChildID, bool aWithVideo); - AudioChannelState GetStateInternal(AudioChannel aChannel, uint64_t aChildID, + AudioChannelState GetStateInternal(AudioChannelType aType, uint64_t aChildID, bool aElementHidden, bool aElementWasHidden); /* Update the internal type value following the visibility changes */ - void UpdateChannelType(AudioChannel aChannel, uint64_t aChildID, + void UpdateChannelType(AudioChannelType aType, uint64_t aChildID, bool aElementHidden, bool aElementWasHidden); /* Send the default-volume-channel-changed notification */ - void SetDefaultVolumeControlChannelInternal(int32_t aChannel, + void SetDefaultVolumeControlChannelInternal(AudioChannelType aType, bool aHidden, uint64_t aChildID); AudioChannelService(); @@ -167,22 +161,24 @@ protected: bool CheckVolumeFadedCondition(AudioChannelInternalType aType, bool aElementHidden); - AudioChannelInternalType GetInternalType(AudioChannel aChannel, + const char* ChannelName(AudioChannelType aType); + + AudioChannelInternalType GetInternalType(AudioChannelType aType, bool aElementHidden); class AudioChannelAgentData { public: - AudioChannelAgentData(AudioChannel aChannel, + AudioChannelAgentData(AudioChannelType aType, bool aElementHidden, AudioChannelState aState, bool aWithVideo) - : mChannel(aChannel) + : mType(aType) , mElementHidden(aElementHidden) , mState(aState) , mWithVideo(aWithVideo) {} - AudioChannel mChannel; + AudioChannelType mType; bool mElementHidden; AudioChannelState mState; const bool mWithVideo; @@ -211,8 +207,8 @@ protected: #endif nsTArray mChannelCounters[AUDIO_CHANNEL_INT_LAST]; - int32_t mCurrentHigherChannel; - int32_t mCurrentVisibleHigherChannel; + AudioChannelType mCurrentHigherChannel; + AudioChannelType mCurrentVisibleHigherChannel; nsTArray mWithVideoChildIDs; diff --git a/dom/audiochannel/AudioChannelServiceChild.cpp b/dom/audiochannel/AudioChannelServiceChild.cpp index 40310fcca087..023eec896e2b 100644 --- a/dom/audiochannel/AudioChannelServiceChild.cpp +++ b/dom/audiochannel/AudioChannelServiceChild.cpp @@ -72,15 +72,13 @@ AudioChannelServiceChild::GetState(AudioChannelAgent* aAgent, bool aElementHidde AudioChannelState state = AUDIO_CHANNEL_STATE_MUTED; bool oldElementHidden = data->mElementHidden; - UpdateChannelType(data->mChannel, CONTENT_PROCESS_ID_MAIN, aElementHidden, - oldElementHidden); + UpdateChannelType(data->mType, CONTENT_PROCESS_ID_MAIN, aElementHidden, oldElementHidden); // Update visibility. data->mElementHidden = aElementHidden; ContentChild* cc = ContentChild::GetSingleton(); - cc->SendAudioChannelGetState(data->mChannel, aElementHidden, oldElementHidden, - &state); + cc->SendAudioChannelGetState(data->mType, aElementHidden, oldElementHidden, &state); data->mState = state; cc->SendAudioChannelChangedNotification(); @@ -89,12 +87,14 @@ AudioChannelServiceChild::GetState(AudioChannelAgent* aAgent, bool aElementHidde void AudioChannelServiceChild::RegisterAudioChannelAgent(AudioChannelAgent* aAgent, - AudioChannel aChannel, + AudioChannelType aType, bool aWithVideo) { - AudioChannelService::RegisterAudioChannelAgent(aAgent, aChannel, aWithVideo); + MOZ_ASSERT(aType != AUDIO_CHANNEL_DEFAULT); - ContentChild::GetSingleton()->SendAudioChannelRegisterType(aChannel, aWithVideo); + AudioChannelService::RegisterAudioChannelAgent(aAgent, aType, aWithVideo); + + ContentChild::GetSingleton()->SendAudioChannelRegisterType(aType, aWithVideo); nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { @@ -117,7 +117,7 @@ AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent) AudioChannelService::UnregisterAudioChannelAgent(aAgent); ContentChild::GetSingleton()->SendAudioChannelUnregisterType( - data.mChannel, data.mElementHidden, data.mWithVideo); + data.mType, data.mElementHidden, data.mWithVideo); nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { @@ -132,11 +132,11 @@ AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent) } void -AudioChannelServiceChild::SetDefaultVolumeControlChannel(int32_t aChannel, - bool aHidden) +AudioChannelServiceChild::SetDefaultVolumeControlChannel( + AudioChannelType aType, bool aHidden) { ContentChild *cc = ContentChild::GetSingleton(); if (cc) { - cc->SendAudioChannelChangeDefVolChannel(aChannel, aHidden); + cc->SendAudioChannelChangeDefVolChannel(aType, aHidden); } } diff --git a/dom/audiochannel/AudioChannelServiceChild.h b/dom/audiochannel/AudioChannelServiceChild.h index cf56150e135f..a51762bdfa14 100644 --- a/dom/audiochannel/AudioChannelServiceChild.h +++ b/dom/audiochannel/AudioChannelServiceChild.h @@ -31,7 +31,7 @@ public: static void Shutdown(); virtual void RegisterAudioChannelAgent(AudioChannelAgent* aAgent, - AudioChannel aChannel, + AudioChannelType aType, bool aWithVideo); virtual void UnregisterAudioChannelAgent(AudioChannelAgent* aAgent); @@ -42,8 +42,7 @@ public: virtual AudioChannelState GetState(AudioChannelAgent* aAgent, bool aElementHidden); - virtual void SetDefaultVolumeControlChannel(int32_t aChannel, - bool aHidden); + virtual void SetDefaultVolumeControlChannel(AudioChannelType aType, bool aHidden); protected: AudioChannelServiceChild(); diff --git a/dom/audiochannel/tests/TestAudioChannelService.cpp b/dom/audiochannel/tests/TestAudioChannelService.cpp index 7629e3df2a50..e2e5bfc93068 100644 --- a/dom/audiochannel/tests/TestAudioChannelService.cpp +++ b/dom/audiochannel/tests/TestAudioChannelService.cpp @@ -31,8 +31,8 @@ class Agent : public nsIAudioChannelAgentCallback, public: NS_DECL_ISUPPORTS - Agent(AudioChannel aChannel) - : mChannel(aChannel) + Agent(AudioChannelType aType) + : mType(aType) , mWaitCallback(false) , mRegistered(false) , mCanPlay(AUDIO_CHANNEL_STATE_MUTED) @@ -51,12 +51,10 @@ public: { nsresult rv = NS_OK; if (video) { - rv = mAgent->InitWithVideo(nullptr, static_cast(mChannel), - this, true); + rv = mAgent->InitWithVideo(nullptr, mType, this, true); } else { - rv = mAgent->InitWithWeakCallback(nullptr, static_cast(mChannel), - this); + rv = mAgent->InitWithWeakCallback(nullptr, mType, this); } NS_ENSURE_SUCCESS(rv, rv); @@ -129,7 +127,7 @@ public: } nsCOMPtr mAgent; - AudioChannel mChannel; + AudioChannelType mType; bool mWaitCallback; bool mRegistered; AudioChannelState mCanPlay; @@ -141,7 +139,7 @@ NS_IMPL_ISUPPORTS2(Agent, nsIAudioChannelAgentCallback, nsresult TestDoubleStartPlaying() { - nsRefPtr agent = new Agent(AudioChannel::Normal); + nsRefPtr agent = new Agent(AUDIO_CHANNEL_NORMAL); nsresult rv = agent->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -160,7 +158,7 @@ TestDoubleStartPlaying() nsresult TestOneNormalChannel() { - nsRefPtr agent = new Agent(AudioChannel::Normal); + nsRefPtr agent = new Agent(AUDIO_CHANNEL_NORMAL); nsresult rv = agent->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -184,11 +182,11 @@ TestOneNormalChannel() nsresult TestTwoNormalChannels() { - nsRefPtr agent1 = new Agent(AudioChannel::Normal); + nsRefPtr agent1 = new Agent(AUDIO_CHANNEL_NORMAL); nsresult rv = agent1->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr agent2 = new Agent(AudioChannel::Normal); + nsRefPtr agent2 = new Agent(AUDIO_CHANNEL_NORMAL); rv = agent2->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -225,11 +223,11 @@ TestTwoNormalChannels() nsresult TestContentChannels() { - nsRefPtr agent1 = new Agent(AudioChannel::Content); + nsRefPtr agent1 = new Agent(AUDIO_CHANNEL_CONTENT); nsresult rv = agent1->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr agent2 = new Agent(AudioChannel::Content); + nsRefPtr agent2 = new Agent(AUDIO_CHANNEL_CONTENT); rv = agent2->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -310,15 +308,15 @@ TestContentChannels() nsresult TestFadedState() { - nsRefPtr normalAgent = new Agent(AudioChannel::Normal); + nsRefPtr normalAgent = new Agent(AUDIO_CHANNEL_NORMAL); nsresult rv = normalAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr contentAgent = new Agent(AudioChannel::Content); + nsRefPtr contentAgent = new Agent(AUDIO_CHANNEL_CONTENT); rv = contentAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr notificationAgent = new Agent(AudioChannel::Notification); + nsRefPtr notificationAgent = new Agent(AUDIO_CHANNEL_NOTIFICATION); rv = notificationAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -389,32 +387,32 @@ TestFadedState() nsresult TestPriorities() { - nsRefPtr normalAgent = new Agent(AudioChannel::Normal); + nsRefPtr normalAgent = new Agent(AUDIO_CHANNEL_NORMAL); nsresult rv = normalAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr contentAgent = new Agent(AudioChannel::Content); + nsRefPtr contentAgent = new Agent(AUDIO_CHANNEL_CONTENT); rv = contentAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr notificationAgent = new Agent(AudioChannel::Notification); + nsRefPtr notificationAgent = new Agent(AUDIO_CHANNEL_NOTIFICATION); rv = notificationAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr alarmAgent = new Agent(AudioChannel::Alarm); + nsRefPtr alarmAgent = new Agent(AUDIO_CHANNEL_ALARM); rv = alarmAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr telephonyAgent = new Agent(AudioChannel::Telephony); + nsRefPtr telephonyAgent = new Agent(AUDIO_CHANNEL_TELEPHONY); rv = telephonyAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr ringerAgent = new Agent(AudioChannel::Ringer); + nsRefPtr ringerAgent = new Agent(AUDIO_CHANNEL_RINGER); rv = ringerAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); nsRefPtr pNotificationAgent = - new Agent(AudioChannel::Publicnotification); + new Agent(AUDIO_CHANNEL_PUBLICNOTIFICATION); rv = pNotificationAgent->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -546,11 +544,11 @@ TestPriorities() nsresult TestOneVideoNormalChannel() { - nsRefPtr agent1 = new Agent(AudioChannel::Normal); + nsRefPtr agent1 = new Agent(AUDIO_CHANNEL_NORMAL); nsresult rv = agent1->Init(true); NS_ENSURE_SUCCESS(rv, rv); - nsRefPtr agent2 = new Agent(AudioChannel::Content); + nsRefPtr agent2 = new Agent(AUDIO_CHANNEL_CONTENT); rv = agent2->Init(false); NS_ENSURE_SUCCESS(rv, rv); @@ -651,11 +649,11 @@ int main(int argc, char** argv) return 1; } - // Channel type with AudioChannel::Telephony cannot be unregistered until the + // Channel type with AUDIO_CHANNEL_TELEPHONY cannot be unregistered until the // main thread has chances to process 1500 millisecond timer. In order to // skip ambiguous return value of ChannelsActiveWithHigherPriorityThan(), new // test cases are added before any test case that registers the channel type - // with AudioChannel::Telephony channel. + // with AUDIO_CHANNEL_TELEPHONY channel. if (NS_FAILED(TestOneVideoNormalChannel())) { return 1; } diff --git a/dom/audiochannel/tests/moz.build b/dom/audiochannel/tests/moz.build index 57f14bfa449d..9ab9fe0a3cfc 100644 --- a/dom/audiochannel/tests/moz.build +++ b/dom/audiochannel/tests/moz.build @@ -8,8 +8,5 @@ CPP_UNIT_TESTS += [ 'TestAudioChannelService.cpp', ] -if CONFIG['OS_ARCH'] == 'WINNT': - DEFINES['NOMINMAX'] = True - FAIL_ON_WARNINGS = True diff --git a/dom/camera/DOMCameraControl.cpp b/dom/camera/DOMCameraControl.cpp index 3de5228197bc..35654cdda6f4 100644 --- a/dom/camera/DOMCameraControl.cpp +++ b/dom/camera/DOMCameraControl.cpp @@ -699,7 +699,7 @@ nsDOMCameraControl::StartRecording(const CameraStartRecordingOptions& aOptions, mAudioChannelAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1"); if (mAudioChannelAgent) { // Camera app will stop recording when it falls to the background, so no callback is necessary. - mAudioChannelAgent->Init(mWindow, (int32_t)AudioChannel::Content, nullptr); + mAudioChannelAgent->Init(mWindow, AUDIO_CHANNEL_CONTENT, nullptr); // Video recording doesn't output any sound, so it's not necessary to check canPlay. int32_t canPlay; mAudioChannelAgent->StartPlaying(&canPlay); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 255610e0ba01..4ae5486dd9f7 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -1899,7 +1899,7 @@ ContentParent::RecvFirstIdle() } bool -ContentParent::RecvAudioChannelGetState(const AudioChannel& aChannel, +ContentParent::RecvAudioChannelGetState(const AudioChannelType& aType, const bool& aElementHidden, const bool& aElementWasHidden, AudioChannelState* aState) @@ -1908,33 +1908,33 @@ ContentParent::RecvAudioChannelGetState(const AudioChannel& aChannel, AudioChannelService::GetAudioChannelService(); *aState = AUDIO_CHANNEL_STATE_NORMAL; if (service) { - *aState = service->GetStateInternal(aChannel, mChildID, + *aState = service->GetStateInternal(aType, mChildID, aElementHidden, aElementWasHidden); } return true; } bool -ContentParent::RecvAudioChannelRegisterType(const AudioChannel& aChannel, +ContentParent::RecvAudioChannelRegisterType(const AudioChannelType& aType, const bool& aWithVideo) { nsRefPtr service = AudioChannelService::GetAudioChannelService(); if (service) { - service->RegisterType(aChannel, mChildID, aWithVideo); + service->RegisterType(aType, mChildID, aWithVideo); } return true; } bool -ContentParent::RecvAudioChannelUnregisterType(const AudioChannel& aChannel, +ContentParent::RecvAudioChannelUnregisterType(const AudioChannelType& aType, const bool& aElementHidden, const bool& aWithVideo) { nsRefPtr service = AudioChannelService::GetAudioChannelService(); if (service) { - service->UnregisterType(aChannel, aElementHidden, mChildID, aWithVideo); + service->UnregisterType(aType, aElementHidden, mChildID, aWithVideo); } return true; } @@ -1951,13 +1951,13 @@ ContentParent::RecvAudioChannelChangedNotification() } bool -ContentParent::RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel, - const bool& aHidden) +ContentParent::RecvAudioChannelChangeDefVolChannel( + const AudioChannelType& aType, const bool& aHidden) { nsRefPtr service = AudioChannelService::GetAudioChannelService(); if (service) { - service->SetDefaultVolumeControlChannelInternal(aChannel, + service->SetDefaultVolumeControlChannelInternal(aType, aHidden, mChildID); } return true; diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index a88c3b23acd2..15f3e67cc635 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -490,20 +490,20 @@ private: virtual bool RecvFirstIdle() MOZ_OVERRIDE; - virtual bool RecvAudioChannelGetState(const AudioChannel& aChannel, + virtual bool RecvAudioChannelGetState(const AudioChannelType& aType, const bool& aElementHidden, const bool& aElementWasHidden, AudioChannelState* aValue) MOZ_OVERRIDE; - virtual bool RecvAudioChannelRegisterType(const AudioChannel& aChannel, + virtual bool RecvAudioChannelRegisterType(const AudioChannelType& aType, const bool& aWithVideo) MOZ_OVERRIDE; - virtual bool RecvAudioChannelUnregisterType(const AudioChannel& aChannel, + virtual bool RecvAudioChannelUnregisterType(const AudioChannelType& aType, const bool& aElementHidden, const bool& aWithVideo) MOZ_OVERRIDE; virtual bool RecvAudioChannelChangedNotification() MOZ_OVERRIDE; - virtual bool RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel, + virtual bool RecvAudioChannelChangeDefVolChannel(const AudioChannelType& aType, const bool& aHidden) MOZ_OVERRIDE; virtual bool RecvBroadcastVolume(const nsString& aVolumeName) MOZ_OVERRIDE; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 274b8a84bc19..62d30c9a5c65 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -46,7 +46,7 @@ using struct mozilla::null_t from "ipc/IPCMessageUtils.h"; using struct mozilla::void_t from "ipc/IPCMessageUtils.h"; using mozilla::dom::asmjscache::OpenMode from "mozilla/dom/asmjscache/AsmJSCache.h"; using mozilla::dom::asmjscache::WriteParams from "mozilla/dom/asmjscache/AsmJSCache.h"; -using mozilla::dom::AudioChannel from "mozilla/dom/AudioChannelBinding.h"; +using mozilla::dom::AudioChannelType from "AudioChannelCommon.h"; using mozilla::dom::AudioChannelState from "AudioChannelCommon.h"; using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h"; using mozilla::hal::ProcessPriority from "mozilla/HalTypes.h"; @@ -515,17 +515,18 @@ parent: async FirstIdle(); // Get Muted from the main AudioChannelService. - sync AudioChannelGetState(AudioChannel aChannel, bool aElementHidden, + sync AudioChannelGetState(AudioChannelType aType, bool aElementHidden, bool aElementWasHidden) returns (AudioChannelState value); - sync AudioChannelRegisterType(AudioChannel aChannel, bool aWithVideo); - sync AudioChannelUnregisterType(AudioChannel aChannel, + sync AudioChannelRegisterType(AudioChannelType aType, bool aWithVideo); + sync AudioChannelUnregisterType(AudioChannelType aType, bool aElementHidden, bool aWithVideo); async AudioChannelChangedNotification(); - async AudioChannelChangeDefVolChannel(int32_t aChannel, bool aHidden); + async AudioChannelChangeDefVolChannel(AudioChannelType aType, + bool aHidden); async FilePathUpdateNotify(nsString aType, nsString aStorageName, diff --git a/dom/ipc/TabMessageUtils.h b/dom/ipc/TabMessageUtils.h index b52c14c1fb98..b3f73cc1fca6 100644 --- a/dom/ipc/TabMessageUtils.h +++ b/dom/ipc/TabMessageUtils.h @@ -8,7 +8,6 @@ #include "AudioChannelCommon.h" #include "ipc/IPCMessageUtils.h" -#include "mozilla/dom/AudioChannelBinding.h" #include "nsIDOMEvent.h" #include "nsCOMPtr.h" @@ -59,40 +58,18 @@ struct ParamTraits } }; -template<> -struct ParamTraits -{ - typedef mozilla::dom::AudioChannel paramType; - - static bool IsLegalValue(const paramType &aValue) { - return aValue <= mozilla::dom::AudioChannel::Publicnotification; - } - - static void Write(Message* aMsg, const paramType& aValue) { - MOZ_ASSERT(IsLegalValue(aValue)); - WriteParam(aMsg, (uint32_t)aValue); - } - - static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { - uint32_t value; - if(!ReadParam(aMsg, aIter, &value) || - !IsLegalValue(paramType(value))) { - return false; - } - *aResult = paramType(value); - return true; - } - - static void Log(const paramType& aParam, std::wstring* aLog) - { - } -}; +template <> +struct ParamTraits + : public EnumSerializer +{ }; template <> struct ParamTraits : public EnumSerializer + mozilla::dom::AUDIO_CHANNEL_STATE_NORMAL, + mozilla::dom::AUDIO_CHANNEL_STATE_LAST> { }; } diff --git a/dom/system/gonk/AudioChannelManager.cpp b/dom/system/gonk/AudioChannelManager.cpp index d5da28d7858f..87cd1760ba30 100644 --- a/dom/system/gonk/AudioChannelManager.cpp +++ b/dom/system/gonk/AudioChannelManager.cpp @@ -25,7 +25,7 @@ NS_IMPL_RELEASE_INHERITED(AudioChannelManager, DOMEventTargetHelper) AudioChannelManager::AudioChannelManager() : mState(SWITCH_STATE_UNKNOWN) - , mVolumeChannel(-1) + , mVolumeChannel(AUDIO_CHANNEL_DEFAULT) { RegisterSwitchObserver(SWITCH_HEADPHONES, this); mState = GetCurrentSwitchState(SWITCH_HEADPHONES); @@ -80,10 +80,11 @@ AudioChannelManager::SetVolumeControlChannel(const nsAString& aChannel) return false; } - AudioChannel newChannel = AudioChannelService::GetAudioChannel(aChannel); - + AudioChannelType oldVolumeChannel = mVolumeChannel; // Only normal channel doesn't need permission. - if (newChannel != AudioChannel::Normal) { + if (aChannel.EqualsASCII("normal")) { + mVolumeChannel = AUDIO_CHANNEL_NORMAL; + } else { nsCOMPtr permissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); if (!permissionManager) { @@ -96,14 +97,23 @@ AudioChannelManager::SetVolumeControlChannel(const nsAString& aChannel) if (perm != nsIPermissionManager::ALLOW_ACTION) { return false; } + + if (aChannel.EqualsASCII("content")) { + mVolumeChannel = AUDIO_CHANNEL_CONTENT; + } else if (aChannel.EqualsASCII("notification")) { + mVolumeChannel = AUDIO_CHANNEL_NOTIFICATION; + } else if (aChannel.EqualsASCII("alarm")) { + mVolumeChannel = AUDIO_CHANNEL_ALARM; + } else if (aChannel.EqualsASCII("telephony")) { + mVolumeChannel = AUDIO_CHANNEL_TELEPHONY; + } else if (aChannel.EqualsASCII("ringer")) { + mVolumeChannel = AUDIO_CHANNEL_RINGER; + } } - if (mVolumeChannel == (int32_t)newChannel) { + if (oldVolumeChannel == mVolumeChannel) { return true; } - - mVolumeChannel = (int32_t)newChannel; - NotifyVolumeControlChannelChanged(); return true; } @@ -111,10 +121,18 @@ AudioChannelManager::SetVolumeControlChannel(const nsAString& aChannel) bool AudioChannelManager::GetVolumeControlChannel(nsAString & aChannel) { - if (mVolumeChannel >= 0) { - AudioChannelService::GetAudioChannelString( - static_cast(mVolumeChannel), - aChannel); + if (mVolumeChannel == AUDIO_CHANNEL_NORMAL) { + aChannel.AssignASCII("normal"); + } else if (mVolumeChannel == AUDIO_CHANNEL_CONTENT) { + aChannel.AssignASCII("content"); + } else if (mVolumeChannel == AUDIO_CHANNEL_NOTIFICATION) { + aChannel.AssignASCII("notification"); + } else if (mVolumeChannel == AUDIO_CHANNEL_ALARM) { + aChannel.AssignASCII("alarm"); + } else if (mVolumeChannel == AUDIO_CHANNEL_TELEPHONY) { + aChannel.AssignASCII("telephony"); + } else if (mVolumeChannel == AUDIO_CHANNEL_RINGER) { + aChannel.AssignASCII("ringer"); } else { aChannel.AssignASCII(""); } @@ -135,7 +153,7 @@ AudioChannelManager::NotifyVolumeControlChannelChanged() if (isActive) { service->SetDefaultVolumeControlChannel(mVolumeChannel, isActive); } else { - service->SetDefaultVolumeControlChannel(-1, isActive); + service->SetDefaultVolumeControlChannel(AUDIO_CHANNEL_DEFAULT, isActive); } } diff --git a/dom/system/gonk/AudioChannelManager.h b/dom/system/gonk/AudioChannelManager.h index ba9c619043da..e05a40fbe551 100644 --- a/dom/system/gonk/AudioChannelManager.h +++ b/dom/system/gonk/AudioChannelManager.h @@ -66,7 +66,7 @@ private: void NotifyVolumeControlChannelChanged(); hal::SwitchState mState; - int32_t mVolumeChannel; + AudioChannelType mVolumeChannel; }; } // namespace system diff --git a/dom/system/gonk/AudioManager.cpp b/dom/system/gonk/AudioManager.cpp index 6b52407b4eb4..80acea99014a 100644 --- a/dom/system/gonk/AudioManager.cpp +++ b/dom/system/gonk/AudioManager.cpp @@ -129,17 +129,14 @@ public: int32_t volIndex = JSVAL_TO_INT(aResult); if (aName.EqualsLiteral("audio.volume.content")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Content, - volIndex); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_CONTENT, volIndex); } else if (aName.EqualsLiteral("audio.volume.notification")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Notification, + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_NOTIFICATION, volIndex); } else if (aName.EqualsLiteral("audio.volume.alarm")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Alarm, - volIndex); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_ALARM, volIndex); } else if (aName.EqualsLiteral("audio.volume.telephony")) { - audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Telephony, - volIndex); + audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_TELEPHONY, volIndex); } else if (aName.EqualsLiteral("audio.volume.bt_sco")) { static_cast(audioManager.get())->SetStreamVolumeIndex( AUDIO_STREAM_BLUETOOTH_SCO, volIndex); @@ -534,9 +531,9 @@ AudioManager::SetPhoneState(int32_t aState) MOZ_ASSERT(mPhoneAudioAgent); if (aState == PHONE_STATE_IN_CALL) { // Telephony doesn't be paused by any other channels. - mPhoneAudioAgent->Init(nullptr, (int32_t)AudioChannel::Telephony, nullptr); + mPhoneAudioAgent->Init(nullptr, AUDIO_CHANNEL_TELEPHONY, nullptr); } else { - mPhoneAudioAgent->Init(nullptr, (int32_t)AudioChannel::Ringer, nullptr); + mPhoneAudioAgent->Init(nullptr, AUDIO_CHANNEL_RINGER, nullptr); } // Telephony can always play. @@ -611,8 +608,8 @@ NS_IMETHODIMP AudioManager::SetAudioChannelVolume(int32_t aChannel, int32_t aIndex) { nsresult status; - switch (static_cast(aChannel)) { - case AudioChannel::Content: + switch (aChannel) { + case AUDIO_CHANNEL_CONTENT: // sync FMRadio's volume with content channel. if (IsDeviceOn(AUDIO_DEVICE_OUT_FM)) { status = SetStreamVolumeIndex(AUDIO_STREAM_FM, aIndex); @@ -622,15 +619,15 @@ AudioManager::SetAudioChannelVolume(int32_t aChannel, int32_t aIndex) { NS_ENSURE_SUCCESS(status, status); status = SetStreamVolumeIndex(AUDIO_STREAM_SYSTEM, aIndex); break; - case AudioChannel::Notification: + case AUDIO_CHANNEL_NOTIFICATION: status = SetStreamVolumeIndex(AUDIO_STREAM_NOTIFICATION, aIndex); NS_ENSURE_SUCCESS(status, status); status = SetStreamVolumeIndex(AUDIO_STREAM_RING, aIndex); break; - case AudioChannel::Alarm: + case AUDIO_CHANNEL_ALARM: status = SetStreamVolumeIndex(AUDIO_STREAM_ALARM, aIndex); break; - case AudioChannel::Telephony: + case AUDIO_CHANNEL_TELEPHONY: status = SetStreamVolumeIndex(AUDIO_STREAM_VOICE_CALL, aIndex); break; default: @@ -646,21 +643,21 @@ AudioManager::GetAudioChannelVolume(int32_t aChannel, int32_t* aIndex) { return NS_ERROR_NULL_POINTER; } - switch (static_cast(aChannel)) { - case AudioChannel::Content: + switch (aChannel) { + case AUDIO_CHANNEL_CONTENT: MOZ_ASSERT(mCurrentStreamVolumeTbl[AUDIO_STREAM_MUSIC] == mCurrentStreamVolumeTbl[AUDIO_STREAM_SYSTEM]); *aIndex = mCurrentStreamVolumeTbl[AUDIO_STREAM_MUSIC]; break; - case AudioChannel::Notification: + case AUDIO_CHANNEL_NOTIFICATION: MOZ_ASSERT(mCurrentStreamVolumeTbl[AUDIO_STREAM_NOTIFICATION] == mCurrentStreamVolumeTbl[AUDIO_STREAM_RING]); *aIndex = mCurrentStreamVolumeTbl[AUDIO_STREAM_NOTIFICATION]; break; - case AudioChannel::Alarm: + case AUDIO_CHANNEL_ALARM: *aIndex = mCurrentStreamVolumeTbl[AUDIO_STREAM_ALARM]; break; - case AudioChannel::Telephony: + case AUDIO_CHANNEL_TELEPHONY: *aIndex = mCurrentStreamVolumeTbl[AUDIO_STREAM_VOICE_CALL]; break; default: @@ -677,21 +674,21 @@ AudioManager::GetMaxAudioChannelVolume(int32_t aChannel, int32_t* aMaxIndex) { } int32_t stream; - switch (static_cast(aChannel)) { - case AudioChannel::Content: + switch (aChannel) { + case AUDIO_CHANNEL_CONTENT: MOZ_ASSERT(sMaxStreamVolumeTbl[AUDIO_STREAM_MUSIC] == sMaxStreamVolumeTbl[AUDIO_STREAM_SYSTEM]); stream = AUDIO_STREAM_MUSIC; break; - case AudioChannel::Notification: + case AUDIO_CHANNEL_NOTIFICATION: MOZ_ASSERT(sMaxStreamVolumeTbl[AUDIO_STREAM_NOTIFICATION] == sMaxStreamVolumeTbl[AUDIO_STREAM_RING]); stream = AUDIO_STREAM_NOTIFICATION; break; - case AudioChannel::Alarm: + case AUDIO_CHANNEL_ALARM: stream = AUDIO_STREAM_ALARM; break; - case AudioChannel::Telephony: + case AUDIO_CHANNEL_TELEPHONY: stream = AUDIO_STREAM_VOICE_CALL; break; default: