| OLD | NEW |
| 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 "content/renderer/media/webaudio_capturer_source.h" | 5 #include "content/renderer/media/webaudio_capturer_source.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "content/renderer/media/webrtc_local_audio_track.h" | 9 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 WebAudioCapturerSource::~WebAudioCapturerSource() { | 29 WebAudioCapturerSource::~WebAudioCapturerSource() { |
| 30 DCHECK(thread_checker_.CalledOnValidThread()); | 30 DCHECK(thread_checker_.CalledOnValidThread()); |
| 31 removeFromBlinkSource(); | 31 removeFromBlinkSource(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void WebAudioCapturerSource::setFormat( | 34 void WebAudioCapturerSource::setFormat( |
| 35 size_t number_of_channels, float sample_rate) { | 35 size_t number_of_channels, float sample_rate) { |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 DVLOG(1) << "WebAudioCapturerSource::setFormat(sample_rate=" | 37 DVLOG(1) << "WebAudioCapturerSource::setFormat(sample_rate=" |
| 38 << sample_rate << ")"; | 38 << sample_rate << ")"; |
| 39 if (number_of_channels > 2) { | |
| 40 // TODO(xians): Handle more than just the mono and stereo cases. | |
| 41 LOG(WARNING) << "WebAudioCapturerSource::setFormat() : unhandled format."; | |
| 42 return; | |
| 43 } | |
| 44 | 39 |
| 40 // If the channel count is greater than 8, use discrete layout. However, |
| 41 // anything beyond 8 is ignored by the subsequent (WebRTC) audio pipeline. |
| 45 ChannelLayout channel_layout = | 42 ChannelLayout channel_layout = |
| 46 number_of_channels == 1 ? CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; | 43 number_of_channels > 8 ? media::CHANNEL_LAYOUT_DISCRETE |
| 44 : media::GuessChannelLayout(number_of_channels); |
| 47 | 45 |
| 48 base::AutoLock auto_lock(lock_); | 46 base::AutoLock auto_lock(lock_); |
| 47 |
| 49 // Set the format used by this WebAudioCapturerSource. We are using 10ms data | 48 // Set the format used by this WebAudioCapturerSource. We are using 10ms data |
| 50 // as buffer size since that is the native buffer size of WebRtc packet | 49 // as buffer size since that is the native buffer size of WebRtc packet |
| 51 // running on. | 50 // running on. |
| 52 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 51 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 53 sample_rate, 16, sample_rate / 100); | 52 sample_rate, 16, sample_rate / 100); |
| 53 |
| 54 // Take care of the discrete channel layout case. |
| 55 params_.set_channels_for_discrete(number_of_channels); |
| 56 |
| 54 audio_format_changed_ = true; | 57 audio_format_changed_ = true; |
| 55 | 58 |
| 56 wrapper_bus_ = AudioBus::CreateWrapper(params_.channels()); | 59 wrapper_bus_ = AudioBus::CreateWrapper(params_.channels()); |
| 57 capture_bus_ = AudioBus::Create(params_); | 60 capture_bus_ = AudioBus::Create(params_); |
| 61 |
| 58 fifo_.reset(new AudioFifo( | 62 fifo_.reset(new AudioFifo( |
| 59 params_.channels(), | 63 params_.channels(), |
| 60 kMaxNumberOfBuffersInFifo * params_.frames_per_buffer())); | 64 kMaxNumberOfBuffersInFifo * params_.frames_per_buffer())); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void WebAudioCapturerSource::Start(WebRtcLocalAudioTrack* track) { | 67 void WebAudioCapturerSource::Start(WebRtcLocalAudioTrack* track) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 DCHECK(track); | 69 DCHECK(track); |
| 66 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
| 67 track_ = track; | 71 track_ = track; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // WebAudioCapturerSource reference still registered as an audio consumer on | 134 // WebAudioCapturerSource reference still registered as an audio consumer on |
| 131 // the blink side. | 135 // the blink side. |
| 132 void WebAudioCapturerSource::removeFromBlinkSource() { | 136 void WebAudioCapturerSource::removeFromBlinkSource() { |
| 133 if (!blink_source_.isNull()) { | 137 if (!blink_source_.isNull()) { |
| 134 blink_source_.removeAudioConsumer(this); | 138 blink_source_.removeAudioConsumer(this); |
| 135 blink_source_.reset(); | 139 blink_source_.reset(); |
| 136 } | 140 } |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace content | 143 } // namespace content |
| OLD | NEW |