henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | #include <string> |
| 29 | |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 30 | #include "talk/app/webrtc/remotevideocapturer.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 31 | #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 32 | #include "talk/app/webrtc/videosource.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | #include "talk/app/webrtc/videotrack.h" |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 34 | #include "talk/media/base/fakemediaengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include "talk/media/webrtc/webrtcvideoframe.h" |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 36 | #include "talk/session/media/channelmanager.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 37 | #include "webrtc/base/gunit.h" |
| 38 | #include "webrtc/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | |
| 40 | using webrtc::FakeVideoTrackRenderer; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 41 | using webrtc::VideoSource; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | using webrtc::VideoTrack; |
| 43 | using webrtc::VideoTrackInterface; |
| 44 | |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 45 | namespace { |
| 46 | |
| 47 | class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { |
| 48 | public: |
| 49 | using cricket::WebRtcVideoFrame::SetRotation; |
| 50 | }; |
| 51 | |
| 52 | } // namespace |
| 53 | |
| 54 | class VideoTrackTest : public testing::Test { |
| 55 | public: |
| 56 | VideoTrackTest() { |
| 57 | static const char kVideoTrackId[] = "track_id"; |
| 58 | |
| 59 | channel_manager_.reset(new cricket::ChannelManager( |
solenberg | facbbec | 2015-09-24 00:41:50 -0700 | [diff] [blame] | 60 | new cricket::FakeMediaEngine(), rtc::Thread::Current())); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 61 | EXPECT_TRUE(channel_manager_->Init()); |
| 62 | video_track_ = VideoTrack::Create( |
| 63 | kVideoTrackId, |
| 64 | VideoSource::Create(channel_manager_.get(), |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 65 | new webrtc::RemoteVideoCapturer(), NULL, true)); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | protected: |
| 69 | rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; |
| 70 | rtc::scoped_refptr<VideoTrackInterface> video_track_; |
| 71 | }; |
| 72 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | // Test adding renderers to a video track and render to them by providing |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 74 | // frames to the source. |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 75 | TEST_F(VideoTrackTest, RenderVideo) { |
| 76 | // FakeVideoTrackRenderer register itself to |video_track_| |
guoweis@webrtc.org | f9a75d9 | 2015-03-10 06:37:00 +0000 | [diff] [blame] | 77 | rtc::scoped_ptr<FakeVideoTrackRenderer> renderer_1( |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 78 | new FakeVideoTrackRenderer(video_track_.get())); |
guoweis@webrtc.org | f9a75d9 | 2015-03-10 06:37:00 +0000 | [diff] [blame] | 79 | |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 80 | cricket::VideoRenderer* renderer_input = |
| 81 | video_track_->GetSource()->FrameInput(); |
| 82 | ASSERT_FALSE(renderer_input == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | cricket::WebRtcVideoFrame frame; |
nisse | 8b1e431 | 2016-01-18 01:46:27 -0800 | [diff] [blame] | 85 | frame.InitToBlack(123, 123, 0); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 86 | renderer_input->RenderFrame(&frame); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | EXPECT_EQ(1, renderer_1->num_rendered_frames()); |
| 88 | |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 89 | EXPECT_EQ(123, renderer_1->width()); |
| 90 | EXPECT_EQ(123, renderer_1->height()); |
| 91 | |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 92 | // FakeVideoTrackRenderer register itself to |video_track_| |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 93 | rtc::scoped_ptr<FakeVideoTrackRenderer> renderer_2( |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 94 | new FakeVideoTrackRenderer(video_track_.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 96 | renderer_input->RenderFrame(&frame); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | EXPECT_EQ(123, renderer_1->width()); |
| 99 | EXPECT_EQ(123, renderer_1->height()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | EXPECT_EQ(123, renderer_2->width()); |
| 101 | EXPECT_EQ(123, renderer_2->height()); |
| 102 | |
| 103 | EXPECT_EQ(2, renderer_1->num_rendered_frames()); |
| 104 | EXPECT_EQ(1, renderer_2->num_rendered_frames()); |
| 105 | |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 106 | video_track_->RemoveRenderer(renderer_1.get()); |
| 107 | renderer_input->RenderFrame(&frame); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | |
| 109 | EXPECT_EQ(2, renderer_1->num_rendered_frames()); |
| 110 | EXPECT_EQ(2, renderer_2->num_rendered_frames()); |
| 111 | } |