Chromium Code Reviews| 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "content/renderer/media/rtc_media_constraints.h" | 6 #include "content/renderer/media/rtc_media_constraints.h" |
| 7 #include "content/renderer/media/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 8 #include "content/renderer/media/webrtc_local_audio_track.h" | 8 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
| 10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 int session_id)); | 58 int session_id)); |
| 59 MOCK_METHOD0(Start, void()); | 59 MOCK_METHOD0(Start, void()); |
| 60 MOCK_METHOD0(Stop, void()); | 60 MOCK_METHOD0(Stop, void()); |
| 61 MOCK_METHOD1(SetVolume, void(double volume)); | 61 MOCK_METHOD1(SetVolume, void(double volume)); |
| 62 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); | 62 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); |
| 63 | 63 |
| 64 protected: | 64 protected: |
| 65 virtual ~MockCapturerSource() {} | 65 virtual ~MockCapturerSource() {} |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class MockWebRtcAudioCapturerSink : public WebRtcAudioCapturerSink { | 68 class MockWebRtcAudioCapturerSink : public PeerConnectionAudioSink { |
|
tommi (sloooow) - chröme
2013/11/29 13:00:20
change name to MockPeerConnectionAudioSink. Alter
no longer working on chromium
2013/11/29 15:02:04
Done.
| |
| 69 public: | 69 public: |
| 70 MockWebRtcAudioCapturerSink() {} | 70 MockWebRtcAudioCapturerSink() {} |
| 71 ~MockWebRtcAudioCapturerSink() {} | 71 ~MockWebRtcAudioCapturerSink() {} |
| 72 MOCK_METHOD9(CaptureData, int(const std::vector<int>& channels, | 72 MOCK_METHOD9(OnData, int(const int16* audio_data, |
| 73 const int16* audio_data, | 73 int sample_rate, |
| 74 int sample_rate, | 74 int number_of_channels, |
| 75 int number_of_channels, | 75 int number_of_frames, |
| 76 int number_of_frames, | 76 const std::vector<int>& channels, |
| 77 int audio_delay_milliseconds, | 77 int audio_delay_milliseconds, |
| 78 int current_volume, | 78 int current_volume, |
| 79 bool need_audio_processing, | 79 bool need_audio_processing, |
| 80 bool key_pressed)); | 80 bool key_pressed)); |
| 81 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); | 81 MOCK_METHOD1(OnSetFormat, void(const media::AudioParameters& params)); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 class WebRtcAudioCapturerTest : public testing::Test { | 86 class WebRtcAudioCapturerTest : public testing::Test { |
| 87 protected: | 87 protected: |
| 88 WebRtcAudioCapturerTest() | 88 WebRtcAudioCapturerTest() |
| 89 #if defined(OS_ANDROID) | 89 #if defined(OS_ANDROID) |
| 90 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 90 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 91 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 960) { | 91 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 960) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); | 138 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); |
| 139 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
| 140 const int expected_buffer_size = params_.sample_rate() / 100; | 140 const int expected_buffer_size = params_.sample_rate() / 100; |
| 141 #else | 141 #else |
| 142 const int expected_buffer_size = params_.frames_per_buffer(); | 142 const int expected_buffer_size = params_.frames_per_buffer(); |
| 143 #endif | 143 #endif |
| 144 bool expected_need_audio_processing = true; | 144 bool expected_need_audio_processing = true; |
| 145 media::AudioCapturerSource::CaptureCallback* callback = | 145 media::AudioCapturerSource::CaptureCallback* callback = |
| 146 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); | 146 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); |
| 147 // Verify the sink is getting the correct values. | 147 // Verify the sink is getting the correct values. |
| 148 EXPECT_CALL(*sink, SetCaptureFormat(_)); | 148 EXPECT_CALL(*sink, OnSetFormat(_)); |
| 149 EXPECT_CALL(*sink, | 149 EXPECT_CALL(*sink, |
| 150 CaptureData(_, _, params_.sample_rate(), params_.channels(), | 150 OnData(_, params_.sample_rate(), params_.channels(), |
| 151 expected_buffer_size, delay_ms, | 151 expected_buffer_size, _, delay_ms, |
| 152 expected_volume_value, expected_need_audio_processing, | 152 expected_volume_value, expected_need_audio_processing, |
| 153 key_pressed)).Times(AtLeast(1)); | 153 key_pressed)).Times(AtLeast(1)); |
| 154 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); | 154 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); |
| 155 | 155 |
| 156 // Verify the cached values in the capturer fits what we expect. | 156 // Verify the cached values in the capturer fits what we expect. |
| 157 base::TimeDelta cached_delay; | 157 base::TimeDelta cached_delay; |
| 158 int cached_volume = !expected_volume_value; | 158 int cached_volume = !expected_volume_value; |
| 159 bool cached_key_pressed = !key_pressed; | 159 bool cached_key_pressed = !key_pressed; |
| 160 capturer_->GetAudioProcessingParams(&cached_delay, &cached_volume, | 160 capturer_->GetAudioProcessingParams(&cached_delay, &cached_volume, |
| 161 &cached_key_pressed); | 161 &cached_key_pressed); |
| 162 EXPECT_EQ(cached_delay.InMilliseconds(), delay_ms); | 162 EXPECT_EQ(cached_delay.InMilliseconds(), delay_ms); |
| 163 EXPECT_EQ(cached_volume, expected_volume_value); | 163 EXPECT_EQ(cached_volume, expected_volume_value); |
| 164 EXPECT_EQ(cached_key_pressed, key_pressed); | 164 EXPECT_EQ(cached_key_pressed, key_pressed); |
| 165 | 165 |
| 166 track_->RemoveSink(sink.get()); | 166 track_->RemoveSink(sink.get()); |
| 167 EXPECT_CALL(*capturer_source_.get(), Stop()); | 167 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 168 capturer_->Stop(); | 168 capturer_->Stop(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // namespace content | 171 } // namespace content |
| OLD | NEW |