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

Side by Side Diff: media/audio/linux/audio_manager_linux.cc

Issue 9255017: Add thread safety to AudioManagerBase to protect access to the audio thread member variable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix style issue Created 8 years, 11 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 | « media/audio/linux/alsa_output_unittest.cc ('k') | 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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 4
5 #include "media/audio/linux/audio_manager_linux.h" 5 #include "media/audio/linux/audio_manager_linux.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/nix/xdg_util.h" 10 #include "base/nix/xdg_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 bool AudioManagerLinux::HasAudioOutputDevices() { 42 bool AudioManagerLinux::HasAudioOutputDevices() {
43 return HasAnyAlsaAudioDevice(kStreamPlayback); 43 return HasAnyAlsaAudioDevice(kStreamPlayback);
44 } 44 }
45 45
46 bool AudioManagerLinux::HasAudioInputDevices() { 46 bool AudioManagerLinux::HasAudioInputDevices() {
47 return HasAnyAlsaAudioDevice(kStreamCapture); 47 return HasAnyAlsaAudioDevice(kStreamCapture);
48 } 48 }
49 49
50 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( 50 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream(
51 const AudioParameters& params) { 51 const AudioParameters& params) {
52 // Early return for testing hook. Do this before checking for 52 // Early return for testing hook.
53 // |initialized_|. 53 if (params.format == AudioParameters::AUDIO_MOCK)
54 if (params.format == AudioParameters::AUDIO_MOCK) {
55 return FakeAudioOutputStream::MakeFakeStream(params); 54 return FakeAudioOutputStream::MakeFakeStream(params);
56 }
57
58 if (!initialized()) {
59 // We should never get here since this method is called on the audio thread.
60 NOTREACHED();
61 return NULL;
62 }
63 55
64 // Don't allow opening more than |kMaxOutputStreams| streams. 56 // Don't allow opening more than |kMaxOutputStreams| streams.
65 if (active_output_stream_count_ >= kMaxOutputStreams) 57 if (active_output_stream_count_ >= kMaxOutputStreams)
66 return NULL; 58 return NULL;
67 59
68 AudioOutputStream* stream = NULL; 60 AudioOutputStream* stream = NULL;
69 #if defined(USE_PULSEAUDIO) 61 #if defined(USE_PULSEAUDIO)
70 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { 62 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
71 stream = new PulseAudioOutputStream(params, this); 63 stream = new PulseAudioOutputStream(params, this);
72 } else { 64 } else {
(...skipping 17 matching lines...) Expand all
90 const AudioParameters& params, const std::string& device_id) { 82 const AudioParameters& params, const std::string& device_id) {
91 if (!params.IsValid() || params.channels > kMaxInputChannels || 83 if (!params.IsValid() || params.channels > kMaxInputChannels ||
92 device_id.empty()) { 84 device_id.empty()) {
93 return NULL; 85 return NULL;
94 } 86 }
95 87
96 if (params.format == AudioParameters::AUDIO_MOCK) { 88 if (params.format == AudioParameters::AUDIO_MOCK) {
97 return FakeAudioInputStream::MakeFakeStream(params); 89 return FakeAudioInputStream::MakeFakeStream(params);
98 } 90 }
99 91
100 if (!initialized())
101 return NULL;
102
103 std::string device_name = (device_id == AudioManagerBase::kDefaultDeviceId) ? 92 std::string device_name = (device_id == AudioManagerBase::kDefaultDeviceId) ?
104 AlsaPcmInputStream::kAutoSelectDevice : device_id; 93 AlsaPcmInputStream::kAutoSelectDevice : device_id;
105 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { 94 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) {
106 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 95 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
107 switches::kAlsaInputDevice); 96 switches::kAlsaInputDevice);
108 } 97 }
109 98
110 AlsaPcmInputStream* stream = new AlsaPcmInputStream(this, 99 AlsaPcmInputStream* stream = new AlsaPcmInputStream(this,
111 device_name, params, wrapper_.get()); 100 device_name, params, wrapper_.get());
112 101
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 << wrapper_->StrError(error); 299 << wrapper_->StrError(error);
311 } 300 }
312 } 301 }
313 302
314 return has_device; 303 return has_device;
315 } 304 }
316 305
317 AudioManager* CreateAudioManager() { 306 AudioManager* CreateAudioManager() {
318 return new AudioManagerLinux(); 307 return new AudioManagerLinux();
319 } 308 }
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_output_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698