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