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