mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
c1485b21e1
- bug 1179662 rename AudioNode::Stream() to GetStream() as it may return null r=padenot (d2d7e5f90) - bug 1197043 remove unnecessary aSampleRate parameter for AudioNodeStream creation r=padenot (3733ceb56) - bug 1197043 rename Add/RemoveStream to Add/RemoveStreamGraphThread r=padenot (f648b8251) - bug 1197043 introduce MediaStreamGraph::AddStream() r=padenot (ac021d4b2) - bug 1197043 move AudioNodeStream creation to stream class r=padenot (a90a05910) - bug 1197043 use flags to distinguish between external streams and events r=padenot (024dd96f1) - Bug 1176300 - Move libsoundtouch to lgpllibs; r=glandium (99a546adf) - Bug 1176300 - Add lgpllibs library to build system; r=glandium (bb4d07670) - Bug 1176300 - Update libsoundtouch to patched r222; r=padenot (hg rev 8c32c900cb48) - Bug 1176300 - Add soundtouch factory functions for DLL memory handling on windows; r=padenot (hg rev 84a1ffbc2db8) - Bug 901633 - Part 1 - Implement a generic audio packetizer. r=jesup (a38c2d70b) - Bug 901633 - Part 2 - Make AudioChannelFormat and AudioSegment more generic. r=roc (556b7349f) - Bug 901633 - Part 3 - Fix TrackEncoder to use the new AudioChunk methods. r=jesup (56e018f83) - Bug 901633 - Part 4 - Update AudioNodeStream to use new chunk methods. r=roc (9df19b894) - Bug 901633 - Part 6 - Update DelayBuffer to use the new AudioChunk methods. r=karlt (6d5684334) - Bug 901633 - Part 7 - Update AudioNodeExternalInputStream to use the new AudioChunk methods. r=karlt (caa3afa01) - Bug 1155089: Fix hazard analysis bustage on a CLOSED TREE. r=bustage (8d23ccf39) - Bug 1166183 - Back out the direct listener removal landed by mistake in bug 1141781. r=jesup (745d683d4) - Bug 1166183 - Reset PipelineListener's flag after ReplaceTrack(). r=bwc (2fb38ca01) - Bug 1170059 - Fix -Wunreachable-code clang warnings in webrtc/signaling. r=jesup (0d99b30ca) - Bug 1139144 - Remove unused empty() definition from databuffer.h. r=mt (2fef64e3c) - Bug 822129: don't alloc/free on every packet send in MediaPipeline r=bwc (ddfdc9455) - Bug 1172397 - Check for Conduit/Type mismatch on every frame. r=jesup, r=bwc (a399a3336) - Bug 1137169 - Uninitialised value uses related to mozilla::dom::WebAdioUtils::SpeexResamplerProcess. r=rjesup. (ce14ac278) - Bug 901633 - Part 5 - Make MediaPipeline downmix and properly convert audio for webrtc.org code. r=jesup (89138b5d5) - Bug 901633 - Part 8 - Use our new generic packetizer in the MediaPipeline so that we can packetize stereo easily. r=jesup (fb5d075b6) - Bug 901633 - Part 9 - Make the necessary changes to VoEExternalMediaImpl::ExternalRecordingInsertData so that it the number of channels is forwarded down the webrtc.org code. r=jesup (d5d7dd4ca) - Bug 901633 - Part 10 - Change the receiving side of the MediaPipeline so that it can detect and handle stereo. r=jesup (a73c1520f) - Bug 901633 - Part 11 - Add an API in webrtc.org's output mixer to get the output channel count. r=jesup (4b396b85e) - Bug 901633 - Part 12 - Add a function to deinterleave and convert an audio buffer. r=jesup (47ce3c7a5) - Bug 901633 - Part 13 - Teach the resampler at the input of the MSG to dynamically change its channel count if needed. r=jesup (120c8d037) - Bug 901633 - Part 14 - Add testing for our audio processing functions. r=jesup (5aa95b82e) - Bug 901633 - Part 15 - Remove an allocation on the sending side, out of the packetizer. r=jesup (df8aed252) - Bug 901633 - Part 16 - Remove another allocation in the sending side r=jesup (1e2fc8bca) - Bug 1196408 - Make sure we only report a corrupt/slow video frame once. r=cpearce (5bae2f17a) - bug 1162364 report telemetry on WMFMediaDataDecoder errors r=cpearce,f=vladan,bsmedberg (e217618ef) - Bug 1193864 - Fixed dom/media/platforms/wmf/ compilation on mingw. r=cpearce (4e8c0ecd7) - Bug 1141139: Enable low latency decoding on Windows. r=cpearce (9e0a36e27) - Bug 1193547 - Fallback to software decoding explicitly if the GPU doesn't support decoding the current resolution in hardware. r=cpearce,jya (7fbab8784) - Bug 1196417 - Make video software fallback only affect the current video instead of the entire browser. r=cpearce (3e83f0677)
211 lines
7.2 KiB
C++
211 lines
7.2 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, uint32_t aContextId)
|
|
: AudioNodeStream(aEngine, NO_STREAM_FLAGS, aSampleRate, aContextId)
|
|
{
|
|
MOZ_COUNT_CTOR(AudioNodeExternalInputStream);
|
|
}
|
|
|
|
AudioNodeExternalInputStream::~AudioNodeExternalInputStream()
|
|
{
|
|
MOZ_COUNT_DTOR(AudioNodeExternalInputStream);
|
|
}
|
|
|
|
/* static */ already_AddRefed<AudioNodeExternalInputStream>
|
|
AudioNodeExternalInputStream::Create(MediaStreamGraph* aGraph,
|
|
AudioNodeEngine* aEngine)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aGraph->GraphRate() == aEngine->NodeMainThread()->Context()->SampleRate());
|
|
|
|
nsRefPtr<AudioNodeExternalInputStream> stream =
|
|
new AudioNodeExternalInputStream(aEngine, aGraph->GraphRate(),
|
|
aEngine->NodeMainThread()->Context()->Id());
|
|
aGraph->AddStream(stream);
|
|
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, AudioChunk *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,
|
|
AudioChunk* 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;
|
|
}
|
|
}
|
|
|
|
AllocateAudioBlock(aFallbackChannelCount, aBlock);
|
|
|
|
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;
|
|
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 = GraphTimeToStreamTime(interval.mStart);
|
|
StreamTime outputEnd = GraphTimeToStreamTime(interval.mEnd);
|
|
StreamTime ticks = outputEnd - outputStart;
|
|
|
|
if (interval.mInputIsBlocked) {
|
|
segment.AppendNullData(ticks);
|
|
} else {
|
|
StreamTime inputStart =
|
|
std::min(inputSegment.GetDuration(),
|
|
source->GraphTimeToStreamTime(interval.mStart));
|
|
StreamTime inputEnd =
|
|
std::min(inputSegment.GetDuration(),
|
|
source->GraphTimeToStreamTime(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) {
|
|
AudioChunk tmpChunk;
|
|
ConvertSegmentToAudioBlock(&audioSegments[i], &tmpChunk, inputChannels);
|
|
if (!tmpChunk.IsNull()) {
|
|
if (accumulateIndex == 0) {
|
|
AllocateAudioBlock(inputChannels, &mLastChunks[0]);
|
|
}
|
|
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
|