OLD | NEW |
| (Empty) |
1 /* | |
2 * libjingle | |
3 * Copyright 2008 Google Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright notice, | |
9 * this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 * this list of conditions and the following disclaimer in the documentation | |
12 * and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 // Author: Ronghua Wu (ronghuawu@google.com) | |
29 | |
30 #include <string> | |
31 | |
32 #include "talk/media/base/testutils.h" | |
33 #include "talk/media/webrtc/webrtcpassthroughrender.h" | |
34 #include "webrtc/base/gunit.h" | |
35 | |
36 class WebRtcPassthroughRenderTest : public testing::Test { | |
37 public: | |
38 class ExternalRenderer : public webrtc::VideoRenderCallback { | |
39 public: | |
40 ExternalRenderer() : frame_num_(0) { | |
41 } | |
42 | |
43 virtual ~ExternalRenderer() { | |
44 } | |
45 | |
46 virtual int32_t RenderFrame(const uint32_t stream_id, | |
47 const webrtc::VideoFrame& videoFrame) { | |
48 ++frame_num_; | |
49 LOG(INFO) << "RenderFrame stream_id: " << stream_id | |
50 << " frame_num: " << frame_num_; | |
51 return 0; | |
52 } | |
53 | |
54 int frame_num() const { | |
55 return frame_num_; | |
56 } | |
57 | |
58 private: | |
59 int frame_num_; | |
60 }; | |
61 | |
62 WebRtcPassthroughRenderTest() | |
63 : renderer_(new cricket::WebRtcPassthroughRender()) { | |
64 } | |
65 | |
66 ~WebRtcPassthroughRenderTest() { | |
67 } | |
68 | |
69 webrtc::VideoRenderCallback* AddIncomingRenderStream(int stream_id) { | |
70 return renderer_->AddIncomingRenderStream(stream_id, 0, 0, 0, 0, 0); | |
71 } | |
72 | |
73 bool HasIncomingRenderStream(int stream_id) { | |
74 return renderer_->HasIncomingRenderStream(stream_id); | |
75 } | |
76 | |
77 bool DeleteIncomingRenderStream(int stream_id) { | |
78 return (renderer_->DeleteIncomingRenderStream(stream_id) == 0); | |
79 } | |
80 | |
81 bool AddExternalRenderCallback(int stream_id, | |
82 webrtc::VideoRenderCallback* renderer) { | |
83 return (renderer_->AddExternalRenderCallback(stream_id, renderer) == 0); | |
84 } | |
85 | |
86 bool StartRender(int stream_id) { | |
87 return (renderer_->StartRender(stream_id) == 0); | |
88 } | |
89 | |
90 bool StopRender(int stream_id) { | |
91 return (renderer_->StopRender(stream_id) == 0); | |
92 } | |
93 | |
94 private: | |
95 rtc::scoped_ptr<cricket::WebRtcPassthroughRender> renderer_; | |
96 }; | |
97 | |
98 TEST_F(WebRtcPassthroughRenderTest, Streams) { | |
99 const int stream_id1 = 1234; | |
100 const int stream_id2 = 5678; | |
101 const int stream_id3 = 9012; // A stream that doesn't exist. | |
102 webrtc::VideoRenderCallback* stream = NULL; | |
103 // Add a new stream | |
104 stream = AddIncomingRenderStream(stream_id1); | |
105 EXPECT_TRUE(stream != NULL); | |
106 EXPECT_TRUE(HasIncomingRenderStream(stream_id1)); | |
107 // Tried to add a already existed stream should return null | |
108 stream =AddIncomingRenderStream(stream_id1); | |
109 EXPECT_TRUE(stream == NULL); | |
110 stream = AddIncomingRenderStream(stream_id2); | |
111 EXPECT_TRUE(stream != NULL); | |
112 EXPECT_TRUE(HasIncomingRenderStream(stream_id2)); | |
113 // Remove the stream | |
114 EXPECT_FALSE(DeleteIncomingRenderStream(stream_id3)); | |
115 EXPECT_TRUE(DeleteIncomingRenderStream(stream_id2)); | |
116 EXPECT_TRUE(!HasIncomingRenderStream(stream_id2)); | |
117 // Add back the removed stream | |
118 stream = AddIncomingRenderStream(stream_id2); | |
119 EXPECT_TRUE(stream != NULL); | |
120 EXPECT_TRUE(HasIncomingRenderStream(stream_id2)); | |
121 } | |
122 | |
123 TEST_F(WebRtcPassthroughRenderTest, Renderer) { | |
124 webrtc::VideoFrame frame; | |
125 const int stream_id1 = 1234; | |
126 const int stream_id2 = 5678; | |
127 const int stream_id3 = 9012; // A stream that doesn't exist. | |
128 webrtc::VideoRenderCallback* stream1 = NULL; | |
129 webrtc::VideoRenderCallback* stream2 = NULL; | |
130 // Add two new stream | |
131 stream1 = AddIncomingRenderStream(stream_id1); | |
132 EXPECT_TRUE(stream1 != NULL); | |
133 EXPECT_TRUE(HasIncomingRenderStream(stream_id1)); | |
134 stream2 = AddIncomingRenderStream(stream_id2); | |
135 EXPECT_TRUE(stream2 != NULL); | |
136 EXPECT_TRUE(HasIncomingRenderStream(stream_id2)); | |
137 // Register the external renderer | |
138 WebRtcPassthroughRenderTest::ExternalRenderer renderer1; | |
139 WebRtcPassthroughRenderTest::ExternalRenderer renderer2; | |
140 EXPECT_FALSE(AddExternalRenderCallback(stream_id3, &renderer1)); | |
141 EXPECT_TRUE(AddExternalRenderCallback(stream_id1, &renderer1)); | |
142 EXPECT_TRUE(AddExternalRenderCallback(stream_id2, &renderer2)); | |
143 int test_frame_num = 10; | |
144 // RenderFrame without starting the render | |
145 for (int i = 0; i < test_frame_num; ++i) { | |
146 stream1->RenderFrame(stream_id1, frame); | |
147 } | |
148 EXPECT_EQ(0, renderer1.frame_num()); | |
149 // Start the render and test again. | |
150 EXPECT_FALSE(StartRender(stream_id3)); | |
151 EXPECT_TRUE(StartRender(stream_id1)); | |
152 for (int i = 0; i < test_frame_num; ++i) { | |
153 stream1->RenderFrame(stream_id1, frame); | |
154 } | |
155 EXPECT_EQ(test_frame_num, renderer1.frame_num()); | |
156 // Stop the render and test again. | |
157 EXPECT_FALSE(StopRender(stream_id3)); | |
158 EXPECT_TRUE(StopRender(stream_id1)); | |
159 for (int i = 0; i < test_frame_num; ++i) { | |
160 stream1->RenderFrame(stream_id1, frame); | |
161 } | |
162 // The frame number should not have changed. | |
163 EXPECT_EQ(test_frame_num, renderer1.frame_num()); | |
164 | |
165 // Test on stream2 with a differnt number. | |
166 EXPECT_TRUE(StartRender(stream_id2)); | |
167 test_frame_num = 30; | |
168 for (int i = 0; i < test_frame_num; ++i) { | |
169 stream2->RenderFrame(stream_id2, frame); | |
170 } | |
171 EXPECT_EQ(test_frame_num, renderer2.frame_num()); | |
172 } | |
OLD | NEW |