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

Side by Side Diff: media/audio/pulse/pulse_util.cc

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix Windows CQ errors. Created 4 years, 3 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 #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
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).InSecondsF() * sample_rate *
144 pa_usec_t latency_micros = 0; 156 bytes_per_frame;
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 } 157 }
154 158
155 // Helper macro for CreateInput/OutputStream() to avoid code spam and 159 // Helper macro for CreateInput/OutputStream() to avoid code spam and
156 // string bloat. 160 // string bloat.
157 #define RETURN_ON_FAILURE(expression, message) do { \ 161 #define RETURN_ON_FAILURE(expression, message) do { \
158 if (!(expression)) { \ 162 if (!(expression)) { \
159 DLOG(ERROR) << message; \ 163 DLOG(ERROR) << message; \
160 return false; \ 164 return false; \
161 } \ 165 } \
162 } while (0) 166 } while (0)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 357 }
354 358
355 return true; 359 return true;
356 } 360 }
357 361
358 #undef RETURN_ON_FAILURE 362 #undef RETURN_ON_FAILURE
359 363
360 } // namespace pulse 364 } // namespace pulse
361 365
362 } // namespace media 366 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698