Bug 673154 - Use nsAutoArrayPtr for SoundDataValue allocations to simplify ownership. r=cpearce

This commit is contained in:
David Volgyes 2011-07-29 13:54:21 +12:00
Родитель 2f39e6408b
Коммит e446815189
2 изменённых файлов: 14 добавлений и 16 удалений

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

@ -369,7 +369,7 @@ nsresult nsOggReader::DecodeVorbis(ogg_packet* aPacket) {
ogg_int64_t endSample = aPacket->granulepos; ogg_int64_t endSample = aPacket->granulepos;
while ((samples = vorbis_synthesis_pcmout(&mVorbisState->mDsp, &pcm)) > 0) { while ((samples = vorbis_synthesis_pcmout(&mVorbisState->mDsp, &pcm)) > 0) {
mVorbisState->ValidateVorbisPacketSamples(aPacket, samples); mVorbisState->ValidateVorbisPacketSamples(aPacket, samples);
SoundDataValue* buffer = new SoundDataValue[samples * channels]; nsAutoArrayPtr<SoundDataValue> buffer(new SoundDataValue[samples * channels]);
for (PRUint32 j = 0; j < channels; ++j) { for (PRUint32 j = 0; j < channels; ++j) {
VorbisPCMValue* channel = pcm[j]; VorbisPCMValue* channel = pcm[j];
for (PRUint32 i = 0; i < PRUint32(samples); ++i) { for (PRUint32 i = 0; i < PRUint32(samples); ++i) {
@ -379,13 +379,12 @@ nsresult nsOggReader::DecodeVorbis(ogg_packet* aPacket) {
PRInt64 duration = mVorbisState->Time((PRInt64)samples); PRInt64 duration = mVorbisState->Time((PRInt64)samples);
PRInt64 startTime = mVorbisState->Time(endSample - samples); PRInt64 startTime = mVorbisState->Time(endSample - samples);
SoundData* s = new SoundData(mPageOffset, mAudioQueue.Push(new SoundData(mPageOffset,
startTime, startTime,
duration, duration,
samples, samples,
buffer, buffer.forget(),
channels); channels));
mAudioQueue.Push(s);
endSample -= samples; endSample -= samples;
if (vorbis_synthesis_read(&mVorbisState->mDsp, samples) != 0) { if (vorbis_synthesis_read(&mVorbisState->mDsp, samples) != 0) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;

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

@ -484,7 +484,7 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset)
VorbisPCMValue** pcm = 0; VorbisPCMValue** pcm = 0;
PRInt32 samples = 0; PRInt32 samples = 0;
while ((samples = vorbis_synthesis_pcmout(&mVorbisDsp, &pcm)) > 0) { while ((samples = vorbis_synthesis_pcmout(&mVorbisDsp, &pcm)) > 0) {
SoundDataValue* buffer = new SoundDataValue[samples * mChannels]; nsAutoArrayPtr<SoundDataValue> buffer(new SoundDataValue[samples * mChannels]);
for (PRUint32 j = 0; j < mChannels; ++j) { for (PRUint32 j = 0; j < mChannels; ++j) {
VorbisPCMValue* channel = pcm[j]; VorbisPCMValue* channel = pcm[j];
for (PRUint32 i = 0; i < PRUint32(samples); ++i) { for (PRUint32 i = 0; i < PRUint32(samples); ++i) {
@ -505,13 +505,12 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset)
PRInt64 time = tstamp_usecs + total_duration; PRInt64 time = tstamp_usecs + total_duration;
total_samples += samples; total_samples += samples;
SoundData* s = new SoundData(aOffset, mAudioQueue.Push(new SoundData(aOffset,
time, time,
duration, duration,
samples, samples,
buffer, buffer.forget(),
mChannels); mChannels));
mAudioQueue.Push(s);
mAudioSamples += samples; mAudioSamples += samples;
if (vorbis_synthesis_read(&mVorbisDsp, samples) != 0) { if (vorbis_synthesis_read(&mVorbisDsp, samples) != 0) {
return PR_FALSE; return PR_FALSE;