mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
22d3be643b
- fix mac build (11ff07d07d) - Merge branch 'dev' of https://github.com/rmottola/Arctic-Fox into dev (b1d5bda99a) - Bug 1171682 - Disable WebGL in safemode. r=jgilbert (4b388af71d) - Bug 1212724 - Fix compile error in non-unified mode. r=nical (a089c1d600) - bug 1210266 remove unused AudioNode::Callback() r=padenot (7cf3b8ac8d) - bug 1210266 unfriend AudioBufferSourceNode from AudioNode r=padenot (91055f431b) - bug 1210267 use DOMEventTargetHelper::LastRelease instead of custom Release r=baku (f81093ce16) - bug 1179662 call DisconnectFromGraph once only during unlink r=padenot (d95a512d7c) - Bug 1189506. Give AudioContext non-owning pointers to all its AudioNodes. r=karl (f9c2505e25) - bug 1197028 move AllocateAudioBlock to AudioBlock.h r=padenot (59e140347f) - bug 1197028 introduce AudioBlockBuffer r=padenot (bc33ccfc7f) - bug 1199559 write offline buffer in a format suitable for direct use by AudioBuffer r=padenot (69fd69c667) - bug 1199560 finish offline audio context processing even when allocation fails r=padenot (5863c0a56a) - Bug 1140448 - Improving the performances of how AudioEventTimeline calculates values, r=padenot (1a239c48e7) - bug 1191648 don't keep ScriptProcessorNode alive when it has no audioprocess listener r=padenot (8e1e5eb67d) - bug 1191649 determine ScriptProcessor connected status on main thread r=padenot (a919a422c4) - bug 1191648 don't create audioprocess event when there is no listener r=padenot (98ed82f86a) - bug 1199559 write audioprocess input buffer in a format suitable for direct use by AudioBuffer r=padenot (9ffcb9c64d) - bug 1197028 use AudioChunk::ChannelCount() r=padenot (1cf63e9959) - Bug 1148230 - Eliminate the duplicate subexpression (0f1ad073ff) - bug 1197028 use AudioChunk::GetDuration() r=padenot (b9c30d524c) - bug 1197028 introduce AudioBlock to keep track of downstream references to AudioBlockBuffer r=padenot (dfe5d1cb2f) - bug 1199559 add a helper to fallibly allocate ThreadSharedFloatArrayBufferList with buffers r=padenot (4e0c756087) - bug 1197028 use AudioBlock for web audio processing to reuse buffers shared downstream r=padenot (bf12911645) - bug 1201854 handle stop time precisely even when resampling r=padenot (8901626678) - back out part of bug 1197028 (d5d5bfc98a) - Bug 1189506. Put AudioContext::State inline. r=karl (ded4e9a6c0) - bug 916387 keep ScriptProcessorNode alive after input is GCed r=padenot (9430a56c6a) - Bug 1157137 - Fix WebAudio ScriptProcessorNode sometimes gaining high latency. r=padenot (32eadcafaf) - Bug 1189506. Pass AudioContext to AudioNodeStream::Create. r=karlt (8446b0d16d) - bug 1205558 remove unnecessary ScriptProcessorNodeEngine::mSource r=padenot (1e058b4390) - bug 1053011 align "extra" time on AudioContext with processing block size r=padenot (afeb49adbb) - Bug 1188099 - (Part 3) Introduce [ChromeOnly] SpeechSynthesis.forceEnd for tests. r=smaug r=kdavis (53d765144f) - Bug 1189506. Convert ChangeExplicitBlockerCount to MediaStream::Suspend/Resume. r=padenot (cb074a339e) - bug 1205540 don't send more null chunks than necessary to AnalyserNode r=padenot (d382e1f4ae) - bug 1205540 provide querying whether engines need to continue processing even without input r=padenot (36e44cb77b) - bug 1203380 destroy AudioBlocks on AudioNodeStream on graph thread r=padenot (777e68da76) - Bug 1201393. Create an iterator for MediaStreamGraph to iterate over all its streams. r=karlt (3fe295d8c4) - Bug 1195051 - Part 1: Do not unmute the destination node as soon as the AudioContext is constructed; r=padenot (4243840184) - Bug 1195051 - Part 2: Mute the destination node when the AudioContext is suspended, and unmute when resumed; r=padenot (e07d9e3268) - Bug 1201393. Make suspended MediaStreams implicitly always block. r=padenot (d4557acf43) - Bug 1189506. Make AudioContext responsible for tracking all nodes which need to be suspended and resumed. r=padenot (04410070e7) - Bug 1189506. Make suspending/resuming streams more reusable. r=padenot (503052804e) - bug 1201855 rearrange CopyFromBuffer to separate code using numFrames r=padenot (9e2147d19c) - revert blocked to finished (2bed009b25) - bug 1205540 account for active inputs and skip processing when streams are inactive r=padenot (a20049ae19) - bug 864171 move "extra" time accounting for AudioContext with no nodes to destination stream r=padenot (8ef43b8f25) - bug 1208327 make enum AudioContextOperation strongly typed and forward declare instead of including AudioContext.h r=roc (35cc6748c6) - Bug 1201393. Remove usage of FLAG_BLOCK_OUTPUT from MediaRecorder. r=jwwang (d7ddf40ba2) - Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from MediaRecorder. r=jwwang (587979ca8a) - Bug 1189506. Remove usage of FLAG_BLOCK_OUTPUT from MediaManager. r=jesup (d2cb000648) - Bug 1201393. Remove usage of FLAG_BLOCK_* from OutputStreamData::Connect. r=jwwang (e31f1effc4) - Bug 1189506. Don't bother blocking captured media-element MediaStreams while we're not decoding. r=jwwang (c7240f6fc3) - Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from AudioParam/AudioNode. r=padenot (57a3e05283) - bug 1191649 add notification of input node changes r=padenot (752ae93e82) - bug 916387 add a notification of garbage collected input node r=padenot (6336b50f51) - Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from MediaStreamAudioSourceNode. r=jwwang (df4d77f09a) - Bug 1189506. Remove aFlags parameter from AllocateInputPort. r=karlt (b62e152ec3) - bug 1205540 make source stream available during RemoveInput r=padenot (45341fac7f) - Bug 1189506. Remove MediaInputPort::mFlags. r=karlt (61cb5dce71) - Bug 1170958 - Allow MediaInputPort to lock to a specific input track. r=roc (a5ba676c3d) - Bug 1200579 - Stop copying AudioParam timelines. r=karlt (0720f80914) - bug 1209286 remove now unnecessary StreamTimeToDOMTime and DOMTimeToStreamTime r=padenot (ff93dd9d3a) - Bug 1140450 - Lower speex_resampler quality for Web Audio API. r=padenot (2f34f0b90c) - bug 1201855 keep track of buffer position even when there are no channels r=padenot (f3cdcd3bfc) - bug 1201855 send ended event even when the buffer has no channel data r=padenot (5175efcf0a) - backout from from bug 1197028 (ab2235c6b9) - Bug 1163958 - Reduce the allocation in MediaStreamGraph - patch 2, r=padenot (0b00b72341) - Bug 1189506. Fix multi-track MediaStream audio output. r=karlt (b136e91cc5) - Bug 1189506. Simplify PlayAudio based on the fact that track time units == stream time units. r=karlt (e3a164170c) - Bug 1189506. Remove misleading comment. r=karlt (f491ee4f02) - Bug 1189506. Simplify blocking code now that stream blocking decision are always independent of other streams. r=karlt (646ee9a8da) - Bug 1189506. Remove MediaStream::mBlockInThisPhase. r=karlt (4cfc75216f) - Bug 1189506. Remove mExplicitBlockerCount and related code since it's always zero now. r=karlt (1d45b877fc) - Bug 1189506. Remove unused MediaStreamGraph::GetBufferedTicks. r=karlt (5f90c53e87) - Bug 1189506. Simplify blocking calculations based on the observation that once a stream starts blocking in a given processing interval, it must stay blocked. r=karlt (bd1d2a90d0) - Bug 1189506. Replace MediaStream::mBlocked with simpler MediaStream::mStartBlocking. r=karlt (215bacd2fd) - Bug 1189506. Inline RecomputeBlocking. r=karlt (336a6ab1e9) - Bug 1189506. Inline ComputeStreamBlockTime. r=karlt (0b0256bb64) - Bug 1189506. Remove unused NotifyConsumptionChanged. r=karlt (c9f1250b34) - Bug 1189506. Remove unused mFlushSourcesNow/mFlushSourcesOnNextIteration. r=karlt (734d5fff71) - Bug 1189506. Factor out code from OneIteration into helper methods. r=karlt (52b5030073) - Bug 1189506. Move setting of mStateComputedTime to OneIteration so it's near setting mProcessedTime. r=karlt (c3507aaa84) - Bug 1189506. No need to pass aNextCurrentTime to UpdateCurrentTimeForStreams. r=karlt (1c6141e03e) - Bug 1189506. Inline StreamNotifyOutput/StreamNotifyFinished. r=karlt (cdac2c6405) - Bug 1189506. Rename StreamTimeToGraphTime/GraphTimeToStreamTime to ...WithBlocking. r=karlt (e61ffd53a4) - bug 1199559 permit writing to ThreadSharedFloatArrayBufferList when not shared r=padenot (4eaa511691) - bug 1199559 add a factory method to accept generated buffer contents in a format suitable for direct use r=padenot (801f9c6c35) - Bug 1170958 - Add input stream and track as args to NotifyQueuedTrackChanges. r=roc (b3677c801a) - bug 1196111 don't keep AudioContext alive from AudioBuffer r=baku (f1b113c655) - bug 1207003 fetch stream position once instead of three times r=padenot (2cef872dc0) - bug 1207003 remove unused aStream parameter r=padenot (8c3fa1ee88) - bug 1207003 add GraphTime parameter to ProcessBlock() and remove GetCurrentPosition() r=padenot (5f442537a2) - bug 1206362 be careful about double -> int conversion r=padenot (956051f9f1) - Bug 1189506. Remove invalid assertion. r=karlt (4fa8b5a7b1) - Bug 1189506. Create StreamTimeToGraphTime/GraphTimeToStreamTime that don't take account of blocking, and call them from AudioNodeStream. r=karlt (d10f5b1b62) - bug 1205558 use destination stream for audio node engine time r=padenot (a9361c32ac) - bug 1205558 remove unused AudioNodeStream* aSource parameter r=padenot (7667751920) - Bug 1189506. Use mProcessedTime in some places instead of passing aFrm. r=karlt (c5537555e5) - Bug 1189506. Use mStateComputedTime in some places instead of passing aTo. r=karlt (69ed378a74) - Bug 1189506. Use mProcessedTime/mStateComputedTime in ProduceDataForStreamsBlockByBlock. karlt (bc1c49c537) - bug 1214493 restore fractional start time accidentally rounded in 13e85dc6b41b r=padenot (87b7b5de82) - missing bit of 1205558 (a46dbdc0de) - Bug 1185176 - Account for the fact that it is possible for nodes to not have streams. r=karlt (1b5729312b) - Bug 1210266 use parameter index instead of node callback for sending timeline events r=padenot (6501350f34) - remove blocked for finished (89fcb0509c) - bug 1215096 correct off-by-one error in playback position of resampled buffers r=padenot (38c7351675) - bug 1020370 adjust assert to tolerate large skipFracNum r=padenot (f4f5c7f10f) - bug 1020370 use int64_t to avoid overflow in subsample calcs r=padenot (9ec82a2c36) - missing bit of bug 1201855 use unsigned integers for buffer positions (7e83ff4598) - bug 1179662 call UnregisterAudioBufferSourceNode only once r=padenot (40a5d8ab9a) - bug 1205558 introduce SecondsToNearestStreamTime r=padenot (719acd8bc2) - missing bits of Bug 1189506. Make AudioContext responsible (8bd5a1044d) - Bug 1189506. Call GraphTimeToStreamTime in ExtractPendingInput since we know no blocking time has been determined yet. r=karlt (bab799c1d0)
216 lines
7.3 KiB
C++
216 lines
7.3 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
/* 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 "AudioNodeEngine.h"
|
|
#include "AudioNodeExternalInputStream.h"
|
|
#include "AudioChannelFormat.h"
|
|
#include "mozilla/dom/MediaStreamAudioSourceNode.h"
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
namespace mozilla {
|
|
|
|
AudioNodeExternalInputStream::AudioNodeExternalInputStream(AudioNodeEngine* aEngine, TrackRate aSampleRate)
|
|
: AudioNodeStream(aEngine, NO_STREAM_FLAGS, aSampleRate)
|
|
{
|
|
MOZ_COUNT_CTOR(AudioNodeExternalInputStream);
|
|
}
|
|
|
|
AudioNodeExternalInputStream::~AudioNodeExternalInputStream()
|
|
{
|
|
MOZ_COUNT_DTOR(AudioNodeExternalInputStream);
|
|
}
|
|
|
|
/* static */ already_AddRefed<AudioNodeExternalInputStream>
|
|
AudioNodeExternalInputStream::Create(MediaStreamGraph* aGraph,
|
|
AudioNodeEngine* aEngine)
|
|
{
|
|
AudioContext* ctx = aEngine->NodeMainThread()->Context();
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aGraph->GraphRate() == ctx->SampleRate());
|
|
|
|
RefPtr<AudioNodeExternalInputStream> stream =
|
|
new AudioNodeExternalInputStream(aEngine, aGraph->GraphRate());
|
|
aGraph->AddStream(stream,
|
|
ctx->ShouldSuspendNewStream() ? MediaStreamGraph::ADD_STREAM_SUSPENDED : 0);
|
|
return stream.forget();
|
|
}
|
|
|
|
/**
|
|
* Copies the data in aInput to aOffsetInBlock within aBlock.
|
|
* aBlock must have been allocated with AllocateInputBlock and have a channel
|
|
* count that's a superset of the channels in aInput.
|
|
*/
|
|
template <typename T>
|
|
static void
|
|
CopyChunkToBlock(AudioChunk& aInput, AudioBlock *aBlock,
|
|
uint32_t aOffsetInBlock)
|
|
{
|
|
uint32_t blockChannels = aBlock->ChannelCount();
|
|
nsAutoTArray<const T*,2> channels;
|
|
if (aInput.IsNull()) {
|
|
channels.SetLength(blockChannels);
|
|
PodZero(channels.Elements(), blockChannels);
|
|
} else {
|
|
const nsTArray<const T*>& inputChannels = aInput.ChannelData<T>();
|
|
channels.SetLength(inputChannels.Length());
|
|
PodCopy(channels.Elements(), inputChannels.Elements(), channels.Length());
|
|
if (channels.Length() != blockChannels) {
|
|
// We only need to upmix here because aBlock's channel count has been
|
|
// chosen to be a superset of the channel count of every chunk.
|
|
AudioChannelsUpMix(&channels, blockChannels, static_cast<T*>(nullptr));
|
|
}
|
|
}
|
|
|
|
for (uint32_t c = 0; c < blockChannels; ++c) {
|
|
float* outputData = aBlock->ChannelFloatsForWrite(c) + aOffsetInBlock;
|
|
if (channels[c]) {
|
|
ConvertAudioSamplesWithScale(channels[c], outputData, aInput.GetDuration(), aInput.mVolume);
|
|
} else {
|
|
PodZero(outputData, aInput.GetDuration());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Converts the data in aSegment to a single chunk aBlock. aSegment must have
|
|
* duration WEBAUDIO_BLOCK_SIZE. aFallbackChannelCount is a superset of the
|
|
* channels in every chunk of aSegment. aBlock must be float format or null.
|
|
*/
|
|
static void ConvertSegmentToAudioBlock(AudioSegment* aSegment,
|
|
AudioBlock* aBlock,
|
|
int32_t aFallbackChannelCount)
|
|
{
|
|
NS_ASSERTION(aSegment->GetDuration() == WEBAUDIO_BLOCK_SIZE, "Bad segment duration");
|
|
|
|
{
|
|
AudioSegment::ChunkIterator ci(*aSegment);
|
|
NS_ASSERTION(!ci.IsEnded(), "Should be at least one chunk!");
|
|
if (ci->GetDuration() == WEBAUDIO_BLOCK_SIZE &&
|
|
(ci->IsNull() || ci->mBufferFormat == AUDIO_FORMAT_FLOAT32)) {
|
|
// Return this chunk directly to avoid copying data.
|
|
*aBlock = *ci;
|
|
return;
|
|
}
|
|
}
|
|
|
|
aBlock->AllocateChannels(aFallbackChannelCount);
|
|
|
|
uint32_t duration = 0;
|
|
for (AudioSegment::ChunkIterator ci(*aSegment); !ci.IsEnded(); ci.Next()) {
|
|
switch (ci->mBufferFormat) {
|
|
case AUDIO_FORMAT_S16: {
|
|
CopyChunkToBlock<int16_t>(*ci, aBlock, duration);
|
|
break;
|
|
}
|
|
case AUDIO_FORMAT_FLOAT32: {
|
|
CopyChunkToBlock<float>(*ci, aBlock, duration);
|
|
break;
|
|
}
|
|
case AUDIO_FORMAT_SILENCE:
|
|
break;
|
|
}
|
|
duration += ci->GetDuration();
|
|
}
|
|
}
|
|
|
|
void
|
|
AudioNodeExternalInputStream::ProcessInput(GraphTime aFrom, GraphTime aTo,
|
|
uint32_t aFlags)
|
|
{
|
|
// According to spec, number of outputs is always 1.
|
|
MOZ_ASSERT(mLastChunks.Length() == 1);
|
|
|
|
// GC stuff can result in our input stream being destroyed before this stream.
|
|
// Handle that.
|
|
if (!IsEnabled() || mInputs.IsEmpty() || mPassThrough) {
|
|
mLastChunks[0].SetNull(WEBAUDIO_BLOCK_SIZE);
|
|
AdvanceOutputSegment();
|
|
return;
|
|
}
|
|
|
|
MOZ_ASSERT(mInputs.Length() == 1);
|
|
|
|
MediaStream* source = mInputs[0]->GetSource();
|
|
nsAutoTArray<AudioSegment,1> audioSegments;
|
|
uint32_t inputChannels = 0;
|
|
for (StreamBuffer::TrackIter tracks(source->mBuffer, MediaSegment::AUDIO);
|
|
!tracks.IsEnded(); tracks.Next()) {
|
|
const StreamBuffer::Track& inputTrack = *tracks;
|
|
if (!mInputs[0]->PassTrackThrough(tracks->GetID())) {
|
|
continue;
|
|
}
|
|
|
|
const AudioSegment& inputSegment =
|
|
*static_cast<AudioSegment*>(inputTrack.GetSegment());
|
|
if (inputSegment.IsNull()) {
|
|
continue;
|
|
}
|
|
|
|
AudioSegment& segment = *audioSegments.AppendElement();
|
|
GraphTime next;
|
|
for (GraphTime t = aFrom; t < aTo; t = next) {
|
|
MediaInputPort::InputInterval interval = mInputs[0]->GetNextInputInterval(t);
|
|
interval.mEnd = std::min(interval.mEnd, aTo);
|
|
if (interval.mStart >= interval.mEnd)
|
|
break;
|
|
next = interval.mEnd;
|
|
|
|
StreamTime outputStart = GraphTimeToStreamTimeWithBlocking(interval.mStart);
|
|
StreamTime outputEnd = GraphTimeToStreamTimeWithBlocking(interval.mEnd);
|
|
StreamTime ticks = outputEnd - outputStart;
|
|
|
|
if (interval.mInputIsBlocked) {
|
|
segment.AppendNullData(ticks);
|
|
} else {
|
|
StreamTime inputStart =
|
|
std::min(inputSegment.GetDuration(),
|
|
source->GraphTimeToStreamTimeWithBlocking(interval.mStart));
|
|
StreamTime inputEnd =
|
|
std::min(inputSegment.GetDuration(),
|
|
source->GraphTimeToStreamTimeWithBlocking(interval.mEnd));
|
|
|
|
segment.AppendSlice(inputSegment, inputStart, inputEnd);
|
|
// Pad if we're looking past the end of the track
|
|
segment.AppendNullData(ticks - (inputEnd - inputStart));
|
|
}
|
|
}
|
|
|
|
for (AudioSegment::ChunkIterator iter(segment); !iter.IsEnded(); iter.Next()) {
|
|
inputChannels = GetAudioChannelsSuperset(inputChannels, iter->ChannelCount());
|
|
}
|
|
}
|
|
|
|
uint32_t accumulateIndex = 0;
|
|
if (inputChannels) {
|
|
nsAutoTArray<float,GUESS_AUDIO_CHANNELS*WEBAUDIO_BLOCK_SIZE> downmixBuffer;
|
|
for (uint32_t i = 0; i < audioSegments.Length(); ++i) {
|
|
AudioBlock tmpChunk;
|
|
ConvertSegmentToAudioBlock(&audioSegments[i], &tmpChunk, inputChannels);
|
|
if (!tmpChunk.IsNull()) {
|
|
if (accumulateIndex == 0) {
|
|
mLastChunks[0].AllocateChannels(inputChannels);
|
|
}
|
|
AccumulateInputChunk(accumulateIndex, tmpChunk, &mLastChunks[0], &downmixBuffer);
|
|
accumulateIndex++;
|
|
}
|
|
}
|
|
}
|
|
if (accumulateIndex == 0) {
|
|
mLastChunks[0].SetNull(WEBAUDIO_BLOCK_SIZE);
|
|
}
|
|
|
|
// Using AudioNodeStream's AdvanceOutputSegment to push the media stream graph along with null data.
|
|
AdvanceOutputSegment();
|
|
}
|
|
|
|
bool
|
|
AudioNodeExternalInputStream::IsEnabled()
|
|
{
|
|
return ((MediaStreamAudioSourceNodeEngine*)Engine())->IsEnabled();
|
|
}
|
|
|
|
} // namespace mozilla
|