Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "WebAudioUtils.h" |
michael@0 | 8 | #include "AudioNodeStream.h" |
michael@0 | 9 | #include "AudioParamTimeline.h" |
michael@0 | 10 | #include "blink/HRTFDatabaseLoader.h" |
michael@0 | 11 | #include "speex/speex_resampler.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | |
michael@0 | 15 | namespace dom { |
michael@0 | 16 | |
michael@0 | 17 | struct ConvertTimeToTickHelper |
michael@0 | 18 | { |
michael@0 | 19 | AudioNodeStream* mSourceStream; |
michael@0 | 20 | AudioNodeStream* mDestinationStream; |
michael@0 | 21 | |
michael@0 | 22 | static int64_t Convert(double aTime, void* aClosure) |
michael@0 | 23 | { |
michael@0 | 24 | ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure); |
michael@0 | 25 | MOZ_ASSERT(This->mSourceStream->SampleRate() == This->mDestinationStream->SampleRate()); |
michael@0 | 26 | return This->mSourceStream-> |
michael@0 | 27 | TicksFromDestinationTime(This->mDestinationStream, aTime); |
michael@0 | 28 | } |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | void |
michael@0 | 32 | WebAudioUtils::ConvertAudioParamToTicks(AudioParamTimeline& aParam, |
michael@0 | 33 | AudioNodeStream* aSource, |
michael@0 | 34 | AudioNodeStream* aDest) |
michael@0 | 35 | { |
michael@0 | 36 | MOZ_ASSERT(!aSource || aSource->SampleRate() == aDest->SampleRate()); |
michael@0 | 37 | ConvertTimeToTickHelper ctth; |
michael@0 | 38 | ctth.mSourceStream = aSource; |
michael@0 | 39 | ctth.mDestinationStream = aDest; |
michael@0 | 40 | aParam.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth, aDest->SampleRate()); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void |
michael@0 | 44 | WebAudioUtils::Shutdown() |
michael@0 | 45 | { |
michael@0 | 46 | WebCore::HRTFDatabaseLoader::shutdown(); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | int |
michael@0 | 50 | WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler, |
michael@0 | 51 | uint32_t aChannel, |
michael@0 | 52 | const float* aIn, uint32_t* aInLen, |
michael@0 | 53 | float* aOut, uint32_t* aOutLen) |
michael@0 | 54 | { |
michael@0 | 55 | #ifdef MOZ_SAMPLE_TYPE_S16 |
michael@0 | 56 | nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp1; |
michael@0 | 57 | nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp2; |
michael@0 | 58 | tmp1.SetLength(*aInLen); |
michael@0 | 59 | tmp2.SetLength(*aOutLen); |
michael@0 | 60 | ConvertAudioSamples(aIn, tmp1.Elements(), *aInLen); |
michael@0 | 61 | int result = speex_resampler_process_int(aResampler, aChannel, tmp1.Elements(), aInLen, tmp2.Elements(), aOutLen); |
michael@0 | 62 | ConvertAudioSamples(tmp2.Elements(), aOut, *aOutLen); |
michael@0 | 63 | return result; |
michael@0 | 64 | #else |
michael@0 | 65 | return speex_resampler_process_float(aResampler, aChannel, aIn, aInLen, aOut, aOutLen); |
michael@0 | 66 | #endif |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | int |
michael@0 | 70 | WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler, |
michael@0 | 71 | uint32_t aChannel, |
michael@0 | 72 | const int16_t* aIn, uint32_t* aInLen, |
michael@0 | 73 | float* aOut, uint32_t* aOutLen) |
michael@0 | 74 | { |
michael@0 | 75 | nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp; |
michael@0 | 76 | #ifdef MOZ_SAMPLE_TYPE_S16 |
michael@0 | 77 | tmp.SetLength(*aOutLen); |
michael@0 | 78 | int result = speex_resampler_process_int(aResampler, aChannel, aIn, aInLen, tmp.Elements(), aOutLen); |
michael@0 | 79 | ConvertAudioSamples(tmp.Elements(), aOut, *aOutLen); |
michael@0 | 80 | return result; |
michael@0 | 81 | #else |
michael@0 | 82 | tmp.SetLength(*aInLen); |
michael@0 | 83 | ConvertAudioSamples(aIn, tmp.Elements(), *aInLen); |
michael@0 | 84 | int result = speex_resampler_process_float(aResampler, aChannel, tmp.Elements(), aInLen, aOut, aOutLen); |
michael@0 | 85 | return result; |
michael@0 | 86 | #endif |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | int |
michael@0 | 90 | WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler, |
michael@0 | 91 | uint32_t aChannel, |
michael@0 | 92 | const int16_t* aIn, uint32_t* aInLen, |
michael@0 | 93 | int16_t* aOut, uint32_t* aOutLen) |
michael@0 | 94 | { |
michael@0 | 95 | #ifdef MOZ_SAMPLE_TYPE_S16 |
michael@0 | 96 | return speex_resampler_process_int(aResampler, aChannel, aIn, aInLen, aOut, aOutLen); |
michael@0 | 97 | #else |
michael@0 | 98 | nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp1; |
michael@0 | 99 | nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp2; |
michael@0 | 100 | tmp1.SetLength(*aInLen); |
michael@0 | 101 | tmp2.SetLength(*aOutLen); |
michael@0 | 102 | ConvertAudioSamples(aIn, tmp1.Elements(), *aInLen); |
michael@0 | 103 | int result = speex_resampler_process_float(aResampler, aChannel, tmp1.Elements(), aInLen, tmp2.Elements(), aOutLen); |
michael@0 | 104 | ConvertAudioSamples(tmp2.Elements(), aOut, *aOutLen); |
michael@0 | 105 | return result; |
michael@0 | 106 | #endif |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | } |
michael@0 | 110 | } |