1 /*
2 * Copyright (c) 2012 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 "webrtc/modules/video_capture/include/video_capture_factory.h"
12 #include "webrtc/test/channel_transport/include/channel_transport.h"
13 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h"
14 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest_defines.h"
15 #include "webrtc/video_engine/test/auto_test/primitives/base_primitives.h"
16 #include "webrtc/video_engine/test/auto_test/primitives/general_primitives.h"
17 #include "webrtc/video_engine/test/libvietest/include/tb_interfaces.h"
18
ViEBaseStandardTest()19 void ViEAutoTest::ViEBaseStandardTest() {
20 // ***************************************************************
21 // Begin create/initialize WebRTC Video Engine for testing
22 // ***************************************************************
23
24 TbInterfaces interfaces("ViEBaseStandardTest");
25
26 // ***************************************************************
27 // Engine ready. Set up the test case:
28 // ***************************************************************
29 int video_channel = -1;
30 EXPECT_EQ(0, interfaces.base->CreateChannel(video_channel));
31
32 webrtc::VideoCaptureModule* video_capture_module = NULL;
33 const unsigned int kMaxDeviceNameLength = 128;
34 char device_name[kMaxDeviceNameLength];
35 memset(device_name, 0, kMaxDeviceNameLength);
36 int capture_id;
37
38 webrtc::ViEBase* base_interface = interfaces.base;
39 webrtc::ViERender* render_interface = interfaces.render;
40 webrtc::ViECapture* capture_interface = interfaces.capture;
41
42 FindCaptureDeviceOnSystem(capture_interface,
43 device_name,
44 kMaxDeviceNameLength,
45 &capture_id,
46 &video_capture_module);
47
48 EXPECT_TRUE(video_capture_module);
49 if (!video_capture_module)
50 return;
51
52 EXPECT_EQ(0, capture_interface->ConnectCaptureDevice(capture_id,
53 video_channel));
54 EXPECT_EQ(0, capture_interface->StartCapture(capture_id));
55
56 ConfigureRtpRtcp(interfaces.rtp_rtcp, kNack, video_channel);
57
58 EXPECT_EQ(0, render_interface->RegisterVideoRenderModule(*_vrm1));
59 EXPECT_EQ(0, render_interface->RegisterVideoRenderModule(*_vrm2));
60
61 RenderInWindow(render_interface, capture_id, _window1, 0);
62 RenderInWindow(render_interface, video_channel, _window2, 1);
63
64 // ***************************************************************
65 // Run the actual test:
66 // ***************************************************************
67 ViETest::Log("You should shortly see a local preview from camera %s"
68 " in window 1 and the remote video in window 2.", device_name);
69 ::TestI420CallSetup(interfaces.codec, interfaces.video_engine,
70 base_interface, interfaces.network, interfaces.rtp_rtcp,
71 video_channel, device_name);
72
73 // ***************************************************************
74 // Testing finished. Tear down Video Engine
75 // ***************************************************************
76 EXPECT_EQ(0, capture_interface->StopCapture(capture_id));
77 EXPECT_EQ(0, base_interface->StopReceive(video_channel));
78
79 EXPECT_EQ(0, render_interface->StopRender(video_channel));
80 EXPECT_EQ(0, render_interface->RemoveRenderer(video_channel));
81 EXPECT_EQ(0, render_interface->RemoveRenderer(capture_id));
82
83 EXPECT_EQ(0, render_interface->DeRegisterVideoRenderModule(*_vrm1));
84 EXPECT_EQ(0, render_interface->DeRegisterVideoRenderModule(*_vrm2));
85
86 EXPECT_EQ(0, capture_interface->ReleaseCaptureDevice(capture_id));
87
88 video_capture_module->Release();
89 video_capture_module = NULL;
90
91 EXPECT_EQ(0, base_interface->DeleteChannel(video_channel));
92 }
93
ViEBaseExtendedTest()94 void ViEAutoTest::ViEBaseExtendedTest() {
95 // Start with standard test
96 ViEBaseAPITest();
97 ViEBaseStandardTest();
98 }
99
ViEBaseAPITest()100 void ViEAutoTest::ViEBaseAPITest() {
101 // ***************************************************************
102 // Begin create/initialize WebRTC Video Engine for testing
103 // ***************************************************************
104 // Get the ViEBase API
105 webrtc::ViEBase* vie_base = webrtc::ViEBase::GetInterface(NULL);
106 EXPECT_EQ(NULL, vie_base) << "Should return null for a bad ViE pointer";
107
108 webrtc::VideoEngine* video_engine = webrtc::VideoEngine::Create();
109 EXPECT_TRUE(NULL != video_engine);
110
111 std::string trace_file_path =
112 ViETest::GetResultOutputPath() + "ViEBaseAPI_trace.txt";
113 EXPECT_EQ(0, video_engine->SetTraceFile(trace_file_path.c_str()));
114
115 vie_base = webrtc::ViEBase::GetInterface(video_engine);
116 EXPECT_TRUE(NULL != vie_base);
117
118 webrtc::ViENetwork* vie_network =
119 webrtc::ViENetwork::GetInterface(video_engine);
120 EXPECT_TRUE(vie_network != NULL);
121
122 webrtc::ViERTP_RTCP* vie_rtp =
123 webrtc::ViERTP_RTCP::GetInterface(video_engine);
124 EXPECT_TRUE(vie_rtp != NULL);
125
126 // ***************************************************************
127 // Engine ready. Begin testing class
128 // ***************************************************************
129 char version[1024] = "";
130 EXPECT_EQ(0, vie_base->GetVersion(version));
131 EXPECT_EQ(0, vie_base->LastError());
132
133 int video_channel = -1;
134 EXPECT_EQ(0, vie_base->Init());
135 EXPECT_EQ(0, vie_base->CreateChannel(video_channel));
136
137 int video_channel2 = -1;
138 int video_channel3 = -1;
139 EXPECT_EQ(0, vie_base->CreateChannel(video_channel2));
140 EXPECT_NE(video_channel, video_channel2) <<
141 "Should allocate new number for independent channel";
142
143 EXPECT_EQ(0, vie_base->DeleteChannel(video_channel2));
144
145 EXPECT_EQ(-1, vie_base->CreateChannel(video_channel2, video_channel + 1))
146 << "Should fail since neither channel exists (the second must)";
147
148 // Create a receive only channel and a send channel. Verify we can't send on
149 // the receive only channel.
150 EXPECT_EQ(0, vie_base->CreateReceiveChannel(video_channel2,
151 video_channel));
152 EXPECT_EQ(0, vie_base->CreateChannel(video_channel3, video_channel));
153
154 const char* ip_address = "127.0.0.1\0";
155 const int send_port = 1234;
156
157 EXPECT_EQ(0, vie_rtp->SetLocalSSRC(video_channel, 1));
158 EXPECT_EQ(0, vie_rtp->SetLocalSSRC(video_channel, 2));
159 EXPECT_EQ(0, vie_rtp->SetLocalSSRC(video_channel, 3));
160
161 webrtc::test::VideoChannelTransport* video_channel_transport_1 =
162 new webrtc::test::VideoChannelTransport(vie_network, video_channel);
163
164 ASSERT_EQ(0, video_channel_transport_1->SetSendDestination(ip_address,
165 send_port));
166
167 webrtc::test::VideoChannelTransport* video_channel_transport_2 =
168 new webrtc::test::VideoChannelTransport(vie_network, video_channel2);
169
170 webrtc::test::VideoChannelTransport* video_channel_transport_3 =
171 new webrtc::test::VideoChannelTransport(vie_network, video_channel3);
172
173 ASSERT_EQ(0, video_channel_transport_3->SetSendDestination(ip_address,
174 send_port + 4));
175
176 EXPECT_EQ(0, vie_base->StartSend(video_channel));
177 EXPECT_EQ(-1, vie_base->StartSend(video_channel2));
178 EXPECT_EQ(0, vie_base->StartSend(video_channel3));
179 EXPECT_EQ(0, vie_base->StopSend(video_channel));
180 EXPECT_EQ(0, vie_base->StopSend(video_channel3));
181
182 // Test Voice Engine integration with Video Engine.
183 webrtc::VoiceEngine* voice_engine = NULL;
184 webrtc::VoEBase* voe_base = NULL;
185 int audio_channel = -1;
186
187 voice_engine = webrtc::VoiceEngine::Create();
188 EXPECT_TRUE(NULL != voice_engine);
189
190 voe_base = webrtc::VoEBase::GetInterface(voice_engine);
191 EXPECT_TRUE(NULL != voe_base);
192 EXPECT_EQ(0, voe_base->Init());
193
194 audio_channel = voe_base->CreateChannel();
195 EXPECT_NE(-1, audio_channel);
196
197 // Connect before setting VoE.
198 EXPECT_NE(0, vie_base->ConnectAudioChannel(video_channel, audio_channel))
199 << "Should fail since Voice Engine is not set yet.";
200
201 // Then do it right.
202 EXPECT_EQ(0, vie_base->SetVoiceEngine(voice_engine));
203 EXPECT_EQ(0, vie_base->ConnectAudioChannel(video_channel, audio_channel));
204
205 // ***************************************************************
206 // Testing finished. Tear down Video Engine
207 // ***************************************************************
208 EXPECT_NE(0, vie_base->DisconnectAudioChannel(video_channel + 5)) <<
209 "Should fail: disconnecting bogus channel";
210
211 EXPECT_EQ(0, vie_base->DisconnectAudioChannel(video_channel));
212
213 // Clean up voice engine
214 EXPECT_EQ(0, vie_rtp->Release());
215 EXPECT_EQ(0, vie_network->Release());
216 EXPECT_EQ(0, vie_base->SetVoiceEngine(NULL));
217 // VoiceEngine reference counting is per object, not per interface, so
218 // Release should return != 0.
219 EXPECT_NE(0, voe_base->Release());
220 EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine));
221
222 webrtc::ViEBase* vie_base2 = webrtc::ViEBase::GetInterface(video_engine);
223 EXPECT_TRUE(NULL != vie_base2);
224
225 EXPECT_EQ(1, vie_base->Release()) <<
226 "There should be one interface left.";
227
228 EXPECT_FALSE(webrtc::VideoEngine::Delete(video_engine)) <<
229 "Should fail since there are interfaces left.";
230
231 delete video_channel_transport_1;
232 delete video_channel_transport_2;
233 delete video_channel_transport_3;
234 EXPECT_EQ(0, vie_base->Release());
235 EXPECT_TRUE(webrtc::VideoEngine::Delete(video_engine));
236 }
237