OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 18 matching lines...) Expand all Loading... |
29 #define TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ | 29 #define TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ |
30 | 30 |
31 #include <string> | 31 #include <string> |
32 #include <vector> | 32 #include <vector> |
33 | 33 |
34 #include "talk/media/base/fakenetworkinterface.h" | 34 #include "talk/media/base/fakenetworkinterface.h" |
35 #include "talk/media/base/fakevideocapturer.h" | 35 #include "talk/media/base/fakevideocapturer.h" |
36 #include "talk/media/base/fakevideorenderer.h" | 36 #include "talk/media/base/fakevideorenderer.h" |
37 #include "talk/media/base/mediachannel.h" | 37 #include "talk/media/base/mediachannel.h" |
38 #include "talk/media/base/streamparams.h" | 38 #include "talk/media/base/streamparams.h" |
| 39 #include "talk/media/webrtc/fakewebrtccall.h" |
39 #include "webrtc/base/bytebuffer.h" | 40 #include "webrtc/base/bytebuffer.h" |
40 #include "webrtc/base/gunit.h" | 41 #include "webrtc/base/gunit.h" |
41 #include "webrtc/base/timeutils.h" | 42 #include "webrtc/base/timeutils.h" |
| 43 #include "webrtc/call.h" |
42 | 44 |
43 #define EXPECT_FRAME_WAIT(c, w, h, t) \ | 45 #define EXPECT_FRAME_WAIT(c, w, h, t) \ |
44 EXPECT_EQ_WAIT((c), renderer_.num_rendered_frames(), (t)); \ | 46 EXPECT_EQ_WAIT((c), renderer_.num_rendered_frames(), (t)); \ |
45 EXPECT_EQ((w), renderer_.width()); \ | 47 EXPECT_EQ((w), renderer_.width()); \ |
46 EXPECT_EQ((h), renderer_.height()); \ | 48 EXPECT_EQ((h), renderer_.height()); \ |
47 EXPECT_EQ(0, renderer_.errors()); \ | 49 EXPECT_EQ(0, renderer_.errors()); \ |
48 | 50 |
49 #define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ | 51 #define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ |
50 EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \ | 52 EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \ |
51 EXPECT_EQ((w), (r).width()); \ | 53 EXPECT_EQ((w), (r).width()); \ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 91 } |
90 | 92 |
91 // Fake video engine that makes it possible to test enabling and disabling | 93 // Fake video engine that makes it possible to test enabling and disabling |
92 // capturer (checking that the engine state is updated and that the capturer | 94 // capturer (checking that the engine state is updated and that the capturer |
93 // is indeed capturing) without having to create a channel. It also makes it | 95 // is indeed capturing) without having to create a channel. It also makes it |
94 // possible to test that the media processors are indeed being called when | 96 // possible to test that the media processors are indeed being called when |
95 // registered. | 97 // registered. |
96 template<class T> | 98 template<class T> |
97 class VideoEngineOverride : public T { | 99 class VideoEngineOverride : public T { |
98 public: | 100 public: |
99 VideoEngineOverride() : T(nullptr) { | 101 VideoEngineOverride() : T() { |
100 } | 102 } |
101 virtual ~VideoEngineOverride() { | 103 virtual ~VideoEngineOverride() { |
102 } | 104 } |
103 bool is_camera_on() const { return T::GetVideoCapturer()->IsRunning(); } | 105 bool is_camera_on() const { return T::GetVideoCapturer()->IsRunning(); } |
104 void set_has_senders(bool has_senders) { | 106 void set_has_senders(bool has_senders) { |
105 cricket::VideoCapturer* video_capturer = T::GetVideoCapturer(); | 107 cricket::VideoCapturer* video_capturer = T::GetVideoCapturer(); |
106 if (has_senders) { | 108 if (has_senders) { |
107 video_capturer->SignalVideoFrame.connect(this, | 109 video_capturer->SignalVideoFrame.connect(this, |
108 &VideoEngineOverride<T>::OnLocalFrame); | 110 &VideoEngineOverride<T>::OnLocalFrame); |
109 } else { | 111 } else { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 443 } |
442 | 444 |
443 VideoEngineOverride<E> engine_; | 445 VideoEngineOverride<E> engine_; |
444 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_; | 446 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_; |
445 }; | 447 }; |
446 | 448 |
447 template<class E, class C> | 449 template<class E, class C> |
448 class VideoMediaChannelTest : public testing::Test, | 450 class VideoMediaChannelTest : public testing::Test, |
449 public sigslot::has_slots<> { | 451 public sigslot::has_slots<> { |
450 protected: | 452 protected: |
| 453 VideoMediaChannelTest<E, C>() |
| 454 : call_(webrtc::Call::Create(webrtc::Call::Config())) {} |
| 455 |
451 virtual cricket::VideoCodec DefaultCodec() = 0; | 456 virtual cricket::VideoCodec DefaultCodec() = 0; |
452 | 457 |
453 virtual cricket::StreamParams DefaultSendStreamParams() { | 458 virtual cricket::StreamParams DefaultSendStreamParams() { |
454 return cricket::StreamParams::CreateLegacy(kSsrc); | 459 return cricket::StreamParams::CreateLegacy(kSsrc); |
455 } | 460 } |
456 | 461 |
457 virtual void SetUp() { | 462 virtual void SetUp() { |
458 cricket::Device device("test", "device"); | 463 cricket::Device device("test", "device"); |
459 engine_.Init(); | 464 engine_.Init(); |
460 channel_.reset(engine_.CreateChannel(cricket::VideoOptions(), NULL)); | 465 channel_.reset( |
| 466 engine_.CreateChannel(call_.get(), cricket::VideoOptions())); |
461 EXPECT_TRUE(channel_.get() != NULL); | 467 EXPECT_TRUE(channel_.get() != NULL); |
462 ConnectVideoChannelError(); | 468 ConnectVideoChannelError(); |
463 network_interface_.SetDestination(channel_.get()); | 469 network_interface_.SetDestination(channel_.get()); |
464 channel_->SetInterface(&network_interface_); | 470 channel_->SetInterface(&network_interface_); |
465 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; | 471 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; |
466 channel_->SetRecvCodecs(engine_.codecs()); | 472 channel_->SetRecvCodecs(engine_.codecs()); |
467 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); | 473 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); |
468 video_capturer_.reset(CreateFakeVideoCapturer()); | 474 video_capturer_.reset(CreateFakeVideoCapturer()); |
469 cricket::VideoFormat format(640, 480, | 475 cricket::VideoFormat format(640, 480, |
470 cricket::VideoFormat::FpsToInterval(30), | 476 cricket::VideoFormat::FpsToInterval(30), |
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 // is no signalled yet. With unsignalled recv enabled, we will drop frames | 1866 // is no signalled yet. With unsignalled recv enabled, we will drop frames |
1861 // instead of packets. | 1867 // instead of packets. |
1862 EXPECT_EQ(0, renderer2_.num_rendered_frames()); | 1868 EXPECT_EQ(0, renderer2_.num_rendered_frames()); |
1863 // Give a chance for the decoder to process before adding the receiver. | 1869 // Give a chance for the decoder to process before adding the receiver. |
1864 rtc::Thread::Current()->ProcessMessages(100); | 1870 rtc::Thread::Current()->ProcessMessages(100); |
1865 // Ensure that we can remove the unsignalled recv stream that was created | 1871 // Ensure that we can remove the unsignalled recv stream that was created |
1866 // when the first video packet with unsignalled recv ssrc is received. | 1872 // when the first video packet with unsignalled recv ssrc is received. |
1867 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc + 2)); | 1873 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc + 2)); |
1868 } | 1874 } |
1869 | 1875 |
| 1876 const rtc::scoped_ptr<webrtc::Call> call_; |
1870 VideoEngineOverride<E> engine_; | 1877 VideoEngineOverride<E> engine_; |
1871 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_; | 1878 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_; |
1872 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_2_; | 1879 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_2_; |
1873 rtc::scoped_ptr<C> channel_; | 1880 rtc::scoped_ptr<C> channel_; |
1874 cricket::FakeNetworkInterface network_interface_; | 1881 cricket::FakeNetworkInterface network_interface_; |
1875 cricket::FakeVideoRenderer renderer_; | 1882 cricket::FakeVideoRenderer renderer_; |
1876 cricket::VideoMediaChannel::Error media_error_; | 1883 cricket::VideoMediaChannel::Error media_error_; |
1877 | 1884 |
1878 // Used by test cases where 2 streams are run on the same channel. | 1885 // Used by test cases where 2 streams are run on the same channel. |
1879 cricket::FakeVideoRenderer renderer2_; | 1886 cricket::FakeVideoRenderer renderer2_; |
1880 }; | 1887 }; |
1881 | 1888 |
1882 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT | 1889 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT |
OLD | NEW |