| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 | 10 |
| 11 #include <memory> |
| 12 |
| 11 #include "webrtc/api/video/i420_buffer.h" | 13 #include "webrtc/api/video/i420_buffer.h" |
| 12 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
" | 14 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
" |
| 13 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" | 15 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" |
| 14 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" | 16 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" |
| 15 #include "webrtc/modules/video_coding/include/video_coding.h" | 17 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 18 #include "webrtc/rtc_base/ptr_util.h" |
| 16 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
| 17 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 18 #include "webrtc/test/testsupport/mock/mock_frame_reader.h" | 21 #include "webrtc/test/testsupport/mock/mock_frame_reader.h" |
| 19 #include "webrtc/test/testsupport/mock/mock_frame_writer.h" | 22 #include "webrtc/test/testsupport/mock/mock_frame_writer.h" |
| 20 #include "webrtc/test/testsupport/packet_reader.h" | 23 #include "webrtc/test/testsupport/packet_reader.h" |
| 21 #include "webrtc/test/testsupport/unittest_utils.h" | 24 #include "webrtc/test/testsupport/unittest_utils.h" |
| 22 #include "webrtc/typedefs.h" | 25 #include "webrtc/typedefs.h" |
| 23 | 26 |
| 24 using ::testing::_; | 27 using ::testing::_; |
| 25 using ::testing::AtLeast; | 28 using ::testing::AtLeast; |
| 26 using ::testing::Return; | 29 using ::testing::Return; |
| 27 | 30 |
| 28 namespace webrtc { | 31 namespace webrtc { |
| 29 namespace test { | 32 namespace test { |
| 30 | 33 |
| 31 // Very basic testing for VideoProcessor. It's mostly tested by running the | 34 namespace { |
| 32 // video_quality_measurement program. | 35 |
| 36 const int kWidth = 352; |
| 37 const int kHeight = 288; |
| 38 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420. |
| 39 const int kFramerate = 30; |
| 40 const int kNumFrames = 2; |
| 41 |
| 42 } // namespace |
| 43 |
| 33 class VideoProcessorTest : public testing::Test { | 44 class VideoProcessorTest : public testing::Test { |
| 34 protected: | 45 protected: |
| 35 MockVideoEncoder encoder_mock_; | 46 VideoProcessorTest() { |
| 36 MockVideoDecoder decoder_mock_; | |
| 37 MockFrameReader frame_reader_mock_; | |
| 38 MockFrameWriter frame_writer_mock_; | |
| 39 MockPacketManipulator packet_manipulator_mock_; | |
| 40 Stats stats_; | |
| 41 TestConfig config_; | |
| 42 VideoCodec codec_settings_; | |
| 43 | |
| 44 VideoProcessorTest() {} | |
| 45 virtual ~VideoProcessorTest() {} | |
| 46 void SetUp() { | |
| 47 // Get a codec configuration struct and configure it. | 47 // Get a codec configuration struct and configure it. |
| 48 VideoCodingModule::Codec(kVideoCodecVP8, &codec_settings_); | 48 VideoCodingModule::Codec(kVideoCodecVP8, &codec_settings_); |
| 49 config_.codec_settings = &codec_settings_; | 49 config_.codec_settings = &codec_settings_; |
| 50 config_.codec_settings->startBitrate = 100; | 50 config_.codec_settings->startBitrate = 100; |
| 51 config_.codec_settings->width = 352; | 51 config_.codec_settings->width = kWidth; |
| 52 config_.codec_settings->height = 288; | 52 config_.codec_settings->height = kHeight; |
| 53 config_.codec_settings->maxFramerate = kFramerate; |
| 54 |
| 55 EXPECT_CALL(frame_reader_mock_, NumberOfFrames()) |
| 56 .WillRepeatedly(Return(kNumFrames)); |
| 57 EXPECT_CALL(frame_reader_mock_, FrameLength()) |
| 58 .WillRepeatedly(Return(kFrameSize)); |
| 59 video_processor_ = rtc::MakeUnique<VideoProcessorImpl>( |
| 60 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, |
| 61 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_, |
| 62 nullptr /* source_frame_writer */, nullptr /* encoded_frame_writer */, |
| 63 nullptr /* decoded_frame_writer */); |
| 53 } | 64 } |
| 54 void TearDown() {} | |
| 55 | 65 |
| 56 void ExpectInit() { | 66 void ExpectInit() { |
| 57 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); | 67 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); |
| 58 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)) | 68 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)) |
| 59 .Times(AtLeast(1)); | 69 .Times(AtLeast(1)); |
| 60 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); | 70 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); |
| 61 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)) | 71 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)) |
| 62 .Times(AtLeast(1)); | 72 .Times(AtLeast(1)); |
| 63 EXPECT_CALL(frame_reader_mock_, NumberOfFrames()).WillRepeatedly(Return(1)); | |
| 64 EXPECT_CALL(frame_reader_mock_, FrameLength()).WillOnce(Return(152064)); | |
| 65 } | 73 } |
| 74 |
| 75 MockVideoEncoder encoder_mock_; |
| 76 MockVideoDecoder decoder_mock_; |
| 77 MockFrameReader frame_reader_mock_; |
| 78 MockFrameWriter frame_writer_mock_; |
| 79 MockPacketManipulator packet_manipulator_mock_; |
| 80 VideoCodec codec_settings_; |
| 81 TestConfig config_; |
| 82 Stats stats_; |
| 83 std::unique_ptr<VideoProcessorImpl> video_processor_; |
| 66 }; | 84 }; |
| 67 | 85 |
| 68 TEST_F(VideoProcessorTest, Init) { | 86 TEST_F(VideoProcessorTest, Init) { |
| 69 ExpectInit(); | 87 ExpectInit(); |
| 70 VideoProcessorImpl video_processor( | 88 video_processor_->Init(); |
| 71 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, &frame_writer_mock_, | |
| 72 &packet_manipulator_mock_, config_, &stats_, | |
| 73 nullptr /* source_frame_writer */, nullptr /* encoded_frame_writer */, | |
| 74 nullptr /* decoded_frame_writer */); | |
| 75 video_processor.Init(); | |
| 76 } | 89 } |
| 77 | 90 |
| 78 TEST_F(VideoProcessorTest, ProcessFrame) { | 91 TEST_F(VideoProcessorTest, ProcessFrames) { |
| 79 ExpectInit(); | 92 ExpectInit(); |
| 80 EXPECT_CALL(encoder_mock_, Encode(_, _, _)).Times(1); | 93 video_processor_->Init(); |
| 94 |
| 81 EXPECT_CALL(frame_reader_mock_, ReadFrame()) | 95 EXPECT_CALL(frame_reader_mock_, ReadFrame()) |
| 82 .WillOnce(Return(I420Buffer::Create(50, 50))); | 96 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); |
| 83 // Since we don't return any callback from the mock, the decoder will not | 97 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, |
| 84 // be more than initialized... | 98 1 * 90000 / kFramerate), |
| 85 VideoProcessorImpl video_processor( | 99 _, _)) |
| 86 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, &frame_writer_mock_, | 100 .Times(1); |
| 87 &packet_manipulator_mock_, config_, &stats_, | 101 video_processor_->ProcessFrame(0); |
| 88 nullptr /* source_frame_writer */, nullptr /* encoded_frame_writer */, | 102 |
| 89 nullptr /* decoded_frame_writer */); | 103 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, |
| 90 video_processor.Init(); | 104 2 * 90000 / kFramerate), |
| 91 video_processor.ProcessFrame(0); | 105 _, _)) |
| 106 .Times(1); |
| 107 video_processor_->ProcessFrame(1); |
| 92 } | 108 } |
| 93 | 109 |
| 94 } // namespace test | 110 } // namespace test |
| 95 } // namespace webrtc | 111 } // namespace webrtc |
| OLD | NEW |