mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
1bdb34c6ec
This renames the following (in alphabetical order, non-exhaustive): AudioCaptureStream -> AudioCaptureTrack AudioNodeStream -> AudioNodeTrack AudioNodeExternalInputStream -> AudioNodeExternalInputTrack DirectMediaStreamTrackListener -> DirectMediaTrackListener MediaStream -> MediaTrack - Note that there's also dom::MediaTrack. Namespaces differentiate them. MediaStreamGraph -> MediaTrackGraph MediaStreamTrackListener -> MediaTrackListener MSG -> MTG (in comments) ProcessedMediaStream -> ProcessedMediaTrack SharedDummyStream -> SharedDummyTrack SourceMediaStream -> SourceMediaTrack StreamTime -> TrackTime TrackUnionStream -> ForwardedInputTrack - Because this no longer takes a union of anything, but only a single track as input. Other minor classes, members and comments have been updated to reflect these name changes. Differential Revision: https://phabricator.services.mozilla.com/D46146 --HG-- rename : dom/media/AudioCaptureStream.cpp => dom/media/AudioCaptureTrack.cpp rename : dom/media/AudioCaptureStream.h => dom/media/AudioCaptureTrack.h rename : dom/media/TrackUnionStream.cpp => dom/media/ForwardedInputTrack.cpp rename : dom/media/TrackUnionStream.h => dom/media/ForwardedInputTrack.h rename : dom/media/MediaStreamGraph.cpp => dom/media/MediaTrackGraph.cpp rename : dom/media/MediaStreamGraph.h => dom/media/MediaTrackGraph.h rename : dom/media/MediaStreamGraphImpl.h => dom/media/MediaTrackGraphImpl.h rename : dom/media/MediaStreamListener.cpp => dom/media/MediaTrackListener.cpp rename : dom/media/MediaStreamListener.h => dom/media/MediaTrackListener.h rename : dom/media/webaudio/AudioNodeExternalInputStream.cpp => dom/media/webaudio/AudioNodeExternalInputTrack.cpp rename : dom/media/webaudio/AudioNodeExternalInputStream.h => dom/media/webaudio/AudioNodeExternalInputTrack.h rename : dom/media/webaudio/AudioNodeStream.cpp => dom/media/webaudio/AudioNodeTrack.cpp rename : dom/media/webaudio/AudioNodeStream.h => dom/media/webaudio/AudioNodeTrack.h extra : moz-landing-system : lando
177 lines
5.8 KiB
C++
177 lines
5.8 KiB
C++
/* -*- 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 "AudioParam.h"
|
|
#include "mozilla/dom/AudioParamBinding.h"
|
|
#include "AudioNodeEngine.h"
|
|
#include "AudioNodeTrack.h"
|
|
#include "AudioContext.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(AudioParam)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AudioParam)
|
|
tmp->DisconnectFromGraphAndDestroyTrack();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNode)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AudioParam)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNode)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(AudioParam)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(AudioParam)
|
|
NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE(AudioParam)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioParam, AddRef)
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioParam, Release)
|
|
|
|
AudioParam::AudioParam(AudioNode* aNode, uint32_t aIndex, const char* aName,
|
|
float aDefaultValue, float aMinValue, float aMaxValue)
|
|
: AudioParamTimeline(aDefaultValue),
|
|
mNode(aNode),
|
|
mName(aName),
|
|
mIndex(aIndex),
|
|
mDefaultValue(aDefaultValue),
|
|
mMinValue(aMinValue),
|
|
mMaxValue(aMaxValue) {}
|
|
|
|
AudioParam::~AudioParam() { DisconnectFromGraphAndDestroyTrack(); }
|
|
|
|
JSObject* AudioParam::WrapObject(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
return AudioParam_Binding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
void AudioParam::DisconnectFromGraphAndDestroyTrack() {
|
|
MOZ_ASSERT(mRefCnt.get() > mInputNodes.Length(),
|
|
"Caller should be holding a reference or have called "
|
|
"mRefCnt.stabilizeForDeletion()");
|
|
|
|
while (!mInputNodes.IsEmpty()) {
|
|
uint32_t i = mInputNodes.Length() - 1;
|
|
RefPtr<AudioNode> input = mInputNodes[i].mInputNode;
|
|
mInputNodes.RemoveElementAt(i);
|
|
input->RemoveOutputParam(this);
|
|
}
|
|
|
|
if (mNodeTrackPort) {
|
|
mNodeTrackPort->Destroy();
|
|
mNodeTrackPort = nullptr;
|
|
}
|
|
|
|
if (mTrack) {
|
|
mTrack->Destroy();
|
|
mTrack = nullptr;
|
|
}
|
|
}
|
|
|
|
mozilla::MediaTrack* AudioParam::GetTrack() const { return mTrack; }
|
|
|
|
mozilla::MediaTrack* AudioParam::Track() {
|
|
if (mTrack) {
|
|
return mTrack;
|
|
}
|
|
|
|
AudioNodeEngine* engine = new AudioNodeEngine(nullptr);
|
|
mTrack = AudioNodeTrack::Create(mNode->Context(), engine,
|
|
AudioNodeTrack::NO_TRACK_FLAGS,
|
|
mNode->Context()->Graph());
|
|
|
|
// Force the input to have only one channel, and make it down-mix using
|
|
// the speaker rules if needed.
|
|
mTrack->SetChannelMixingParametersImpl(1, ChannelCountMode::Explicit,
|
|
ChannelInterpretation::Speakers);
|
|
// Mark as an AudioParam helper track
|
|
mTrack->SetAudioParamHelperTrack();
|
|
|
|
// Setup the AudioParam's track as an input to the owner AudioNode's track
|
|
AudioNodeTrack* nodeTrack = mNode->GetTrack();
|
|
if (nodeTrack) {
|
|
mNodeTrackPort = nodeTrack->AllocateInputPort(mTrack);
|
|
}
|
|
|
|
// Send the track to the timeline on the MTG side.
|
|
AudioTimelineEvent event(mTrack);
|
|
SendEventToEngine(event);
|
|
|
|
return mTrack;
|
|
}
|
|
|
|
static const char* ToString(AudioTimelineEvent::Type aType) {
|
|
switch (aType) {
|
|
case AudioTimelineEvent::SetValue:
|
|
return "SetValue";
|
|
case AudioTimelineEvent::SetValueAtTime:
|
|
return "SetValueAtTime";
|
|
case AudioTimelineEvent::LinearRamp:
|
|
return "LinearRamp";
|
|
case AudioTimelineEvent::ExponentialRamp:
|
|
return "ExponentialRamp";
|
|
case AudioTimelineEvent::SetTarget:
|
|
return "SetTarget";
|
|
case AudioTimelineEvent::SetValueCurve:
|
|
return "SetValueCurve";
|
|
case AudioTimelineEvent::Track:
|
|
return "Track";
|
|
case AudioTimelineEvent::Cancel:
|
|
return "Cancel";
|
|
default:
|
|
return "unknown AudioTimelineEvent";
|
|
}
|
|
}
|
|
|
|
void AudioParam::SendEventToEngine(const AudioTimelineEvent& aEvent) {
|
|
WEB_AUDIO_API_LOG(
|
|
"%f: %s for %u %s %s=%g time=%f %s=%g", GetParentObject()->CurrentTime(),
|
|
mName, ParentNodeId(), ToString(aEvent.mType),
|
|
aEvent.mType == AudioTimelineEvent::SetValueCurve ? "length" : "value",
|
|
aEvent.mType == AudioTimelineEvent::SetValueCurve
|
|
? static_cast<double>(aEvent.mCurveLength)
|
|
: static_cast<double>(aEvent.mValue),
|
|
aEvent.Time<double>(),
|
|
aEvent.mType == AudioTimelineEvent::SetValueCurve ? "duration"
|
|
: "constant",
|
|
aEvent.mType == AudioTimelineEvent::SetValueCurve ? aEvent.mDuration
|
|
: aEvent.mTimeConstant);
|
|
|
|
AudioNodeTrack* track = mNode->GetTrack();
|
|
if (track) {
|
|
track->SendTimelineEvent(mIndex, aEvent);
|
|
}
|
|
}
|
|
|
|
void AudioParam::CleanupOldEvents() {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
double currentTime = mNode->Context()->CurrentTime();
|
|
|
|
CleanupEventsOlderThan(currentTime);
|
|
}
|
|
|
|
float AudioParamTimeline::AudioNodeInputValue(size_t aCounter) const {
|
|
MOZ_ASSERT(mTrack);
|
|
|
|
// If we have a chunk produced by the AudioNode inputs to the AudioParam,
|
|
// get its value now. We use aCounter to tell us which frame of the last
|
|
// AudioChunk to look at.
|
|
float audioNodeInputValue = 0.0f;
|
|
const AudioBlock& lastAudioNodeChunk = mTrack->LastChunks()[0];
|
|
if (!lastAudioNodeChunk.IsNull()) {
|
|
MOZ_ASSERT(lastAudioNodeChunk.GetDuration() == WEBAUDIO_BLOCK_SIZE);
|
|
audioNodeInputValue =
|
|
static_cast<const float*>(lastAudioNodeChunk.mChannelData[0])[aCounter];
|
|
audioNodeInputValue *= lastAudioNodeChunk.mVolume;
|
|
}
|
|
|
|
return audioNodeInputValue;
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|