зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1248861: P3. Use AlignedAudioBuffer object with AudioData. r=cpearce
MozReview-Commit-ID: 7HiF4eHlRwB
This commit is contained in:
Родитель
0bff39bbe6
Коммит
ec928c4c2f
|
@ -41,7 +41,10 @@ public:
|
|||
|
||||
while (aFrames > 0) {
|
||||
uint32_t samples = GetChunkSamples(aFrames, aChannels, maxSlop);
|
||||
auto buffer = MakeUnique<AudioDataValue[]>(samples);
|
||||
AlignedAudioBuffer buffer(samples);
|
||||
if (!buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy audio data to buffer using caller-provided functor.
|
||||
uint32_t framesCopied = aCopyFunc(buffer.get(), samples);
|
||||
|
|
|
@ -46,7 +46,8 @@ AudioData::EnsureAudioBuffer()
|
|||
size_t
|
||||
AudioData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
size_t size = aMallocSizeOf(this) + aMallocSizeOf(mAudioData.get());
|
||||
size_t size =
|
||||
aMallocSizeOf(this) + mAudioData.SizeOfExcludingThis(aMallocSizeOf);
|
||||
if (mAudioBuffer) {
|
||||
size += mAudioBuffer->SizeOfIncludingThis(aMallocSizeOf);
|
||||
}
|
||||
|
|
|
@ -352,7 +352,7 @@ public:
|
|||
int64_t aTime,
|
||||
int64_t aDuration,
|
||||
uint32_t aFrames,
|
||||
UniquePtr<AudioDataValue[]> aData,
|
||||
AlignedAudioBuffer&& aData,
|
||||
uint32_t aChannels,
|
||||
uint32_t aRate)
|
||||
: MediaData(sType, aOffset, aTime, aDuration, aFrames)
|
||||
|
@ -387,7 +387,7 @@ public:
|
|||
// mChannels channels, each with mFrames frames
|
||||
RefPtr<SharedBuffer> mAudioBuffer;
|
||||
// mFrames frames, each with mChannels values
|
||||
UniquePtr<AudioDataValue[]> mAudioData;
|
||||
AlignedAudioBuffer mAudioData;
|
||||
|
||||
protected:
|
||||
~AudioData() {}
|
||||
|
|
|
@ -2511,7 +2511,10 @@ MediaDecoderStateMachine::DropAudioUpToSeekTarget(MediaData* aSample)
|
|||
}
|
||||
uint32_t frames = audio->mFrames - static_cast<uint32_t>(framesToPrune.value());
|
||||
uint32_t channels = audio->mChannels;
|
||||
auto audioData = MakeUnique<AudioDataValue[]>(frames * channels);
|
||||
AlignedAudioBuffer audioData(frames * channels);
|
||||
if (!audioData) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(audioData.get(),
|
||||
audio->mAudioData.get() + (framesToPrune.value() * channels),
|
||||
frames * channels * sizeof(AudioDataValue));
|
||||
|
|
|
@ -528,7 +528,10 @@ nsresult OggReader::DecodeVorbis(ogg_packet* aPacket) {
|
|||
ogg_int64_t endFrame = aPacket->granulepos;
|
||||
while ((frames = vorbis_synthesis_pcmout(&mVorbisState->mDsp, &pcm)) > 0) {
|
||||
mVorbisState->ValidateVorbisPacketSamples(aPacket, frames);
|
||||
auto buffer = MakeUnique<AudioDataValue[]>(frames * channels);
|
||||
AlignedAudioBuffer buffer(frames * channels);
|
||||
if (!buffer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
for (uint32_t j = 0; j < channels; ++j) {
|
||||
VorbisPCMValue* channel = pcm[j];
|
||||
for (uint32_t i = 0; i < uint32_t(frames); ++i) {
|
||||
|
@ -577,7 +580,10 @@ nsresult OggReader::DecodeOpus(ogg_packet* aPacket) {
|
|||
if (frames < 120 || frames > 5760)
|
||||
return NS_ERROR_FAILURE;
|
||||
uint32_t channels = mOpusState->mChannels;
|
||||
auto buffer = MakeUnique<AudioDataValue[]>(frames * channels);
|
||||
AlignedAudioBuffer buffer(frames * channels);
|
||||
if (!buffer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Decode to the appropriate sample type.
|
||||
#ifdef MOZ_SAMPLE_TYPE_FLOAT32
|
||||
|
@ -617,7 +623,10 @@ nsresult OggReader::DecodeOpus(ogg_packet* aPacket) {
|
|||
}
|
||||
int32_t keepFrames = frames - skipFrames;
|
||||
int samples = keepFrames * channels;
|
||||
auto trimBuffer = MakeUnique<AudioDataValue[]>(samples);
|
||||
AlignedAudioBuffer trimBuffer(samples);
|
||||
if (!trimBuffer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int i = 0; i < samples; i++)
|
||||
trimBuffer[i] = buffer[skipFrames*channels + i];
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#include "mozilla/mozalloc.h" // for operator new, and new (fallible)
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/TaskQueue.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/UniquePtrExtensions.h"
|
||||
#include "nsRect.h"
|
||||
#include "PlatformDecoderModule.h"
|
||||
#include "TimeUnits.h"
|
||||
|
@ -194,8 +192,7 @@ public:
|
|||
frames.value() > (UINT32_MAX / mChannelCount)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto samples =
|
||||
MakeUniqueFallible<AudioDataValue[]>(frames.value() * mChannelCount);
|
||||
AlignedAudioBuffer samples(frames.value() * mChannelCount);
|
||||
if (!samples) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,10 @@ OpusDataDecoder::DoDecode(MediaRawData* aSample)
|
|||
return -1;
|
||||
}
|
||||
|
||||
auto buffer = MakeUnique<AudioDataValue[]>(frames * channels);
|
||||
AlignedAudioBuffer buffer(frames * channels);
|
||||
if (!buffer) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Decode to the appropriate sample type.
|
||||
#ifdef MOZ_SAMPLE_TYPE_FLOAT32
|
||||
|
|
|
@ -184,13 +184,16 @@ VorbisDataDecoder::DoDecode(MediaRawData* aSample)
|
|||
aTstampUsecs,
|
||||
0,
|
||||
0,
|
||||
nullptr,
|
||||
AlignedAudioBuffer(),
|
||||
mVorbisDsp.vi->channels,
|
||||
mVorbisDsp.vi->rate));
|
||||
}
|
||||
while (frames > 0) {
|
||||
uint32_t channels = mVorbisDsp.vi->channels;
|
||||
auto buffer = MakeUnique<AudioDataValue[]>(frames*channels);
|
||||
AlignedAudioBuffer buffer(frames*channels);
|
||||
if (!buffer) {
|
||||
return -1;
|
||||
}
|
||||
for (uint32_t j = 0; j < channels; ++j) {
|
||||
VorbisPCMValue* channel = pcm[j];
|
||||
for (uint32_t i = 0; i < uint32_t(frames); ++i) {
|
||||
|
|
|
@ -99,7 +99,10 @@ WaveDataDecoder::DoDecode(MediaRawData* aSample)
|
|||
|
||||
int32_t frames = aLength * 8 / mInfo.mBitDepth / mInfo.mChannels;
|
||||
|
||||
auto buffer = MakeUnique<AudioDataValue[]>(frames * mInfo.mChannels);
|
||||
AlignedAudioBuffer buffer(frames * mInfo.mChannels);
|
||||
if (!buffer) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < frames; ++i) {
|
||||
for (unsigned int j = 0; j < mInfo.mChannels; ++j) {
|
||||
if (mInfo.mProfile == 6) { //ALAW Data
|
||||
|
|
|
@ -37,7 +37,11 @@ AudioCallbackAdapter::Decoded(const nsTArray<int16_t>& aPCM, uint64_t aTimeStamp
|
|||
|
||||
size_t numFrames = aPCM.Length() / aChannels;
|
||||
MOZ_ASSERT((aPCM.Length() % aChannels) == 0);
|
||||
auto audioData = MakeUnique<AudioDataValue[]>(aPCM.Length());
|
||||
AlignedAudioBuffer audioData(aPCM.Length());
|
||||
if (!audioData) {
|
||||
mCallback->Error();
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < aPCM.Length(); ++i) {
|
||||
audioData[i] = AudioSampleToFloat(aPCM[i]);
|
||||
|
|
|
@ -218,7 +218,10 @@ public:
|
|||
#endif
|
||||
|
||||
const int32_t numFrames = numSamples / numChannels;
|
||||
auto audio = MakeUnique<AudioDataValue[]>(numSamples);
|
||||
AlignedAudioBuffer audio(numSamples);
|
||||
if (!audio) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
const uint8_t* bufferStart = static_cast<uint8_t*>(aBuffer) + offset;
|
||||
PodCopy(audio.get(), reinterpret_cast<const AudioDataValue*>(bufferStart),
|
||||
|
|
|
@ -220,7 +220,10 @@ AppleATDecoder::DecodeSample(MediaRawData* aSample)
|
|||
{ channels, (UInt32)aSample->Size(), aSample->Data() };
|
||||
|
||||
// Decompressed audio buffer
|
||||
auto decoded = MakeUnique<AudioDataValue[]>(maxDecodedSamples);
|
||||
AlignedAudioBuffer decoded(maxDecodedSamples);
|
||||
if (!decoded) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
do {
|
||||
AudioBufferList decBuffer;
|
||||
|
@ -273,7 +276,10 @@ AppleATDecoder::DecodeSample(MediaRawData* aSample)
|
|||
duration.ToSeconds());
|
||||
#endif
|
||||
|
||||
auto data = MakeUnique<AudioDataValue[]>(outputData.Length());
|
||||
AlignedAudioBuffer data(outputData.Length());
|
||||
if (!data) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
PodCopy(data.get(), &outputData[0], outputData.Length());
|
||||
RefPtr<AudioData> audio = new AudioData(aSample->mOffset,
|
||||
aSample->mTime,
|
||||
|
|
|
@ -48,12 +48,15 @@ FFmpegAudioDecoder<LIBAV_VER>::InitCodecContext()
|
|||
(mLib->mVersion == 53) ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_FLT;
|
||||
}
|
||||
|
||||
static UniquePtr<AudioDataValue[]>
|
||||
static AlignedAudioBuffer
|
||||
CopyAndPackAudio(AVFrame* aFrame, uint32_t aNumChannels, uint32_t aNumAFrames)
|
||||
{
|
||||
MOZ_ASSERT(aNumChannels <= MAX_CHANNELS);
|
||||
|
||||
auto audio = MakeUnique<AudioDataValue[]>(aNumChannels * aNumAFrames);
|
||||
AlignedAudioBuffer audio(aNumChannels * aNumAFrames);
|
||||
if (!audio) {
|
||||
return audio;
|
||||
}
|
||||
|
||||
if (aFrame->format == AV_SAMPLE_FMT_FLT) {
|
||||
// Audio data already packed. No need to do anything other than copy it
|
||||
|
@ -127,12 +130,12 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePacket(MediaRawData* aSample)
|
|||
uint32_t numChannels = mCodecContext->channels;
|
||||
uint32_t samplingRate = mCodecContext->sample_rate;
|
||||
|
||||
UniquePtr<AudioDataValue[]> audio =
|
||||
AlignedAudioBuffer audio =
|
||||
CopyAndPackAudio(mFrame, numChannels, mFrame->nb_samples);
|
||||
|
||||
media::TimeUnit duration =
|
||||
FramesToTimeUnit(mFrame->nb_samples, samplingRate);
|
||||
if (!duration.IsValid()) {
|
||||
if (!audio || !duration.IsValid()) {
|
||||
NS_WARNING("Invalid count of accumulated audio samples");
|
||||
mCallback->Error();
|
||||
return;
|
||||
|
|
|
@ -290,7 +290,10 @@ WMFAudioMFTManager::Output(int64_t aStreamOffset,
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
auto audioData = MakeUnique<AudioDataValue[]>(numSamples);
|
||||
AlignedAudioBuffer audioData(numSamples);
|
||||
if (!audioData) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
int16_t* pcm = (int16_t*)data;
|
||||
for (int32_t i = 0; i < numSamples; ++i) {
|
||||
|
|
|
@ -218,7 +218,10 @@ bool WaveReader::DecodeAudioData()
|
|||
sizeof(AudioDataValue) / MAX_CHANNELS,
|
||||
"bufferSize calculation could overflow.");
|
||||
const size_t bufferSize = static_cast<size_t>(frames * mChannels);
|
||||
auto sampleBuffer = MakeUnique<AudioDataValue[]>(bufferSize);
|
||||
AlignedAudioBuffer sampleBuffer(bufferSize);
|
||||
if (!sampleBuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static_assert(uint64_t(BLOCK_SIZE) < UINT_MAX / sizeof(char),
|
||||
"BLOCK_SIZE too large for enumerator.");
|
||||
|
|
Загрузка…
Ссылка в новой задаче