| 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" | |
| 64 #include "media/audio/audio_device_thread.h" | 62 #include "media/audio/audio_device_thread.h" |
| 65 #include "media/audio/audio_input_ipc.h" | 63 #include "media/audio/audio_input_ipc.h" |
| 66 #include "media/audio/scoped_task_runner_observer.h" | 64 #include "media/audio/scoped_task_runner_observer.h" |
| 67 #include "media/base/audio_capturer_source.h" | 65 #include "media/base/audio_capturer_source.h" |
| 68 #include "media/base/audio_parameters.h" | 66 #include "media/base/audio_parameters.h" |
| 69 #include "media/base/media_export.h" | 67 #include "media/base/media_export.h" |
| 70 | 68 |
| 71 namespace media { | 69 namespace media { |
| 72 | 70 |
| 73 // TODO(henrika): This class is based on the AudioOutputDevice class and it has | 71 // 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... |
| 123 // sends IPC messages on that thread. | 121 // sends IPC messages on that thread. |
| 124 void StartUpOnIOThread(); | 122 void StartUpOnIOThread(); |
| 125 void ShutDownOnIOThread(); | 123 void ShutDownOnIOThread(); |
| 126 void SetVolumeOnIOThread(double volume); | 124 void SetVolumeOnIOThread(double volume); |
| 127 void SetAutomaticGainControlOnIOThread(bool enabled); | 125 void SetAutomaticGainControlOnIOThread(bool enabled); |
| 128 | 126 |
| 129 // base::MessageLoop::DestructionObserver implementation for the IO loop. | 127 // base::MessageLoop::DestructionObserver implementation for the IO loop. |
| 130 // If the IO loop dies before we do, we shut down the audio thread from here. | 128 // If the IO loop dies before we do, we shut down the audio thread from here. |
| 131 void WillDestroyCurrentMessageLoop() override; | 129 void WillDestroyCurrentMessageLoop() override; |
| 132 | 130 |
| 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 | |
| 146 AudioParameters audio_parameters_; | 131 AudioParameters audio_parameters_; |
| 147 | 132 |
| 148 CaptureCallback* callback_; | 133 CaptureCallback* callback_; |
| 149 | 134 |
| 150 // A pointer to the IPC layer that takes care of sending requests over to | 135 // A pointer to the IPC layer that takes care of sending requests over to |
| 151 // the AudioInputRendererHost. Only valid when state_ != IPC_CLOSED and must | 136 // the AudioInputRendererHost. Only valid when state_ != IPC_CLOSED and must |
| 152 // only be accessed on the IO thread. | 137 // only be accessed on the IO thread. |
| 153 std::unique_ptr<AudioInputIPC> ipc_; | 138 std::unique_ptr<AudioInputIPC> ipc_; |
| 154 | 139 |
| 155 // Current state (must only be accessed from the IO thread). See comments for | 140 // Current state (must only be accessed from the IO thread). See comments for |
| (...skipping 18 matching lines...) Expand all Loading... |
| 174 std::unique_ptr<AudioDeviceThread> audio_thread_; | 159 std::unique_ptr<AudioDeviceThread> audio_thread_; |
| 175 | 160 |
| 176 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 161 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
| 177 // so we don't start the audio thread pointing to a potentially freed | 162 // so we don't start the audio thread pointing to a potentially freed |
| 178 // |callback_|. | 163 // |callback_|. |
| 179 // | 164 // |
| 180 // TODO(miu): Replace this by changing AudioCapturerSource to accept the | 165 // TODO(miu): Replace this by changing AudioCapturerSource to accept the |
| 181 // callback via Start(). See http://crbug.com/151051 for details. | 166 // callback via Start(). See http://crbug.com/151051 for details. |
| 182 bool stopping_hack_; | 167 bool stopping_hack_; |
| 183 | 168 |
| 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 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 | |
| 200 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); | 169 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); |
| 201 }; | 170 }; |
| 202 | 171 |
| 203 } // namespace media | 172 } // namespace media |
| 204 | 173 |
| 205 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ | 174 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ |
| OLD | NEW |