Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: media/audio/audio_input_device.h

Issue 2888383002: Stop source and fire MediaStreamTrack ended event if missing audio input callbacks are detected. (Closed)
Patch Set: Code review (ossu@ and tommi@). Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_|.
139 // SetLastCallbackTime() is called by AudioInputDevice::AudioThreadCallback on
140 // the audio thread and posts a task to SetLastCallbackTimeOnIOThread() which
141 // sets the variable.
142 void SetLastCallbackTime(base::TimeTicks last_callback_time);
143 void SetLastCallbackTimeOnIOThread(base::TimeTicks last_callback_time);
144
131 AudioParameters audio_parameters_; 145 AudioParameters audio_parameters_;
132 146
133 CaptureCallback* callback_; 147 CaptureCallback* callback_;
134 148
135 // A pointer to the IPC layer that takes care of sending requests over to 149 // 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 150 // the AudioInputRendererHost. Only valid when state_ != IPC_CLOSED and must
137 // only be accessed on the IO thread. 151 // only be accessed on the IO thread.
138 std::unique_ptr<AudioInputIPC> ipc_; 152 std::unique_ptr<AudioInputIPC> ipc_;
139 153
140 // Current state (must only be accessed from the IO thread). See comments for 154 // Current state (must only be accessed from the IO thread). See comments for
(...skipping 18 matching lines...) Expand all
159 std::unique_ptr<AudioDeviceThread> audio_thread_; 173 std::unique_ptr<AudioDeviceThread> audio_thread_;
160 174
161 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() 175 // 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 176 // so we don't start the audio thread pointing to a potentially freed
163 // |callback_|. 177 // |callback_|.
164 // 178 //
165 // TODO(miu): Replace this by changing AudioCapturerSource to accept the 179 // TODO(miu): Replace this by changing AudioCapturerSource to accept the
166 // callback via Start(). See http://crbug.com/151051 for details. 180 // callback via Start(). See http://crbug.com/151051 for details.
167 bool stopping_hack_; 181 bool stopping_hack_;
168 182
183 // Mechanism for detecting if we don't get callbacks for some period of time.
184 // |check_alive_timer_| runs the check regularly.
185 // |last_callback_time_| stores the time for the last callback.
186 // Both must only be accessed on the IO thread.
187 base::RepeatingTimer check_alive_timer_;
188 base::TimeTicks last_callback_time_;
189
190 // Flags that missing callbacks has been detected. Used for statistics,
191 // reported when stopping. Must only be accessed on the IO thread.
ossu-chromium 2017/05/22 11:27:35 Aren't there annotations to enforce that?
Henrik Grunell 2017/05/22 15:04:54 Nope.
192 bool missing_callbacks_detected_;
193
169 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); 194 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice);
170 }; 195 };
171 196
172 } // namespace media 197 } // namespace media
173 198
174 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ 199 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698