2012-09-18 16:07:33 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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 "AudioDestinationNode.h"
|
|
|
|
#include "mozilla/dom/AudioDestinationNodeBinding.h"
|
2013-10-08 11:20:33 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "AudioChannelAgent.h"
|
2013-02-04 15:07:25 -08:00
|
|
|
#include "AudioNodeEngine.h"
|
|
|
|
#include "AudioNodeStream.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
2013-05-16 16:30:57 -07:00
|
|
|
#include "OfflineAudioCompletionEvent.h"
|
2013-10-08 11:20:33 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIDocShell.h"
|
2013-10-11 04:55:47 -07:00
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-09-18 16:07:33 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-05-16 16:30:42 -07:00
|
|
|
class OfflineDestinationNodeEngine : public AudioNodeEngine
|
|
|
|
{
|
|
|
|
public:
|
2013-05-16 16:30:57 -07:00
|
|
|
typedef AutoFallibleTArray<nsAutoArrayPtr<float>, 2> InputChannels;
|
|
|
|
|
2013-05-16 16:30:42 -07:00
|
|
|
OfflineDestinationNodeEngine(AudioDestinationNode* aNode,
|
|
|
|
uint32_t aNumberOfChannels,
|
|
|
|
uint32_t aLength,
|
|
|
|
float aSampleRate)
|
|
|
|
: AudioNodeEngine(aNode)
|
2013-05-16 16:30:57 -07:00
|
|
|
, mWriteIndex(0)
|
2013-05-16 16:30:42 -07:00
|
|
|
, mLength(aLength)
|
|
|
|
, mSampleRate(aSampleRate)
|
|
|
|
{
|
2013-05-16 16:30:57 -07:00
|
|
|
// These allocations might fail if content provides a huge number of
|
|
|
|
// channels or size, but it's OK since we'll deal with the failure
|
|
|
|
// gracefully.
|
|
|
|
if (mInputChannels.SetLength(aNumberOfChannels)) {
|
|
|
|
static const fallible_t fallible = fallible_t();
|
|
|
|
for (uint32_t i = 0; i < aNumberOfChannels; ++i) {
|
|
|
|
mInputChannels[i] = new(fallible) float[aLength];
|
|
|
|
if (!mInputChannels[i]) {
|
|
|
|
mInputChannels.Clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 16:30:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ProduceAudioBlock(AudioNodeStream* aStream,
|
|
|
|
const AudioChunk& aInput,
|
|
|
|
AudioChunk* aOutput,
|
|
|
|
bool* aFinished) MOZ_OVERRIDE
|
|
|
|
{
|
2013-05-16 16:30:57 -07:00
|
|
|
// Do this just for the sake of political correctness; this output
|
|
|
|
// will not go anywhere.
|
2013-05-16 16:30:42 -07:00
|
|
|
*aOutput = aInput;
|
2013-05-16 16:30:57 -07:00
|
|
|
|
|
|
|
// Handle the case of allocation failure in the input buffer
|
|
|
|
if (mInputChannels.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record our input buffer
|
|
|
|
MOZ_ASSERT(mWriteIndex < mLength, "How did this happen?");
|
|
|
|
const uint32_t duration = std::min(WEBAUDIO_BLOCK_SIZE, mLength - mWriteIndex);
|
2013-05-29 16:33:14 -07:00
|
|
|
const uint32_t commonChannelCount = std::min(mInputChannels.Length(),
|
|
|
|
aInput.mChannelData.Length());
|
|
|
|
// First, copy as many channels in the input as we have
|
|
|
|
for (uint32_t i = 0; i < commonChannelCount; ++i) {
|
2013-05-16 16:30:57 -07:00
|
|
|
if (aInput.IsNull()) {
|
|
|
|
PodZero(mInputChannels[i] + mWriteIndex, duration);
|
|
|
|
} else {
|
|
|
|
const float* inputBuffer = static_cast<const float*>(aInput.mChannelData[i]);
|
|
|
|
if (duration == WEBAUDIO_BLOCK_SIZE) {
|
|
|
|
// Use the optimized version of the copy with scale operation
|
|
|
|
AudioBlockCopyChannelWithScale(inputBuffer, aInput.mVolume,
|
|
|
|
mInputChannels[i] + mWriteIndex);
|
|
|
|
} else {
|
|
|
|
if (aInput.mVolume == 1.0f) {
|
|
|
|
PodCopy(mInputChannels[i] + mWriteIndex, inputBuffer, duration);
|
|
|
|
} else {
|
|
|
|
for (uint32_t j = 0; j < duration; ++j) {
|
|
|
|
mInputChannels[i][mWriteIndex + j] = aInput.mVolume * inputBuffer[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 16:33:14 -07:00
|
|
|
// Then, silence all of the remaining channels
|
|
|
|
for (uint32_t i = commonChannelCount; i < mInputChannels.Length(); ++i) {
|
|
|
|
PodZero(mInputChannels[i] + mWriteIndex, duration);
|
|
|
|
}
|
2013-05-16 16:30:57 -07:00
|
|
|
mWriteIndex += duration;
|
|
|
|
|
|
|
|
if (mWriteIndex == mLength) {
|
|
|
|
SendBufferToMainThread(aStream);
|
|
|
|
*aFinished = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendBufferToMainThread(AudioNodeStream* aStream)
|
|
|
|
{
|
|
|
|
class Command : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Command(AudioNodeStream* aStream,
|
|
|
|
InputChannels& aInputChannels,
|
|
|
|
uint32_t aLength,
|
|
|
|
float aSampleRate)
|
|
|
|
: mStream(aStream)
|
|
|
|
, mLength(aLength)
|
|
|
|
, mSampleRate(aSampleRate)
|
|
|
|
{
|
|
|
|
mInputChannels.SwapElements(aInputChannels);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run()
|
|
|
|
{
|
|
|
|
// If it's not safe to run scripts right now, schedule this to run later
|
|
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
nsContentUtils::AddScriptRunner(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<AudioContext> context;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mStream->Engine()->NodeMutex());
|
|
|
|
AudioNode* node = mStream->Engine()->Node();
|
|
|
|
if (node) {
|
|
|
|
context = node->Context();
|
2013-09-09 22:10:53 -07:00
|
|
|
MOZ_ASSERT(context, "node hasn't kept context alive");
|
2013-05-16 16:30:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!context) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-09-09 22:10:53 -07:00
|
|
|
context->Shutdown(); // drops self reference
|
2013-05-16 16:30:57 -07:00
|
|
|
|
|
|
|
AutoPushJSContext cx(context->GetJSContext());
|
|
|
|
if (cx) {
|
|
|
|
JSAutoRequest ar(cx);
|
|
|
|
|
|
|
|
// Create the input buffer
|
|
|
|
nsRefPtr<AudioBuffer> renderedBuffer = new AudioBuffer(context,
|
|
|
|
mLength,
|
|
|
|
mSampleRate);
|
|
|
|
if (!renderedBuffer->InitializeBuffers(mInputChannels.Length(), cx)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < mInputChannels.Length(); ++i) {
|
|
|
|
renderedBuffer->SetRawChannelContents(cx, i, mInputChannels[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<OfflineAudioCompletionEvent> event =
|
|
|
|
new OfflineAudioCompletionEvent(context, nullptr, nullptr);
|
|
|
|
event->InitEvent(renderedBuffer);
|
|
|
|
context->DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsRefPtr<AudioNodeStream> mStream;
|
|
|
|
InputChannels mInputChannels;
|
|
|
|
uint32_t mLength;
|
|
|
|
float mSampleRate;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Empty out the source array to make sure we don't attempt to collect
|
|
|
|
// more input data in the future.
|
|
|
|
NS_DispatchToMainThread(new Command(aStream, mInputChannels, mLength, mSampleRate));
|
2013-05-16 16:30:42 -07:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:30:57 -07:00
|
|
|
private:
|
|
|
|
// The input to the destination node is recorded in the mInputChannels buffer.
|
|
|
|
// When this buffer fills up with mLength frames, the buffered input is sent
|
|
|
|
// to the main thread in order to dispatch OfflineAudioCompletionEvent.
|
|
|
|
InputChannels mInputChannels;
|
|
|
|
// An index representing the next offset in mInputChannels to be written to.
|
|
|
|
uint32_t mWriteIndex;
|
|
|
|
// How many frames the OfflineAudioContext intends to produce.
|
2013-05-16 16:30:42 -07:00
|
|
|
uint32_t mLength;
|
|
|
|
float mSampleRate;
|
|
|
|
};
|
|
|
|
|
2013-07-03 17:44:32 -07:00
|
|
|
class DestinationNodeEngine : public AudioNodeEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit DestinationNodeEngine(AudioDestinationNode* aNode)
|
|
|
|
: AudioNodeEngine(aNode)
|
|
|
|
, mVolume(1.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ProduceAudioBlock(AudioNodeStream* aStream,
|
|
|
|
const AudioChunk& aInput,
|
|
|
|
AudioChunk* aOutput,
|
|
|
|
bool* aFinished) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
*aOutput = aInput;
|
|
|
|
aOutput->mVolume *= mVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetDoubleParameter(uint32_t aIndex, double aParam) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
if (aIndex == VOLUME) {
|
|
|
|
mVolume = aParam;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Parameters {
|
|
|
|
VOLUME,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
float mVolume;
|
|
|
|
};
|
|
|
|
|
2013-10-08 11:20:33 -07:00
|
|
|
static bool UseAudioChannelService()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.useAudioChannelService");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED_1(AudioDestinationNode, AudioNode,
|
|
|
|
mAudioChannelAgent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioDestinationNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAudioChannelAgentCallback)
|
2013-10-16 02:27:45 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2013-10-08 11:20:33 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(AudioNode)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(AudioDestinationNode, AudioNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(AudioDestinationNode, AudioNode)
|
2013-02-12 08:42:59 -08:00
|
|
|
|
2013-05-16 16:30:42 -07:00
|
|
|
AudioDestinationNode::AudioDestinationNode(AudioContext* aContext,
|
|
|
|
bool aIsOffline,
|
|
|
|
uint32_t aNumberOfChannels,
|
|
|
|
uint32_t aLength,
|
|
|
|
float aSampleRate)
|
2013-04-27 15:44:50 -07:00
|
|
|
: AudioNode(aContext,
|
2013-05-16 16:30:42 -07:00
|
|
|
aIsOffline ? aNumberOfChannels : 2,
|
2013-04-27 15:44:50 -07:00
|
|
|
ChannelCountMode::Explicit,
|
|
|
|
ChannelInterpretation::Speakers)
|
2013-05-16 16:30:42 -07:00
|
|
|
, mFramesToProduce(aLength)
|
2013-10-11 04:55:47 -07:00
|
|
|
, mAudioChannel(AudioChannel::Normal)
|
2012-09-18 16:07:33 -07:00
|
|
|
{
|
2013-05-16 16:30:42 -07:00
|
|
|
MediaStreamGraph* graph = aIsOffline ?
|
|
|
|
MediaStreamGraph::CreateNonRealtimeInstance() :
|
|
|
|
MediaStreamGraph::GetInstance();
|
|
|
|
AudioNodeEngine* engine = aIsOffline ?
|
|
|
|
new OfflineDestinationNodeEngine(this, aNumberOfChannels,
|
|
|
|
aLength, aSampleRate) :
|
2013-07-03 17:44:32 -07:00
|
|
|
static_cast<AudioNodeEngine*>(new DestinationNodeEngine(this));
|
|
|
|
|
2013-05-16 16:30:42 -07:00
|
|
|
mStream = graph->CreateAudioNodeStream(engine, MediaStreamGraph::EXTERNAL_STREAM);
|
2013-10-08 11:20:33 -07:00
|
|
|
|
|
|
|
if (!aIsOffline && UseAudioChannelService()) {
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
|
|
|
|
if (target) {
|
|
|
|
target->AddSystemEventListener(NS_LITERAL_STRING("visibilitychange"), this,
|
|
|
|
/* useCapture = */ true,
|
|
|
|
/* wantsUntrusted = */ false);
|
|
|
|
}
|
|
|
|
|
2013-10-11 04:55:47 -07:00
|
|
|
CreateAudioChannelAgent();
|
2013-10-08 11:20:33 -07:00
|
|
|
}
|
2012-09-18 16:07:33 -07:00
|
|
|
}
|
|
|
|
|
2013-09-09 22:05:22 -07:00
|
|
|
void
|
|
|
|
AudioDestinationNode::DestroyMediaStream()
|
|
|
|
{
|
2013-10-08 11:20:33 -07:00
|
|
|
if (mAudioChannelAgent && !Context()->IsOffline()) {
|
|
|
|
mAudioChannelAgent->StopPlaying();
|
|
|
|
mAudioChannelAgent = nullptr;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
|
|
|
|
NS_ENSURE_TRUE_VOID(target);
|
|
|
|
|
|
|
|
target->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"), this,
|
|
|
|
/* useCapture = */ true);
|
|
|
|
}
|
|
|
|
|
2013-09-09 22:05:22 -07:00
|
|
|
if (!mStream)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MediaStreamGraph* graph = mStream->Graph();
|
|
|
|
if (graph->IsNonRealtime()) {
|
|
|
|
MediaStreamGraph::DestroyNonRealtimeInstance(graph);
|
|
|
|
}
|
|
|
|
AudioNode::DestroyMediaStream();
|
|
|
|
}
|
|
|
|
|
2013-06-10 10:32:28 -07:00
|
|
|
uint32_t
|
|
|
|
AudioDestinationNode::MaxChannelCount() const
|
|
|
|
{
|
|
|
|
return Context()->MaxChannelCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioDestinationNode::SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (aChannelCount > MaxChannelCount()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioNode::SetChannelCount(aChannelCount, aRv);
|
|
|
|
}
|
|
|
|
|
2013-07-03 17:44:32 -07:00
|
|
|
void
|
|
|
|
AudioDestinationNode::Mute()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(Context() && !Context()->IsOffline());
|
|
|
|
SendDoubleParameterToStream(DestinationNodeEngine::VOLUME, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioDestinationNode::Unmute()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(Context() && !Context()->IsOffline());
|
|
|
|
SendDoubleParameterToStream(DestinationNodeEngine::VOLUME, 1.0f);
|
|
|
|
}
|
|
|
|
|
2013-05-16 16:31:08 -07:00
|
|
|
void
|
2013-09-09 22:10:53 -07:00
|
|
|
AudioDestinationNode::OfflineShutdown()
|
2013-05-16 16:31:08 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(Context() && Context()->IsOffline(),
|
|
|
|
"Should only be called on a valid OfflineAudioContext");
|
2013-09-09 22:10:53 -07:00
|
|
|
|
2013-05-16 16:31:08 -07:00
|
|
|
MediaStreamGraph::DestroyNonRealtimeInstance(mStream->Graph());
|
2013-09-09 22:10:53 -07:00
|
|
|
mOfflineRenderingRef.Drop(this);
|
2013-05-16 16:31:08 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
JSObject*
|
2013-04-25 09:29:54 -07:00
|
|
|
AudioDestinationNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2012-09-18 16:07:33 -07:00
|
|
|
{
|
2013-03-11 16:03:47 -07:00
|
|
|
return AudioDestinationNodeBinding::Wrap(aCx, aScope, this);
|
2012-09-18 16:07:33 -07:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:30:42 -07:00
|
|
|
void
|
|
|
|
AudioDestinationNode::StartRendering()
|
|
|
|
{
|
2013-09-09 22:10:53 -07:00
|
|
|
mOfflineRenderingRef.Take(this);
|
2013-05-16 16:30:42 -07:00
|
|
|
mStream->Graph()->StartNonRealtimeProcessing(mFramesToProduce);
|
|
|
|
}
|
|
|
|
|
2013-10-08 11:20:33 -07:00
|
|
|
void
|
|
|
|
AudioDestinationNode::SetCanPlay(bool aCanPlay)
|
|
|
|
{
|
|
|
|
mStream->SetTrackEnabled(AudioNodeStream::AUDIO_TRACK, aCanPlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AudioDestinationNode::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
|
|
|
if (!type.EqualsLiteral("visibilitychange")) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docshell = do_GetInterface(GetOwner());
|
|
|
|
NS_ENSURE_TRUE(docshell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
bool isActive = false;
|
|
|
|
docshell->GetIsActive(&isActive);
|
|
|
|
|
|
|
|
mAudioChannelAgent->SetVisibilityState(isActive);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AudioDestinationNode::CanPlayChanged(int32_t aCanPlay)
|
|
|
|
{
|
|
|
|
SetCanPlay(aCanPlay == AudioChannelState::AUDIO_CHANNEL_STATE_NORMAL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-11 04:55:47 -07:00
|
|
|
AudioChannel
|
|
|
|
AudioDestinationNode::MozAudioChannelType() const
|
|
|
|
{
|
|
|
|
return mAudioChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioDestinationNode::SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (Context()->IsOffline()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aValue != mAudioChannel &&
|
|
|
|
CheckAudioChannelPermissions(aValue)) {
|
|
|
|
mAudioChannel = aValue;
|
|
|
|
|
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
CreateAudioChannelAgent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AudioDestinationNode::CheckAudioChannelPermissions(AudioChannel aValue)
|
|
|
|
{
|
|
|
|
if (!Preferences::GetBool("media.useAudioChannelService")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only normal channel doesn't need permission.
|
|
|
|
if (aValue == AudioChannel::Normal) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permissionManager =
|
|
|
|
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
if (!permissionManager) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(GetOwner());
|
|
|
|
NS_ASSERTION(sop, "Window didn't QI to nsIScriptObjectPrincipal!");
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
|
|
|
|
|
|
|
|
uint32_t perm = nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
|
|
|
|
nsCString channel;
|
|
|
|
channel.AssignASCII(AudioChannelValues::strings[uint32_t(aValue)].value,
|
|
|
|
AudioChannelValues::strings[uint32_t(aValue)].length);
|
|
|
|
permissionManager->TestExactPermissionFromPrincipal(principal,
|
|
|
|
nsCString(NS_LITERAL_CSTRING("audio-channel-") + channel).get(),
|
|
|
|
&perm);
|
|
|
|
|
|
|
|
return perm == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioDestinationNode::CreateAudioChannelAgent()
|
|
|
|
{
|
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
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(type, this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docshell = do_GetInterface(GetOwner());
|
|
|
|
if (docshell) {
|
|
|
|
bool isActive = false;
|
|
|
|
docshell->GetIsActive(&isActive);
|
|
|
|
mAudioChannelAgent->SetVisibilityState(isActive);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t state = 0;
|
|
|
|
mAudioChannelAgent->StartPlaying(&state);
|
|
|
|
SetCanPlay(state == AudioChannelState::AUDIO_CHANNEL_STATE_NORMAL);
|
|
|
|
}
|
2012-09-18 16:07:33 -07:00
|
|
|
}
|
2013-10-11 04:55:47 -07:00
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
}
|