blob: 2fe4fdec4372b41a8f4a966e3372cad815f4afde [file] [log] [blame]
solenbergc7a8b082015-10-16 14:35:07 -07001/*
2 * Copyright (c) 2015 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 <list>
kwibergb25345e2016-03-12 06:10:44 -080012#include <memory>
solenbergc7a8b082015-10-16 14:35:07 -070013
kjellandera69d9732016-08-31 07:33:05 -070014#include "webrtc/api/call/audio_state.h"
solenbergc7a8b082015-10-16 14:35:07 -070015#include "webrtc/call.h"
ossu29b1a8d2016-06-13 07:34:51 -070016#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
kwibergac9f8762016-09-30 22:29:43 -070017#include "webrtc/test/gtest.h"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010018#include "webrtc/test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070019
20namespace {
21
22struct CallHelper {
ossu29b1a8d2016-06-13 07:34:51 -070023 explicit CallHelper(
24 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
25 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 15:34:49 -080026 webrtc::AudioState::Config audio_state_config;
27 audio_state_config.voice_engine = &voice_engine_;
solenbergc7a8b082015-10-16 14:35:07 -070028 webrtc::Call::Config config;
solenberg566ef242015-11-06 15:34:49 -080029 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070030 call_.reset(webrtc::Call::Create(config));
31 }
32
33 webrtc::Call* operator->() { return call_.get(); }
34
35 private:
solenberg3a941542015-11-16 07:34:50 -080036 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
kwibergb25345e2016-03-12 06:10:44 -080037 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070038};
39} // namespace
40
41namespace webrtc {
42
43TEST(CallTest, ConstructDestruct) {
44 CallHelper call;
45}
46
47TEST(CallTest, CreateDestroy_AudioSendStream) {
48 CallHelper call;
49 AudioSendStream::Config config(nullptr);
50 config.rtp.ssrc = 42;
51 config.voe_channel_id = 123;
52 AudioSendStream* stream = call->CreateAudioSendStream(config);
53 EXPECT_NE(stream, nullptr);
54 call->DestroyAudioSendStream(stream);
55}
56
57TEST(CallTest, CreateDestroy_AudioReceiveStream) {
ossu29b1a8d2016-06-13 07:34:51 -070058 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
59 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
60 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070061 AudioReceiveStream::Config config;
62 config.rtp.remote_ssrc = 42;
63 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070064 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -070065 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
66 EXPECT_NE(stream, nullptr);
67 call->DestroyAudioReceiveStream(stream);
68}
69
70TEST(CallTest, CreateDestroy_AudioSendStreams) {
71 CallHelper call;
72 AudioSendStream::Config config(nullptr);
73 config.voe_channel_id = 123;
74 std::list<AudioSendStream*> streams;
75 for (int i = 0; i < 2; ++i) {
76 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
77 config.rtp.ssrc = ssrc;
78 AudioSendStream* stream = call->CreateAudioSendStream(config);
79 EXPECT_NE(stream, nullptr);
80 if (ssrc & 1) {
81 streams.push_back(stream);
82 } else {
83 streams.push_front(stream);
84 }
85 }
86 for (auto s : streams) {
87 call->DestroyAudioSendStream(s);
88 }
89 streams.clear();
90 }
91}
92
93TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
ossu29b1a8d2016-06-13 07:34:51 -070094 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
95 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
96 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070097 AudioReceiveStream::Config config;
98 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070099 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -0700100 std::list<AudioReceiveStream*> streams;
101 for (int i = 0; i < 2; ++i) {
102 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
103 config.rtp.remote_ssrc = ssrc;
104 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
105 EXPECT_NE(stream, nullptr);
106 if (ssrc & 1) {
107 streams.push_back(stream);
108 } else {
109 streams.push_front(stream);
110 }
111 }
112 for (auto s : streams) {
113 call->DestroyAudioReceiveStream(s);
114 }
115 streams.clear();
116 }
117}
118} // namespace webrtc