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

Side by Side Diff: content/renderer/media/webaudio_capturer_source.cc

Issue 37793005: move the APM to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added a switch, it uses the APM in WebRtc if the switch is off, otherwise use the APM in Chrome. Created 7 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 unified diff | Download patch | Annotate | Revision Log
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 "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 "content/renderer/media/webrtc_local_audio_source_provider.h" 8 #include "content/renderer/media/webrtc_audio_capturer.h"
9 #include "content/renderer/media/webrtc_local_audio_track.h" 9 #include "content/renderer/media/webrtc_local_audio_track.h"
10 10
11 using media::AudioBus; 11 using media::AudioBus;
12 using media::AudioFifo; 12 using media::AudioFifo;
13 using media::AudioParameters; 13 using media::AudioParameters;
14 using media::ChannelLayout; 14 using media::ChannelLayout;
15 using media::CHANNEL_LAYOUT_MONO; 15 using media::CHANNEL_LAYOUT_MONO;
16 using media::CHANNEL_LAYOUT_STEREO; 16 using media::CHANNEL_LAYOUT_STEREO;
17 17
18 static const int kMaxNumberOfBuffersInFifo = 5; 18 static const int kMaxNumberOfBuffersInFifo = 5;
19 19
20 namespace content { 20 namespace content {
21 21
22 WebAudioCapturerSource::WebAudioCapturerSource() 22 WebAudioCapturerSource::WebAudioCapturerSource()
23 : track_(NULL), 23 : track_(NULL),
24 source_provider_(NULL) { 24 capturer_(NULL) {
25 } 25 }
26 26
27 WebAudioCapturerSource::~WebAudioCapturerSource() { 27 WebAudioCapturerSource::~WebAudioCapturerSource() {
28 } 28 }
29 29
30 void WebAudioCapturerSource::setFormat( 30 void WebAudioCapturerSource::setFormat(
31 size_t number_of_channels, float sample_rate) { 31 size_t number_of_channels, float sample_rate) {
32 DCHECK(thread_checker_.CalledOnValidThread()); 32 DCHECK(thread_checker_.CalledOnValidThread());
33 DVLOG(1) << "WebAudioCapturerSource::setFormat(sample_rate=" 33 DLOG(WARNING) << "WebAudioCapturerSource::setFormat(sample_rate="
34 << sample_rate << ")"; 34 << sample_rate << ")";
35 if (number_of_channels > 2) { 35 if (number_of_channels > 2) {
36 // TODO(xians): Handle more than just the mono and stereo cases. 36 // TODO(xians): Handle more than just the mono and stereo cases.
37 LOG(WARNING) << "WebAudioCapturerSource::setFormat() : unhandled format."; 37 LOG(WARNING) << "WebAudioCapturerSource::setFormat() : unhandled format.";
38 return; 38 return;
39 } 39 }
40 40
41 ChannelLayout channel_layout = 41 ChannelLayout channel_layout =
42 number_of_channels == 1 ? CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; 42 number_of_channels == 1 ? CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO;
43 43
(...skipping 11 matching lines...) Expand all
55 track_->SetCaptureFormat(params_); 55 track_->SetCaptureFormat(params_);
56 56
57 wrapper_bus_ = AudioBus::CreateWrapper(params_.channels()); 57 wrapper_bus_ = AudioBus::CreateWrapper(params_.channels());
58 capture_bus_ = AudioBus::Create(params_); 58 capture_bus_ = AudioBus::Create(params_);
59 fifo_.reset(new AudioFifo( 59 fifo_.reset(new AudioFifo(
60 params_.channels(), 60 params_.channels(),
61 kMaxNumberOfBuffersInFifo * params_.frames_per_buffer())); 61 kMaxNumberOfBuffersInFifo * params_.frames_per_buffer()));
62 } 62 }
63 63
64 void WebAudioCapturerSource::Start( 64 void WebAudioCapturerSource::Start(
65 WebRtcLocalAudioTrack* track, 65 WebRtcLocalAudioTrack* track, WebRtcAudioCapturer* capturer) {
66 WebRtcLocalAudioSourceProvider* source_provider) {
67 DCHECK(thread_checker_.CalledOnValidThread()); 66 DCHECK(thread_checker_.CalledOnValidThread());
68 DCHECK(track); 67 DCHECK(track);
69 // |source_provider| may be NULL if no getUserMedia has been called before 68 // |source_provider| may be NULL if no getUserMedia has been called before
70 // calling CreateMediaStreamDestination. 69 // calling CreateMediaStreamDestination.
71 // The downstream client should be configured the same as what WebKit 70 // The downstream client should be configured the same as what WebKit
72 // is feeding it. 71 // is feeding it.
73 track->SetCaptureFormat(params_); 72 if (params_.IsValid())
73 track->SetCaptureFormat(params_);
74 74
75 base::AutoLock auto_lock(lock_); 75 base::AutoLock auto_lock(lock_);
76 track_ = track; 76 track_ = track;
77 source_provider_ = source_provider; 77 capturer_ = capturer;
78 } 78 }
79 79
80 void WebAudioCapturerSource::Stop() { 80 void WebAudioCapturerSource::Stop() {
81 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
82 base::AutoLock auto_lock(lock_); 82 base::AutoLock auto_lock(lock_);
83 track_ = NULL; 83 track_ = NULL;
84 source_provider_ = NULL; 84 capturer_ = NULL;
85 } 85 }
86 86
87 void WebAudioCapturerSource::consumeAudio( 87 void WebAudioCapturerSource::consumeAudio(
88 const WebKit::WebVector<const float*>& audio_data, 88 const WebKit::WebVector<const float*>& audio_data,
89 size_t number_of_frames) { 89 size_t number_of_frames) {
90 base::AutoLock auto_lock(lock_); 90 base::AutoLock auto_lock(lock_);
91 if (!track_) 91 if (!track_)
92 return; 92 return;
93 93
94 wrapper_bus_->set_frames(number_of_frames); 94 wrapper_bus_->set_frames(number_of_frames);
(...skipping 11 matching lines...) Expand all
106 NOTREACHED() << "WebAudioCapturerSource::Consume() : FIFO overrun."; 106 NOTREACHED() << "WebAudioCapturerSource::Consume() : FIFO overrun.";
107 return; 107 return;
108 } 108 }
109 109
110 fifo_->Push(wrapper_bus_.get()); 110 fifo_->Push(wrapper_bus_.get());
111 int capture_frames = params_.frames_per_buffer(); 111 int capture_frames = params_.frames_per_buffer();
112 int delay_ms = 0; 112 int delay_ms = 0;
113 int volume = 0; 113 int volume = 0;
114 bool key_pressed = false; 114 bool key_pressed = false;
115 while (fifo_->frames() >= capture_frames) { 115 while (fifo_->frames() >= capture_frames) {
116 if (source_provider_) { 116 if (capturer_) {
117 source_provider_->GetAudioProcessingParams( 117 capturer_->GetAudioProcessingParams(
118 &delay_ms, &volume, &key_pressed); 118 &delay_ms, &volume, &key_pressed);
119 } 119 }
120 fifo_->Consume(capture_bus_.get(), 0, capture_frames); 120 fifo_->Consume(capture_bus_.get(), 0, capture_frames);
121 // TODO(xians): Convert the format and feed it to the track.
121 track_->Capture(capture_bus_.get(), delay_ms, volume, key_pressed); 122 track_->Capture(capture_bus_.get(), delay_ms, volume, key_pressed);
122 } 123 }
123 } 124 }
124 125
125 } // namespace content 126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698