mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-13 23:17:57 +00:00
81075674d3
Backed out changeset 80e8530f06ea (bug 804387) Backed out changeset 3de2271ad47f (bug 804387) Backed out changeset 00f86870931c (bug 804837) Backed out changeset 0e3f20927c50 (bug 804387) Backed out changeset e6ef90038007 (bug 804387) Backed out changeset 0ad6f67a95f9 (bug 804387) Backed out changeset d0772aba503c (bug 804387) Backed out changeset 5477b87ff03e (bug 804387) Backed out changeset 1d7ec5adc49f (bug 804387) Backed out changeset 11f4d740cd6c (bug 804387) Backed out changeset e6254d8997ab (bug 804387) Backed out changeset 372322f3264d (bug 804387) Backed out changeset 53d5ed687612 (bug 804387) Backed out changeset 000b88ac40a7 (bug 804387)
116 lines
3.2 KiB
C++
116 lines
3.2 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 "AudioBuffer.h"
|
|
#include "mozilla/dom/AudioBufferBinding.h"
|
|
#include "nsContentUtils.h"
|
|
#include "AudioContext.h"
|
|
#include "jsfriendapi.h"
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AudioBuffer)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mContext)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChannels)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
tmp->ClearJSChannels();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AudioBuffer)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContext)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(AudioBuffer)
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
for (uint32_t i = 0; i < tmp->mChannels.Length(); ++i) {
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mChannels[i])
|
|
}
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(AudioBuffer)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(AudioBuffer)
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioBuffer)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
AudioBuffer::AudioBuffer(AudioContext* aContext, uint32_t aLength,
|
|
uint32_t aSampleRate)
|
|
: mContext(aContext),
|
|
mLength(aLength),
|
|
mSampleRate(aSampleRate)
|
|
{
|
|
SetIsDOMBinding();
|
|
|
|
NS_HOLD_JS_OBJECTS(this, AudioBuffer);
|
|
}
|
|
|
|
AudioBuffer::~AudioBuffer()
|
|
{
|
|
ClearJSChannels();
|
|
}
|
|
|
|
void
|
|
AudioBuffer::ClearJSChannels()
|
|
{
|
|
mChannels.Clear();
|
|
NS_DROP_JS_OBJECTS(this, AudioBuffer);
|
|
}
|
|
|
|
bool
|
|
AudioBuffer::InitializeBuffers(uint32_t aNumberOfChannels, JSContext* aJSContext)
|
|
{
|
|
if (!mChannels.SetCapacity(aNumberOfChannels)) {
|
|
return false;
|
|
}
|
|
for (uint32_t i = 0; i < aNumberOfChannels; ++i) {
|
|
JSObject* array = JS_NewFloat32Array(aJSContext, mLength);
|
|
if (!array) {
|
|
return false;
|
|
}
|
|
mChannels.AppendElement(array);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
JSObject*
|
|
AudioBuffer::WrapObject(JSContext* aCx, JSObject* aScope,
|
|
bool* aTriedToWrap)
|
|
{
|
|
return AudioBufferBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
|
}
|
|
|
|
JSObject*
|
|
AudioBuffer::GetChannelData(JSContext* aJSContext, uint32_t aChannel,
|
|
ErrorResult& aRv) const
|
|
{
|
|
if (aChannel >= mChannels.Length()) {
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
return nullptr;
|
|
}
|
|
return GetChannelData(aChannel);
|
|
}
|
|
|
|
void
|
|
AudioBuffer::SetChannelDataFromArrayBufferContents(JSContext* aJSContext,
|
|
uint32_t aChannel,
|
|
void* aContents)
|
|
{
|
|
MOZ_ASSERT(aChannel < mChannels.Length());
|
|
JSObject* arrayBuffer = JS_NewArrayBufferWithContents(aJSContext, aContents);
|
|
mChannels[aChannel] = JS_NewFloat32ArrayWithBuffer(aJSContext, arrayBuffer,
|
|
0, -1);
|
|
MOZ_ASSERT(mLength == JS_GetTypedArrayLength(mChannels[aChannel]));
|
|
}
|
|
|
|
}
|
|
}
|
|
|