OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/media/engine/internalencoderfactory.h" | 10 #include "webrtc/media/engine/internalencoderfactory.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 std::set<uint32_t> observed_ssrcs_ GUARDED_BY(crit_); | 132 std::set<uint32_t> observed_ssrcs_ GUARDED_BY(crit_); |
133 }; | 133 }; |
134 | 134 |
135 class PictureIdTest : public test::CallTest { | 135 class PictureIdTest : public test::CallTest { |
136 public: | 136 public: |
137 PictureIdTest() {} | 137 PictureIdTest() {} |
138 | 138 |
139 virtual ~PictureIdTest() { | 139 virtual ~PictureIdTest() { |
140 EXPECT_EQ(nullptr, video_send_stream_); | 140 EXPECT_EQ(nullptr, video_send_stream_); |
141 EXPECT_TRUE(video_receive_streams_.empty()); | 141 EXPECT_TRUE(video_receive_streams_.empty()); |
| 142 |
| 143 task_queue_.SendTask([this]() { |
| 144 Stop(); |
| 145 DestroyStreams(); |
| 146 send_transport_.reset(); |
| 147 receive_transport_.reset(); |
| 148 DestroyCalls(); |
| 149 }); |
142 } | 150 } |
143 | 151 |
144 void SetupEncoder(VideoEncoder* encoder); | 152 void SetupEncoder(VideoEncoder* encoder); |
145 void TestPictureIdContinuousAfterReconfigure( | 153 void TestPictureIdContinuousAfterReconfigure( |
146 const std::vector<int>& ssrc_counts); | 154 const std::vector<int>& ssrc_counts); |
147 void TestPictureIdIncreaseAfterRecreateStreams( | 155 void TestPictureIdIncreaseAfterRecreateStreams( |
148 const std::vector<int>& ssrc_counts); | 156 const std::vector<int>& ssrc_counts); |
149 | 157 |
150 private: | 158 private: |
151 PictureIdObserver observer; | 159 PictureIdObserver observer; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 streams[0].min_bitrate_bps = 3 * kEncoderBitrateBps; | 197 streams[0].min_bitrate_bps = 3 * kEncoderBitrateBps; |
190 streams[0].target_bitrate_bps = 3 * kEncoderBitrateBps; | 198 streams[0].target_bitrate_bps = 3 * kEncoderBitrateBps; |
191 streams[0].max_bitrate_bps = 3 * kEncoderBitrateBps; | 199 streams[0].max_bitrate_bps = 3 * kEncoderBitrateBps; |
192 } | 200 } |
193 | 201 |
194 return streams; | 202 return streams; |
195 } | 203 } |
196 }; | 204 }; |
197 | 205 |
198 void PictureIdTest::SetupEncoder(VideoEncoder* encoder) { | 206 void PictureIdTest::SetupEncoder(VideoEncoder* encoder) { |
199 Call::Config config(event_log_.get()); | 207 task_queue_.SendTask([this, &encoder]() { |
200 CreateCalls(config, config); | 208 Call::Config config(event_log_.get()); |
| 209 CreateCalls(config, config); |
201 | 210 |
202 send_transport_.reset(new test::PacketTransport( | 211 send_transport_.reset(new test::PacketTransport( |
203 sender_call_.get(), &observer, test::PacketTransport::kSender, | 212 &task_queue_, sender_call_.get(), &observer, |
204 payload_type_map_, FakeNetworkPipe::Config())); | 213 test::PacketTransport::kSender, payload_type_map_, |
| 214 FakeNetworkPipe::Config())); |
205 | 215 |
206 CreateSendConfig(kNumSsrcs, 0, 0, send_transport_.get()); | 216 CreateSendConfig(kNumSsrcs, 0, 0, send_transport_.get()); |
207 video_send_config_.encoder_settings.encoder = encoder; | 217 video_send_config_.encoder_settings.encoder = encoder; |
208 video_send_config_.encoder_settings.payload_name = "VP8"; | 218 video_send_config_.encoder_settings.payload_name = "VP8"; |
209 video_encoder_config_.video_stream_factory = | 219 video_encoder_config_.video_stream_factory = |
210 new rtc::RefCountedObject<VideoStreamFactory>(); | 220 new rtc::RefCountedObject<VideoStreamFactory>(); |
211 video_encoder_config_.number_of_streams = 1; | 221 video_encoder_config_.number_of_streams = 1; |
| 222 }); |
212 } | 223 } |
213 | 224 |
214 void PictureIdTest::TestPictureIdContinuousAfterReconfigure( | 225 void PictureIdTest::TestPictureIdContinuousAfterReconfigure( |
215 const std::vector<int>& ssrc_counts) { | 226 const std::vector<int>& ssrc_counts) { |
216 CreateVideoStreams(); | 227 task_queue_.SendTask([this]() { |
217 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); | 228 CreateVideoStreams(); |
| 229 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); |
218 | 230 |
219 // Initial test with a single stream. | 231 // Initial test with a single stream. |
220 Start(); | 232 Start(); |
| 233 }); |
| 234 |
221 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; | 235 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; |
222 | 236 |
223 // Reconfigure VideoEncoder and test picture id increase. | 237 // Reconfigure VideoEncoder and test picture id increase. |
224 // Expect continously increasing picture id, equivalent to no gaps. | 238 // Expect continously increasing picture id, equivalent to no gaps. |
225 observer.SetMaxExpectedPictureIdGap(0); | 239 observer.SetMaxExpectedPictureIdGap(0); |
226 for (int ssrc_count : ssrc_counts) { | 240 for (int ssrc_count : ssrc_counts) { |
227 video_encoder_config_.number_of_streams = ssrc_count; | 241 video_encoder_config_.number_of_streams = ssrc_count; |
228 observer.SetExpectedSsrcs(ssrc_count); | 242 observer.SetExpectedSsrcs(ssrc_count); |
229 observer.ResetObservedSsrcs(); | 243 observer.ResetObservedSsrcs(); |
230 // Make sure the picture_id sequence is continuous on reinit and recreate. | 244 // Make sure the picture_id sequence is continuous on reinit and recreate. |
231 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_.Copy()); | 245 task_queue_.SendTask([this]() { |
| 246 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_.Copy()); |
| 247 }); |
232 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; | 248 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; |
233 } | 249 } |
234 | 250 |
235 Stop(); | 251 task_queue_.SendTask([this]() { |
236 DestroyStreams(); | 252 Stop(); |
| 253 DestroyStreams(); |
| 254 send_transport_.reset(); |
| 255 receive_transport_.reset(); |
| 256 DestroyCalls(); |
| 257 }); |
237 } | 258 } |
238 | 259 |
239 void PictureIdTest::TestPictureIdIncreaseAfterRecreateStreams( | 260 void PictureIdTest::TestPictureIdIncreaseAfterRecreateStreams( |
240 const std::vector<int>& ssrc_counts) { | 261 const std::vector<int>& ssrc_counts) { |
241 CreateVideoStreams(); | 262 task_queue_.SendTask([this]() { |
242 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); | 263 CreateVideoStreams(); |
| 264 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); |
243 | 265 |
244 // Initial test with a single stream. | 266 // Initial test with a single stream. |
245 Start(); | 267 Start(); |
| 268 }); |
| 269 |
246 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; | 270 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; |
247 | 271 |
248 // Recreate VideoSendStream and test picture id increase. | 272 // Recreate VideoSendStream and test picture id increase. |
249 // When the VideoSendStream is destroyed, any frames still in queue is lost | 273 // When the VideoSendStream is destroyed, any frames still in queue is lost |
250 // with it, therefore it is expected that some frames might be lost. | 274 // with it, therefore it is expected that some frames might be lost. |
251 observer.SetMaxExpectedPictureIdGap(kMaxFramesLost); | 275 observer.SetMaxExpectedPictureIdGap(kMaxFramesLost); |
252 for (int ssrc_count : ssrc_counts) { | 276 for (int ssrc_count : ssrc_counts) { |
253 video_encoder_config_.number_of_streams = ssrc_count; | 277 task_queue_.SendTask([this, &ssrc_count]() { |
| 278 video_encoder_config_.number_of_streams = ssrc_count; |
254 | 279 |
255 frame_generator_capturer_->Stop(); | 280 frame_generator_capturer_->Stop(); |
256 sender_call_->DestroyVideoSendStream(video_send_stream_); | 281 sender_call_->DestroyVideoSendStream(video_send_stream_); |
257 | 282 |
258 observer.SetExpectedSsrcs(ssrc_count); | 283 observer.SetExpectedSsrcs(ssrc_count); |
259 observer.ResetObservedSsrcs(); | 284 observer.ResetObservedSsrcs(); |
260 | 285 |
261 video_send_stream_ = sender_call_->CreateVideoSendStream( | 286 video_send_stream_ = sender_call_->CreateVideoSendStream( |
262 video_send_config_.Copy(), video_encoder_config_.Copy()); | 287 video_send_config_.Copy(), video_encoder_config_.Copy()); |
263 video_send_stream_->Start(); | 288 video_send_stream_->Start(); |
264 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); | 289 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); |
265 frame_generator_capturer_->Start(); | 290 frame_generator_capturer_->Start(); |
| 291 }); |
| 292 |
266 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; | 293 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for packets."; |
267 } | 294 } |
268 | 295 |
269 Stop(); | 296 task_queue_.SendTask([this]() { |
270 DestroyStreams(); | 297 Stop(); |
| 298 DestroyStreams(); |
| 299 send_transport_.reset(); |
| 300 receive_transport_.reset(); |
| 301 }); |
271 } | 302 } |
272 | 303 |
273 TEST_F(PictureIdTest, PictureIdContinuousAfterReconfigureVp8) { | 304 TEST_F(PictureIdTest, PictureIdContinuousAfterReconfigureVp8) { |
274 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create()); | 305 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create()); |
275 SetupEncoder(encoder.get()); | 306 SetupEncoder(encoder.get()); |
276 TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1}); | 307 TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1}); |
277 } | 308 } |
278 | 309 |
279 TEST_F(PictureIdTest, PictureIdIncreasingAfterRecreateStreamVp8) { | 310 TEST_F(PictureIdTest, PictureIdIncreasingAfterRecreateStreamVp8) { |
280 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create()); | 311 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 cricket::InternalEncoderFactory internal_encoder_factory; | 347 cricket::InternalEncoderFactory internal_encoder_factory; |
317 SimulcastEncoderAdapter simulcast_encoder_adapter(&internal_encoder_factory); | 348 SimulcastEncoderAdapter simulcast_encoder_adapter(&internal_encoder_factory); |
318 // Make sure that that the picture id is not reset if the stream count goes | 349 // Make sure that that the picture id is not reset if the stream count goes |
319 // down and then up. | 350 // down and then up. |
320 std::vector<int> ssrc_counts = {3, 1, 3}; | 351 std::vector<int> ssrc_counts = {3, 1, 3}; |
321 SetupEncoder(&simulcast_encoder_adapter); | 352 SetupEncoder(&simulcast_encoder_adapter); |
322 TestPictureIdContinuousAfterReconfigure(ssrc_counts); | 353 TestPictureIdContinuousAfterReconfigure(ssrc_counts); |
323 } | 354 } |
324 | 355 |
325 } // namespace webrtc | 356 } // namespace webrtc |
OLD | NEW |