| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" | 
| 6 #include "base/logging.h" | 6 #include "base/logging.h" | 
| 7 #include "content/public/common/content_switches.h" | 7 #include "content/public/common/content_switches.h" | 
| 8 #include "content/renderer/media/mock_media_constraint_factory.h" | 8 #include "content/renderer/media/mock_media_constraint_factory.h" | 
| 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 
| 10 #include "content/renderer/media/webrtc_audio_capturer.h" | 10 #include "content/renderer/media/webrtc_audio_capturer.h" | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 98                              params_.frames_per_buffer()), | 98                              params_.frames_per_buffer()), | 
| 99         constraints, NULL, NULL); | 99         constraints, NULL, NULL); | 
| 100     capturer_source_ = new MockCapturerSource(); | 100     capturer_source_ = new MockCapturerSource(); | 
| 101     EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1)); | 101     EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1)); | 
| 102     EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 102     EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 
| 103     EXPECT_CALL(*capturer_source_.get(), Start()); | 103     EXPECT_CALL(*capturer_source_.get(), Start()); | 
| 104     capturer_->SetCapturerSourceForTesting(capturer_source_, params_); | 104     capturer_->SetCapturerSourceForTesting(capturer_source_, params_); | 
| 105 | 105 | 
| 106     scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 106     scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 
| 107         WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 107         WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 
| 108     track_.reset(new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 108     track_.reset(new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 
| 109     track_->Start(); | 109     track_->Start(); | 
| 110 | 110 | 
| 111     // Connect a mock sink to the track. | 111     // Connect a mock sink to the track. | 
| 112     scoped_ptr<MockPeerConnectionAudioSink> sink( | 112     scoped_ptr<MockPeerConnectionAudioSink> sink( | 
| 113         new MockPeerConnectionAudioSink()); | 113         new MockPeerConnectionAudioSink()); | 
| 114     track_->AddSink(sink.get()); | 114     track_->AddSink(sink.get()); | 
| 115 | 115 | 
| 116     int delay_ms = 65; | 116     int delay_ms = 65; | 
| 117     bool key_pressed = true; | 117     bool key_pressed = true; | 
| 118     double volume = 0.9; | 118     double volume = 0.9; | 
| 119 | 119 | 
| 120     // MaxVolume() in WebRtcAudioCapturer is hard-coded to return 255, we add | 120     // MaxVolume() in WebRtcAudioCapturer is hard-coded to return 255, we add | 
| 121     // 0.5 to do the correct truncation like the production code does. | 121     // 0.5 to do the correct truncation like the production code does. | 
| 122     int expected_volume_value = volume * capturer_->MaxVolume() + 0.5; | 122     int expected_volume_value = volume * capturer_->MaxVolume() + 0.5; | 
| 123     scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); | 123     scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); | 
| 124     audio_bus->Zero(); | 124     audio_bus->Zero(); | 
| 125 | 125 | 
| 126     media::AudioCapturerSource::CaptureCallback* callback = | 126     media::AudioCapturerSource::CaptureCallback* callback = | 
| 127         static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); | 127         static_cast<media::AudioCapturerSource::CaptureCallback*>( | 
|  | 128             capturer_.get()); | 
| 128 | 129 | 
| 129     // Verify the sink is getting the correct values. | 130     // Verify the sink is getting the correct values. | 
| 130     EXPECT_CALL(*sink, FormatIsSet()); | 131     EXPECT_CALL(*sink, FormatIsSet()); | 
| 131     EXPECT_CALL(*sink, | 132     EXPECT_CALL(*sink, | 
| 132                 OnDataCallback(_, _, delay_ms, expected_volume_value, | 133                 OnDataCallback(_, _, delay_ms, expected_volume_value, | 
| 133                                need_audio_processing, key_pressed)) | 134                                need_audio_processing, key_pressed)) | 
| 134         .Times(AtLeast(1)); | 135         .Times(AtLeast(1)); | 
| 135     callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); | 136     callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); | 
| 136 | 137 | 
| 137     // Verify the cached values in the capturer fits what we expect. | 138     // Verify the cached values in the capturer fits what we expect. | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 178   constraint_factory.AddMandatory(dummy_constraint, true); | 179   constraint_factory.AddMandatory(dummy_constraint, true); | 
| 179 | 180 | 
| 180   scoped_refptr<WebRtcAudioCapturer> capturer( | 181   scoped_refptr<WebRtcAudioCapturer> capturer( | 
| 181       WebRtcAudioCapturer::CreateCapturer( | 182       WebRtcAudioCapturer::CreateCapturer( | 
| 182           0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, | 183           0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, | 
| 183                                "", "", params_.sample_rate(), | 184                                "", "", params_.sample_rate(), | 
| 184                                params_.channel_layout(), | 185                                params_.channel_layout(), | 
| 185                                params_.frames_per_buffer()), | 186                                params_.frames_per_buffer()), | 
| 186           constraint_factory.CreateWebMediaConstraints(), NULL, NULL) | 187           constraint_factory.CreateWebMediaConstraints(), NULL, NULL) | 
| 187   ); | 188   ); | 
| 188   EXPECT_TRUE(capturer == NULL); | 189   EXPECT_TRUE(capturer.get() == NULL); | 
| 189 } | 190 } | 
| 190 | 191 | 
| 191 | 192 | 
| 192 }  // namespace content | 193 }  // namespace content | 
| OLD | NEW | 
|---|