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

Unified Diff: media/audio/win/audio_low_latency_input_win.cc

Issue 2689483006: Switch browser side audio capture path to use base time primitives. (Closed)
Patch Set: Bloop Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/win/audio_low_latency_input_win.cc
diff --git a/media/audio/win/audio_low_latency_input_win.cc b/media/audio/win/audio_low_latency_input_win.cc
index 22355580aac45b2c656ae6066bd25fd1b72f1a3f..94fc69e9ad05c6d90031a8331e653ba816fca7e0 100644
--- a/media/audio/win/audio_low_latency_input_win.cc
+++ b/media/audio/win/audio_low_latency_input_win.cc
@@ -326,7 +326,6 @@ void WASAPIAudioInputStream::Run() {
2 * packet_size_frames_ * frame_size_);
std::unique_ptr<uint8_t[]> capture_buffer(new uint8_t[capture_buffer_size]);
- LARGE_INTEGER now_count = {};
bool recording = true;
bool error = false;
double volume = GetVolume();
@@ -401,8 +400,21 @@ void WASAPIAudioInputStream::Run() {
// The value contains two parts (A+B), where A is the delay of the
// first audio frame in the packet and B is the extra delay
// contained in any stored data. Unit is in audio frames.
- QueryPerformanceCounter(&now_count);
// first_audio_frame_timestamp will be 0 if we didn't get a timestamp.
+
+ base::TimeTicks delay_timestamp =
+ base::TimeTicks::FromQPCValue(first_audio_frame_timestamp);
+
+ // TODO(dalecurtis): This is all wrong and brain is mush, fix tomorrow.
miu 2017/02/12 04:21:37 It may help to consult what was done for this same
+ // Needs to compensate for input buffers from past cycles.
+ base::TimeDelta delay =
+ first_audio_frame_timestamp
+ ? base::TimeTicks::Now() - delay_timestamp
+ : base::TimeDelta::FromSecondsD(
+ num_frames_to_read /
+ static_cast<double>(format_.nSamplesPerSec));
+
+#if 0
double audio_delay_frames =
first_audio_frame_timestamp == 0
? num_frames_to_read
@@ -411,7 +423,7 @@ void WASAPIAudioInputStream::Run() {
10000.0) *
ms_to_frame_count_ +
buffer_frame_index - num_frames_to_read;
-
+#endif
// Get a cached AGC volume level which is updated once every second
// on the audio manager thread. Note that, |volume| is also updated
// each time SetVolume() is called through IPC by the render-side AGC.
@@ -419,7 +431,6 @@ void WASAPIAudioInputStream::Run() {
// Deliver captured data to the registered consumer using a packet
// size which was specified at construction.
- uint32_t delay_frames = static_cast<uint32_t>(audio_delay_frames + 0.5);
while (buffer_frame_index >= packet_size_frames_) {
// Copy data to audio bus to match the OnData interface.
uint8_t* audio_data =
@@ -429,8 +440,7 @@ void WASAPIAudioInputStream::Run() {
// Deliver data packet, delay estimation and volume level to
// the user.
- sink_->OnData(this, audio_bus_.get(), delay_frames * frame_size_,
- volume);
+ sink_->OnData(this, audio_bus_.get(), delay, delay_timestamp, volume);
// Store parts of the recorded data which can't be delivered
// using the current packet size. The stored section will be used
@@ -445,11 +455,6 @@ void WASAPIAudioInputStream::Run() {
DCHECK_GE(buffer_frame_index, packet_size_frames_);
buffer_frame_index -= packet_size_frames_;
- if (delay_frames > packet_size_frames_) {
- delay_frames -= packet_size_frames_;
- } else {
- delay_frames = 0;
- }
}
} break;
default:

Powered by Google App Engine
This is Rietveld 408576698