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 { |
| 30 event_.Set(); |
| 31 } |
| 32 |
| 33 rtc::Event event_; |
| 34 } callback; |
| 35 IncomingVideoStreamNoSmoothing stream(&callback); |
| 36 |
| 37 rtc::VideoSinkInterface<VideoFrame>* stream_sink = &stream; |
| 38 stream_sink->OnFrame(VideoFrame()); |
| 39 |
| 40 EXPECT_TRUE(callback.WaitForFrame(500)); |
| 41 } |
| 42 |
| 43 // Tests that if the renderer is too slow, that frames will be dropped and |
| 44 // the "producer thread" (main test thread), will not be blocked from delivering |
| 45 // frames. |
| 46 TEST(IncomingVideoStreamTest, NoSmoothingTooManyFrames) { |
| 47 class TestCallback : public rtc::VideoSinkInterface<VideoFrame> { |
| 48 public: |
| 49 TestCallback() : event_(false, false) {} |
| 50 ~TestCallback() override {} |
| 51 |
| 52 void Continue() { event_.Set(); } |
| 53 int frame_count() const { return frame_count_; } |
| 54 |
| 55 private: |
| 56 void OnFrame(const VideoFrame& frame) override { |
| 57 ++frame_count_; |
| 58 if (frame_count_ == 1) { |
| 59 // Block delivery of frames until we're allowed to continue. |
| 60 event_.Wait(rtc::Event::kForever); |
| 61 } |
| 62 } |
| 63 |
| 64 rtc::Event event_; |
| 65 int frame_count_ = 0; |
| 66 } callback; |
| 67 |
| 68 { |
| 69 IncomingVideoStreamNoSmoothing stream(&callback); |
| 70 |
| 71 rtc::VideoSinkInterface<VideoFrame>* stream_sink = &stream; |
| 72 for (int i = 0; i < 100; ++i) |
| 73 stream_sink->OnFrame(VideoFrame()); |
| 74 // We need to set the 'continue' event before |stream| goes out of scope |
| 75 // since we're currently blocking the queue (i.e. stream can't be deleted). |
| 76 callback.Continue(); |
| 77 } |
| 78 |
| 79 // Once |stream| has been deleted, we're guaranteed that no more calls to |
| 80 // the OnFrame callback will be made, so we can safely check the frame count |
| 81 // without having to worry about synchronization. |
| 82 |
| 83 // In practice frame_count will be ~1. |
| 84 EXPECT_LT(callback.frame_count(), 100); |
| 85 EXPECT_GE(callback.frame_count(), 1); |
| 86 } |
| 87 |
| 88 } // namespace webrtc |
OLD | NEW |