Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: Source/core/platform/audio/HRTFElevation.cpp

Issue 23613007: Fix threading races on HRTFElevation::audioBusMap (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 19 matching lines...) Expand all
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 32
33 #include "core/platform/audio/HRTFElevation.h" 33 #include "core/platform/audio/HRTFElevation.h"
34 34
35 #include <math.h> 35 #include <math.h>
36 #include <algorithm> 36 #include <algorithm>
37 #include "core/platform/audio/AudioBus.h" 37 #include "core/platform/audio/AudioBus.h"
38 #include "core/platform/audio/HRTFPanner.h" 38 #include "core/platform/audio/HRTFPanner.h"
39 #include "wtf/OwnPtr.h" 39 #include "wtf/OwnPtr.h"
40 #include "wtf/ThreadingPrimitives.h"
40 41
41 using namespace std; 42 using namespace std;
42 43
43 namespace WebCore { 44 namespace WebCore {
44 45
45 const unsigned HRTFElevation::AzimuthSpacing = 15; 46 const unsigned HRTFElevation::AzimuthSpacing = 15;
46 const unsigned HRTFElevation::NumberOfRawAzimuths = 360 / AzimuthSpacing; 47 const unsigned HRTFElevation::NumberOfRawAzimuths = 360 / AzimuthSpacing;
47 const unsigned HRTFElevation::InterpolationFactor = 8; 48 const unsigned HRTFElevation::InterpolationFactor = 8;
48 const unsigned HRTFElevation::NumberOfTotalAzimuths = NumberOfRawAzimuths * Inte rpolationFactor; 49 const unsigned HRTFElevation::NumberOfTotalAzimuths = NumberOfRawAzimuths * Inte rpolationFactor;
49 50
50 // Total number of components of an HRTF database. 51 // Total number of components of an HRTF database.
51 const size_t TotalNumberOfResponses = 240; 52 const size_t TotalNumberOfResponses = 240;
52 53
53 // Number of frames in an individual impulse response. 54 // Number of frames in an individual impulse response.
54 const size_t ResponseFrameSize = 256; 55 const size_t ResponseFrameSize = 256;
55 56
56 // Sample-rate of the spatialization impulse responses as stored in the resource file. 57 // Sample-rate of the spatialization impulse responses as stored in the resource file.
57 // The impulse responses may be resampled to a different sample-rate (depending on the audio hardware) when they are loaded. 58 // The impulse responses may be resampled to a different sample-rate (depending on the audio hardware) when they are loaded.
58 const float ResponseSampleRate = 44100; 59 const float ResponseSampleRate = 44100;
59 60
60 #if USE(CONCATENATED_IMPULSE_RESPONSES) 61 #if USE(CONCATENATED_IMPULSE_RESPONSES)
61 // Lazily load a concatenated HRTF database for given subject and store it in a 62 // Lazily load a concatenated HRTF database for given subject and store it in a
62 // local hash table to ensure quick efficient future retrievals. 63 // local hash table to ensure quick efficient future retrievals.
63 static PassRefPtr<AudioBus> getConcatenatedImpulseResponsesForSubject(const Stri ng& subjectName) 64 static PassRefPtr<AudioBus> getConcatenatedImpulseResponsesForSubject(const Stri ng& subjectName)
64 { 65 {
65 typedef HashMap<String, RefPtr<AudioBus> > AudioBusMap; 66 typedef HashMap<String, RefPtr<AudioBus> > AudioBusMap;
66 DEFINE_STATIC_LOCAL(AudioBusMap, audioBusMap, ()); 67 DEFINE_STATIC_LOCAL(AudioBusMap, audioBusMap, ());
68 DEFINE_STATIC_LOCAL(Mutex, mutex, ());
Ken Russell (switch to Gerrit) 2013/09/04 19:57:55 This doesn't look any safer to me. If there is rea
67 69
70 MutexLocker locker(mutex);
68 RefPtr<AudioBus> bus; 71 RefPtr<AudioBus> bus;
69 AudioBusMap::iterator iterator = audioBusMap.find(subjectName); 72 AudioBusMap::iterator iterator = audioBusMap.find(subjectName);
70 if (iterator == audioBusMap.end()) { 73 if (iterator == audioBusMap.end()) {
71 RefPtr<AudioBus> concatenatedImpulseResponses(AudioBus::loadPlatformReso urce(subjectName.utf8().data(), ResponseSampleRate)); 74 RefPtr<AudioBus> concatenatedImpulseResponses(AudioBus::loadPlatformReso urce(subjectName.utf8().data(), ResponseSampleRate));
72 ASSERT(concatenatedImpulseResponses); 75 ASSERT(concatenatedImpulseResponses);
73 if (!concatenatedImpulseResponses) 76 if (!concatenatedImpulseResponses)
74 return 0; 77 return 0;
75 78
76 bus = concatenatedImpulseResponses; 79 bus = concatenatedImpulseResponses;
77 audioBusMap.set(subjectName, bus); 80 audioBusMap.set(subjectName, bus);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay(); 333 double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay();
331 334
332 // Linearly interpolate delays. 335 // Linearly interpolate delays.
333 frameDelayL = (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay 2L; 336 frameDelayL = (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay 2L;
334 frameDelayR = (1.0 - azimuthBlend) * frameDelayR + azimuthBlend * frameDelay 2R; 337 frameDelayR = (1.0 - azimuthBlend) * frameDelayR + azimuthBlend * frameDelay 2R;
335 } 338 }
336 339
337 } // namespace WebCore 340 } // namespace WebCore
338 341
339 #endif // ENABLE(WEB_AUDIO) 342 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698