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 #include "media/audio/mac/audio_low_latency_input_mac.h" | 4 #include "media/audio/mac/audio_low_latency_input_mac.h" |
5 | 5 |
6 #include <CoreServices/CoreServices.h> | 6 #include <CoreServices/CoreServices.h> |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 18 matching lines...) Loading... | |
29 // The stream will be stopped as soon as this time limit is passed. | 29 // The stream will be stopped as soon as this time limit is passed. |
30 const int kMaxErrorTimeoutInSeconds = 1; | 30 const int kMaxErrorTimeoutInSeconds = 1; |
31 | 31 |
32 // A repeating timer is created and started in Start() and it triggers calls | 32 // A repeating timer is created and started in Start() and it triggers calls |
33 // to CheckIfInputStreamIsAlive() where we do periodic checks to see if the | 33 // to CheckIfInputStreamIsAlive() where we do periodic checks to see if the |
34 // input data callback sequence is active or not. If the stream seems dead, | 34 // input data callback sequence is active or not. If the stream seems dead, |
35 // up to |kMaxNumberOfRestartAttempts| restart attempts tries to bring the | 35 // up to |kMaxNumberOfRestartAttempts| restart attempts tries to bring the |
36 // stream back to life. | 36 // stream back to life. |
37 const int kCheckInputIsAliveTimeInSeconds = 5; | 37 const int kCheckInputIsAliveTimeInSeconds = 5; |
38 | 38 |
39 // Number of restart indications required to actually trigger a restart | 39 // Number of restart indications required to trigger a restart after a |
40 // attempt. | 40 // successful start. |
41 const int kNumberOfIndicationsToTriggerRestart = 1; | 41 const int kIndicationsToTriggerRestartAfterSuccessfulStart = 2; |
42 | 42 |
43 // Max number of times we try to restart a stream when it has been categorized | 43 // Max number of times we try to restart a stream when it has been categorized |
44 // as dead. Note that we can do many restarts during an audio session and this | 44 // as dead. Note that we can do many restarts during an audio session and this |
45 // limitation is per detected problem. Once a restart has succeeded, a new | 45 // limitation is per detected problem. Once a restart has succeeded, a new |
46 // sequence of |kMaxNumberOfRestartAttempts| number of restart attempts can be | 46 // sequence of |kMaxNumberOfRestartAttempts| number of restart attempts can be |
47 // done. | 47 // done. |
48 const int kMaxNumberOfRestartAttempts = 1; | 48 const int kMaxNumberOfRestartAttempts = 1; |
49 | 49 |
50 // A one-shot timer is created and started in Start() and it triggers | 50 // A one-shot timer is created and started in Start() and it triggers |
51 // CheckInputStartupSuccess() after this amount of time. UMA stats marked | 51 // CheckInputStartupSuccess() after this amount of time. UMA stats marked |
(...skipping 1213 matching lines...) Loading... | |
1265 // A non-zero value of this counter is a strong indication of a "dead" input | 1265 // A non-zero value of this counter is a strong indication of a "dead" input |
1266 // stream. Reset the same counter if the stream is alive. | 1266 // stream. Reset the same counter if the stream is alive. |
1267 if (time_since_last_callback.InSecondsF() > | 1267 if (time_since_last_callback.InSecondsF() > |
1268 0.5 * kCheckInputIsAliveTimeInSeconds) { | 1268 0.5 * kCheckInputIsAliveTimeInSeconds) { |
1269 ++number_of_restart_indications_; | 1269 ++number_of_restart_indications_; |
1270 } else { | 1270 } else { |
1271 number_of_restart_indications_ = 0; | 1271 number_of_restart_indications_ = 0; |
1272 } | 1272 } |
1273 | 1273 |
1274 // Restart the audio stream if two conditions are met. First, the number of | 1274 // Restart the audio stream if two conditions are met. First, the number of |
1275 // restart indicators must be larger than a threshold, and secondly, only a | 1275 // restart indicators must reach a threshold, and secondly, only a |
1276 // fixed number of restart attempts is allowed. | 1276 // fixed number of restart attempts is allowed. |
1277 // Note that, the threshold is different depending on if the stream is seen | 1277 // Note that, the threshold is different depending on if the stream is seen |
1278 // as dead directly at the first call to Start() (i.e. it has never started) | 1278 // as dead directly at the first call to Start() (i.e. it has never started) |
1279 // or if the stream has started OK at least once but then stopped for some | 1279 // or if the stream has started OK at least once but then stopped for some |
1280 // reason (e.g by placing the device in sleep mode). One restart indication | 1280 // reason (e.g by placing the device in sleep mode). One restart indication |
1281 // is sufficient for the first case (threshold is zero), while a larger value | 1281 // is sufficient for the first case (threshold is zero), while a larger value |
1282 // (threshold > 0) is required for the second case to avoid false alarms when | 1282 // (threshold > 1) is required for the second case to avoid false alarms when |
1283 // e.g. resuming from a suspended state. | 1283 // e.g. resuming from a suspended state. |
1284 const size_t restart_threshold = | 1284 const size_t indications_to_trigger_restart = |
1285 GetInputCallbackIsActive() ? kNumberOfIndicationsToTriggerRestart : 0; | 1285 GetInputCallbackIsActive() |
1286 if (number_of_restart_indications_ > restart_threshold && | 1286 ? kIndicationsToTriggerRestartAfterSuccessfulStart |
1287 : 1; | |
1288 DCHECK_LE(number_of_restart_indications_, indications_to_trigger_restart); | |
1289 if (number_of_restart_indications_ == indications_to_trigger_restart && | |
ossu-chromium
2017/05/22 11:27:35
So, this is functionally equivalent but rephrased
Henrik Grunell
2017/05/22 15:04:54
Yes, exactly. I hope you agree it is. :o
| |
1287 number_of_restart_attempts_ < kMaxNumberOfRestartAttempts) { | 1290 number_of_restart_attempts_ < kMaxNumberOfRestartAttempts) { |
1288 SetInputCallbackIsActive(false); | 1291 SetInputCallbackIsActive(false); |
1289 ++total_number_of_restart_attempts_; | 1292 ++total_number_of_restart_attempts_; |
1290 ++number_of_restart_attempts_; | 1293 ++number_of_restart_attempts_; |
1291 number_of_restart_indications_ = 0; | 1294 number_of_restart_indications_ = 0; |
1292 RestartAudio(); | 1295 RestartAudio(); |
1293 } | 1296 } |
1294 } | 1297 } |
1295 | 1298 |
1296 void AUAudioInputStream::CloseAudioUnit() { | 1299 void AUAudioInputStream::CloseAudioUnit() { |
(...skipping 371 matching lines...) Loading... | |
1668 | 1671 |
1669 number_of_frames_provided_ = 0; | 1672 number_of_frames_provided_ = 0; |
1670 glitches_detected_ = 0; | 1673 glitches_detected_ = 0; |
1671 last_sample_time_ = 0; | 1674 last_sample_time_ = 0; |
1672 last_number_of_frames_ = 0; | 1675 last_number_of_frames_ = 0; |
1673 total_lost_frames_ = 0; | 1676 total_lost_frames_ = 0; |
1674 largest_glitch_frames_ = 0; | 1677 largest_glitch_frames_ = 0; |
1675 } | 1678 } |
1676 | 1679 |
1677 } // namespace media | 1680 } // namespace media |
OLD | NEW |