2013-05-21 19:17:47 +00: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 "MediaStreamAudioDestinationNode.h"
|
2013-07-23 03:54:32 +00:00
|
|
|
#include "nsIDocument.h"
|
2013-05-21 19:17:47 +00:00
|
|
|
#include "mozilla/dom/MediaStreamAudioDestinationNodeBinding.h"
|
|
|
|
#include "AudioNodeEngine.h"
|
|
|
|
#include "AudioNodeStream.h"
|
|
|
|
#include "DOMMediaStream.h"
|
2016-04-06 12:46:56 +00:00
|
|
|
#include "MediaStreamTrack.h"
|
2013-05-21 19:17:47 +00:00
|
|
|
#include "TrackUnionStream.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-12-15 18:24:43 +00:00
|
|
|
class AudioDestinationTrackSource final :
|
2016-09-16 09:25:38 +00:00
|
|
|
public MediaStreamTrackSource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioDestinationTrackSource,
|
|
|
|
MediaStreamTrackSource)
|
|
|
|
|
|
|
|
AudioDestinationTrackSource(MediaStreamAudioDestinationNode* aNode,
|
|
|
|
nsIPrincipal* aPrincipal)
|
|
|
|
: MediaStreamTrackSource(aPrincipal, nsString())
|
|
|
|
, mNode(aNode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy() override
|
|
|
|
{
|
|
|
|
if (mNode) {
|
|
|
|
mNode->DestroyMediaStream();
|
|
|
|
mNode = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaSourceEnum GetMediaSource() const override
|
|
|
|
{
|
|
|
|
return MediaSourceEnum::AudioCapture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stop() override
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-12-15 18:24:43 +00:00
|
|
|
~AudioDestinationTrackSource() = default;
|
2016-09-16 09:25:38 +00:00
|
|
|
|
|
|
|
RefPtr<MediaStreamAudioDestinationNode> mNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(AudioDestinationTrackSource,
|
|
|
|
MediaStreamTrackSource)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(AudioDestinationTrackSource,
|
|
|
|
MediaStreamTrackSource)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioDestinationTrackSource)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MediaStreamTrackSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioDestinationTrackSource,
|
|
|
|
MediaStreamTrackSource,
|
|
|
|
mNode)
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaStreamAudioDestinationNode, AudioNode, mDOMStream)
|
2013-05-21 19:17:47 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaStreamAudioDestinationNode)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(AudioNode)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(MediaStreamAudioDestinationNode, AudioNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MediaStreamAudioDestinationNode, AudioNode)
|
|
|
|
|
|
|
|
MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* aContext)
|
|
|
|
: AudioNode(aContext,
|
|
|
|
2,
|
|
|
|
ChannelCountMode::Explicit,
|
|
|
|
ChannelInterpretation::Speakers)
|
2015-07-02 07:30:58 +00:00
|
|
|
, mDOMStream(
|
2016-04-25 03:43:27 +00:00
|
|
|
DOMAudioNodeMediaStream::CreateTrackUnionStreamAsInput(GetOwner(),
|
|
|
|
this,
|
|
|
|
aContext->Graph()))
|
2013-05-21 19:17:47 +00:00
|
|
|
{
|
2015-03-02 09:08:40 +00:00
|
|
|
// Ensure an audio track with the correct ID is exposed to JS
|
2016-02-01 14:46:34 +00:00
|
|
|
nsIDocument* doc = aContext->GetParentObject()->GetExtantDoc();
|
2016-04-06 12:46:56 +00:00
|
|
|
RefPtr<MediaStreamTrackSource> source =
|
2016-09-16 09:25:38 +00:00
|
|
|
new AudioDestinationTrackSource(this, doc->NodePrincipal());
|
2016-08-12 11:50:41 +00:00
|
|
|
RefPtr<MediaStreamTrack> track =
|
|
|
|
mDOMStream->CreateDOMTrack(AudioNodeStream::AUDIO_TRACK,
|
|
|
|
MediaSegment::AUDIO, source,
|
|
|
|
MediaTrackConstraints());
|
|
|
|
mDOMStream->AddTrackInternal(track);
|
2015-03-02 09:08:40 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
ProcessedMediaStream* outputStream = mDOMStream->GetInputStream()->AsProcessedStream();
|
2015-03-02 09:08:40 +00:00
|
|
|
MOZ_ASSERT(!!outputStream);
|
|
|
|
AudioNodeEngine* engine = new AudioNodeEngine(this);
|
2015-09-08 13:22:16 +00:00
|
|
|
mStream = AudioNodeStream::Create(aContext, engine,
|
2016-09-05 15:25:41 +00:00
|
|
|
AudioNodeStream::EXTERNAL_OUTPUT,
|
|
|
|
aContext->Graph());
|
2015-09-30 01:31:53 +00:00
|
|
|
mPort = outputStream->AllocateInputPort(mStream, AudioNodeStream::AUDIO_TRACK);
|
2013-05-21 19:17:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 18:24:43 +00:00
|
|
|
/* static */ already_AddRefed<MediaStreamAudioDestinationNode>
|
|
|
|
MediaStreamAudioDestinationNode::Create(AudioContext& aAudioContext,
|
|
|
|
const AudioNodeOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2014-07-08 21:23:17 +00:00
|
|
|
{
|
2016-12-15 18:24:43 +00:00
|
|
|
if (aAudioContext.IsOffline()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAudioContext.CheckClosed(aRv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MediaStreamAudioDestinationNode> audioNode =
|
|
|
|
new MediaStreamAudioDestinationNode(&aAudioContext);
|
|
|
|
|
|
|
|
audioNode->Initialize(aOptions, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return audioNode.forget();
|
2014-07-08 21:23:17 +00:00
|
|
|
}
|
|
|
|
|
2014-04-13 18:08:10 +00:00
|
|
|
size_t
|
|
|
|
MediaStreamAudioDestinationNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
// Future:
|
|
|
|
// - mDOMStream
|
|
|
|
size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
amount += mPort->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
MediaStreamAudioDestinationNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-05-21 19:17:47 +00:00
|
|
|
void
|
|
|
|
MediaStreamAudioDestinationNode::DestroyMediaStream()
|
|
|
|
{
|
|
|
|
AudioNode::DestroyMediaStream();
|
|
|
|
if (mPort) {
|
|
|
|
mPort->Destroy();
|
|
|
|
mPort = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 14:13:33 +00:00
|
|
|
MediaStreamAudioDestinationNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-05-21 19:17:47 +00: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 14:13:33 +00:00
|
|
|
return MediaStreamAudioDestinationNodeBinding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 19:17:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|