Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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/video/video_capture_input.h" | 10 #include "webrtc/video/video_capture_input.h" |
| 11 | 11 |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
| 17 #include "webrtc/common.h" | 17 #include "webrtc/common.h" |
| 18 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" | 18 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" |
| 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 20 #include "webrtc/system_wrappers/include/event_wrapper.h" | 20 #include "webrtc/system_wrappers/include/event_wrapper.h" |
|
mflodman
2015/12/10 08:11:34
Remove.
pbos-webrtc
2015/12/10 11:44:55
Done.
| |
| 21 #include "webrtc/system_wrappers/include/ref_count.h" | 21 #include "webrtc/system_wrappers/include/ref_count.h" |
| 22 #include "webrtc/system_wrappers/include/scoped_vector.h" | 22 #include "webrtc/system_wrappers/include/scoped_vector.h" |
| 23 #include "webrtc/test/fake_texture_frame.h" | 23 #include "webrtc/test/fake_texture_frame.h" |
| 24 #include "webrtc/video/send_statistics_proxy.h" | 24 #include "webrtc/video/send_statistics_proxy.h" |
| 25 | 25 |
| 26 using ::testing::_; | 26 using ::testing::_; |
| 27 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 28 using ::testing::NiceMock; | 28 using ::testing::NiceMock; |
| 29 using ::testing::Return; | 29 using ::testing::Return; |
| 30 using ::testing::WithArg; | 30 using ::testing::WithArg; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 44 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 44 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
| 45 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, | 45 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, |
| 46 const ScopedVector<VideoFrame>& frames2); | 46 const ScopedVector<VideoFrame>& frames2); |
| 47 VideoFrame* CreateVideoFrame(uint8_t length); | 47 VideoFrame* CreateVideoFrame(uint8_t length); |
| 48 | 48 |
| 49 class VideoCaptureInputTest : public ::testing::Test { | 49 class VideoCaptureInputTest : public ::testing::Test { |
| 50 protected: | 50 protected: |
| 51 VideoCaptureInputTest() | 51 VideoCaptureInputTest() |
| 52 : mock_process_thread_(new NiceMock<MockProcessThread>), | 52 : mock_process_thread_(new NiceMock<MockProcessThread>), |
| 53 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), | 53 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), |
| 54 output_frame_event_(EventWrapper::Create()), | 54 output_frame_event_(false, false), |
| 55 stats_proxy_(Clock::GetRealTimeClock(), | 55 stats_proxy_(Clock::GetRealTimeClock(), |
| 56 webrtc::VideoSendStream::Config(nullptr)) {} | 56 webrtc::VideoSendStream::Config(nullptr)) {} |
| 57 | 57 |
| 58 virtual void SetUp() { | 58 virtual void SetUp() { |
| 59 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) | 59 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) |
| 60 .WillRepeatedly( | 60 .WillRepeatedly( |
| 61 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); | 61 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); |
| 62 | 62 |
| 63 Config config; | 63 Config config; |
| 64 input_.reset(new internal::VideoCaptureInput( | 64 input_.reset(new internal::VideoCaptureInput( |
| 65 mock_process_thread_.get(), mock_frame_callback_.get(), nullptr, | 65 mock_process_thread_.get(), mock_frame_callback_.get(), nullptr, |
| 66 &stats_proxy_, nullptr, nullptr)); | 66 &stats_proxy_, nullptr, nullptr)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void TearDown() { | 69 virtual void TearDown() { |
| 70 // VideoCaptureInput accesses |mock_process_thread_| in destructor and | 70 // VideoCaptureInput accesses |mock_process_thread_| in destructor and |
| 71 // should | 71 // should |
| 72 // be deleted first. | 72 // be deleted first. |
| 73 input_.reset(); | 73 input_.reset(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void AddInputFrame(VideoFrame* frame) { | 76 void AddInputFrame(VideoFrame* frame) { |
| 77 input_->IncomingCapturedFrame(*frame); | 77 input_->IncomingCapturedFrame(*frame); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void AddOutputFrame(const VideoFrame& frame) { | 80 void AddOutputFrame(const VideoFrame& frame) { |
| 81 if (frame.native_handle() == NULL) | 81 if (frame.native_handle() == NULL) |
| 82 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); | 82 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); |
| 83 output_frames_.push_back(new VideoFrame(frame)); | 83 output_frames_.push_back(new VideoFrame(frame)); |
| 84 output_frame_event_->Set(); | 84 output_frame_event_.Set(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void WaitOutputFrame() { | 87 void WaitOutputFrame() { |
| 88 EXPECT_EQ(kEventSignaled, output_frame_event_->Wait(FRAME_TIMEOUT_MS)); | 88 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 rtc::scoped_ptr<MockProcessThread> mock_process_thread_; | 91 rtc::scoped_ptr<MockProcessThread> mock_process_thread_; |
| 92 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; | 92 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; |
| 93 | 93 |
| 94 // Used to send input capture frames to VideoCaptureInput. | 94 // Used to send input capture frames to VideoCaptureInput. |
| 95 rtc::scoped_ptr<internal::VideoCaptureInput> input_; | 95 rtc::scoped_ptr<internal::VideoCaptureInput> input_; |
| 96 | 96 |
| 97 // Input capture frames of VideoCaptureInput. | 97 // Input capture frames of VideoCaptureInput. |
| 98 ScopedVector<VideoFrame> input_frames_; | 98 ScopedVector<VideoFrame> input_frames_; |
| 99 | 99 |
| 100 // Indicate an output frame has arrived. | 100 // Indicate an output frame has arrived. |
| 101 rtc::scoped_ptr<EventWrapper> output_frame_event_; | 101 rtc::Event output_frame_event_; |
| 102 | 102 |
| 103 // Output delivered frames of VideoCaptureInput. | 103 // Output delivered frames of VideoCaptureInput. |
| 104 ScopedVector<VideoFrame> output_frames_; | 104 ScopedVector<VideoFrame> output_frames_; |
| 105 | 105 |
| 106 // The pointers of Y plane buffers of output frames. This is used to verify | 106 // The pointers of Y plane buffers of output frames. This is used to verify |
| 107 // the frame are swapped and not copied. | 107 // the frame are swapped and not copied. |
| 108 std::vector<const uint8_t*> output_frame_ybuffers_; | 108 std::vector<const uint8_t*> output_frame_ybuffers_; |
| 109 SendStatisticsProxy stats_proxy_; | 109 SendStatisticsProxy stats_proxy_; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { | 112 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { |
| 113 // Indicate an output frame has arrived. | 113 // Indicate an output frame has arrived. |
| 114 rtc::scoped_ptr<EventWrapper> frame_destroyed_event(EventWrapper::Create()); | 114 rtc::Event frame_destroyed_event(false, false); |
| 115 class TestBuffer : public webrtc::I420Buffer { | 115 class TestBuffer : public webrtc::I420Buffer { |
| 116 public: | 116 public: |
| 117 explicit TestBuffer(EventWrapper* event) | 117 explicit TestBuffer(rtc::Event* event) : I420Buffer(5, 5), event_(event) {} |
| 118 : I420Buffer(5, 5), event_(event) {} | |
| 119 | 118 |
| 120 private: | 119 private: |
| 121 friend class rtc::RefCountedObject<TestBuffer>; | 120 friend class rtc::RefCountedObject<TestBuffer>; |
| 122 ~TestBuffer() override { event_->Set(); } | 121 ~TestBuffer() override { event_->Set(); } |
| 123 EventWrapper* event_; | 122 rtc::Event* const event_; |
| 124 }; | 123 }; |
| 125 | 124 |
| 126 VideoFrame frame( | 125 VideoFrame frame( |
| 127 new rtc::RefCountedObject<TestBuffer>(frame_destroyed_event.get()), 1, 1, | 126 new rtc::RefCountedObject<TestBuffer>(&frame_destroyed_event), 1, 1, |
| 128 kVideoRotation_0); | 127 kVideoRotation_0); |
| 129 | 128 |
| 130 AddInputFrame(&frame); | 129 AddInputFrame(&frame); |
| 131 WaitOutputFrame(); | 130 WaitOutputFrame(); |
| 132 | 131 |
| 133 EXPECT_EQ(output_frames_[0]->video_frame_buffer().get(), | 132 EXPECT_EQ(output_frames_[0]->video_frame_buffer().get(), |
| 134 frame.video_frame_buffer().get()); | 133 frame.video_frame_buffer().get()); |
| 135 output_frames_.clear(); | 134 output_frames_.clear(); |
| 136 frame.Reset(); | 135 frame.Reset(); |
| 137 EXPECT_EQ(kEventSignaled, frame_destroyed_event->Wait(FRAME_TIMEOUT_MS)); | 136 EXPECT_TRUE(frame_destroyed_event.Wait(FRAME_TIMEOUT_MS)); |
| 138 } | 137 } |
| 139 | 138 |
| 140 TEST_F(VideoCaptureInputTest, TestNtpTimeStampSetIfRenderTimeSet) { | 139 TEST_F(VideoCaptureInputTest, TestNtpTimeStampSetIfRenderTimeSet) { |
| 141 input_frames_.push_back(CreateVideoFrame(0)); | 140 input_frames_.push_back(CreateVideoFrame(0)); |
| 142 input_frames_[0]->set_render_time_ms(5); | 141 input_frames_[0]->set_render_time_ms(5); |
| 143 input_frames_[0]->set_ntp_time_ms(0); | 142 input_frames_[0]->set_ntp_time_ms(0); |
| 144 | 143 |
| 145 AddInputFrame(input_frames_[0]); | 144 AddInputFrame(input_frames_[0]); |
| 146 WaitOutputFrame(); | 145 WaitOutputFrame(); |
| 147 EXPECT_GT(output_frames_[0]->ntp_time_ms(), | 146 EXPECT_GT(output_frames_[0]->ntp_time_ms(), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 164 input_frames_.push_back(CreateVideoFrame(0)); | 163 input_frames_.push_back(CreateVideoFrame(0)); |
| 165 | 164 |
| 166 input_frames_[0]->set_ntp_time_ms(17); | 165 input_frames_[0]->set_ntp_time_ms(17); |
| 167 AddInputFrame(input_frames_[0]); | 166 AddInputFrame(input_frames_[0]); |
| 168 WaitOutputFrame(); | 167 WaitOutputFrame(); |
| 169 EXPECT_EQ(output_frames_[0]->timestamp(), | 168 EXPECT_EQ(output_frames_[0]->timestamp(), |
| 170 input_frames_[0]->ntp_time_ms() * 90); | 169 input_frames_[0]->ntp_time_ms() * 90); |
| 171 | 170 |
| 172 // Repeat frame with the same NTP timestamp should drop. | 171 // Repeat frame with the same NTP timestamp should drop. |
| 173 AddInputFrame(input_frames_[0]); | 172 AddInputFrame(input_frames_[0]); |
| 174 EXPECT_EQ(kEventTimeout, output_frame_event_->Wait(FRAME_TIMEOUT_MS)); | 173 EXPECT_FALSE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
| 175 | 174 |
| 176 // As should frames with a decreased NTP timestamp. | 175 // As should frames with a decreased NTP timestamp. |
| 177 input_frames_[0]->set_ntp_time_ms(input_frames_[0]->ntp_time_ms() - 1); | 176 input_frames_[0]->set_ntp_time_ms(input_frames_[0]->ntp_time_ms() - 1); |
| 178 AddInputFrame(input_frames_[0]); | 177 AddInputFrame(input_frames_[0]); |
| 179 EXPECT_EQ(kEventTimeout, output_frame_event_->Wait(FRAME_TIMEOUT_MS)); | 178 EXPECT_FALSE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
| 180 | 179 |
| 181 // But delivering with an increased NTP timestamp should succeed. | 180 // But delivering with an increased NTP timestamp should succeed. |
| 182 input_frames_[0]->set_ntp_time_ms(4711); | 181 input_frames_[0]->set_ntp_time_ms(4711); |
| 183 AddInputFrame(input_frames_[0]); | 182 AddInputFrame(input_frames_[0]); |
| 184 WaitOutputFrame(); | 183 WaitOutputFrame(); |
| 185 EXPECT_EQ(output_frames_[1]->timestamp(), | 184 EXPECT_EQ(output_frames_[1]->timestamp(), |
| 186 input_frames_[0]->ntp_time_ms() * 90); | 185 input_frames_[0]->ntp_time_ms() * 90); |
| 187 } | 186 } |
| 188 | 187 |
| 189 TEST_F(VideoCaptureInputTest, TestTextureFrames) { | 188 TEST_F(VideoCaptureInputTest, TestTextureFrames) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 const int kSizeY = width * height * 2; | 295 const int kSizeY = width * height * 2; |
| 297 uint8_t buffer[kSizeY]; | 296 uint8_t buffer[kSizeY]; |
| 298 memset(buffer, data, kSizeY); | 297 memset(buffer, data, kSizeY); |
| 299 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, | 298 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, |
| 300 width / 2); | 299 width / 2); |
| 301 frame->set_render_time_ms(data); | 300 frame->set_render_time_ms(data); |
| 302 return frame; | 301 return frame; |
| 303 } | 302 } |
| 304 | 303 |
| 305 } // namespace webrtc | 304 } // namespace webrtc |
| OLD | NEW |