OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/audio_mixer_alsa.h" | 5 #include "chrome/browser/chromeos/audio_mixer_alsa.h" |
6 | 6 |
7 #include <alsa/asoundlib.h> | 7 #include <alsa/asoundlib.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" |
10 #include "base/task.h" | 11 #include "base/task.h" |
11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/browser_thread.h" | 14 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 | 17 |
17 namespace chromeos { | 18 namespace chromeos { |
18 | 19 |
19 // Connect to the ALSA mixer using their simple element API. Init is performed | 20 // Connect to the ALSA mixer using their simple element API. Init is performed |
20 // asynchronously on the worker thread. | 21 // asynchronously on the worker thread. |
21 // | 22 // |
22 // To get a wider range and finer control over volume levels, first the Master | 23 // To get a wider range and finer control over volume levels, first the Master |
23 // level is set, then if the PCM element exists, the total level is refined by | 24 // level is set, then if the PCM element exists, the total level is refined by |
24 // adjusting that as well. If the PCM element has more volume steps, it allows | 25 // adjusting that as well. If the PCM element has more volume steps, it allows |
25 // for finer granularity in the total volume. | 26 // for finer granularity in the total volume. |
26 | 27 |
27 typedef long alsa_long_t; // 'long' is required for ALSA API calls. | 28 typedef long alsa_long_t; // 'long' is required for ALSA API calls. |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const char* kMasterVolume = "Master"; | 32 const char kMasterVolume[] = "Master"; |
32 const char* kPCMVolume = "PCM"; | 33 const char kPCMVolume[] = "PCM"; |
33 const double kDefaultMinVolume = -90.0; | 34 const double kDefaultMinVolume = -90.0; |
34 const double kDefaultMaxVolume = 0.0; | 35 const double kDefaultMaxVolume = 0.0; |
35 const double kPrefVolumeInvalid = -999.0; | 36 const double kPrefVolumeInvalid = -999.0; |
36 const int kPrefMuteOff = 0; | 37 const int kPrefMuteOff = 0; |
37 const int kPrefMuteOn = 1; | 38 const int kPrefMuteOn = 1; |
38 const int kPrefMuteInvalid = 2; | 39 const int kPrefMuteInvalid = 2; |
39 | 40 |
40 } // namespace | 41 } // namespace |
41 | 42 |
42 AudioMixerAlsa::AudioMixerAlsa() | 43 AudioMixerAlsa::AudioMixerAlsa() |
43 : min_volume_(kDefaultMinVolume), | 44 : min_volume_(kDefaultMinVolume), |
44 max_volume_(kDefaultMaxVolume), | 45 max_volume_(kDefaultMaxVolume), |
45 save_volume_(0), | 46 save_volume_(0), |
46 mixer_state_(UNINITIALIZED), | 47 mixer_state_(UNINITIALIZED), |
47 alsa_mixer_(NULL), | 48 alsa_mixer_(NULL), |
48 elem_master_(NULL), | 49 elem_master_(NULL), |
49 elem_pcm_(NULL) { | 50 elem_pcm_(NULL) { |
50 } | 51 } |
51 | 52 |
52 AudioMixerAlsa::~AudioMixerAlsa() { | 53 AudioMixerAlsa::~AudioMixerAlsa() { |
53 FreeAlsaMixer(); | 54 FreeAlsaMixer(); |
54 if (thread_ != NULL) { | 55 if (thread_ != NULL) { |
55 // A ScopedAllowIO object is required to join the thread when calling Stop. | 56 // A ScopedAllowIO object is required to join the thread when calling Stop. |
56 // The worker thread should be idle at this time. | 57 // The worker thread should be idle at this time. |
57 // See http://crosbug.com/11110 for discussion. | 58 // See http://crosbug.com/11110 for discussion. |
58 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; | 59 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |
| 60 thread_->message_loop()->AssertIdle(); |
59 | 61 |
60 thread_->Stop(); | 62 thread_->Stop(); |
61 thread_.reset(); | 63 thread_.reset(); |
62 } | 64 } |
63 } | 65 } |
64 | 66 |
65 void AudioMixerAlsa::Init(InitDoneCallback* callback) { | 67 void AudioMixerAlsa::Init(InitDoneCallback* callback) { |
66 DCHECK(callback); | 68 DCHECK(callback); |
67 if (!InitThread()) { | 69 if (!InitThread()) { |
68 callback->Run(false); | 70 callback->Run(false); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 439 |
438 void AudioMixerAlsa::SetElementMuted_Locked(snd_mixer_elem_t* elem, bool mute) { | 440 void AudioMixerAlsa::SetElementMuted_Locked(snd_mixer_elem_t* elem, bool mute) { |
439 int enabled = mute ? 0 : 1; | 441 int enabled = mute ? 0 : 1; |
440 snd_mixer_selem_set_playback_switch_all(elem, enabled); | 442 snd_mixer_selem_set_playback_switch_all(elem, enabled); |
441 | 443 |
442 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) | 444 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) |
443 << " to " << enabled; | 445 << " to " << enabled; |
444 } | 446 } |
445 | 447 |
446 } // namespace chromeos | 448 } // namespace chromeos |
447 | |
OLD | NEW |