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/event.h" | 16 #include "webrtc/base/event.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/common.h" | 18 #include "webrtc/common.h" |
19 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" | 19 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" |
| 20 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" |
20 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
21 #include "webrtc/system_wrappers/include/ref_count.h" | 22 #include "webrtc/system_wrappers/include/ref_count.h" |
22 #include "webrtc/system_wrappers/include/scoped_vector.h" | 23 #include "webrtc/system_wrappers/include/scoped_vector.h" |
23 #include "webrtc/test/fake_texture_frame.h" | 24 #include "webrtc/test/fake_texture_frame.h" |
24 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
25 | 26 |
26 using ::testing::_; | 27 using ::testing::_; |
27 using ::testing::Invoke; | 28 using ::testing::Invoke; |
28 using ::testing::NiceMock; | 29 using ::testing::NiceMock; |
29 using ::testing::Return; | 30 using ::testing::Return; |
(...skipping 12 matching lines...) Expand all Loading... |
42 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 43 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
43 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 44 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
44 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 45 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
45 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, | 46 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, |
46 const ScopedVector<VideoFrame>& frames2); | 47 const ScopedVector<VideoFrame>& frames2); |
47 VideoFrame* CreateVideoFrame(uint8_t length); | 48 VideoFrame* CreateVideoFrame(uint8_t length); |
48 | 49 |
49 class VideoCaptureInputTest : public ::testing::Test { | 50 class VideoCaptureInputTest : public ::testing::Test { |
50 protected: | 51 protected: |
51 VideoCaptureInputTest() | 52 VideoCaptureInputTest() |
52 : mock_process_thread_(new NiceMock<MockProcessThread>), | 53 : vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
53 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), | 54 nullptr, |
| 55 nullptr)), |
54 output_frame_event_(false, false), | 56 output_frame_event_(false, false), |
55 stats_proxy_(Clock::GetRealTimeClock(), | 57 stats_proxy_(Clock::GetRealTimeClock(), |
56 webrtc::VideoSendStream::Config(nullptr), | 58 webrtc::VideoSendStream::Config(nullptr), |
57 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo) {} | 59 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo) {} |
58 | 60 |
59 virtual void SetUp() { | 61 virtual void SetUp() { |
60 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) | 62 EXPECT_CALL(mock_frame_callback_, DeliverFrame(_)) |
61 .WillRepeatedly( | 63 .WillRepeatedly( |
62 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); | 64 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); |
63 | 65 |
64 Config config; | 66 VideoSendStream::Config config(nullptr); |
| 67 config.encoder_settings.encoder = &mock_encoder_; |
| 68 config.encoder_settings.payload_type = 42; |
65 input_.reset(new internal::VideoCaptureInput( | 69 input_.reset(new internal::VideoCaptureInput( |
66 mock_process_thread_.get(), mock_frame_callback_.get(), nullptr, | 70 &mock_process_thread_, &mock_frame_callback_, vcm_.get(), nullptr, |
67 &stats_proxy_, nullptr, nullptr)); | 71 config, &stats_proxy_, nullptr)); |
| 72 input_->TriggerSetSendCodec(VideoCodec()); |
68 } | 73 } |
69 | 74 |
70 virtual void TearDown() { | 75 virtual void TearDown() { |
71 // VideoCaptureInput accesses |mock_process_thread_| in destructor and | 76 // VideoCaptureInput accesses |mock_process_thread_| in destructor and |
72 // should | 77 // should |
73 // be deleted first. | 78 // be deleted first. |
74 input_.reset(); | 79 input_.reset(); |
75 } | 80 } |
76 | 81 |
77 void AddInputFrame(VideoFrame* frame) { | 82 void AddInputFrame(VideoFrame* frame) { |
78 input_->IncomingCapturedFrame(*frame); | 83 input_->IncomingCapturedFrame(*frame); |
79 } | 84 } |
80 | 85 |
81 void AddOutputFrame(const VideoFrame& frame) { | 86 void AddOutputFrame(const VideoFrame& frame) { |
82 if (frame.native_handle() == NULL) | 87 if (frame.native_handle() == NULL) |
83 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); | 88 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); |
84 output_frames_.push_back(new VideoFrame(frame)); | 89 output_frames_.push_back(new VideoFrame(frame)); |
85 output_frame_event_.Set(); | 90 output_frame_event_.Set(); |
86 } | 91 } |
87 | 92 |
88 void WaitOutputFrame() { | 93 void WaitOutputFrame() { |
89 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); | 94 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
90 } | 95 } |
91 | 96 |
92 rtc::scoped_ptr<MockProcessThread> mock_process_thread_; | 97 NiceMock<MockProcessThread> mock_process_thread_; |
93 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; | 98 NiceMock<MockVideoCaptureCallback> mock_frame_callback_; |
| 99 rtc::scoped_ptr<VideoCodingModule> vcm_; |
| 100 NiceMock<MockVideoEncoder> mock_encoder_; |
94 | 101 |
95 // Used to send input capture frames to VideoCaptureInput. | 102 // Used to send input capture frames to VideoCaptureInput. |
96 rtc::scoped_ptr<internal::VideoCaptureInput> input_; | 103 rtc::scoped_ptr<internal::VideoCaptureInput> input_; |
97 | 104 |
98 // Input capture frames of VideoCaptureInput. | 105 // Input capture frames of VideoCaptureInput. |
99 ScopedVector<VideoFrame> input_frames_; | 106 ScopedVector<VideoFrame> input_frames_; |
100 | 107 |
101 // Indicate an output frame has arrived. | 108 // Indicate an output frame has arrived. |
102 rtc::Event output_frame_event_; | 109 rtc::Event output_frame_event_; |
103 | 110 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 const int kSizeY = width * height * 2; | 303 const int kSizeY = width * height * 2; |
297 uint8_t buffer[kSizeY]; | 304 uint8_t buffer[kSizeY]; |
298 memset(buffer, data, kSizeY); | 305 memset(buffer, data, kSizeY); |
299 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, | 306 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, |
300 width / 2); | 307 width / 2); |
301 frame->set_render_time_ms(data); | 308 frame->set_render_time_ms(data); |
302 return frame; | 309 return frame; |
303 } | 310 } |
304 | 311 |
305 } // namespace webrtc | 312 } // namespace webrtc |
OLD | NEW |