2012-08-31 13:59:37 -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/. */
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#ifndef AudioContext_h_
|
|
|
|
#define AudioContext_h_
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2012-09-07 15:13:26 -07:00
|
|
|
#include "EnableWebAudioCheck.h"
|
2013-02-01 14:13:23 -08:00
|
|
|
#include "MediaBufferDecoder.h"
|
2013-07-24 00:31:06 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDOMEventTargetHelper.h"
|
|
|
|
#include "nsHashKeys.h"
|
2013-04-24 20:32:41 -07:00
|
|
|
#include "nsTHashtable.h"
|
2013-08-27 19:59:14 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2012-08-31 13:59:37 -07:00
|
|
|
|
2013-03-14 18:01:02 -07:00
|
|
|
// X11 has a #define for CurrentTime. Unbelievable :-(.
|
|
|
|
// See content/media/DOMMediaStream.h for more fun!
|
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 08:28:33 -07:00
|
|
|
class nsPIDOMWindow;
|
2012-08-31 13:59:37 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-08-15 12:44:14 -07:00
|
|
|
class DOMMediaStream;
|
2012-08-31 13:59:37 -07:00
|
|
|
class ErrorResult;
|
2013-08-15 12:44:14 -07:00
|
|
|
class MediaStream;
|
|
|
|
class MediaStreamGraph;
|
2012-08-31 13:59:37 -07:00
|
|
|
|
2012-09-07 15:13:26 -07:00
|
|
|
namespace dom {
|
|
|
|
|
2013-03-31 20:41:14 -07:00
|
|
|
class AnalyserNode;
|
2012-09-21 15:42:14 -07:00
|
|
|
class AudioBuffer;
|
2012-11-05 16:26:03 -08:00
|
|
|
class AudioBufferSourceNode;
|
|
|
|
class AudioDestinationNode;
|
|
|
|
class AudioListener;
|
2012-11-07 17:59:14 -08:00
|
|
|
class BiquadFilterNode;
|
2013-05-05 08:49:37 -07:00
|
|
|
class ChannelMergerNode;
|
2013-05-05 08:49:13 -07:00
|
|
|
class ChannelSplitterNode;
|
2013-06-10 13:07:55 -07:00
|
|
|
class ConvolverNode;
|
2012-10-31 17:26:03 -07:00
|
|
|
class DelayNode;
|
2012-11-06 17:01:11 -08:00
|
|
|
class DynamicsCompressorNode;
|
2012-11-05 16:26:03 -08:00
|
|
|
class GainNode;
|
2013-07-24 20:01:49 -07:00
|
|
|
class HTMLMediaElement;
|
|
|
|
class MediaElementAudioSourceNode;
|
2013-08-22 22:17:08 -07:00
|
|
|
class GlobalObject;
|
2013-05-21 12:17:47 -07:00
|
|
|
class MediaStreamAudioDestinationNode;
|
2013-07-24 04:29:39 -07:00
|
|
|
class MediaStreamAudioSourceNode;
|
2013-08-19 11:53:00 -07:00
|
|
|
class OscillatorNode;
|
2012-11-05 18:14:13 -08:00
|
|
|
class PannerNode;
|
2013-04-13 18:37:04 -07:00
|
|
|
class ScriptProcessorNode;
|
2013-05-13 21:12:30 -07:00
|
|
|
class WaveShaperNode;
|
2013-06-19 15:24:26 -07:00
|
|
|
class PeriodicWave;
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-04-24 21:28:39 -07:00
|
|
|
class AudioContext MOZ_FINAL : public nsDOMEventTargetHelper,
|
2012-09-07 15:13:26 -07:00
|
|
|
public EnableWebAudioCheck
|
2012-08-31 13:59:37 -07:00
|
|
|
{
|
2013-05-16 16:30:42 -07:00
|
|
|
AudioContext(nsPIDOMWindow* aParentWindow,
|
|
|
|
bool aIsOffline,
|
|
|
|
uint32_t aNumberOfChannels = 0,
|
|
|
|
uint32_t aLength = 0,
|
|
|
|
float aSampleRate = 0.0f);
|
|
|
|
~AudioContext();
|
2012-08-31 13:59:37 -07:00
|
|
|
|
|
|
|
public:
|
2013-04-24 21:28:39 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioContext,
|
|
|
|
nsDOMEventTargetHelper)
|
2012-08-31 13:59:37 -07:00
|
|
|
|
2013-04-12 08:28:33 -07:00
|
|
|
nsPIDOMWindow* GetParentObject() const
|
2012-08-31 13:59:37 -07:00
|
|
|
{
|
2013-04-24 21:28:39 -07:00
|
|
|
return GetOwner();
|
2012-08-31 13:59:37 -07:00
|
|
|
}
|
|
|
|
|
2013-04-22 08:45:34 -07:00
|
|
|
void Shutdown();
|
2013-03-21 19:59:33 -07:00
|
|
|
void Suspend();
|
|
|
|
void Resume();
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
2012-08-31 13:59:37 -07:00
|
|
|
|
2013-05-16 16:30:57 -07:00
|
|
|
using nsDOMEventTargetHelper::DispatchTrustedEvent;
|
|
|
|
|
2013-05-16 16:30:41 -07:00
|
|
|
// Constructor for regular AudioContext
|
2012-08-31 13:59:37 -07:00
|
|
|
static already_AddRefed<AudioContext>
|
2012-12-03 08:07:49 -08:00
|
|
|
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
|
2012-08-31 13:59:37 -07:00
|
|
|
|
2013-05-16 16:30:41 -07:00
|
|
|
// Constructor for offline AudioContext
|
|
|
|
static already_AddRefed<AudioContext>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
uint32_t aNumberOfChannels,
|
|
|
|
uint32_t aLength,
|
|
|
|
float aSampleRate,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
// AudioContext methods
|
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
AudioDestinationNode* Destination() const
|
|
|
|
{
|
|
|
|
return mDestination;
|
|
|
|
}
|
|
|
|
|
2012-11-29 19:31:39 -08:00
|
|
|
float SampleRate() const
|
|
|
|
{
|
2013-05-24 10:09:29 -07:00
|
|
|
return mSampleRate;
|
2012-11-29 19:31:39 -08:00
|
|
|
}
|
|
|
|
|
2013-03-14 18:01:02 -07:00
|
|
|
double CurrentTime() const;
|
|
|
|
|
2012-11-05 16:26:03 -08:00
|
|
|
AudioListener* Listener();
|
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
already_AddRefed<AudioBufferSourceNode> CreateBufferSource();
|
|
|
|
|
2012-09-21 15:42:14 -07:00
|
|
|
already_AddRefed<AudioBuffer>
|
|
|
|
CreateBuffer(JSContext* aJSContext, uint32_t aNumberOfChannels,
|
|
|
|
uint32_t aLength, float aSampleRate,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-05-03 13:42:28 -07:00
|
|
|
already_AddRefed<AudioBuffer>
|
2013-08-05 10:40:01 -07:00
|
|
|
CreateBuffer(JSContext* aJSContext, const ArrayBuffer& aBuffer,
|
2013-05-03 13:42:28 -07:00
|
|
|
bool aMixToMono, ErrorResult& aRv);
|
|
|
|
|
2013-05-21 12:17:47 -07:00
|
|
|
already_AddRefed<MediaStreamAudioDestinationNode>
|
2013-07-18 02:57:38 -07:00
|
|
|
CreateMediaStreamDestination(ErrorResult& aRv);
|
2013-05-21 12:17:47 -07:00
|
|
|
|
2013-04-13 18:37:04 -07:00
|
|
|
already_AddRefed<ScriptProcessorNode>
|
|
|
|
CreateScriptProcessor(uint32_t aBufferSize,
|
|
|
|
uint32_t aNumberOfInputChannels,
|
|
|
|
uint32_t aNumberOfOutputChannels,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<ScriptProcessorNode>
|
|
|
|
CreateJavaScriptNode(uint32_t aBufferSize,
|
|
|
|
uint32_t aNumberOfInputChannels,
|
|
|
|
uint32_t aNumberOfOutputChannels,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return CreateScriptProcessor(aBufferSize, aNumberOfInputChannels,
|
|
|
|
aNumberOfOutputChannels, aRv);
|
|
|
|
}
|
|
|
|
|
2013-03-31 20:41:14 -07:00
|
|
|
already_AddRefed<AnalyserNode>
|
|
|
|
CreateAnalyser();
|
|
|
|
|
2012-10-31 12:09:32 -07:00
|
|
|
already_AddRefed<GainNode>
|
|
|
|
CreateGain();
|
|
|
|
|
2013-05-13 21:12:30 -07:00
|
|
|
already_AddRefed<WaveShaperNode>
|
|
|
|
CreateWaveShaper();
|
|
|
|
|
2013-04-11 19:08:05 -07:00
|
|
|
already_AddRefed<GainNode>
|
|
|
|
CreateGainNode()
|
|
|
|
{
|
|
|
|
return CreateGain();
|
|
|
|
}
|
|
|
|
|
2013-07-24 20:01:49 -07:00
|
|
|
already_AddRefed<MediaElementAudioSourceNode>
|
|
|
|
CreateMediaElementSource(HTMLMediaElement& aMediaElement, ErrorResult& aRv);
|
2013-07-24 04:29:39 -07:00
|
|
|
already_AddRefed<MediaStreamAudioSourceNode>
|
2013-07-24 19:07:34 -07:00
|
|
|
CreateMediaStreamSource(DOMMediaStream& aMediaStream, ErrorResult& aRv);
|
2013-07-24 04:29:39 -07:00
|
|
|
|
2012-10-31 17:26:03 -07:00
|
|
|
already_AddRefed<DelayNode>
|
2012-11-19 12:52:29 -08:00
|
|
|
CreateDelay(double aMaxDelayTime, ErrorResult& aRv);
|
2012-10-31 17:26:03 -07:00
|
|
|
|
2013-04-11 19:08:05 -07:00
|
|
|
already_AddRefed<DelayNode>
|
|
|
|
CreateDelayNode(double aMaxDelayTime, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return CreateDelay(aMaxDelayTime, aRv);
|
|
|
|
}
|
|
|
|
|
2012-11-05 18:14:13 -08:00
|
|
|
already_AddRefed<PannerNode>
|
|
|
|
CreatePanner();
|
|
|
|
|
2013-06-10 13:07:55 -07:00
|
|
|
already_AddRefed<ConvolverNode>
|
|
|
|
CreateConvolver();
|
|
|
|
|
2013-05-05 08:49:13 -07:00
|
|
|
already_AddRefed<ChannelSplitterNode>
|
|
|
|
CreateChannelSplitter(uint32_t aNumberOfOutputs, ErrorResult& aRv);
|
|
|
|
|
2013-05-05 08:49:37 -07:00
|
|
|
already_AddRefed<ChannelMergerNode>
|
|
|
|
CreateChannelMerger(uint32_t aNumberOfInputs, ErrorResult& aRv);
|
|
|
|
|
2012-11-06 17:01:11 -08:00
|
|
|
already_AddRefed<DynamicsCompressorNode>
|
|
|
|
CreateDynamicsCompressor();
|
|
|
|
|
2012-11-07 17:59:14 -08:00
|
|
|
already_AddRefed<BiquadFilterNode>
|
|
|
|
CreateBiquadFilter();
|
|
|
|
|
2013-08-19 11:53:00 -07:00
|
|
|
already_AddRefed<OscillatorNode>
|
|
|
|
CreateOscillator();
|
|
|
|
|
2013-06-19 15:24:26 -07:00
|
|
|
already_AddRefed<PeriodicWave>
|
|
|
|
CreatePeriodicWave(const Float32Array& aRealData, const Float32Array& aImagData,
|
|
|
|
ErrorResult& aRv);
|
2013-05-28 04:19:07 -07:00
|
|
|
|
2013-02-01 14:13:23 -08:00
|
|
|
void DecodeAudioData(const ArrayBuffer& aBuffer,
|
|
|
|
DecodeSuccessCallback& aSuccessCallback,
|
|
|
|
const Optional<OwningNonNull<DecodeErrorCallback> >& aFailureCallback);
|
|
|
|
|
2013-05-16 16:30:41 -07:00
|
|
|
// OfflineAudioContext methods
|
2013-05-16 16:30:42 -07:00
|
|
|
void StartRendering();
|
2013-05-16 16:30:41 -07:00
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
|
2013-05-16 16:31:08 -07:00
|
|
|
bool IsOffline() const { return mIsOffline; }
|
2013-02-04 15:07:25 -08:00
|
|
|
|
|
|
|
MediaStreamGraph* Graph() const;
|
|
|
|
MediaStream* DestinationStream() const;
|
2013-04-11 05:47:57 -07:00
|
|
|
void UnregisterAudioBufferSourceNode(AudioBufferSourceNode* aNode);
|
|
|
|
void UnregisterPannerNode(PannerNode* aNode);
|
2013-08-19 11:57:00 -07:00
|
|
|
void UnregisterOscillatorNode(OscillatorNode* aNode);
|
2013-04-22 18:23:54 -07:00
|
|
|
void UnregisterScriptProcessorNode(ScriptProcessorNode* aNode);
|
2013-04-11 05:47:57 -07:00
|
|
|
void UpdatePannerSource();
|
2013-02-04 15:07:25 -08:00
|
|
|
|
2013-06-10 10:32:28 -07:00
|
|
|
uint32_t MaxChannelCount() const;
|
|
|
|
|
2013-07-03 17:44:32 -07:00
|
|
|
void Mute() const;
|
|
|
|
void Unmute() const;
|
|
|
|
|
2013-04-14 11:18:43 -07:00
|
|
|
JSContext* GetJSContext() const;
|
|
|
|
|
2013-02-01 14:13:23 -08:00
|
|
|
private:
|
|
|
|
void RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob);
|
2013-08-02 09:07:17 -07:00
|
|
|
void ShutdownDecoder();
|
2013-02-01 14:13:23 -08:00
|
|
|
|
|
|
|
friend struct ::mozilla::WebAudioDecodeJob;
|
|
|
|
|
2012-08-31 13:59:37 -07:00
|
|
|
private:
|
2013-05-24 10:09:29 -07:00
|
|
|
// Note that it's important for mSampleRate to be initialized before
|
|
|
|
// mDestination, as mDestination's constructor needs to access it!
|
|
|
|
const float mSampleRate;
|
2012-09-18 16:07:33 -07:00
|
|
|
nsRefPtr<AudioDestinationNode> mDestination;
|
2012-11-05 16:26:03 -08:00
|
|
|
nsRefPtr<AudioListener> mListener;
|
2013-02-01 14:13:23 -08:00
|
|
|
MediaBufferDecoder mDecoder;
|
2013-07-16 02:00:36 -07:00
|
|
|
nsTArray<nsRefPtr<WebAudioDecodeJob> > mDecodeJobs;
|
2013-04-24 20:32:41 -07:00
|
|
|
// Two hashsets containing all the PannerNodes and AudioBufferSourceNodes,
|
|
|
|
// to compute the doppler shift, and also to stop AudioBufferSourceNodes.
|
|
|
|
// These are all weak pointers.
|
|
|
|
nsTHashtable<nsPtrHashKey<PannerNode> > mPannerNodes;
|
|
|
|
nsTHashtable<nsPtrHashKey<AudioBufferSourceNode> > mAudioBufferSourceNodes;
|
2013-08-19 11:57:00 -07:00
|
|
|
nsTHashtable<nsPtrHashKey<OscillatorNode> > mOscillatorNodes;
|
2013-04-24 20:32:41 -07:00
|
|
|
// Hashset containing all ScriptProcessorNodes in order to stop them.
|
|
|
|
// These are all weak pointers.
|
|
|
|
nsTHashtable<nsPtrHashKey<ScriptProcessorNode> > mScriptProcessorNodes;
|
2013-06-10 10:32:28 -07:00
|
|
|
// Number of channels passed in the OfflineAudioContext ctor.
|
|
|
|
uint32_t mNumberOfChannels;
|
2013-05-16 16:30:41 -07:00
|
|
|
bool mIsOffline;
|
2012-08-31 13:59:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2012-09-07 15:13:26 -07:00
|
|
|
}
|
2012-08-31 13:59:37 -07:00
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#endif
|
|
|
|
|