2013-01-13 14:46:57 -08:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_AUDIONODESTREAM_H_
|
|
|
|
#define MOZILLA_AUDIONODESTREAM_H_
|
|
|
|
|
|
|
|
#include "MediaStreamGraph.h"
|
2013-04-27 16:25:23 -07:00
|
|
|
#include "mozilla/dom/AudioNodeBinding.h"
|
2013-09-05 13:25:17 -07:00
|
|
|
#include "AudioSegment.h"
|
2013-01-13 14:46:57 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-03-12 08:16:42 -07:00
|
|
|
namespace dom {
|
|
|
|
struct ThreeDPoint;
|
2013-05-01 18:02:31 -07:00
|
|
|
class AudioParamTimeline;
|
2014-01-15 03:08:20 -08:00
|
|
|
class AudioContext;
|
2013-03-12 08:16:42 -07:00
|
|
|
}
|
|
|
|
|
2013-01-13 14:46:57 -08:00
|
|
|
class ThreadSharedFloatArrayBufferList;
|
2013-09-05 13:25:17 -07:00
|
|
|
class AudioNodeEngine;
|
2013-01-13 14:46:57 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An AudioNodeStream produces one audio track with ID AUDIO_TRACK.
|
|
|
|
* The start time of the AudioTrack is aligned to the start time of the
|
|
|
|
* AudioContext's destination node stream, plus some multiple of BLOCK_SIZE
|
|
|
|
* samples.
|
|
|
|
*
|
|
|
|
* An AudioNodeStream has an AudioNodeEngine plugged into it that does the
|
|
|
|
* actual audio processing. AudioNodeStream contains the glue code that
|
|
|
|
* integrates audio processing with the MediaStreamGraph.
|
|
|
|
*/
|
|
|
|
class AudioNodeStream : public ProcessedMediaStream {
|
2014-03-04 13:06:57 -08:00
|
|
|
typedef dom::ChannelCountMode ChannelCountMode;
|
|
|
|
typedef dom::ChannelInterpretation ChannelInterpretation;
|
|
|
|
|
2013-01-13 14:46:57 -08:00
|
|
|
public:
|
2014-01-15 03:08:20 -08:00
|
|
|
typedef mozilla::dom::AudioContext AudioContext;
|
|
|
|
|
2013-01-13 14:46:57 -08:00
|
|
|
enum { AUDIO_TRACK = 1 };
|
|
|
|
|
2013-05-05 08:48:45 -07:00
|
|
|
typedef nsAutoTArray<AudioChunk, 1> OutputChunks;
|
|
|
|
|
2013-01-13 14:46:57 -08:00
|
|
|
/**
|
|
|
|
* Transfers ownership of aEngine to the new AudioNodeStream.
|
|
|
|
*/
|
2013-03-17 17:37:47 -07:00
|
|
|
AudioNodeStream(AudioNodeEngine* aEngine,
|
2013-05-24 10:09:29 -07:00
|
|
|
MediaStreamGraph::AudioNodeStreamKind aKind,
|
2014-11-20 11:41:18 -08:00
|
|
|
TrackRate aSampleRate);
|
2014-07-15 08:37:45 -07:00
|
|
|
|
|
|
|
protected:
|
2013-01-13 14:46:57 -08:00
|
|
|
~AudioNodeStream();
|
|
|
|
|
2014-07-15 08:37:45 -07:00
|
|
|
public:
|
2013-01-13 14:46:57 -08:00
|
|
|
// Control API
|
|
|
|
/**
|
|
|
|
* Sets a parameter that's a time relative to some stream's played time.
|
|
|
|
* This time is converted to a time relative to this stream when it's set.
|
|
|
|
*/
|
2014-01-15 03:08:20 -08:00
|
|
|
void SetStreamTimeParameter(uint32_t aIndex, AudioContext* aContext,
|
2013-01-13 14:46:57 -08:00
|
|
|
double aStreamTime);
|
|
|
|
void SetDoubleParameter(uint32_t aIndex, double aValue);
|
|
|
|
void SetInt32Parameter(uint32_t aIndex, int32_t aValue);
|
2013-01-28 14:42:27 -08:00
|
|
|
void SetTimelineParameter(uint32_t aIndex, const dom::AudioParamTimeline& aValue);
|
2013-03-12 08:16:42 -07:00
|
|
|
void SetThreeDPointParameter(uint32_t aIndex, const dom::ThreeDPoint& aValue);
|
2014-03-15 12:00:17 -07:00
|
|
|
void SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList>&& aBuffer);
|
2013-05-13 21:12:30 -07:00
|
|
|
// This consumes the contents of aData. aData will be emptied after this returns.
|
|
|
|
void SetRawArrayData(nsTArray<float>& aData);
|
2013-04-27 16:25:23 -07:00
|
|
|
void SetChannelMixingParameters(uint32_t aNumberOfChannels,
|
2014-03-04 13:06:57 -08:00
|
|
|
ChannelCountMode aChannelCountMoe,
|
|
|
|
ChannelInterpretation aChannelInterpretation);
|
2014-08-18 17:12:50 -07:00
|
|
|
void SetPassThrough(bool aPassThrough);
|
2014-03-04 13:06:57 -08:00
|
|
|
ChannelInterpretation GetChannelInterpretation()
|
|
|
|
{
|
|
|
|
return mChannelInterpretation;
|
|
|
|
}
|
|
|
|
|
2013-05-01 18:02:31 -07:00
|
|
|
void SetAudioParamHelperStream()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mAudioParamStream, "Can only do this once");
|
|
|
|
mAudioParamStream = true;
|
|
|
|
}
|
2013-01-13 14:46:57 -08:00
|
|
|
|
2013-12-05 12:23:57 -08:00
|
|
|
virtual AudioNodeStream* AsAudioNodeStream() MOZ_OVERRIDE { return this; }
|
2013-01-13 14:46:57 -08:00
|
|
|
|
|
|
|
// Graph thread only
|
|
|
|
void SetStreamTimeParameterImpl(uint32_t aIndex, MediaStream* aRelativeToStream,
|
|
|
|
double aStreamTime);
|
2013-04-27 16:25:23 -07:00
|
|
|
void SetChannelMixingParametersImpl(uint32_t aNumberOfChannels,
|
2014-03-04 13:06:57 -08:00
|
|
|
ChannelCountMode aChannelCountMoe,
|
|
|
|
ChannelInterpretation aChannelInterpretation);
|
2014-03-04 13:53:55 -08:00
|
|
|
virtual void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) MOZ_OVERRIDE;
|
2014-07-16 17:55:55 -07:00
|
|
|
/**
|
|
|
|
* Produce the next block of output, before input is provided.
|
|
|
|
* ProcessInput() will be called later, and it then should not change
|
|
|
|
* the output. This is used only for DelayNodeEngine in a feedback loop.
|
|
|
|
*/
|
|
|
|
void ProduceOutputBeforeInput(GraphTime aFrom);
|
2014-09-17 22:20:43 -07:00
|
|
|
StreamTime GetCurrentPosition();
|
2013-05-01 18:02:31 -07:00
|
|
|
bool IsAudioParamStream() const
|
|
|
|
{
|
|
|
|
return mAudioParamStream;
|
|
|
|
}
|
2013-08-26 10:19:36 -07:00
|
|
|
|
2013-05-05 08:48:45 -07:00
|
|
|
const OutputChunks& LastChunks() const
|
2013-05-01 20:12:59 -07:00
|
|
|
{
|
2013-05-05 08:48:45 -07:00
|
|
|
return mLastChunks;
|
2013-05-01 20:12:59 -07:00
|
|
|
}
|
2013-06-18 20:09:44 -07:00
|
|
|
virtual bool MainThreadNeedsUpdates() const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
// Only source and external streams need updates on the main thread.
|
|
|
|
return (mKind == MediaStreamGraph::SOURCE_STREAM && mFinished) ||
|
|
|
|
mKind == MediaStreamGraph::EXTERNAL_STREAM;
|
|
|
|
}
|
2013-07-24 03:11:35 -07:00
|
|
|
virtual bool IsIntrinsicallyConsumed() const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-13 14:46:57 -08:00
|
|
|
|
|
|
|
// Any thread
|
|
|
|
AudioNodeEngine* Engine() { return mEngine; }
|
2013-05-24 10:09:29 -07:00
|
|
|
TrackRate SampleRate() const { return mSampleRate; }
|
2013-01-13 14:46:57 -08:00
|
|
|
|
2014-02-26 14:45:04 -08:00
|
|
|
/**
|
2014-10-20 17:54:24 -07:00
|
|
|
* Convert a time in seconds on the destination stream to ticks
|
|
|
|
* on this stream, including fractional position between ticks.
|
2014-02-26 14:45:04 -08:00
|
|
|
*/
|
2014-10-20 17:54:24 -07:00
|
|
|
double FractionalTicksFromDestinationTime(AudioNodeStream* aDestination,
|
|
|
|
double aSeconds);
|
2014-02-16 12:46:56 -08:00
|
|
|
/**
|
2014-09-17 22:20:43 -07:00
|
|
|
* Convert a time in seconds on the destination stream to StreamTime
|
2014-02-16 12:46:56 -08:00
|
|
|
* on this stream.
|
|
|
|
*/
|
2014-09-17 22:20:43 -07:00
|
|
|
StreamTime TicksFromDestinationTime(MediaStream* aDestination,
|
2014-02-16 12:46:56 -08:00
|
|
|
double aSeconds);
|
|
|
|
/**
|
|
|
|
* Get the destination stream time in seconds corresponding to a position on
|
|
|
|
* this stream.
|
|
|
|
*/
|
|
|
|
double DestinationTimeFromTicks(AudioNodeStream* aDestination,
|
2014-09-17 22:20:43 -07:00
|
|
|
StreamTime aPosition);
|
2014-02-16 12:46:56 -08:00
|
|
|
|
2014-04-13 11:08:10 -07:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
void SizeOfAudioNodesIncludingThis(MallocSizeOf aMallocSizeOf,
|
|
|
|
AudioNodeSizes& aUsage) const;
|
|
|
|
|
2013-01-13 14:46:57 -08:00
|
|
|
protected:
|
2013-07-24 03:11:35 -07:00
|
|
|
void AdvanceOutputSegment();
|
2013-01-13 14:46:57 -08:00
|
|
|
void FinishOutput();
|
2013-07-24 03:11:35 -07:00
|
|
|
void AccumulateInputChunk(uint32_t aInputIndex, const AudioChunk& aChunk,
|
|
|
|
AudioChunk* aBlock,
|
|
|
|
nsTArray<float>* aDownmixBuffer);
|
|
|
|
void UpMixDownMixChunk(const AudioChunk* aChunk, uint32_t aOutputChannelCount,
|
|
|
|
nsTArray<const void*>& aOutputChannels,
|
|
|
|
nsTArray<float>& aDownmixBuffer);
|
|
|
|
|
2014-03-31 14:26:02 -07:00
|
|
|
uint32_t ComputedNumberOfChannels(uint32_t aInputChannelCount);
|
2013-05-05 08:48:45 -07:00
|
|
|
void ObtainInputBlock(AudioChunk& aTmpChunk, uint32_t aPortIndex);
|
2013-01-13 14:46:57 -08:00
|
|
|
|
|
|
|
// The engine that will generate output for this node.
|
|
|
|
nsAutoPtr<AudioNodeEngine> mEngine;
|
|
|
|
// The last block produced by this node.
|
2013-05-05 08:48:45 -07:00
|
|
|
OutputChunks mLastChunks;
|
2013-05-24 10:09:29 -07:00
|
|
|
// The stream's sampling rate
|
|
|
|
const TrackRate mSampleRate;
|
2013-03-17 17:37:47 -07:00
|
|
|
// Whether this is an internal or external stream
|
|
|
|
MediaStreamGraph::AudioNodeStreamKind mKind;
|
2013-04-13 18:37:04 -07:00
|
|
|
// The number of input channels that this stream requires. 0 means don't care.
|
|
|
|
uint32_t mNumberOfInputChannels;
|
2013-04-27 16:25:23 -07:00
|
|
|
// The mixing modes
|
2014-03-04 13:06:57 -08:00
|
|
|
ChannelCountMode mChannelCountMode;
|
|
|
|
ChannelInterpretation mChannelInterpretation;
|
2013-04-29 13:58:19 -07:00
|
|
|
// Whether the stream should be marked as finished as soon
|
|
|
|
// as the current time range has been computed block by block.
|
|
|
|
bool mMarkAsFinishedAfterThisBlock;
|
2013-05-01 18:02:31 -07:00
|
|
|
// Whether the stream is an AudioParamHelper stream.
|
|
|
|
bool mAudioParamStream;
|
2014-08-18 17:12:50 -07:00
|
|
|
// Whether the stream just passes its input through.
|
|
|
|
bool mPassThrough;
|
2013-01-13 14:46:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZILLA_AUDIONODESTREAM_H_ */
|