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 // Low-latency audio capturing class utilizing audio input stream provided | 5 // Low-latency audio capturing class utilizing audio input stream provided |
6 // by a server (browser) process by use of an IPC interface. | 6 // by a server (browser) process by use of an IPC interface. |
7 // | 7 // |
8 // Relationship of classes: | 8 // Relationship of classes: |
9 // | 9 // |
10 // AudioInputController AudioInputDevice | 10 // AudioInputController AudioInputDevice |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 #ifndef MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ | 53 #ifndef MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ |
54 #define MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ | 54 #define MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ |
55 | 55 |
56 #include <memory> | 56 #include <memory> |
57 #include <string> | 57 #include <string> |
58 | 58 |
59 #include "base/compiler_specific.h" | 59 #include "base/compiler_specific.h" |
60 #include "base/macros.h" | 60 #include "base/macros.h" |
61 #include "base/memory/shared_memory.h" | 61 #include "base/memory/shared_memory.h" |
| 62 #include "base/time/time.h" |
| 63 #include "base/timer/timer.h" |
62 #include "media/audio/audio_device_thread.h" | 64 #include "media/audio/audio_device_thread.h" |
63 #include "media/audio/audio_input_ipc.h" | 65 #include "media/audio/audio_input_ipc.h" |
64 #include "media/audio/scoped_task_runner_observer.h" | 66 #include "media/audio/scoped_task_runner_observer.h" |
65 #include "media/base/audio_capturer_source.h" | 67 #include "media/base/audio_capturer_source.h" |
66 #include "media/base/audio_parameters.h" | 68 #include "media/base/audio_parameters.h" |
67 #include "media/base/media_export.h" | 69 #include "media/base/media_export.h" |
68 | 70 |
69 namespace media { | 71 namespace media { |
70 | 72 |
71 // TODO(henrika): This class is based on the AudioOutputDevice class and it has | 73 // TODO(henrika): This class is based on the AudioOutputDevice class and it has |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // sends IPC messages on that thread. | 123 // sends IPC messages on that thread. |
122 void StartUpOnIOThread(); | 124 void StartUpOnIOThread(); |
123 void ShutDownOnIOThread(); | 125 void ShutDownOnIOThread(); |
124 void SetVolumeOnIOThread(double volume); | 126 void SetVolumeOnIOThread(double volume); |
125 void SetAutomaticGainControlOnIOThread(bool enabled); | 127 void SetAutomaticGainControlOnIOThread(bool enabled); |
126 | 128 |
127 // base::MessageLoop::DestructionObserver implementation for the IO loop. | 129 // base::MessageLoop::DestructionObserver implementation for the IO loop. |
128 // If the IO loop dies before we do, we shut down the audio thread from here. | 130 // If the IO loop dies before we do, we shut down the audio thread from here. |
129 void WillDestroyCurrentMessageLoop() override; | 131 void WillDestroyCurrentMessageLoop() override; |
130 | 132 |
| 133 // Checks if we have gotten callbacks within a certain time period. If no |
| 134 // callbacks have been received, we report a capture error to the capture |
| 135 // callback. Must be called on IO thread. |
| 136 void CheckIfInputStreamIsAlive(); |
| 137 |
| 138 // Sets the last callback time |last_callback_time_ms_| to the current time. |
| 139 // SetLastCallbackTimeToNow() posts a task on the IO thread to run |
| 140 // SetLastCallbackTimeToNowOnIOThread() which actually sets the variable. We |
| 141 // don't need high precision so we don't have to care about the delay added |
| 142 // with posting the task. |
| 143 void SetLastCallbackTimeToNow(); |
| 144 void SetLastCallbackTimeToNowOnIOThread(); |
| 145 |
131 AudioParameters audio_parameters_; | 146 AudioParameters audio_parameters_; |
132 | 147 |
133 CaptureCallback* callback_; | 148 CaptureCallback* callback_; |
134 | 149 |
135 // A pointer to the IPC layer that takes care of sending requests over to | 150 // A pointer to the IPC layer that takes care of sending requests over to |
136 // the AudioInputRendererHost. Only valid when state_ != IPC_CLOSED and must | 151 // the AudioInputRendererHost. Only valid when state_ != IPC_CLOSED and must |
137 // only be accessed on the IO thread. | 152 // only be accessed on the IO thread. |
138 std::unique_ptr<AudioInputIPC> ipc_; | 153 std::unique_ptr<AudioInputIPC> ipc_; |
139 | 154 |
140 // Current state (must only be accessed from the IO thread). See comments for | 155 // Current state (must only be accessed from the IO thread). See comments for |
(...skipping 18 matching lines...) Expand all Loading... |
159 std::unique_ptr<AudioDeviceThread> audio_thread_; | 174 std::unique_ptr<AudioDeviceThread> audio_thread_; |
160 | 175 |
161 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 176 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
162 // so we don't start the audio thread pointing to a potentially freed | 177 // so we don't start the audio thread pointing to a potentially freed |
163 // |callback_|. | 178 // |callback_|. |
164 // | 179 // |
165 // TODO(miu): Replace this by changing AudioCapturerSource to accept the | 180 // TODO(miu): Replace this by changing AudioCapturerSource to accept the |
166 // callback via Start(). See http://crbug.com/151051 for details. | 181 // callback via Start(). See http://crbug.com/151051 for details. |
167 bool stopping_hack_; | 182 bool stopping_hack_; |
168 | 183 |
| 184 // Mechanism for detecting if we don't get callbacks for some period of time. |
| 185 // |check_alive_timer_| runs the check regularly. |
| 186 // |last_callback_time_| stores the time for the last callback. |
| 187 // Both must only be accessed on the IO thread. |
| 188 // TODO(grunell): Change from TimeTicks to Atomic32 and remove the task |
| 189 // posting in SetLastCallbackTimeToNow(). The Atomic32 variable would have to |
| 190 // represent some time in seconds or tenths of seconds to be able to span over |
| 191 // enough time. Atomic64 cannot be used since it's not supported on 32-bit |
| 192 // platforms. |
| 193 std::unique_ptr<base::RepeatingTimer> check_alive_timer_; |
| 194 base::TimeTicks last_callback_time_; |
| 195 |
| 196 // Flags that missing callbacks has been detected. Used for statistics, |
| 197 // reported when stopping. Must only be accessed on the IO thread. |
| 198 bool missing_callbacks_detected_; |
| 199 |
169 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); | 200 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); |
170 }; | 201 }; |
171 | 202 |
172 } // namespace media | 203 } // namespace media |
173 | 204 |
174 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ | 205 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ |
OLD | NEW |