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

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 2689483006: Switch browser side audio capture path to use base time primitives. (Closed)
Patch Set: 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 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/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 : controller_(controller), 108 : controller_(controller),
109 weak_controller_(controller->weak_ptr_factory_.GetWeakPtr()) {} 109 weak_controller_(controller->weak_ptr_factory_.GetWeakPtr()) {}
110 ~AudioCallback() override {} 110 ~AudioCallback() override {}
111 111
112 bool received_callback() const { return received_callback_; } 112 bool received_callback() const { return received_callback_; }
113 bool error_during_callback() const { return error_during_callback_; } 113 bool error_during_callback() const { return error_during_callback_; }
114 114
115 private: 115 private:
116 void OnData(AudioInputStream* stream, 116 void OnData(AudioInputStream* stream,
117 const AudioBus* source, 117 const AudioBus* source,
118 uint32_t hardware_delay_bytes, 118 base::TimeDelta delay,
119 base::TimeTicks delay_timestamp,
119 double volume) override { 120 double volume) override {
120 TRACE_EVENT0("audio", "AC::OnData"); 121 TRACE_EVENT0("audio", "AC::OnData");
121 122
122 received_callback_ = true; 123 received_callback_ = true;
123 124
124 DeliverDataToSyncWriter(source, hardware_delay_bytes, volume); 125 DeliverDataToSyncWriter(source, delay, delay_timestamp, volume);
125 PerformOptionalDebugRecording(source); 126 PerformOptionalDebugRecording(source);
126 } 127 }
127 128
128 void OnError(AudioInputStream* stream) override { 129 void OnError(AudioInputStream* stream) override {
129 error_during_callback_ = true; 130 error_during_callback_ = true;
130 controller_->task_runner_->PostTask( 131 controller_->task_runner_->PostTask(
131 FROM_HERE, 132 FROM_HERE,
132 base::Bind(&AudioInputController::DoReportError, weak_controller_)); 133 base::Bind(&AudioInputController::DoReportError, weak_controller_));
133 } 134 }
134 135
(...skipping 13 matching lines...) Expand all
148 // audio streams. 149 // audio streams.
149 std::unique_ptr<AudioBus> source_copy = 150 std::unique_ptr<AudioBus> source_copy =
150 AudioBus::Create(source->channels(), source->frames()); 151 AudioBus::Create(source->channels(), source->frames());
151 source->CopyTo(source_copy.get()); 152 source->CopyTo(source_copy.get());
152 controller_->task_runner_->PostTask( 153 controller_->task_runner_->PostTask(
153 FROM_HERE, base::Bind(&AudioInputController::WriteInputDataForDebugging, 154 FROM_HERE, base::Bind(&AudioInputController::WriteInputDataForDebugging,
154 weak_controller_, base::Passed(&source_copy))); 155 weak_controller_, base::Passed(&source_copy)));
155 } 156 }
156 157
157 void DeliverDataToSyncWriter(const AudioBus* source, 158 void DeliverDataToSyncWriter(const AudioBus* source,
158 uint32_t hardware_delay_bytes, 159 base::TimeDelta delay,
160 base::TimeTicks delay_timestamp,
159 double volume) { 161 double volume) {
160 bool key_pressed = controller_->CheckForKeyboardInput(); 162 bool key_pressed = controller_->CheckForKeyboardInput();
161 controller_->sync_writer_->Write(source, volume, key_pressed, 163 controller_->sync_writer_->Write(source, volume, key_pressed, delay,
162 hardware_delay_bytes); 164 delay_timestamp);
o1ka 2017/02/10 13:28:50 Should we probably adjust delay and delay_timestam
DaleCurtis 2017/02/11 01:43:13 delay should always be provided relative to delay_
163 165
164 // The way the two classes interact here, could be done in a nicer way. 166 // The way the two classes interact here, could be done in a nicer way.
165 // As is, we call the AIC here to check the audio power, return and then 167 // As is, we call the AIC here to check the audio power, return and then
166 // post a task to the AIC based on what the AIC said. 168 // post a task to the AIC based on what the AIC said.
167 // The reason for this is to keep all PostTask calls from the hw callback 169 // The reason for this is to keep all PostTask calls from the hw callback
168 // thread to the AIC, that use a weak pointer, in the same class. 170 // thread to the AIC, that use a weak pointer, in the same class.
169 float average_power_dbfs; 171 float average_power_dbfs;
170 int mic_volume_percent; 172 int mic_volume_percent;
171 if (controller_->CheckAudioPower(source, volume, &average_power_dbfs, 173 if (controller_->CheckAudioPower(source, volume, &average_power_dbfs,
172 &mic_volume_percent)) { 174 &mic_volume_percent)) {
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 case AudioParameters::Format::AUDIO_PCM_LOW_LATENCY: 682 case AudioParameters::Format::AUDIO_PCM_LOW_LATENCY:
681 return AudioInputController::StreamType::LOW_LATENCY; 683 return AudioInputController::StreamType::LOW_LATENCY;
682 default: 684 default:
683 // Currently, the remaining supported type is fake. Reconsider if other 685 // Currently, the remaining supported type is fake. Reconsider if other
684 // formats become supported. 686 // formats become supported.
685 return AudioInputController::StreamType::FAKE; 687 return AudioInputController::StreamType::FAKE;
686 } 688 }
687 } 689 }
688 690
689 } // namespace media 691 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698