OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/environment.h" |
| 6 #include "base/test/test_timeouts.h" |
| 7 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 8 #include "content/test/webrtc_audio_device_test.h" |
| 9 #include "media/audio/audio_util.h" |
| 10 #include "testing/gmock/include/gmock/gmock.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" |
| 13 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" |
| 14 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" |
| 15 |
| 16 using testing::_; |
| 17 using testing::InvokeWithoutArgs; |
| 18 using testing::Return; |
| 19 using testing::StrEq; |
| 20 |
| 21 namespace { |
| 22 |
| 23 ACTION_P(QuitMessageLoop, loop_or_proxy) { |
| 24 loop_or_proxy->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 25 } |
| 26 |
| 27 class AudioUtil : public AudioUtilInterface { |
| 28 public: |
| 29 virtual double GetAudioHardwareSampleRate() OVERRIDE { |
| 30 return media::GetAudioHardwareSampleRate(); |
| 31 } |
| 32 virtual double GetAudioInputHardwareSampleRate() OVERRIDE { |
| 33 return media::GetAudioInputHardwareSampleRate(); |
| 34 } |
| 35 }; |
| 36 |
| 37 bool IsRunningHeadless() { |
| 38 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 39 if (env->HasVar("CHROME_HEADLESS")) |
| 40 return true; |
| 41 return false; |
| 42 } |
| 43 |
| 44 } // end namespace |
| 45 |
| 46 // Basic test that instantiates and initializes an instance of |
| 47 // WebRtcAudioDeviceImpl. |
| 48 // TODO(tommi): Re-enable when the flakiness of CpuWindows in webrtc has |
| 49 // been fixed. |
| 50 TEST_F(WebRTCAudioDeviceTest, DISABLED_Construct) { |
| 51 AudioUtil audio_util; |
| 52 set_audio_util_callback(&audio_util); |
| 53 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 54 new WebRtcAudioDeviceImpl()); |
| 55 audio_device->SetSessionId(1); |
| 56 |
| 57 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 58 ASSERT_TRUE(engine.valid()); |
| 59 |
| 60 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 61 int err = base->Init(audio_device); |
| 62 EXPECT_EQ(0, err); |
| 63 EXPECT_EQ(0, base->Terminate()); |
| 64 } |
| 65 |
| 66 // Uses WebRtcAudioDeviceImpl to play a local wave file. |
| 67 // Disabled when running headless since the bots don't have the required config. |
| 68 // TODO(tommi): Re-enable when the flakiness of CpuWindows in webrtc has |
| 69 // been fixed. |
| 70 TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) { |
| 71 if (IsRunningHeadless()) |
| 72 return; |
| 73 |
| 74 std::string file_path( |
| 75 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); |
| 76 |
| 77 AudioUtil audio_util; |
| 78 set_audio_util_callback(&audio_util); |
| 79 |
| 80 EXPECT_CALL(media_observer(), |
| 81 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); |
| 82 EXPECT_CALL(media_observer(), |
| 83 OnSetAudioStreamPlaying(_, 1, true)).Times(1); |
| 84 EXPECT_CALL(media_observer(), |
| 85 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); |
| 86 EXPECT_CALL(media_observer(), |
| 87 OnDeleteAudioStream(_, 1)).Times(1); |
| 88 |
| 89 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 90 new WebRtcAudioDeviceImpl()); |
| 91 audio_device->SetSessionId(1); |
| 92 |
| 93 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 94 ASSERT_TRUE(engine.valid()); |
| 95 |
| 96 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 97 ASSERT_TRUE(base.valid()); |
| 98 int err = base->Init(audio_device); |
| 99 ASSERT_EQ(0, err); |
| 100 |
| 101 int ch = base->CreateChannel(); |
| 102 EXPECT_NE(-1, ch); |
| 103 EXPECT_EQ(0, base->StartPlayout(ch)); |
| 104 |
| 105 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get()); |
| 106 int duration = 0; |
| 107 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, |
| 108 webrtc::kFileFormatPcm16kHzFile)); |
| 109 EXPECT_NE(0, duration); |
| 110 |
| 111 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, |
| 112 webrtc::kFileFormatPcm16kHzFile)); |
| 113 |
| 114 message_loop_.PostDelayedTask(FROM_HERE, |
| 115 new MessageLoop::QuitTask(), |
| 116 TestTimeouts::action_timeout_ms()); |
| 117 message_loop_.Run(); |
| 118 |
| 119 EXPECT_EQ(0, base->Terminate()); |
| 120 } |
OLD | NEW |