| OLD | NEW |
| 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 | 4 |
| 5 #include "media/audio/audio_manager_base.h" | 5 #include "media/audio/audio_manager_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 static const int kMaxInputChannels = 2; | 37 static const int kMaxInputChannels = 2; |
| 38 | 38 |
| 39 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; | 39 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; |
| 40 const char AudioManagerBase::kDefaultDeviceId[] = "default"; | 40 const char AudioManagerBase::kDefaultDeviceId[] = "default"; |
| 41 | 41 |
| 42 AudioManagerBase::AudioManagerBase() | 42 AudioManagerBase::AudioManagerBase() |
| 43 : num_active_input_streams_(0), | 43 : num_active_input_streams_(0), |
| 44 max_num_output_streams_(kDefaultMaxOutputStreams), | 44 max_num_output_streams_(kDefaultMaxOutputStreams), |
| 45 max_num_input_streams_(kDefaultMaxInputStreams), | 45 max_num_input_streams_(kDefaultMaxInputStreams), |
| 46 num_output_streams_(0), | 46 num_output_streams_(0), |
| 47 num_input_streams_(0) { | 47 num_input_streams_(0), |
| 48 audio_thread_(new base::Thread("AudioThread")) { |
| 49 #if defined(OS_WIN) |
| 50 audio_thread_->init_com_with_mta(true); |
| 51 #endif |
| 52 CHECK(audio_thread_->Start()); |
| 53 message_loop_ = audio_thread_->message_loop_proxy(); |
| 54 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 55 &AudioManagerBase::InitializeOnAudioThread, base::Unretained(this))); |
| 48 } | 56 } |
| 49 | 57 |
| 50 AudioManagerBase::~AudioManagerBase() { | 58 AudioManagerBase::~AudioManagerBase() { |
| 51 // The platform specific AudioManager implementation must have already | 59 // The platform specific AudioManager implementation must have already |
| 52 // stopped the audio thread. Otherwise, we may destroy audio streams before | 60 // stopped the audio thread. Otherwise, we may destroy audio streams before |
| 53 // stopping the thread, resulting an unexpected behavior. | 61 // stopping the thread, resulting an unexpected behavior. |
| 54 // This way we make sure activities of the audio streams are all stopped | 62 // This way we make sure activities of the audio streams are all stopped |
| 55 // before we destroy them. | 63 // before we destroy them. |
| 56 CHECK(!audio_thread_.get()); | 64 CHECK(!audio_thread_.get()); |
| 57 // All the output streams should have been deleted. | 65 // All the output streams should have been deleted. |
| 58 DCHECK_EQ(0, num_output_streams_); | 66 DCHECK_EQ(0, num_output_streams_); |
| 59 // All the input streams should have been deleted. | 67 // All the input streams should have been deleted. |
| 60 DCHECK_EQ(0, num_input_streams_); | 68 DCHECK_EQ(0, num_input_streams_); |
| 61 } | 69 } |
| 62 | 70 |
| 63 void AudioManagerBase::Init() { | 71 void AudioManagerBase::InitializeOnAudioThread() { |
| 64 base::AutoLock lock(audio_thread_lock_); | 72 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 65 DCHECK(!audio_thread_.get()); | |
| 66 audio_thread_.reset(new base::Thread("AudioThread")); | |
| 67 #if defined(OS_WIN) | |
| 68 audio_thread_->init_com_with_mta(true); | |
| 69 #endif | |
| 70 CHECK(audio_thread_->Start()); | |
| 71 message_loop_ = audio_thread_->message_loop_proxy(); | |
| 72 } | 73 } |
| 73 | 74 |
| 74 string16 AudioManagerBase::GetAudioInputDeviceModel() { | 75 string16 AudioManagerBase::GetAudioInputDeviceModel() { |
| 75 return string16(); | 76 return string16(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { | 79 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { |
| 79 base::AutoLock lock(audio_thread_lock_); | 80 base::AutoLock lock(audio_thread_lock_); |
| 80 // Don't return |message_loop_| here because we don't want any new tasks to | 81 // Don't return |message_loop_| here because we don't want any new tasks to |
| 81 // come in once we've started tearing down the audio thread. | 82 // come in once we've started tearing down the audio thread. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 output_listeners_.RemoveObserver(listener); | 337 output_listeners_.RemoveObserver(listener); |
| 337 } | 338 } |
| 338 | 339 |
| 339 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() { | 340 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() { |
| 340 DCHECK(message_loop_->BelongsToCurrentThread()); | 341 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 341 DVLOG(1) << "Firing OnDeviceChange() notifications."; | 342 DVLOG(1) << "Firing OnDeviceChange() notifications."; |
| 342 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange()); | 343 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange()); |
| 343 } | 344 } |
| 344 | 345 |
| 345 } // namespace media | 346 } // namespace media |
| OLD | NEW |