OLD | NEW |
---|---|
1 // Copyright (c) 2010 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_output_controller.h" | 5 #include "media/audio/audio_output_controller.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 | 8 |
9 namespace media { | |
10 | |
9 // Signal a pause in low-latency mode. | 11 // Signal a pause in low-latency mode. |
10 static const int kPauseMark = -1; | 12 static const int kPauseMark = -1; |
11 | 13 |
12 namespace { | |
13 // Return true if the parameters for creating an audio stream is valid. | |
14 // Return false otherwise. | |
15 static bool CheckParameters(AudioParameters params) { | |
16 if (!params.IsValid()) | |
17 return false; | |
Ami GONE FROM CHROMIUM
2011/03/04 22:52:04
Wow.
scherkus (not reviewing)
2011/03/07 14:57:56
I think when AudioParameters::IsValid() was create
| |
18 return true; | |
19 } | |
20 | |
21 } // namespace | |
22 | |
23 namespace media { | |
24 | |
25 AudioOutputController::AudioOutputController(EventHandler* handler, | 14 AudioOutputController::AudioOutputController(EventHandler* handler, |
26 uint32 capacity, | 15 uint32 capacity, |
27 SyncReader* sync_reader) | 16 SyncReader* sync_reader) |
28 : handler_(handler), | 17 : handler_(handler), |
29 stream_(NULL), | 18 stream_(NULL), |
30 volume_(1.0), | 19 volume_(1.0), |
31 state_(kEmpty), | 20 state_(kEmpty), |
32 buffer_(0, capacity), | 21 buffer_(0, capacity), |
33 pending_request_(false), | 22 pending_request_(false), |
34 sync_reader_(sync_reader), | 23 sync_reader_(sync_reader), |
35 message_loop_(NULL) { | 24 message_loop_(NULL) { |
36 } | 25 } |
37 | 26 |
38 AudioOutputController::~AudioOutputController() { | 27 AudioOutputController::~AudioOutputController() { |
39 DCHECK(kClosed == state_); | 28 DCHECK(kClosed == state_); |
40 } | 29 } |
41 | 30 |
42 // static | 31 // static |
43 scoped_refptr<AudioOutputController> AudioOutputController::Create( | 32 scoped_refptr<AudioOutputController> AudioOutputController::Create( |
44 EventHandler* event_handler, | 33 EventHandler* event_handler, |
45 AudioParameters params, | 34 AudioParameters params, |
46 uint32 buffer_capacity) { | 35 uint32 buffer_capacity) { |
47 | 36 |
48 if (!CheckParameters(params)) | 37 if (!params.IsValid()) |
49 return NULL; | 38 return NULL; |
50 | 39 |
51 if (!AudioManager::GetAudioManager()) | 40 if (!AudioManager::GetAudioManager()) |
52 return NULL; | 41 return NULL; |
53 | 42 |
54 // Starts the audio controller thread. | 43 // Starts the audio controller thread. |
55 scoped_refptr<AudioOutputController> controller(new AudioOutputController( | 44 scoped_refptr<AudioOutputController> controller(new AudioOutputController( |
56 event_handler, buffer_capacity, NULL)); | 45 event_handler, buffer_capacity, NULL)); |
57 | 46 |
58 controller->message_loop_ = | 47 controller->message_loop_ = |
59 AudioManager::GetAudioManager()->GetMessageLoop(); | 48 AudioManager::GetAudioManager()->GetMessageLoop(); |
60 controller->message_loop_->PostTask( | 49 controller->message_loop_->PostTask( |
61 FROM_HERE, | 50 FROM_HERE, |
62 NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, | 51 NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, |
63 params)); | 52 params)); |
64 return controller; | 53 return controller; |
65 } | 54 } |
66 | 55 |
67 // static | 56 // static |
68 scoped_refptr<AudioOutputController> AudioOutputController::CreateLowLatency( | 57 scoped_refptr<AudioOutputController> AudioOutputController::CreateLowLatency( |
69 EventHandler* event_handler, | 58 EventHandler* event_handler, |
70 AudioParameters params, | 59 AudioParameters params, |
71 SyncReader* sync_reader) { | 60 SyncReader* sync_reader) { |
72 | 61 |
73 DCHECK(sync_reader); | 62 DCHECK(sync_reader); |
74 | 63 |
75 if (!CheckParameters(params)) | 64 if (!params.IsValid()) |
76 return NULL; | 65 return NULL; |
77 | 66 |
78 if (!AudioManager::GetAudioManager()) | 67 if (!AudioManager::GetAudioManager()) |
79 return NULL; | 68 return NULL; |
80 | 69 |
81 // Starts the audio controller thread. | 70 // Starts the audio controller thread. |
82 scoped_refptr<AudioOutputController> controller(new AudioOutputController( | 71 scoped_refptr<AudioOutputController> controller(new AudioOutputController( |
83 event_handler, 0, sync_reader)); | 72 event_handler, 0, sync_reader)); |
84 | 73 |
85 controller->message_loop_ = | 74 controller->message_loop_ = |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 buffers_state.pending_bytes += buffer_.forward_bytes(); | 313 buffers_state.pending_bytes += buffer_.forward_bytes(); |
325 | 314 |
326 // If we need more data then call the event handler to ask for more data. | 315 // If we need more data then call the event handler to ask for more data. |
327 // It is okay that we don't lock in this block because the parameters are | 316 // It is okay that we don't lock in this block because the parameters are |
328 // correct and in the worst case we are just asking more data than needed. | 317 // correct and in the worst case we are just asking more data than needed. |
329 base::AutoUnlock auto_unlock(lock_); | 318 base::AutoUnlock auto_unlock(lock_); |
330 handler_->OnMoreData(this, buffers_state); | 319 handler_->OnMoreData(this, buffers_state); |
331 } | 320 } |
332 | 321 |
333 } // namespace media | 322 } // namespace media |
OLD | NEW |