| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2016 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 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "webrtc/base/event.h" | |
| 13 #include "webrtc/common_video/include/incoming_video_stream.h" | |
| 14 #include "webrtc/media/base/videosinkinterface.h" | |
| 15 #include "webrtc/video_frame.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 | |
| 19 // Basic test that checks if the no-smoothing implementation delivers a frame. | |
| 20 TEST(IncomingVideoStreamTest, NoSmoothingOneFrame) { | |
| 21 class TestCallback : public rtc::VideoSinkInterface<VideoFrame> { | |
| 22 public: | |
| 23 TestCallback() : event_(false, false) {} | |
| 24 ~TestCallback() override {} | |
| 25 | |
| 26 bool WaitForFrame(int milliseconds) { return event_.Wait(milliseconds); } | |
| 27 | |
| 28 private: | |
| 29 void OnFrame(const VideoFrame& frame) override { event_.Set(); } | |
| 30 | |
| 31 rtc::Event event_; | |
| 32 } callback; | |
| 33 IncomingVideoStreamNoSmoothing stream(&callback); | |
| 34 | |
| 35 rtc::VideoSinkInterface<VideoFrame>* stream_sink = &stream; | |
| 36 stream_sink->OnFrame(VideoFrame()); | |
| 37 | |
| 38 EXPECT_TRUE(callback.WaitForFrame(500)); | |
| 39 } | |
| 40 | |
| 41 // Tests that if the renderer is too slow, that frames will not be dropped and | |
| 42 // still the "producer thread" (main test thread), will not be blocked from | |
| 43 // delivering frames. | |
| 44 TEST(IncomingVideoStreamTest, NoSmoothingManyFrames) { | |
| 45 rtc::Event done(false, false); | |
| 46 | |
| 47 class TestCallback : public rtc::VideoSinkInterface<VideoFrame> { | |
| 48 public: | |
| 49 explicit TestCallback(rtc::Event* done) | |
| 50 : event_(false, false), done_(done) {} | |
| 51 ~TestCallback() override {} | |
| 52 | |
| 53 void Continue() { event_.Set(); } | |
| 54 int frame_count() const { return frame_count_; } | |
| 55 | |
| 56 private: | |
| 57 void OnFrame(const VideoFrame& frame) override { | |
| 58 ++frame_count_; | |
| 59 if (frame_count_ == 1) { | |
| 60 // Block delivery of frames until we're allowed to continue. | |
| 61 event_.Wait(rtc::Event::kForever); | |
| 62 } else if (frame_count_ == 100) { | |
| 63 done_->Set(); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 rtc::Event event_; | |
| 68 rtc::Event* done_; | |
| 69 int frame_count_ = 0; | |
| 70 } callback(&done); | |
| 71 | |
| 72 { | |
| 73 IncomingVideoStreamNoSmoothing stream(&callback); | |
| 74 | |
| 75 rtc::VideoSinkInterface<VideoFrame>* stream_sink = &stream; | |
| 76 for (int i = 0; i < 100; ++i) | |
| 77 stream_sink->OnFrame(VideoFrame()); | |
| 78 // Unblock the 'processing' of the first frame and wait for all the frames | |
| 79 // to be processed. | |
| 80 EXPECT_LE(callback.frame_count(), 1); | |
| 81 callback.Continue(); | |
| 82 done.Wait(rtc::Event::kForever); | |
| 83 } | |
| 84 | |
| 85 EXPECT_EQ(callback.frame_count(), 100); | |
| 86 } | |
| 87 | |
| 88 } // namespace webrtc | |
| OLD | NEW |