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 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
7 | 7 |
8 #include "base/atomic_ref_count.h" | 8 #include "base/atomic_ref_count.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/threading/thread_checker.h" | |
12 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
14 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
15 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
16 #include "media/audio/audio_power_monitor.h" | 15 #include "media/audio/audio_power_monitor.h" |
17 #include "media/audio/audio_source_diverter.h" | 16 #include "media/audio/audio_source_diverter.h" |
18 #include "media/audio/simple_sources.h" | 17 #include "media/audio/simple_sources.h" |
19 #include "media/base/media_export.h" | 18 #include "media/base/media_export.h" |
20 | 19 |
21 // An AudioOutputController controls an AudioOutputStream and provides data | 20 // An AudioOutputController controls an AudioOutputStream and provides data |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // A synchronous reader interface used by AudioOutputController for | 75 // A synchronous reader interface used by AudioOutputController for |
77 // synchronous reading. | 76 // synchronous reading. |
78 // TODO(crogers): find a better name for this class and the Read() method | 77 // TODO(crogers): find a better name for this class and the Read() method |
79 // now that it can handle synchronized I/O. | 78 // now that it can handle synchronized I/O. |
80 class SyncReader { | 79 class SyncReader { |
81 public: | 80 public: |
82 virtual ~SyncReader() {} | 81 virtual ~SyncReader() {} |
83 | 82 |
84 // Notify the synchronous reader the number of bytes in the | 83 // Notify the synchronous reader the number of bytes in the |
85 // AudioOutputController not yet played. This is used by SyncReader to | 84 // AudioOutputController not yet played. This is used by SyncReader to |
86 // prepare more data and perform synchronization. Also inform about if any | 85 // prepare more data and perform synchronization. |
87 // frames has been skipped by the renderer (typically the OS). The renderer | 86 virtual void UpdatePendingBytes(uint32 bytes) = 0; |
88 // source can handle this appropriately depending on the type of source. An | |
89 // ordinary file playout would ignore this. | |
90 virtual void UpdatePendingBytes(uint32_t bytes, | |
91 uint32_t frames_skipped) = 0; | |
92 | 87 |
93 // Attempts to completely fill |dest|, zeroing |dest| if the request can not | 88 // Attempts to completely fill |dest|, zeroing |dest| if the request can not |
94 // be fulfilled (due to timeout). | 89 // be fulfilled (due to timeout). |
95 virtual void Read(AudioBus* dest) = 0; | 90 virtual void Read(AudioBus* dest) = 0; |
96 | 91 |
97 // Close this synchronous reader. | 92 // Close this synchronous reader. |
98 virtual void Close() = 0; | 93 virtual void Close() = 0; |
99 }; | 94 }; |
100 | 95 |
101 // Factory method for creating an AudioOutputController. | 96 // Factory method for creating an AudioOutputController. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // | 146 // |
152 // Changing the output device causes the controller to go through | 147 // Changing the output device causes the controller to go through |
153 // the same state transition back to the current state as a call to | 148 // the same state transition back to the current state as a call to |
154 // OnDeviceChange (unless it is currently diverting, see | 149 // OnDeviceChange (unless it is currently diverting, see |
155 // Start/StopDiverting below, in which case the state transition | 150 // Start/StopDiverting below, in which case the state transition |
156 // will happen when StopDiverting is called). | 151 // will happen when StopDiverting is called). |
157 void SwitchOutputDevice(const std::string& output_device_id, | 152 void SwitchOutputDevice(const std::string& output_device_id, |
158 const base::Closure& callback); | 153 const base::Closure& callback); |
159 | 154 |
160 // AudioSourceCallback implementation. | 155 // AudioSourceCallback implementation. |
161 int OnMoreData(AudioBus* dest, | 156 int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) override; |
162 uint32_t total_bytes_delay, | |
163 uint32_t frames_skipped) override; | |
164 void OnError(AudioOutputStream* stream) override; | 157 void OnError(AudioOutputStream* stream) override; |
165 | 158 |
166 // AudioDeviceListener implementation. When called AudioOutputController will | 159 // AudioDeviceListener implementation. When called AudioOutputController will |
167 // shutdown the existing |stream_|, transition to the kRecreating state, | 160 // shutdown the existing |stream_|, transition to the kRecreating state, |
168 // create a new stream, and then transition back to an equivalent state prior | 161 // create a new stream, and then transition back to an equivalent state prior |
169 // to being called. | 162 // to being called. |
170 void OnDeviceChange() override; | 163 void OnDeviceChange() override; |
171 | 164 |
172 // AudioSourceDiverter implementation. | 165 // AudioSourceDiverter implementation. |
173 const AudioParameters& GetAudioParameters() override; | 166 const AudioParameters& GetAudioParameters() override; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // be accessed while |error_lock_| is held. | 257 // be accessed while |error_lock_| is held. |
265 bool ignore_errors_during_stop_close_; | 258 bool ignore_errors_during_stop_close_; |
266 base::Lock error_lock_; | 259 base::Lock error_lock_; |
267 | 260 |
268 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 261 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
269 }; | 262 }; |
270 | 263 |
271 } // namespace media | 264 } // namespace media |
272 | 265 |
273 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 266 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |