• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //
12 // vie_autotest_image_process.cc
13 //
14 
15 // Settings
16 #include "webrtc/engine_configurations.h"
17 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h"
18 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest_defines.h"
19 
20 #include "webrtc/video_engine/test/libvietest/include/tb_capture_device.h"
21 #include "webrtc/video_engine/test/libvietest/include/tb_interfaces.h"
22 #include "webrtc/video_engine/test/libvietest/include/tb_video_channel.h"
23 
24 class MyEffectFilter: public webrtc::ViEEffectFilter
25 {
26 public:
MyEffectFilter()27     MyEffectFilter() {}
28 
~MyEffectFilter()29     ~MyEffectFilter() {}
30 
Transform(int size,unsigned char * frame_buffer,int64_t ntp_time_ms,unsigned int timestamp,unsigned int width,unsigned int height)31     virtual int Transform(int size,
32                           unsigned char* frame_buffer,
33                           int64_t ntp_time_ms,
34                           unsigned int timestamp,
35                           unsigned int width,
36                           unsigned int height)
37     {
38         // Black and white
39         memset(frame_buffer + (2 * size) / 3, 0x7f, size / 3);
40         return 0;
41     }
42 };
43 
ViEImageProcessStandardTest()44 void ViEAutoTest::ViEImageProcessStandardTest()
45 {
46     //***************************************************************
47     //	Begin create/initialize WebRTC Video Engine for testing
48     //***************************************************************
49     int rtpPort = 6000;
50     // Create VIE
51     TbInterfaces ViE("ViEImageProcessAPITest");
52     // Create a video channel
53     TbVideoChannel tbChannel(ViE, webrtc::kVideoCodecVP8);
54     // Create a capture device
55     TbCaptureDevice tbCapture(ViE);
56 
57     tbCapture.ConnectTo(tbChannel.videoChannel);
58     tbChannel.StartReceive(rtpPort);
59     tbChannel.StartSend(rtpPort);
60 
61     MyEffectFilter effectFilter;
62 
63     RenderCaptureDeviceAndOutputStream(&ViE, &tbChannel, &tbCapture);
64 
65     ViETest::Log("Capture device is renderered in Window 1");
66     ViETest::Log("Remote stream is renderered in Window 2");
67     AutoTestSleep(kAutoTestSleepTimeMs);
68 
69     //***************************************************************
70     //	Engine ready. Begin testing class
71     //***************************************************************
72 
73 
74     EXPECT_EQ(0, ViE.image_process->RegisterCaptureEffectFilter(
75         tbCapture.captureId, effectFilter));
76 
77     ViETest::Log("Black and white filter registered for capture device, "
78                  "affects both windows");
79     AutoTestSleep(kAutoTestSleepTimeMs);
80 
81     EXPECT_EQ(0, ViE.image_process->DeregisterCaptureEffectFilter(
82         tbCapture.captureId));
83 
84     EXPECT_EQ(0, ViE.image_process->RegisterRenderEffectFilter(
85         tbChannel.videoChannel, effectFilter));
86 
87     ViETest::Log("Remove capture effect filter, adding filter for incoming "
88                  "stream");
89     ViETest::Log("Only Window 2 should be black and white");
90     AutoTestSleep(kAutoTestSleepTimeMs);
91 
92     EXPECT_EQ(0, ViE.render->StopRender(tbCapture.captureId));
93     EXPECT_EQ(0, ViE.render->RemoveRenderer(tbCapture.captureId));
94 
95     int rtpPort2 = rtpPort + 100;
96     // Create a video channel
97     TbVideoChannel tbChannel2(ViE, webrtc::kVideoCodecVP8);
98 
99     tbCapture.ConnectTo(tbChannel2.videoChannel);
100     tbChannel2.StartReceive(rtpPort2);
101     tbChannel2.StartSend(rtpPort2);
102 
103     EXPECT_EQ(0, ViE.render->AddRenderer(
104         tbChannel2.videoChannel, _window1, 1, 0.0, 0.0, 1.0, 1.0));
105     EXPECT_EQ(0, ViE.render->StartRender(tbChannel2.videoChannel));
106     EXPECT_EQ(0, ViE.image_process->DeregisterRenderEffectFilter(
107         tbChannel.videoChannel));
108 
109     ViETest::Log("Local renderer removed, added new channel and rendering in "
110                  "Window1.");
111 
112     EXPECT_EQ(0, ViE.image_process->RegisterCaptureEffectFilter(
113         tbCapture.captureId, effectFilter));
114 
115     ViETest::Log("Black and white filter registered for capture device, "
116                  "affects both windows");
117     AutoTestSleep(kAutoTestSleepTimeMs);
118 
119     EXPECT_EQ(0, ViE.image_process->DeregisterCaptureEffectFilter(
120         tbCapture.captureId));
121 
122     EXPECT_EQ(0, ViE.image_process->RegisterSendEffectFilter(
123         tbChannel.videoChannel, effectFilter));
124 
125     ViETest::Log("Capture filter removed.");
126     ViETest::Log("Black and white filter registered for one channel, Window2 "
127                  "should be black and white");
128     AutoTestSleep(kAutoTestSleepTimeMs);
129 
130     EXPECT_EQ(0, ViE.image_process->DeregisterSendEffectFilter(
131         tbChannel.videoChannel));
132 
133     //***************************************************************
134     //	Testing finished. Tear down Video Engine
135     //***************************************************************
136 }
137 
ViEImageProcessExtendedTest()138 void ViEAutoTest::ViEImageProcessExtendedTest()
139 {
140 }
141 
ViEImageProcessAPITest()142 void ViEAutoTest::ViEImageProcessAPITest()
143 {
144     TbInterfaces ViE("ViEImageProcessAPITest");
145     TbVideoChannel tbChannel(ViE, webrtc::kVideoCodecVP8);
146     TbCaptureDevice tbCapture(ViE);
147 
148     tbCapture.ConnectTo(tbChannel.videoChannel);
149 
150     MyEffectFilter effectFilter;
151 
152     //
153     // Capture effect filter
154     //
155     // Add effect filter
156     EXPECT_EQ(0, ViE.image_process->RegisterCaptureEffectFilter(
157         tbCapture.captureId, effectFilter));
158     // Add again -> error
159     EXPECT_NE(0, ViE.image_process->RegisterCaptureEffectFilter(
160         tbCapture.captureId, effectFilter));
161     EXPECT_EQ(0, ViE.image_process->DeregisterCaptureEffectFilter(
162         tbCapture.captureId));
163     EXPECT_EQ(0, ViE.image_process->DeregisterCaptureEffectFilter(
164         tbCapture.captureId));
165 
166     // Non-existing capture device
167     EXPECT_NE(0, ViE.image_process->RegisterCaptureEffectFilter(
168         tbChannel.videoChannel, effectFilter));
169 
170     //
171     // Render effect filter
172     //
173     EXPECT_EQ(0, ViE.image_process->RegisterRenderEffectFilter(
174         tbChannel.videoChannel, effectFilter));
175     EXPECT_NE(0, ViE.image_process->RegisterRenderEffectFilter(
176         tbChannel.videoChannel, effectFilter));
177     EXPECT_EQ(0, ViE.image_process->DeregisterRenderEffectFilter(
178         tbChannel.videoChannel));
179     EXPECT_EQ(0, ViE.image_process->DeregisterRenderEffectFilter(
180         tbChannel.videoChannel));
181 
182     // Non-existing channel id
183     EXPECT_NE(0, ViE.image_process->RegisterRenderEffectFilter(
184         tbCapture.captureId, effectFilter));
185 
186     //
187     // Send effect filter
188     //
189     EXPECT_EQ(0, ViE.image_process->RegisterSendEffectFilter(
190         tbChannel.videoChannel, effectFilter));
191     EXPECT_NE(0, ViE.image_process->RegisterSendEffectFilter(
192         tbChannel.videoChannel, effectFilter));
193     EXPECT_EQ(0, ViE.image_process->DeregisterSendEffectFilter(
194         tbChannel.videoChannel));
195     EXPECT_EQ(0, ViE.image_process->DeregisterSendEffectFilter(
196         tbChannel.videoChannel));
197     EXPECT_NE(0, ViE.image_process->RegisterSendEffectFilter(
198         tbCapture.captureId, effectFilter));
199 
200     //
201     // Deflickering
202     //
203     EXPECT_EQ(0, ViE.image_process->EnableDeflickering(
204         tbCapture.captureId, true));
205     EXPECT_NE(0, ViE.image_process->EnableDeflickering(
206         tbCapture.captureId, true));
207     EXPECT_EQ(0, ViE.image_process->EnableDeflickering(
208         tbCapture.captureId, false));
209     EXPECT_NE(0, ViE.image_process->EnableDeflickering(
210         tbCapture.captureId, false));
211     EXPECT_NE(0, ViE.image_process->EnableDeflickering(
212         tbChannel.videoChannel, true));
213 
214     //
215     // Color enhancement
216     //
217     EXPECT_EQ(0, ViE.image_process->EnableColorEnhancement(
218         tbChannel.videoChannel, false));
219     EXPECT_EQ(0, ViE.image_process->EnableColorEnhancement(
220         tbChannel.videoChannel, true));
221     EXPECT_EQ(0, ViE.image_process->EnableColorEnhancement(
222         tbChannel.videoChannel, false));
223     EXPECT_NE(0, ViE.image_process->EnableColorEnhancement(
224         tbCapture.captureId, true));
225 }
226