2013-07-24 15:29:39 +04: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"
|
2015-09-30 04:31:53 +03:00
|
|
|
#include "AudioStreamTrack.h"
|
2014-04-25 18:32:00 +04:00
|
|
|
#include "nsIDocument.h"
|
2014-12-17 20:03:34 +03:00
|
|
|
#include "mozilla/CORSMode.h"
|
2013-07-24 15:29:39 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-25 06:07:34 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamAudioSourceNode)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamAudioSourceNode)
|
2016-06-21 14:45:52 +03:00
|
|
|
tmp->Destroy();
|
2013-07-25 06:07:34 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInputStream)
|
2016-01-22 06:29:40 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInputTrack)
|
2013-07-25 06:07:34 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(AudioNode)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaStreamAudioSourceNode, AudioNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputStream)
|
2016-01-22 06:29:40 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputTrack)
|
2013-07-25 06:07:34 +04:00
|
|
|
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)
|
|
|
|
|
2015-12-10 19:25:54 +03:00
|
|
|
MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AudioContext* aContext)
|
2013-07-24 15:29:39 +04:00
|
|
|
: AudioNode(aContext,
|
|
|
|
2,
|
|
|
|
ChannelCountMode::Max,
|
2015-12-10 19:25:54 +03:00
|
|
|
ChannelInterpretation::Speakers)
|
2013-07-24 15:29:39 +04:00
|
|
|
{
|
2015-12-10 19:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<MediaStreamAudioSourceNode>
|
|
|
|
MediaStreamAudioSourceNode::Create(AudioContext* aContext,
|
|
|
|
DOMMediaStream* aStream, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
RefPtr<MediaStreamAudioSourceNode> node =
|
|
|
|
new MediaStreamAudioSourceNode(aContext);
|
|
|
|
|
|
|
|
node->Init(aStream, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::Init(DOMMediaStream* aMediaStream, ErrorResult& aRv)
|
|
|
|
{
|
2015-12-10 18:51:02 +03:00
|
|
|
MOZ_ASSERT(aMediaStream);
|
|
|
|
MediaStream* inputStream = aMediaStream->GetPlaybackStream();
|
|
|
|
MediaStreamGraph* graph = Context()->Graph();
|
|
|
|
if (NS_WARN_IF(graph != inputStream->Graph())) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-10 19:25:54 +03:00
|
|
|
mInputStream = aMediaStream;
|
2014-04-25 18:32:00 +04:00
|
|
|
AudioNodeEngine* engine = new MediaStreamAudioSourceNodeEngine(this);
|
2015-12-10 18:51:02 +03:00
|
|
|
mStream = AudioNodeExternalInputStream::Create(graph, engine);
|
2014-06-04 06:51:48 +04:00
|
|
|
mInputStream->AddConsumerToKeepAlive(static_cast<nsIDOMEventTarget*>(this));
|
2014-04-25 18:32:00 +04:00
|
|
|
|
2016-01-22 06:29:40 +03:00
|
|
|
mInputStream->RegisterTrackListener(this);
|
|
|
|
AttachToFirstTrack(mInputStream);
|
2013-07-25 06:07:34 +04:00
|
|
|
}
|
|
|
|
|
2016-06-21 14:45:52 +03:00
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::Destroy()
|
|
|
|
{
|
|
|
|
if (mInputStream) {
|
|
|
|
mInputStream->UnregisterTrackListener(this);
|
|
|
|
mInputStream = nullptr;
|
|
|
|
}
|
|
|
|
DetachFromTrack();
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamAudioSourceNode::~MediaStreamAudioSourceNode()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
2016-01-22 06:29:40 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::AttachToTrack(const RefPtr<MediaStreamTrack>& aTrack)
|
2013-07-25 06:07:34 +04:00
|
|
|
{
|
2016-01-22 06:29:40 +03:00
|
|
|
MOZ_ASSERT(!mInputTrack);
|
2016-08-17 15:26:47 +03:00
|
|
|
MOZ_ASSERT(aTrack->AsAudioStreamTrack());
|
|
|
|
|
2016-01-22 06:29:40 +03:00
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2014-04-25 18:32:00 +04:00
|
|
|
}
|
2016-01-22 06:29:40 +03:00
|
|
|
|
|
|
|
mInputTrack = aTrack;
|
|
|
|
ProcessedMediaStream* outputStream =
|
|
|
|
static_cast<ProcessedMediaStream*>(mStream.get());
|
|
|
|
mInputPort = mInputTrack->ForwardTrackContentsTo(outputStream);
|
|
|
|
PrincipalChanged(mInputTrack); // trigger enabling/disabling of the connector
|
|
|
|
mInputTrack->AddPrincipalChangeObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::DetachFromTrack()
|
|
|
|
{
|
|
|
|
if (mInputTrack) {
|
|
|
|
mInputTrack->RemovePrincipalChangeObserver(this);
|
|
|
|
mInputTrack = nullptr;
|
|
|
|
}
|
|
|
|
if (mInputPort) {
|
|
|
|
mInputPort->Destroy();
|
|
|
|
mInputPort = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::AttachToFirstTrack(const RefPtr<DOMMediaStream>& aMediaStream)
|
|
|
|
{
|
|
|
|
nsTArray<RefPtr<AudioStreamTrack>> tracks;
|
|
|
|
aMediaStream->GetAudioTracks(tracks);
|
|
|
|
|
2016-05-26 16:56:58 +03:00
|
|
|
for (const RefPtr<AudioStreamTrack>& track : tracks) {
|
|
|
|
if (track->Ended()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttachToTrack(track);
|
2016-06-27 18:30:01 +03:00
|
|
|
MarkActive();
|
2016-01-22 06:29:40 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-06-27 18:30:01 +03:00
|
|
|
|
|
|
|
// There was no track available. We'll allow the node to be garbage collected.
|
|
|
|
MarkInactive();
|
2016-01-22 06:29:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack)
|
|
|
|
{
|
|
|
|
if (mInputTrack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:26:47 +03:00
|
|
|
if (!aTrack->AsAudioStreamTrack()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-22 06:29:40 +03:00
|
|
|
AttachToTrack(aTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
|
|
|
|
{
|
|
|
|
if (aTrack != mInputTrack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DetachFromTrack();
|
|
|
|
AttachToFirstTrack(mInputStream);
|
2014-04-25 18:32:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-22 06:29:40 +03:00
|
|
|
* 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
|
2014-04-25 18:32:00 +04:00
|
|
|
* 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
|
2016-01-22 06:29:40 +03:00
|
|
|
* governed by the new stream principal is not available to the MediaStreamGraph
|
|
|
|
* before this change completes. Otherwise, a site could get access to
|
2014-04-25 18:32:00 +04:00
|
|
|
* 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
|
2016-01-22 06:29:40 +03:00
|
|
|
* under the new principal to flow. This might be unnecessary if the principal
|
2014-04-25 18:32:00 +04:00
|
|
|
* change is changing to be the document principal.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-22 06:29:40 +03:00
|
|
|
MediaStreamAudioSourceNode::PrincipalChanged(MediaStreamTrack* aMediaStreamTrack)
|
2014-04-25 18:32:00 +04:00
|
|
|
{
|
2016-01-22 06:29:40 +03:00
|
|
|
MOZ_ASSERT(aMediaStreamTrack == mInputTrack);
|
|
|
|
|
2014-04-25 18:32:00 +04:00
|
|
|
bool subsumes = false;
|
2016-04-26 18:46:31 +03:00
|
|
|
nsIDocument* doc = nullptr;
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* parent = Context()->GetParentObject()) {
|
2016-04-26 18:46:31 +03:00
|
|
|
doc = parent->GetExtantDoc();
|
2014-07-24 14:01:13 +04:00
|
|
|
if (doc) {
|
|
|
|
nsIPrincipal* docPrincipal = doc->NodePrincipal();
|
2016-01-22 06:29:40 +03:00
|
|
|
nsIPrincipal* trackPrincipal = aMediaStreamTrack->GetPrincipal();
|
|
|
|
if (!trackPrincipal || NS_FAILED(docPrincipal->Subsumes(trackPrincipal, &subsumes))) {
|
2014-07-24 14:01:13 +04:00
|
|
|
subsumes = false;
|
|
|
|
}
|
2014-04-25 18:32:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto stream = static_cast<AudioNodeExternalInputStream*>(mStream.get());
|
2016-04-26 18:46:31 +03:00
|
|
|
bool enabled = subsumes || aMediaStreamTrack->GetCORSMode() != CORS_NONE;
|
|
|
|
stream->SetInt32Parameter(MediaStreamAudioSourceNodeEngine::ENABLE, enabled);
|
|
|
|
|
|
|
|
if (!enabled && doc) {
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("Web Audio"),
|
|
|
|
doc,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
CrossOriginErrorString());
|
|
|
|
}
|
2013-07-24 15:29:39 +04:00
|
|
|
}
|
|
|
|
|
2014-04-13 22:08:10 +04:00
|
|
|
size_t
|
|
|
|
MediaStreamAudioSourceNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
// Future:
|
|
|
|
// - mInputStream
|
|
|
|
size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
|
2016-06-22 19:20:46 +03:00
|
|
|
if (mInputPort) {
|
|
|
|
amount += mInputPort->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
2014-04-13 22:08:10 +04:00
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
MediaStreamAudioSourceNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-07-24 15:29:39 +04:00
|
|
|
void
|
|
|
|
MediaStreamAudioSourceNode::DestroyMediaStream()
|
|
|
|
{
|
|
|
|
if (mInputPort) {
|
|
|
|
mInputPort->Destroy();
|
|
|
|
mInputPort = nullptr;
|
|
|
|
}
|
|
|
|
AudioNode::DestroyMediaStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
MediaStreamAudioSourceNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-24 15:29:39 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return MediaStreamAudioSourceNodeBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-24 15:29:39 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|