Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/environment.h" | 5 #include "base/environment.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "content/renderer/media/webrtc_audio_device_impl.h" | 7 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 8 #include "content/test/webrtc_audio_device_test.h" | 8 #include "content/test/webrtc_audio_device_test.h" |
| 9 #include "media/audio/audio_util.h" | 9 #include "media/audio/audio_util.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h" | 11 #include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h" |
| 12 #include "third_party/webrtc/voice_engine/main/interface/voe_base.h" | 12 #include "third_party/webrtc/voice_engine/main/interface/voe_base.h" |
| 13 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" | 13 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" |
| 14 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" | 14 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" |
| 15 | 15 |
| 16 using testing::_; | 16 using testing::_; |
| 17 using testing::InvokeWithoutArgs; | 17 using testing::InvokeWithoutArgs; |
| 18 using testing::Return; | 18 using testing::Return; |
| 19 using testing::StrEq; | 19 using testing::StrEq; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 ACTION_P(QuitMessageLoop, loop_or_proxy) { | 23 ACTION_P(QuitMessageLoop, loop_or_proxy) { |
| 24 loop_or_proxy->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 24 loop_or_proxy->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 class AudioUtil : public AudioUtilInterface { | 27 class AudioUtil : public AudioUtilInterface { |
| 28 public: | 28 public: |
| 29 AudioUtil() {} | |
| 30 | |
| 29 virtual double GetAudioHardwareSampleRate() OVERRIDE { | 31 virtual double GetAudioHardwareSampleRate() OVERRIDE { |
| 30 return media::GetAudioHardwareSampleRate(); | 32 return media::GetAudioHardwareSampleRate(); |
| 31 } | 33 } |
| 32 virtual double GetAudioInputHardwareSampleRate() OVERRIDE { | 34 virtual double GetAudioInputHardwareSampleRate() OVERRIDE { |
| 33 return media::GetAudioInputHardwareSampleRate(); | 35 return media::GetAudioInputHardwareSampleRate(); |
| 34 } | 36 } |
| 37 private: | |
| 38 DISALLOW_COPY_AND_ASSIGN(AudioUtil); | |
| 39 }; | |
| 40 | |
| 41 class AudioUtilNoHardware : public AudioUtilInterface { | |
| 42 public: | |
| 43 AudioUtilNoHardware(double output_rate, double input_rate) | |
| 44 : output_rate_(output_rate), input_rate_(input_rate) { | |
|
henrika (OOO until Aug 14)
2011/11/16 09:57:58
add two more spaces?
| |
| 45 } | |
| 46 | |
| 47 virtual double GetAudioHardwareSampleRate() OVERRIDE { | |
| 48 return output_rate_; | |
| 49 } | |
| 50 virtual double GetAudioInputHardwareSampleRate() OVERRIDE { | |
| 51 return input_rate_; | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 double output_rate_; | |
| 56 double input_rate_; | |
| 57 DISALLOW_COPY_AND_ASSIGN(AudioUtilNoHardware); | |
| 35 }; | 58 }; |
| 36 | 59 |
| 37 bool IsRunningHeadless() { | 60 bool IsRunningHeadless() { |
| 38 scoped_ptr<base::Environment> env(base::Environment::Create()); | 61 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 39 if (env->HasVar("CHROME_HEADLESS")) | 62 if (env->HasVar("CHROME_HEADLESS")) |
| 40 return true; | 63 return true; |
| 41 return false; | 64 return false; |
| 42 } | 65 } |
| 43 | 66 |
| 44 } // end namespace | 67 } // end namespace |
| 45 | 68 |
| 46 // Basic test that instantiates and initializes an instance of | 69 // Basic test that instantiates and initializes an instance of |
| 47 // WebRtcAudioDeviceImpl. | 70 // WebRtcAudioDeviceImpl. |
| 48 TEST_F(WebRTCAudioDeviceTest, Construct) { | 71 TEST_F(WebRTCAudioDeviceTest, Construct) { |
| 49 AudioUtil audio_util; | 72 AudioUtilNoHardware audio_util(48000.0, 48000.0); |
| 50 set_audio_util_callback(&audio_util); | 73 set_audio_util_callback(&audio_util); |
| 51 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 74 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 52 new WebRtcAudioDeviceImpl()); | 75 new WebRtcAudioDeviceImpl()); |
| 53 audio_device->SetSessionId(1); | 76 audio_device->SetSessionId(1); |
| 54 | 77 |
| 55 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 78 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 56 ASSERT_TRUE(engine.valid()); | 79 ASSERT_TRUE(engine.valid()); |
| 57 | 80 |
| 58 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 81 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 59 int err = base->Init(audio_device); | 82 int err = base->Init(audio_device); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, | 130 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, |
| 108 webrtc::kFileFormatPcm16kHzFile)); | 131 webrtc::kFileFormatPcm16kHzFile)); |
| 109 | 132 |
| 110 message_loop_.PostDelayedTask(FROM_HERE, | 133 message_loop_.PostDelayedTask(FROM_HERE, |
| 111 new MessageLoop::QuitTask(), | 134 new MessageLoop::QuitTask(), |
| 112 TestTimeouts::action_timeout_ms()); | 135 TestTimeouts::action_timeout_ms()); |
| 113 message_loop_.Run(); | 136 message_loop_.Run(); |
| 114 | 137 |
| 115 EXPECT_EQ(0, base->Terminate()); | 138 EXPECT_EQ(0, base->Terminate()); |
| 116 } | 139 } |
| OLD | NEW |