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

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: Pass target playout time to AudioSourceCallback::OnMoreData. Created 4 years, 4 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
chcunningham 2016/07/29 01:21:09 space
jameswest 2016/08/26 02:08:47 Done.
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // 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 3 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 4 // found in the LICENSE file.
4 5
5 #include "media/audio/pulse/pulse_util.h" 6 #include "media/audio/pulse/pulse_util.h"
6 7
7 #include <stdint.h> 8 #include <stdint.h>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/time/time.h"
12 #include "media/audio/audio_device_description.h" 12 #include "media/audio/audio_device_description.h"
13 #include "media/base/audio_parameters.h" 13 #include "media/base/audio_parameters.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)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GetHardwareLatency(stream).InSeconds() * sample_rate * bytes_per_frame;
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 } 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