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" |
| 13 #include "media/base/audio_timestamp_helper.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 namespace pulse { | 17 namespace pulse { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 #if defined(GOOGLE_CHROME_BUILD) | 21 #if defined(GOOGLE_CHROME_BUILD) |
22 static const char kBrowserDisplayName[] = "google-chrome"; | 22 static const char kBrowserDisplayName[] = "google-chrome"; |
23 #else | 23 #else |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 DLOG(WARNING) << "Operation is NULL"; | 129 DLOG(WARNING) << "Operation is NULL"; |
130 return; | 130 return; |
131 } | 131 } |
132 | 132 |
133 while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) | 133 while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) |
134 pa_threaded_mainloop_wait(pa_mainloop); | 134 pa_threaded_mainloop_wait(pa_mainloop); |
135 | 135 |
136 pa_operation_unref(operation); | 136 pa_operation_unref(operation); |
137 } | 137 } |
138 | 138 |
| 139 base::TimeDelta GetHardwareLatency(pa_stream* stream) { |
| 140 DCHECK(stream); |
| 141 int negative = 0; |
| 142 pa_usec_t latency_micros = 0; |
| 143 if (pa_stream_get_latency(stream, &latency_micros, &negative) != 0) |
| 144 return base::TimeDelta(); |
| 145 |
| 146 if (negative) |
| 147 return base::TimeDelta(); |
| 148 |
| 149 return base::TimeDelta::FromMicroseconds(latency_micros); |
| 150 } |
| 151 |
139 int GetHardwareLatencyInBytes(pa_stream* stream, | 152 int GetHardwareLatencyInBytes(pa_stream* stream, |
140 int sample_rate, | 153 int sample_rate, |
141 int bytes_per_frame) { | 154 int bytes_per_frame) { |
142 DCHECK(stream); | 155 DCHECK(stream); |
143 int negative = 0; | 156 return AudioTimestampHelper::TimeToFrames(GetHardwareLatency(stream), |
144 pa_usec_t latency_micros = 0; | 157 sample_rate) * |
145 if (pa_stream_get_latency(stream, &latency_micros, &negative) != 0) | 158 bytes_per_frame; |
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 } | 159 } |
154 | 160 |
155 // Helper macro for CreateInput/OutputStream() to avoid code spam and | 161 // Helper macro for CreateInput/OutputStream() to avoid code spam and |
156 // string bloat. | 162 // string bloat. |
157 #define RETURN_ON_FAILURE(expression, message) do { \ | 163 #define RETURN_ON_FAILURE(expression, message) do { \ |
158 if (!(expression)) { \ | 164 if (!(expression)) { \ |
159 DLOG(ERROR) << message; \ | 165 DLOG(ERROR) << message; \ |
160 return false; \ | 166 return false; \ |
161 } \ | 167 } \ |
162 } while (0) | 168 } while (0) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 359 } |
354 | 360 |
355 return true; | 361 return true; |
356 } | 362 } |
357 | 363 |
358 #undef RETURN_ON_FAILURE | 364 #undef RETURN_ON_FAILURE |
359 | 365 |
360 } // namespace pulse | 366 } // namespace pulse |
361 | 367 |
362 } // namespace media | 368 } // namespace media |
OLD | NEW |