bug 1199559 add a helper to fallibly allocate ThreadSharedFloatArrayBufferList with buffers r=padenot

--HG--
extra : rebase_source : f7d532fb2142624b0a3c3423c954a2e817d529ea
This commit is contained in:
Karl Tomlinson 2015-08-27 20:35:43 +12:00
Родитель c919923973
Коммит 74c733393d
2 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -12,6 +12,26 @@
namespace mozilla {
already_AddRefed<ThreadSharedFloatArrayBufferList>
ThreadSharedFloatArrayBufferList::Create(uint32_t aChannelCount,
size_t aLength,
const mozilla::fallible_t&)
{
nsRefPtr<ThreadSharedFloatArrayBufferList> buffer =
new ThreadSharedFloatArrayBufferList(aChannelCount);
for (uint32_t i = 0; i < aChannelCount; ++i) {
float* channelData = js_pod_malloc<float>(aLength);
if (!channelData) {
return nullptr;
}
buffer->SetData(i, channelData, js_free, channelData);
}
return buffer.forget();
}
void
AllocateAudioBlock(uint32_t aChannelCount, AudioChunk* aChunk)
{

Просмотреть файл

@ -31,12 +31,19 @@ class ThreadSharedFloatArrayBufferList final : public ThreadSharedObject
{
public:
/**
* Construct with null data.
* Construct with null channel data pointers.
*/
explicit ThreadSharedFloatArrayBufferList(uint32_t aCount)
{
mContents.SetLength(aCount);
}
/**
* Create with buffers suitable for transfer to
* JS_NewArrayBufferWithContents(). The buffer contents are uninitialized
* and so should be set using GetDataForWrite().
*/
static already_AddRefed<ThreadSharedFloatArrayBufferList>
Create(uint32_t aChannelCount, size_t aLength, const mozilla::fallible_t&);
struct Storage final
{