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

Side by Side Diff: media/audio/simple_sources.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 years, 10 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
« no previous file with comments | « media/audio/audio_manager.cc ('k') | media/base/android/media_drm_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // MSVC++ requires this to be set before any other includes to get M_PI. 4 // MSVC++ requires this to be set before any other includes to get M_PI.
5 #define _USE_MATH_DEFINES 5 #define _USE_MATH_DEFINES
6 6
7 #include "media/audio/simple_sources.h" 7 #include "media/audio/simple_sources.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <cmath> 12 #include <cmath>
13 13
14 #include "base/files/file.h" 14 #include "base/files/file.h"
15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/time/time.h" 16 #include "base/time/time.h"
18 #include "media/audio/sounds/wav_audio_handler.h" 17 #include "media/audio/sounds/wav_audio_handler.h"
19 #include "media/base/audio_bus.h" 18 #include "media/base/audio_bus.h"
20 19
21 namespace media { 20 namespace media {
22 namespace { 21 namespace {
23 // Opens |wav_filename|, reads it and loads it as a wav file. This function will 22 // Opens |wav_filename|, reads it and loads it as a wav file. This function will
24 // return a null pointer if we can't read the file or if it's malformed. The 23 // return a null pointer if we can't read the file or if it's malformed. The
25 // caller takes ownership of the returned data. The size of the data is stored 24 // caller takes ownership of the returned data. The size of the data is stored
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 base::AutoLock auto_lock(lock_); 86 base::AutoLock auto_lock(lock_);
88 return automatic_beep_; 87 return automatic_beep_;
89 } 88 }
90 89
91 private: 90 private:
92 mutable base::Lock lock_; 91 mutable base::Lock lock_;
93 bool beep_once_; 92 bool beep_once_;
94 bool automatic_beep_; 93 bool automatic_beep_;
95 }; 94 };
96 95
97 static base::LazyInstance<BeepContext>::Leaky g_beep_context = 96 BeepContext* GetBeepContext() {
98 LAZY_INSTANCE_INITIALIZER; 97 static BeepContext* context = new BeepContext();
98 return context;
99 }
100
99 } // namespace 101 } // namespace
100 102
101 ////////////////////////////////////////////////////////////////////////////// 103 //////////////////////////////////////////////////////////////////////////////
102 // SineWaveAudioSource implementation. 104 // SineWaveAudioSource implementation.
103 105
104 SineWaveAudioSource::SineWaveAudioSource(int channels, 106 SineWaveAudioSource::SineWaveAudioSource(int channels,
105 double freq, double sample_freq) 107 double freq, double sample_freq)
106 : channels_(channels), 108 : channels_(channels),
107 f_(freq / sample_freq), 109 f_(freq / sample_freq),
108 time_state_(0), 110 time_state_(0),
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 265
264 int BeepingSource::OnMoreData(base::TimeDelta /* delay */, 266 int BeepingSource::OnMoreData(base::TimeDelta /* delay */,
265 base::TimeTicks /* delay_timestamp */, 267 base::TimeTicks /* delay_timestamp */,
266 int /* prior_frames_skipped */, 268 int /* prior_frames_skipped */,
267 AudioBus* dest) { 269 AudioBus* dest) {
268 // Accumulate the time from the last beep. 270 // Accumulate the time from the last beep.
269 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; 271 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_;
270 272
271 memset(buffer_.get(), 0, buffer_size_); 273 memset(buffer_.get(), 0, buffer_size_);
272 bool should_beep = false; 274 bool should_beep = false;
273 BeepContext* beep_context = g_beep_context.Pointer(); 275 BeepContext* beep_context = GetBeepContext();
274 if (beep_context->automatic_beep()) { 276 if (beep_context->automatic_beep()) {
275 base::TimeDelta delta = interval_from_last_beep_ - 277 base::TimeDelta delta = interval_from_last_beep_ -
276 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); 278 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs);
277 if (delta > base::TimeDelta()) { 279 if (delta > base::TimeDelta()) {
278 should_beep = true; 280 should_beep = true;
279 interval_from_last_beep_ = delta; 281 interval_from_last_beep_ = delta;
280 } 282 }
281 } else { 283 } else {
282 should_beep = beep_context->beep_once(); 284 should_beep = beep_context->beep_once();
283 beep_context->SetBeepOnce(false); 285 beep_context->SetBeepOnce(false);
(...skipping 26 matching lines...) Expand all
310 last_callback_time_ = base::TimeTicks::Now(); 312 last_callback_time_ = base::TimeTicks::Now();
311 dest->FromInterleaved(buffer_.get(), dest->frames(), 313 dest->FromInterleaved(buffer_.get(), dest->frames(),
312 params_.bits_per_sample() / 8); 314 params_.bits_per_sample() / 8);
313 return dest->frames(); 315 return dest->frames();
314 } 316 }
315 317
316 void BeepingSource::OnError(AudioOutputStream* stream) { 318 void BeepingSource::OnError(AudioOutputStream* stream) {
317 } 319 }
318 320
319 void BeepingSource::BeepOnce() { 321 void BeepingSource::BeepOnce() {
320 g_beep_context.Pointer()->SetBeepOnce(true); 322 GetBeepContext()->SetBeepOnce(true);
321 } 323 }
322 324
323 } // namespace media 325 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_manager.cc ('k') | media/base/android/media_drm_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698