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

Unified Diff: content/renderer/media/webrtc_audio_device_impl.cc

Issue 671793004: Clean up the media stream audio track code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 1 month 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: content/renderer/media/webrtc_audio_device_impl.cc
diff --git a/content/renderer/media/webrtc_audio_device_impl.cc b/content/renderer/media/webrtc_audio_device_impl.cc
index 49e90683afdb8c0e6dfc5f15d79758f711f409db..5b87c186e68d7964acbfe5db0ad513ed59cff2f6 100644
--- a/content/renderer/media/webrtc_audio_device_impl.cc
+++ b/content/renderer/media/webrtc_audio_device_impl.cc
@@ -23,14 +23,11 @@ namespace content {
WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()
: ref_count_(0),
audio_transport_callback_(NULL),
- input_delay_ms_(0),
output_delay_ms_(0),
initialized_(false),
playing_(false),
recording_(false),
- microphone_volume_(0),
- is_audio_track_processing_enabled_(
- MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) {
+ microphone_volume_(0) {
DVLOG(1) << "WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()";
// This object can be constructed on either the signaling thread or the main
// thread, so we need to detach these thread checkers here and have them
@@ -63,78 +60,6 @@ int32_t WebRtcAudioDeviceImpl::Release() {
return ret;
}
-int WebRtcAudioDeviceImpl::OnData(const int16* audio_data,
- int sample_rate,
- int number_of_channels,
- int number_of_frames,
- const std::vector<int>& channels,
- int audio_delay_milliseconds,
- int current_volume,
- bool need_audio_processing,
- bool key_pressed) {
- DCHECK(worker_thread_checker_.CalledOnValidThread());
- int total_delay_ms = 0;
- {
- base::AutoLock auto_lock(lock_);
- // Return immediately when not recording or |channels| is empty.
- // See crbug.com/274017: renderer crash dereferencing invalid channels[0].
- if (!recording_ || channels.empty())
- return 0;
-
- // Store the reported audio delay locally.
- input_delay_ms_ = audio_delay_milliseconds;
- total_delay_ms = input_delay_ms_ + output_delay_ms_;
- DVLOG(2) << "total delay: " << input_delay_ms_ + output_delay_ms_;
- }
-
- // Write audio frames in blocks of 10 milliseconds to the registered
- // webrtc::AudioTransport sink. Keep writing until our internal byte
- // buffer is empty.
- const int16* audio_buffer = audio_data;
- const int frames_per_10_ms = (sample_rate / 100);
- CHECK_EQ(number_of_frames % frames_per_10_ms, 0);
- int accumulated_audio_frames = 0;
- uint32_t new_volume = 0;
-
- // The lock here is to protect a race in the resampler inside webrtc when
- // there are more than one input stream calling OnData(), which can happen
- // when the users setup two getUserMedia, one for the microphone, another
- // for WebAudio. Currently we don't have a better way to fix it except for
- // adding a lock here to sequence the call.
- // TODO(xians): Remove this workaround after we move the
- // webrtc::AudioProcessing module to Chrome. See http://crbug/264611 for
- // details.
- base::AutoLock auto_lock(capture_callback_lock_);
- while (accumulated_audio_frames < number_of_frames) {
- // Deliver 10ms of recorded 16-bit linear PCM audio.
- int new_mic_level = audio_transport_callback_->OnDataAvailable(
- &channels[0],
- channels.size(),
- audio_buffer,
- sample_rate,
- number_of_channels,
- frames_per_10_ms,
- total_delay_ms,
- current_volume,
- key_pressed,
- need_audio_processing);
-
- accumulated_audio_frames += frames_per_10_ms;
- audio_buffer += frames_per_10_ms * number_of_channels;
-
- // The latest non-zero new microphone level will be returned.
- if (new_mic_level)
- new_volume = new_mic_level;
- }
-
- return new_volume;
-}
-
-void WebRtcAudioDeviceImpl::OnSetFormat(
- const media::AudioParameters& params) {
- DVLOG(1) << "WebRtcAudioDeviceImpl::OnSetFormat()";
-}
-
void WebRtcAudioDeviceImpl::RenderData(media::AudioBus* audio_bus,
int sample_rate,
int audio_delay_milliseconds,
@@ -157,40 +82,21 @@ void WebRtcAudioDeviceImpl::RenderData(media::AudioBus* audio_bus,
// Get audio frames in blocks of 10 milliseconds from the registered
// webrtc::AudioTransport source. Keep reading until our internal buffer
// is full.
- uint32_t num_audio_frames = 0;
int accumulated_audio_frames = 0;
int16* audio_data = &render_buffer_[0];
while (accumulated_audio_frames < audio_bus->frames()) {
// Get 10ms and append output to temporary byte buffer.
int64_t elapsed_time_ms = -1;
int64_t ntp_time_ms = -1;
- if (is_audio_track_processing_enabled_) {
- // When audio processing is enabled in the audio track, we use
- // PullRenderData() instead of NeedMorePlayData() to avoid passing the
- // render data to the APM in WebRTC as reference signal for echo
- // cancellation.
- static const int kBitsPerByte = 8;
- audio_transport_callback_->PullRenderData(bytes_per_sample * kBitsPerByte,
- sample_rate,
- audio_bus->channels(),
- frames_per_10_ms,
- audio_data,
- &elapsed_time_ms,
- &ntp_time_ms);
- accumulated_audio_frames += frames_per_10_ms;
- } else {
- // TODO(xians): Remove the following code after the APM in WebRTC is
- // deprecated.
- audio_transport_callback_->NeedMorePlayData(frames_per_10_ms,
- bytes_per_sample,
- audio_bus->channels(),
- sample_rate,
- audio_data,
- num_audio_frames,
- &elapsed_time_ms,
- &ntp_time_ms);
- accumulated_audio_frames += num_audio_frames;
- }
+ static const int kBitsPerByte = 8;
+ audio_transport_callback_->PullRenderData(bytes_per_sample * kBitsPerByte,
+ sample_rate,
+ audio_bus->channels(),
+ frames_per_10_ms,
+ audio_data,
+ &elapsed_time_ms,
+ &ntp_time_ms);
+ accumulated_audio_frames += frames_per_10_ms;
if (elapsed_time_ms >= 0) {
*current_time = base::TimeDelta::FromMilliseconds(elapsed_time_ms);
}
@@ -460,9 +366,11 @@ int32_t WebRtcAudioDeviceImpl::PlayoutDelay(uint16_t* delay_ms) const {
int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const {
DCHECK(signaling_thread_checker_.CalledOnValidThread());
- base::AutoLock auto_lock(lock_);
- *delay_ms = static_cast<uint16_t>(input_delay_ms_);
- return 0;
+
+ // There is no way to report a correct delay value to WebRTC since there
+ // might be multiple WebRtcAudioCapturer instances.
+ NOTREACHED();
+ return -1;
}
int32_t WebRtcAudioDeviceImpl::RecordingSampleRate(
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.h ('k') | content/renderer/media/webrtc_local_audio_track.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698