Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: webrtc/audio/audio_state_audio_path_unittest.cc

Issue 2436033002: Replace AudioConferenceMixer with AudioMixer. (Closed)
Patch Set: forgot dependency. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/base/refcountedobject.h"
the sun 2016/11/14 20:03:46 why?
aleloi 2016/11/15 16:56:54 Not needed; removed!
15 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
16 #include "webrtc/test/gtest.h"
17 #include "webrtc/test/mock_voice_engine.h"
18
19 namespace webrtc {
20 namespace test {
21
22 class AudioStateAudioPathTest : public testing::Test {
the sun 2016/11/14 20:03:46 Please avoid fixtures. Like in the stream tests, m
23 public:
24 AudioStateAudioPathTest() : audio_mixer_(AudioMixerImpl::Create()) {
25 using testing::_;
26
27 EXPECT_CALL(voice_engine_, RegisterVoiceEngineObserver(testing::_))
28 .WillOnce(testing::Return(0));
29 EXPECT_CALL(voice_engine_, DeRegisterVoiceEngineObserver())
30 .WillOnce(testing::Return(0));
31 EXPECT_CALL(voice_engine_, audio_device_module());
32 EXPECT_CALL(voice_engine_, audio_processing());
33 EXPECT_CALL(voice_engine_, audio_transport());
34
35 auto device = static_cast<MockAudioDeviceModule*>(
36 voice_engine_.audio_device_module());
37
38 ON_CALL(*device, RegisterAudioCallback(_))
39 .WillByDefault(testing::Invoke([this](AudioTransport* transport) {
40 audio_transport_proxy_ = transport;
41 return 0;
42 }));
43
44 ON_CALL(voice_engine_, audio_transport())
45 .WillByDefault(testing::Return(&original_audio_transport_));
46
47 EXPECT_CALL(voice_engine_, audio_device_module());
48
49 AudioState::Config config;
50 config.voice_engine = &voice_engine_;
51 config.audio_mixer = audio_mixer_;
52
53 audio_state_.reset(new internal::AudioState(config));
54 }
55
56 rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer_; }
57
58 AudioTransport* audio_transport_proxy() { return audio_transport_proxy_; }
59
60 MockAudioTransport& audio_transport() { return original_audio_transport_; }
61
62 private:
63 testing::StrictMock<MockVoiceEngine> voice_engine_;
64 MockAudioTransport original_audio_transport_;
65 std::unique_ptr<internal::AudioState> audio_state_;
66 AudioTransport* audio_transport_proxy_ = nullptr;
67 rtc::scoped_refptr<AudioMixer> audio_mixer_;
68 };
69
70 namespace {
71 class FakeAudioSource : public AudioMixer::Source {
72 public:
73 int Ssrc() const /*override*/ { return 0; }
74
75 int PreferredSampleRate() const /*override*/ { return 8000; }
76
77 MOCK_METHOD2(GetAudioFrameWithInfo,
78 AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame));
79 };
80 } // namespace
81
82 // Test that RecordedDataIsAvailable calls get to the original transport.
83 TEST_F(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) {
84 // Setup completed. Ensure call of old transport is forwarded to new.
85 uint32_t new_mic_level;
86 EXPECT_CALL(audio_transport(),
87 RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, 0, false,
88 testing::Ref(new_mic_level)));
89
90 audio_transport_proxy()->RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0,
91 0, 0, false, new_mic_level);
92 }
93
94 TEST_F(AudioStateAudioPathTest,
95 QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) {
96 FakeAudioSource fake_source;
97
98 mixer()->AddSource(&fake_source);
99
100 EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_))
101 .WillOnce(
102 testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) {
103 audio_frame->sample_rate_hz_ = sample_rate_hz;
104 audio_frame->samples_per_channel_ = sample_rate_hz / 100;
105 audio_frame->num_channels_ = 1;
106 return AudioMixer::Source::AudioFrameInfo::kNormal;
107 }));
108
109 int16_t audio_buffer[80];
110 size_t n_samples_out;
111 int64_t elapsed_time_ms;
112 int64_t ntp_time_ms;
113 audio_transport_proxy()->NeedMorePlayData(80, 2, 1, 8000, audio_buffer,
114 n_samples_out, &elapsed_time_ms,
115 &ntp_time_ms);
116 }
117 } // namespace test
118 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698