OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <memory> | |
12 | |
13 #include "webrtc/audio/audio_state.h" | |
14 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | |
15 #include "webrtc/test/gtest.h" | |
16 #include "webrtc/test/mock_voice_engine.h" | |
17 | |
18 namespace webrtc { | |
19 namespace test { | |
20 | |
21 class AudioStateAudioPathTest : public testing::Test { | |
the sun
2016/11/16 20:22:57
Please avoid fixtures. Like in the stream tests, m
aleloi
2016/11/17 18:12:26
I've removed the fixture and moved the code that e
| |
22 public: | |
23 AudioStateAudioPathTest() : audio_mixer_(AudioMixerImpl::Create()) { | |
24 using testing::_; | |
25 | |
26 EXPECT_CALL(voice_engine_, RegisterVoiceEngineObserver(testing::_)) | |
27 .WillOnce(testing::Return(0)); | |
28 EXPECT_CALL(voice_engine_, DeRegisterVoiceEngineObserver()) | |
29 .WillOnce(testing::Return(0)); | |
30 EXPECT_CALL(voice_engine_, audio_device_module()); | |
31 EXPECT_CALL(voice_engine_, audio_processing()); | |
32 EXPECT_CALL(voice_engine_, audio_transport()); | |
33 | |
34 auto device = static_cast<MockAudioDeviceModule*>( | |
35 voice_engine_.audio_device_module()); | |
36 | |
37 ON_CALL(*device, RegisterAudioCallback(_)) | |
38 .WillByDefault(testing::Invoke([this](AudioTransport* transport) { | |
39 audio_transport_proxy_ = transport; | |
40 return 0; | |
41 })); | |
42 | |
43 ON_CALL(voice_engine_, audio_transport()) | |
44 .WillByDefault(testing::Return(&original_audio_transport_)); | |
45 | |
46 EXPECT_CALL(voice_engine_, audio_device_module()); | |
47 | |
48 AudioState::Config config; | |
49 config.voice_engine = &voice_engine_; | |
50 config.audio_mixer = audio_mixer_; | |
51 | |
52 audio_state_.reset(new internal::AudioState(config)); | |
53 } | |
54 | |
55 rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer_; } | |
56 | |
57 AudioTransport* audio_transport_proxy() { return audio_transport_proxy_; } | |
58 | |
59 MockAudioTransport& audio_transport() { return original_audio_transport_; } | |
60 | |
61 private: | |
62 testing::StrictMock<MockVoiceEngine> voice_engine_; | |
63 MockAudioTransport original_audio_transport_; | |
64 std::unique_ptr<internal::AudioState> audio_state_; | |
65 AudioTransport* audio_transport_proxy_ = nullptr; | |
66 rtc::scoped_refptr<AudioMixer> audio_mixer_; | |
67 }; | |
68 | |
69 namespace { | |
70 class FakeAudioSource : public AudioMixer::Source { | |
71 public: | |
72 int Ssrc() const /*override*/ { return 0; } | |
73 | |
74 int PreferredSampleRate() const /*override*/ { return 8000; } | |
75 | |
76 MOCK_METHOD2(GetAudioFrameWithInfo, | |
77 AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame)); | |
78 }; | |
79 } // namespace | |
80 | |
81 // Test that RecordedDataIsAvailable calls get to the original transport. | |
82 TEST_F(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { | |
83 // Setup completed. Ensure call of old transport is forwarded to new. | |
84 uint32_t new_mic_level; | |
85 EXPECT_CALL(audio_transport(), | |
86 RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, 0, false, | |
87 testing::Ref(new_mic_level))); | |
88 | |
89 audio_transport_proxy()->RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, | |
90 0, 0, false, new_mic_level); | |
91 } | |
92 | |
93 TEST_F(AudioStateAudioPathTest, | |
94 QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) { | |
95 FakeAudioSource fake_source; | |
96 | |
97 mixer()->AddSource(&fake_source); | |
98 | |
99 EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_)) | |
100 .WillOnce( | |
101 testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) { | |
102 audio_frame->sample_rate_hz_ = sample_rate_hz; | |
103 audio_frame->samples_per_channel_ = sample_rate_hz / 100; | |
104 audio_frame->num_channels_ = 1; | |
105 return AudioMixer::Source::AudioFrameInfo::kNormal; | |
106 })); | |
107 | |
108 int16_t audio_buffer[80]; | |
109 size_t n_samples_out; | |
110 int64_t elapsed_time_ms; | |
111 int64_t ntp_time_ms; | |
112 audio_transport_proxy()->NeedMorePlayData(80, 2, 1, 8000, audio_buffer, | |
113 n_samples_out, &elapsed_time_ms, | |
114 &ntp_time_ms); | |
115 } | |
116 } // namespace test | |
117 } // namespace webrtc | |
OLD | NEW |