2013-07-24 04:29:39 -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 "MediaStreamAudioSourceNode.h"
|
|
|
|
#include "mozilla/dom/MediaStreamAudioSourceNodeBinding.h"
|
|
|
|
#include "AudioNodeEngine.h"
|
|
|
|
#include "AudioNodeExternalInputStream.h"
|
2014-04-25 07:32:00 -07:00
|
|
|
#include "nsIDocument.h"
|
2013-07-24 04:29:39 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-24 19:07:34 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamAudioSourceNode)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamAudioSourceNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInputStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(AudioNode)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaStreamAudioSourceNode, AudioNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaStreamAudioSourceNode)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(AudioNode)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(MediaStreamAudioSourceNode, AudioNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MediaStreamAudioSourceNode, AudioNode)
|
|
|
|
|
2013-07-24 04:29:39 -07:00
|
|
|
MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AudioContext* aContext,
|
2013-07-24 19:07:34 -07:00
|
|
|
DOMMediaStream* aMediaStream)
|
2013-07-24 04:29:39 -07:00
|
|
|
: AudioNode(aContext,
|
|
|
|
2,
|
|
|
|
ChannelCountMode::Max,
|
2013-07-24 19:07:34 -07:00
|
|
|
ChannelInterpretation::Speakers),
|
|
|
|
mInputStream(aMediaStream)
|
2013-07-24 04:29:39 -07:00
|
|
|
{
|
2014-04-25 07:32:00 -07:00
|
|
|
AudioNodeEngine* engine = new MediaStreamAudioSourceNodeEngine(this);
|
2013-07-24 04:29:39 -07:00
|
|
|
mStream = aContext->Graph()->CreateAudioNodeExternalInputStream(engine);
|
|
|
|
ProcessedMediaStream* outputStream = static_cast<ProcessedMediaStream*>(mStream.get());
|
|
|
|
mInputPort = outputStream->AllocateInputPort(aMediaStream->GetStream(),
|
|
|
|
MediaInputPort::FLAG_BLOCK_INPUT);
|
2014-06-03 19:51:48 -07:00
|
|
|
mInputStream->AddConsumerToKeepAlive(static_cast<nsIDOMEventTarget*>(this));
|
2014-04-25 07:32:00 -07:00
|
|
|
|
|
|
|
PrincipalChanged(mInputStream); // trigger enabling/disabling of the connector
|
|
|
|
mInputStream->AddPrincipalChangeObserver(this);
|
2013-07-24 19:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamAudioSourceNode::~MediaStreamAudioSourceNode()
|
|
|
|
{
|
2014-04-25 07:32:00 -07:00
|
|
|
if (mInputStream) {
|
|
|
|
mInputStream->RemovePrincipalChangeObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the principal. Note that this will be called on the main thread, but
|
|
|
|
* changes will be enacted on the MediaStreamGraph thread. If the principal
|
|
|
|
* change results in the document principal losing access to the stream, then
|
|
|
|
* there needs to be other measures in place to ensure that any media that is
|
|
|
|
* governed by the new stream principal is not available to the Media Stream
|
|
|
|
* Graph before this change completes. Otherwise, a site could get access to
|
|
|
|
* media that they are not authorized to receive.
|
|
|
|
*
|
|
|
|
* One solution is to block the altered content, call this method, then dispatch
|
|
|
|
* another change request to the MediaStreamGraph thread that allows the content
|
|
|
|
* under the new principal to flow. This might be unnecessary if the principal
|
|
|
|
* change is changing to be the document principal.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::PrincipalChanged(DOMMediaStream* ms)
|
|
|
|
{
|
|
|
|
bool subsumes = false;
|
2014-07-24 03:01:13 -07:00
|
|
|
nsPIDOMWindow* parent = Context()->GetParentObject();
|
|
|
|
if (parent) {
|
|
|
|
nsIDocument* doc = parent->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsIPrincipal* docPrincipal = doc->NodePrincipal();
|
|
|
|
nsIPrincipal* streamPrincipal = mInputStream->GetPrincipal();
|
|
|
|
if (NS_FAILED(docPrincipal->Subsumes(streamPrincipal, &subsumes))) {
|
|
|
|
subsumes = false;
|
|
|
|
}
|
2014-04-25 07:32:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto stream = static_cast<AudioNodeExternalInputStream*>(mStream.get());
|
|
|
|
stream->SetInt32Parameter(MediaStreamAudioSourceNodeEngine::ENABLE, subsumes);
|
2013-07-24 04:29:39 -07:00
|
|
|
}
|
|
|
|
|
2014-04-13 11:08:10 -07:00
|
|
|
size_t
|
|
|
|
MediaStreamAudioSourceNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
// Future:
|
|
|
|
// - mInputStream
|
|
|
|
size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
amount += mInputPort->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
MediaStreamAudioSourceNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-07-24 04:29:39 -07:00
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::DestroyMediaStream()
|
|
|
|
{
|
|
|
|
if (mInputPort) {
|
|
|
|
mInputPort->Destroy();
|
|
|
|
mInputPort = nullptr;
|
|
|
|
}
|
|
|
|
AudioNode::DestroyMediaStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
MediaStreamAudioSourceNode::WrapObject(JSContext* aCx)
|
2013-07-24 04:29:39 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return MediaStreamAudioSourceNodeBinding::Wrap(aCx, this);
|
2013-07-24 04:29:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|