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 <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 class MEDIA_EXPORT AudioOutputController | 64 class MEDIA_EXPORT AudioOutputController |
65 : public base::RefCountedThreadSafe<AudioOutputController>, | 65 : public base::RefCountedThreadSafe<AudioOutputController>, |
66 public AudioOutputStream::AudioSourceCallback, | 66 public AudioOutputStream::AudioSourceCallback, |
67 public AudioSourceDiverter, | 67 public AudioSourceDiverter, |
68 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { | 68 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { |
69 public: | 69 public: |
70 // An event handler that receives events from the AudioOutputController. The | 70 // An event handler that receives events from the AudioOutputController. The |
71 // following methods are called on the audio manager thread. | 71 // following methods are called on the audio manager thread. |
72 class MEDIA_EXPORT EventHandler { | 72 class MEDIA_EXPORT EventHandler { |
73 public: | 73 public: |
74 virtual void OnCreated() = 0; | 74 virtual void OnControllerCreated() = 0; |
75 virtual void OnPlaying() = 0; | 75 virtual void OnControllerPlaying() = 0; |
76 virtual void OnPaused() = 0; | 76 virtual void OnControllerPaused() = 0; |
77 virtual void OnError() = 0; | 77 virtual void OnControllerError() = 0; |
78 | 78 |
79 protected: | 79 protected: |
80 virtual ~EventHandler() {} | 80 virtual ~EventHandler() {} |
81 }; | 81 }; |
82 | 82 |
83 // A synchronous reader interface used by AudioOutputController for | 83 // A synchronous reader interface used by AudioOutputController for |
84 // synchronous reading. | 84 // synchronous reading. |
85 // TODO(crogers): find a better name for this class and the Read() method | 85 // TODO(crogers): find a better name for this class and the Read() method |
86 // now that it can handle synchronized I/O. | 86 // now that it can handle synchronized I/O. |
87 class SyncReader { | 87 class SyncReader { |
(...skipping 13 matching lines...) Expand all Loading... |
101 // be fulfilled (due to timeout). | 101 // be fulfilled (due to timeout). |
102 virtual void Read(AudioBus* dest) = 0; | 102 virtual void Read(AudioBus* dest) = 0; |
103 | 103 |
104 // Close this synchronous reader. | 104 // Close this synchronous reader. |
105 virtual void Close() = 0; | 105 virtual void Close() = 0; |
106 }; | 106 }; |
107 | 107 |
108 // Factory method for creating an AudioOutputController. | 108 // Factory method for creating an AudioOutputController. |
109 // This also creates and opens an AudioOutputStream on the audio manager | 109 // This also creates and opens an AudioOutputStream on the audio manager |
110 // thread, and if this is successful, the |event_handler| will receive an | 110 // thread, and if this is successful, the |event_handler| will receive an |
111 // OnCreated() call from the same audio manager thread. |audio_manager| must | 111 // OnControllerCreated() call from the same audio manager thread. |
112 // outlive AudioOutputController. | 112 // |audio_manager| must outlive AudioOutputController. |
113 // The |output_device_id| can be either empty (default device) or specify a | 113 // The |output_device_id| can be either empty (default device) or specify a |
114 // specific hardware device for audio output. | 114 // specific hardware device for audio output. |
115 static scoped_refptr<AudioOutputController> Create( | 115 static scoped_refptr<AudioOutputController> Create( |
116 AudioManager* audio_manager, EventHandler* event_handler, | 116 AudioManager* audio_manager, EventHandler* event_handler, |
117 const AudioParameters& params, const std::string& output_device_id, | 117 const AudioParameters& params, const std::string& output_device_id, |
118 SyncReader* sync_reader); | 118 SyncReader* sync_reader); |
119 | 119 |
120 // Indicates whether audio power level analysis will be performed. If false, | 120 // Indicates whether audio power level analysis will be performed. If false, |
121 // ReadCurrentPowerAndClip() can not be called. | 121 // ReadCurrentPowerAndClip() can not be called. |
122 static bool will_monitor_audio_levels() { | 122 static bool will_monitor_audio_levels() { |
123 #if defined(OS_ANDROID) || defined(OS_IOS) | 123 #if defined(OS_ANDROID) || defined(OS_IOS) |
124 return false; | 124 return false; |
125 #else | 125 #else |
126 return true; | 126 return true; |
127 #endif | 127 #endif |
128 } | 128 } |
129 | 129 |
130 // Methods to control playback of the stream. | 130 // Methods to control playback of the stream. |
131 | 131 |
132 // Starts the playback of this audio output stream. | 132 // Starts the playback of this audio output stream. |
133 void Play(); | 133 void Play(); |
134 | 134 |
135 // Pause this audio output stream. | 135 // Pause this audio output stream. |
136 void Pause(); | 136 void Pause(); |
137 | 137 |
138 // Closes the audio output stream. The state is changed and the resources | 138 // Closes the audio output stream. The state is changed and the resources |
139 // are freed on the audio manager thread. closed_task is executed after that. | 139 // are freed on the audio manager thread. |closed_task| is executed after |
140 // Callbacks (EventHandler and SyncReader) must exist until closed_task is | 140 // that, on the thread on which Close was called. Callbacks (EventHandler and |
141 // called. | 141 // SyncReader) must exist until closed_task is called, but they are safe |
| 142 // to delete after that. |
142 // | 143 // |
143 // It is safe to call this method more than once. Calls after the first one | 144 // It is safe to call this method more than once. Calls after the first one |
144 // will have no effect. | 145 // will have no effect. |
145 void Close(const base::Closure& closed_task); | 146 void Close(const base::Closure& closed_task); |
146 | 147 |
147 // Sets the volume of the audio output stream. | 148 // Sets the volume of the audio output stream. |
148 void SetVolume(double volume); | 149 void SetVolume(double volume); |
149 | 150 |
150 // Calls |callback| (on the caller's thread) with the current output | 151 // Calls |callback| (on the caller's thread) with the current output |
151 // device ID. | 152 // device ID. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // be accessed while |error_lock_| is held. | 285 // be accessed while |error_lock_| is held. |
285 bool ignore_errors_during_stop_close_; | 286 bool ignore_errors_during_stop_close_; |
286 base::Lock error_lock_; | 287 base::Lock error_lock_; |
287 | 288 |
288 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 289 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
289 }; | 290 }; |
290 | 291 |
291 } // namespace media | 292 } // namespace media |
292 | 293 |
293 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 294 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |