Chromium Code Reviews| 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 #include "media/audio/pulse/pulse_util.h" | 5 #include "media/audio/pulse/pulse_util.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" | |
| 12 #include "media/audio/audio_device_description.h" | 11 #include "media/audio/audio_device_description.h" |
| 13 #include "media/base/audio_parameters.h" | 12 #include "media/base/audio_parameters.h" |
| 14 | 13 |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 namespace pulse { | 16 namespace pulse { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 #if defined(GOOGLE_CHROME_BUILD) | 20 #if defined(GOOGLE_CHROME_BUILD) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 DLOG(WARNING) << "Operation is NULL"; | 128 DLOG(WARNING) << "Operation is NULL"; |
| 130 return; | 129 return; |
| 131 } | 130 } |
| 132 | 131 |
| 133 while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) | 132 while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) |
| 134 pa_threaded_mainloop_wait(pa_mainloop); | 133 pa_threaded_mainloop_wait(pa_mainloop); |
| 135 | 134 |
| 136 pa_operation_unref(operation); | 135 pa_operation_unref(operation); |
| 137 } | 136 } |
| 138 | 137 |
| 138 base::TimeDelta GetHardwareLatency(pa_stream* stream) { | |
| 139 DCHECK(stream); | |
| 140 int negative = 0; | |
| 141 pa_usec_t latency_micros = 0; | |
| 142 if (pa_stream_get_latency(stream, &latency_micros, &negative) != 0) | |
| 143 return base::TimeDelta(); | |
| 144 | |
| 145 if (negative) | |
| 146 return base::TimeDelta(); | |
| 147 | |
| 148 return base::TimeDelta::FromMicroseconds(latency_micros); | |
| 149 } | |
| 150 | |
| 139 int GetHardwareLatencyInBytes(pa_stream* stream, | 151 int GetHardwareLatencyInBytes(pa_stream* stream, |
| 140 int sample_rate, | 152 int sample_rate, |
| 141 int bytes_per_frame) { | 153 int bytes_per_frame) { |
| 142 DCHECK(stream); | 154 DCHECK(stream); |
| 143 int negative = 0; | 155 return GetHardwareLatency(stream).InSeconds() * sample_rate * bytes_per_frame; |
|
miu
2016/08/31 23:26:55
s/InSeconds/InSecondsF/ to prevent serious loss of
James West
2016/09/13 07:40:50
Done.
| |
| 144 pa_usec_t latency_micros = 0; | |
| 145 if (pa_stream_get_latency(stream, &latency_micros, &negative) != 0) | |
| 146 return 0; | |
| 147 | |
| 148 if (negative) | |
| 149 return 0; | |
| 150 | |
| 151 return latency_micros * sample_rate * bytes_per_frame / | |
| 152 base::Time::kMicrosecondsPerSecond; | |
| 153 } | 156 } |
| 154 | 157 |
| 155 // Helper macro for CreateInput/OutputStream() to avoid code spam and | 158 // Helper macro for CreateInput/OutputStream() to avoid code spam and |
| 156 // string bloat. | 159 // string bloat. |
| 157 #define RETURN_ON_FAILURE(expression, message) do { \ | 160 #define RETURN_ON_FAILURE(expression, message) do { \ |
| 158 if (!(expression)) { \ | 161 if (!(expression)) { \ |
| 159 DLOG(ERROR) << message; \ | 162 DLOG(ERROR) << message; \ |
| 160 return false; \ | 163 return false; \ |
| 161 } \ | 164 } \ |
| 162 } while (0) | 165 } while (0) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 } | 356 } |
| 354 | 357 |
| 355 return true; | 358 return true; |
| 356 } | 359 } |
| 357 | 360 |
| 358 #undef RETURN_ON_FAILURE | 361 #undef RETURN_ON_FAILURE |
| 359 | 362 |
| 360 } // namespace pulse | 363 } // namespace pulse |
| 361 | 364 |
| 362 } // namespace media | 365 } // namespace media |
| OLD | NEW |