2013-05-21 12:17:47 -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 "MediaStreamAudioDestinationNode.h"
|
2013-07-22 20:54:32 -07:00
|
|
|
#include "nsIDocument.h"
|
2013-05-21 12:17:47 -07:00
|
|
|
#include "mozilla/dom/MediaStreamAudioDestinationNodeBinding.h"
|
|
|
|
#include "AudioNodeEngine.h"
|
|
|
|
#include "AudioNodeStream.h"
|
|
|
|
#include "DOMMediaStream.h"
|
|
|
|
#include "TrackUnionStream.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaStreamAudioDestinationNode, AudioNode, mDOMStream)
|
2013-05-21 12:17:47 -07: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)
|
|
|
|
|
|
|
|
static const int MEDIA_STREAM_DEST_TRACK_ID = 2;
|
2013-11-12 05:37:17 -08:00
|
|
|
static_assert(MEDIA_STREAM_DEST_TRACK_ID != AudioNodeStream::AUDIO_TRACK,
|
|
|
|
"MediaStreamAudioDestinationNode::MEDIA_STREAM_DEST_TRACK_ID must be a different value than AudioNodeStream::AUDIO_TRACK");
|
2013-05-21 12:17:47 -07:00
|
|
|
|
|
|
|
class MediaStreamDestinationEngine : public AudioNodeEngine {
|
|
|
|
public:
|
|
|
|
MediaStreamDestinationEngine(AudioNode* aNode, ProcessedMediaStream* aOutputStream)
|
|
|
|
: AudioNodeEngine(aNode)
|
|
|
|
, mOutputStream(aOutputStream)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOutputStream);
|
|
|
|
}
|
|
|
|
|
2014-03-04 13:09:49 -08:00
|
|
|
virtual void ProcessBlock(AudioNodeStream* aStream,
|
|
|
|
const AudioChunk& aInput,
|
|
|
|
AudioChunk* aOutput,
|
|
|
|
bool* aFinished) MOZ_OVERRIDE
|
2013-05-21 12:17:47 -07:00
|
|
|
{
|
|
|
|
*aOutput = aInput;
|
|
|
|
StreamBuffer::Track* track = mOutputStream->EnsureTrack(MEDIA_STREAM_DEST_TRACK_ID,
|
|
|
|
aStream->SampleRate());
|
|
|
|
AudioSegment* segment = track->Get<AudioSegment>();
|
|
|
|
segment->AppendAndConsumeChunk(aOutput);
|
|
|
|
}
|
|
|
|
|
2014-04-13 11:08:10 -07:00
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-05-21 12:17:47 -07:00
|
|
|
private:
|
|
|
|
ProcessedMediaStream* mOutputStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This callback is used to ensure that only the audio data for this track is audible
|
|
|
|
static bool FilterAudioNodeStreamTrack(StreamBuffer::Track* aTrack)
|
|
|
|
{
|
|
|
|
return aTrack->GetID() == MEDIA_STREAM_DEST_TRACK_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* aContext)
|
|
|
|
: AudioNode(aContext,
|
|
|
|
2,
|
|
|
|
ChannelCountMode::Explicit,
|
|
|
|
ChannelInterpretation::Speakers)
|
|
|
|
, mDOMStream(DOMAudioNodeMediaStream::CreateTrackUnionStream(GetOwner(),
|
2013-06-27 04:30:41 -07:00
|
|
|
MOZ_THIS_IN_INITIALIZER_LIST(),
|
2013-05-21 12:17:47 -07:00
|
|
|
DOMMediaStream::HINT_CONTENTS_AUDIO))
|
|
|
|
{
|
|
|
|
TrackUnionStream* tus = static_cast<TrackUnionStream*>(mDOMStream->GetStream());
|
|
|
|
MOZ_ASSERT(tus == mDOMStream->GetStream()->AsProcessedStream());
|
|
|
|
tus->SetTrackIDFilter(FilterAudioNodeStreamTrack);
|
|
|
|
|
|
|
|
MediaStreamDestinationEngine* engine = new MediaStreamDestinationEngine(this, tus);
|
|
|
|
mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::INTERNAL_STREAM);
|
|
|
|
mPort = tus->AllocateInputPort(mStream, 0);
|
2013-07-22 20:54:32 -07:00
|
|
|
|
|
|
|
nsIDocument* doc = aContext->GetParentObject()->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
mDOMStream->CombineWithPrincipal(doc->NodePrincipal());
|
|
|
|
}
|
2013-05-21 12:17:47 -07:00
|
|
|
}
|
|
|
|
|
2014-07-08 14:23:17 -07:00
|
|
|
MediaStreamAudioDestinationNode::~MediaStreamAudioDestinationNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-13 11:08:10 -07: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 12:17:47 -07:00
|
|
|
void
|
|
|
|
MediaStreamAudioDestinationNode::DestroyMediaStream()
|
|
|
|
{
|
|
|
|
AudioNode::DestroyMediaStream();
|
|
|
|
if (mPort) {
|
|
|
|
mPort->Destroy();
|
|
|
|
mPort = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
MediaStreamAudioDestinationNode::WrapObject(JSContext* aCx)
|
2013-05-21 12:17:47 -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 MediaStreamAudioDestinationNodeBinding::Wrap(aCx, this);
|
2013-05-21 12:17:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|