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

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

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years 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/audio_input_controller.h ('k') | media/audio/audio_input_controller_unittest.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) 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/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/threading/thread_restrictions.h" 8 #include "base/threading/thread_restrictions.h"
9 #include "media/base/limits.h" 9 #include "media/base/limits.h"
10 10
11 namespace { 11 namespace {
12 const int kMaxInputChannels = 2; 12 const int kMaxInputChannels = 2;
13 const int kTimerResetInterval = 1; // One second. 13 const int kTimerResetInterval = 1; // One second.
14 } 14 }
15 15
16 namespace media { 16 namespace media {
17 17
18 // static 18 // static
19 AudioInputController::Factory* AudioInputController::factory_ = NULL; 19 AudioInputController::Factory* AudioInputController::factory_ = NULL;
20 20
21 AudioInputController::AudioInputController(EventHandler* handler, 21 AudioInputController::AudioInputController(AudioManager* audio_manager,
22 EventHandler* handler,
22 SyncWriter* sync_writer) 23 SyncWriter* sync_writer)
23 : handler_(handler), 24 : audio_manager_(audio_manager),
25 handler_(handler),
24 stream_(NULL), 26 stream_(NULL),
25 ALLOW_THIS_IN_INITIALIZER_LIST(no_data_timer_(FROM_HERE, 27 ALLOW_THIS_IN_INITIALIZER_LIST(no_data_timer_(FROM_HERE,
26 base::TimeDelta::FromSeconds(kTimerResetInterval), 28 base::TimeDelta::FromSeconds(kTimerResetInterval),
27 this, 29 this,
28 &AudioInputController::DoReportNoDataError)), 30 &AudioInputController::DoReportNoDataError)),
29 state_(kEmpty), 31 state_(kEmpty),
30 thread_("AudioInputControllerThread"), 32 thread_("AudioInputControllerThread"),
31 sync_writer_(sync_writer) { 33 sync_writer_(sync_writer) {
34 DCHECK(audio_manager_); // Fail early.
32 } 35 }
33 36
34 AudioInputController::~AudioInputController() { 37 AudioInputController::~AudioInputController() {
35 DCHECK(kClosed == state_ || kCreated == state_ || kEmpty == state_); 38 DCHECK(kClosed == state_ || kCreated == state_ || kEmpty == state_);
36 } 39 }
37 40
38 // static 41 // static
39 scoped_refptr<AudioInputController> AudioInputController::Create( 42 scoped_refptr<AudioInputController> AudioInputController::Create(
43 AudioManager* audio_manager,
40 EventHandler* event_handler, 44 EventHandler* event_handler,
41 const AudioParameters& params) { 45 const AudioParameters& params) {
46 DCHECK(audio_manager);
42 if (!params.IsValid() || (params.channels > kMaxInputChannels)) 47 if (!params.IsValid() || (params.channels > kMaxInputChannels))
43 return NULL; 48 return NULL;
44 49
45 if (factory_) { 50 if (factory_) {
46 return factory_->Create(event_handler, params); 51 return factory_->Create(audio_manager, event_handler, params);
47 } 52 }
48 53
49 scoped_refptr<AudioInputController> controller(new AudioInputController( 54 scoped_refptr<AudioInputController> controller(new AudioInputController(
50 event_handler, NULL)); 55 audio_manager, event_handler, NULL));
51 56
52 // Start the thread and post a task to create the audio input stream. 57 // Start the thread and post a task to create the audio input stream.
53 // Pass an empty string to indicate using default device. 58 // Pass an empty string to indicate using default device.
54 std::string device_id = AudioManagerBase::kDefaultDeviceId; 59 std::string device_id = AudioManagerBase::kDefaultDeviceId;
55 controller->thread_.Start(); 60 controller->thread_.Start();
56 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 61 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
57 &AudioInputController::DoCreate, controller.get(), 62 &AudioInputController::DoCreate, controller.get(),
58 params, device_id)); 63 params, device_id));
59 return controller; 64 return controller;
60 } 65 }
61 66
62 // static 67 // static
63 scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( 68 scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency(
69 AudioManager* audio_manager,
64 EventHandler* event_handler, 70 EventHandler* event_handler,
65 const AudioParameters& params, 71 const AudioParameters& params,
66 const std::string& device_id, 72 const std::string& device_id,
67 SyncWriter* sync_writer) { 73 SyncWriter* sync_writer) {
74 DCHECK(audio_manager);
68 DCHECK(sync_writer); 75 DCHECK(sync_writer);
69 76
70 if (!params.IsValid() || (params.channels > kMaxInputChannels)) 77 if (!params.IsValid() || (params.channels > kMaxInputChannels))
71 return NULL; 78 return NULL;
72 79
73 if (!AudioManager::GetAudioManager())
74 return NULL;
75
76 // Starts the audio controller thread. 80 // Starts the audio controller thread.
77 scoped_refptr<AudioInputController> controller(new AudioInputController( 81 scoped_refptr<AudioInputController> controller(new AudioInputController(
78 event_handler, sync_writer)); 82 audio_manager, event_handler, sync_writer));
79 83
80 // Start the thread and post a task to create the audio input stream. 84 // Start the thread and post a task to create the audio input stream.
81 controller->thread_.Start(); 85 controller->thread_.Start();
82 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 86 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
83 &AudioInputController::DoCreate, controller.get(), params, device_id)); 87 &AudioInputController::DoCreate, controller.get(), params, device_id));
84 return controller; 88 return controller;
85 } 89 }
86 90
87 void AudioInputController::Record() { 91 void AudioInputController::Record() {
88 DCHECK(thread_.IsRunning()); 92 DCHECK(thread_.IsRunning());
(...skipping 18 matching lines...) Expand all
107 // thread (it is missnamed) being used here. This object overrides 111 // thread (it is missnamed) being used here. This object overrides
108 // temporarily this restriction and should be used only in specific 112 // temporarily this restriction and should be used only in specific
109 // infrequent cases where joining is guaranteed to be fast. 113 // infrequent cases where joining is guaranteed to be fast.
110 // Bug: http://code.google.com/p/chromium/issues/detail?id=67806 114 // Bug: http://code.google.com/p/chromium/issues/detail?id=67806
111 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; 115 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
112 thread_.Stop(); 116 thread_.Stop();
113 } 117 }
114 118
115 void AudioInputController::DoCreate(const AudioParameters& params, 119 void AudioInputController::DoCreate(const AudioParameters& params,
116 const std::string& device_id) { 120 const std::string& device_id) {
117 stream_ = AudioManager::GetAudioManager()->MakeAudioInputStream(params, 121 stream_ = audio_manager_->MakeAudioInputStream(params, device_id);
118 device_id);
119 122
120 if (!stream_) { 123 if (!stream_) {
121 // TODO(satish): Define error types. 124 // TODO(satish): Define error types.
122 handler_->OnError(this, 0); 125 handler_->OnError(this, 0);
123 return; 126 return;
124 } 127 }
125 128
126 if (stream_ && !stream_->Open()) { 129 if (stream_ && !stream_->Open()) {
127 stream_->Close(); 130 stream_->Close();
128 stream_ = NULL; 131 stream_ = NULL;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // such cases here. 218 // such cases here.
216 } 219 }
217 220
218 void AudioInputController::OnError(AudioInputStream* stream, int code) { 221 void AudioInputController::OnError(AudioInputStream* stream, int code) {
219 // Handle error on the audio controller thread. 222 // Handle error on the audio controller thread.
220 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 223 thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
221 &AudioInputController::DoReportError, this, code)); 224 &AudioInputController::DoReportError, this, code));
222 } 225 }
223 226
224 } // namespace media 227 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698