2011-10-06 06:44:54 +00:00
|
|
|
/*
|
2012-02-08 07:09:32 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-10-06 06:44:54 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2011-12-08 07:42:18 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/codecs/test/videoprocessor.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-08-07 03:36:54 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2018-10-15 11:55:13 +02:00
|
|
|
#include "api/test/mock_video_decoder.h"
|
|
|
|
|
#include "api/test/mock_video_encoder.h"
|
2018-05-22 13:34:14 +02:00
|
|
|
#include "api/test/videocodec_test_fixture.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/i420_buffer.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/media_constants.h"
|
2018-05-22 13:34:14 +02:00
|
|
|
#include "modules/video_coding/codecs/test/videocodec_test_stats_impl.h"
|
2018-05-16 09:38:42 +02:00
|
|
|
#include "rtc_base/task_queue_for_test.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gmock.h"
|
|
|
|
|
#include "test/gtest.h"
|
|
|
|
|
#include "test/testsupport/mock/mock_frame_reader.h"
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
using ::testing::_;
|
2019-04-12 13:59:09 +02:00
|
|
|
using ::testing::AllOf;
|
|
|
|
|
using ::testing::Field;
|
2017-08-30 06:29:51 -07:00
|
|
|
using ::testing::Property;
|
2019-04-12 13:59:09 +02:00
|
|
|
using ::testing::ResultOf;
|
2011-10-06 06:44:54 +00:00
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2017-08-07 03:36:54 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const int kWidth = 352;
|
|
|
|
|
const int kHeight = 288;
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
class VideoProcessorTest : public ::testing::Test {
|
2011-10-06 06:44:54 +00:00
|
|
|
protected:
|
2018-02-07 13:56:16 +01:00
|
|
|
VideoProcessorTest() : q_("VP queue") {
|
2018-04-13 14:25:22 +02:00
|
|
|
config_.SetCodecSettings(cricket::kVp8CodecName, 1, 1, 1, false, false,
|
2018-04-25 14:46:06 +02:00
|
|
|
false, kWidth, kHeight);
|
2017-08-07 03:36:54 -07:00
|
|
|
|
2018-02-01 13:25:17 +01:00
|
|
|
decoder_mock_ = new MockVideoDecoder();
|
|
|
|
|
decoders_.push_back(std::unique_ptr<VideoDecoder>(decoder_mock_));
|
|
|
|
|
|
2017-10-24 16:03:39 +02:00
|
|
|
ExpectInit();
|
2019-10-15 10:04:57 +02:00
|
|
|
q_.SendTask(
|
|
|
|
|
[this] {
|
|
|
|
|
video_processor_ = std::make_unique<VideoProcessor>(
|
|
|
|
|
&encoder_mock_, &decoders_, &frame_reader_mock_, config_, &stats_,
|
|
|
|
|
&encoded_frame_writers_, /*decoded_frame_writers=*/nullptr);
|
2022-08-11 12:26:09 +02:00
|
|
|
});
|
2018-02-07 13:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~VideoProcessorTest() {
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([this] { video_processor_.reset(); });
|
2012-02-08 07:09:32 +00:00
|
|
|
}
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
void ExpectInit() {
|
2021-08-18 13:34:36 +00:00
|
|
|
EXPECT_CALL(encoder_mock_, InitEncode(_, _));
|
|
|
|
|
EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback);
|
|
|
|
|
EXPECT_CALL(*decoder_mock_, Configure);
|
|
|
|
|
EXPECT_CALL(*decoder_mock_, RegisterDecodeCompleteCallback);
|
2017-08-30 06:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpectRelease() {
|
|
|
|
|
EXPECT_CALL(encoder_mock_, Release()).Times(1);
|
|
|
|
|
EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1);
|
2018-02-01 13:25:17 +01:00
|
|
|
EXPECT_CALL(*decoder_mock_, Release()).Times(1);
|
|
|
|
|
EXPECT_CALL(*decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
2017-08-07 03:36:54 -07:00
|
|
|
|
2019-03-19 18:08:37 +01:00
|
|
|
TaskQueueForTest q_;
|
2018-02-07 13:56:16 +01:00
|
|
|
|
2018-05-22 13:34:14 +02:00
|
|
|
VideoCodecTestFixture::Config config_;
|
2017-08-08 08:35:53 -07:00
|
|
|
|
2017-08-07 03:36:54 -07:00
|
|
|
MockVideoEncoder encoder_mock_;
|
2018-02-01 13:25:17 +01:00
|
|
|
MockVideoDecoder* decoder_mock_;
|
|
|
|
|
std::vector<std::unique_ptr<VideoDecoder>> decoders_;
|
2017-08-07 03:36:54 -07:00
|
|
|
MockFrameReader frame_reader_mock_;
|
2018-05-22 13:34:14 +02:00
|
|
|
VideoCodecTestStatsImpl stats_;
|
2019-03-22 13:41:48 +01:00
|
|
|
VideoProcessor::IvfFileWriterMap encoded_frame_writers_;
|
2017-08-07 08:12:33 -07:00
|
|
|
std::unique_ptr<VideoProcessor> video_processor_;
|
2011-10-06 06:44:54 +00:00
|
|
|
};
|
|
|
|
|
|
2017-08-30 06:29:51 -07:00
|
|
|
TEST_F(VideoProcessorTest, InitRelease) {
|
|
|
|
|
ExpectRelease();
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-30 06:29:51 -07:00
|
|
|
TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
|
|
|
|
|
const int kBitrateKbps = 456;
|
|
|
|
|
const int kFramerateFps = 31;
|
2019-04-12 13:59:09 +02:00
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
|
|
|
|
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
|
|
|
|
|
static_cast<double>(kFramerateFps))))
|
|
|
|
|
.Times(1);
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
2022-12-06 15:36:21 +01:00
|
|
|
EXPECT_CALL(frame_reader_mock_, PullFrame(_, _, _))
|
2017-08-07 03:36:54 -07:00
|
|
|
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
|
2017-08-30 06:29:51 -07:00
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
2019-03-07 12:40:01 +01:00
|
|
|
Encode(Property(&VideoFrame::timestamp, 1 * 90000 / kFramerateFps), _))
|
2017-08-30 06:29:51 -07:00
|
|
|
.Times(1);
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
2019-03-07 12:40:01 +01:00
|
|
|
Encode(Property(&VideoFrame::timestamp, 2 * 90000 / kFramerateFps), _))
|
2017-08-30 06:29:51 -07:00
|
|
|
.Times(1);
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
ExpectRelease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
|
|
|
|
|
const int kBitrateKbps = 456;
|
|
|
|
|
const int kStartFramerateFps = 27;
|
2018-01-24 17:20:18 +01:00
|
|
|
const int kStartTimestamp = 90000 / kStartFramerateFps;
|
2019-04-12 13:59:09 +02:00
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
|
|
|
|
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
|
|
|
|
|
static_cast<double>(kStartFramerateFps))))
|
|
|
|
|
.Times(1);
|
2018-05-16 09:38:42 +02:00
|
|
|
q_.SendTask(
|
2022-08-11 12:26:09 +02:00
|
|
|
[=] { video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
2022-12-06 15:36:21 +01:00
|
|
|
EXPECT_CALL(frame_reader_mock_, PullFrame(_, _, _))
|
2017-08-30 06:29:51 -07:00
|
|
|
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
|
2018-01-24 17:20:18 +01:00
|
|
|
EXPECT_CALL(encoder_mock_,
|
2019-03-07 12:40:01 +01:00
|
|
|
Encode(Property(&VideoFrame::timestamp, kStartTimestamp), _))
|
2017-08-07 03:36:54 -07:00
|
|
|
.Times(1);
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
2017-08-07 03:36:54 -07:00
|
|
|
|
2017-08-30 06:29:51 -07:00
|
|
|
const int kNewFramerateFps = 13;
|
2019-04-12 13:59:09 +02:00
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
|
|
|
|
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
|
|
|
|
|
static_cast<double>(kNewFramerateFps))))
|
|
|
|
|
.Times(1);
|
2018-05-16 09:38:42 +02:00
|
|
|
q_.SendTask(
|
2022-08-11 12:26:09 +02:00
|
|
|
[=] { video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
2018-01-24 17:20:18 +01:00
|
|
|
EXPECT_CALL(encoder_mock_,
|
|
|
|
|
Encode(Property(&VideoFrame::timestamp,
|
|
|
|
|
kStartTimestamp + 90000 / kNewFramerateFps),
|
2019-03-07 12:40:01 +01:00
|
|
|
_))
|
2017-08-07 03:36:54 -07:00
|
|
|
.Times(1);
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
ExpectRelease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoProcessorTest, SetRates) {
|
2019-04-12 13:59:09 +02:00
|
|
|
const uint32_t kBitrateKbps = 123;
|
2017-08-30 06:29:51 -07:00
|
|
|
const int kFramerateFps = 17;
|
2019-04-12 13:59:09 +02:00
|
|
|
|
|
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
|
|
|
|
SetRates(AllOf(ResultOf(
|
|
|
|
|
[](const VideoEncoder::RateControlParameters& params) {
|
|
|
|
|
return params.bitrate.get_sum_kbps();
|
|
|
|
|
},
|
|
|
|
|
kBitrateKbps),
|
|
|
|
|
Field(&VideoEncoder::RateControlParameters::framerate_fps,
|
|
|
|
|
static_cast<double>(kFramerateFps)))))
|
2017-08-30 06:29:51 -07:00
|
|
|
.Times(1);
|
2022-08-11 12:26:09 +02:00
|
|
|
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
2019-04-12 13:59:09 +02:00
|
|
|
const uint32_t kNewBitrateKbps = 456;
|
2017-08-30 06:29:51 -07:00
|
|
|
const int kNewFramerateFps = 34;
|
2019-04-12 13:59:09 +02:00
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
|
|
|
|
SetRates(AllOf(ResultOf(
|
|
|
|
|
[](const VideoEncoder::RateControlParameters& params) {
|
|
|
|
|
return params.bitrate.get_sum_kbps();
|
|
|
|
|
},
|
|
|
|
|
kNewBitrateKbps),
|
|
|
|
|
Field(&VideoEncoder::RateControlParameters::framerate_fps,
|
|
|
|
|
static_cast<double>(kNewFramerateFps)))))
|
2017-08-30 06:29:51 -07:00
|
|
|
.Times(1);
|
2018-05-16 09:38:42 +02:00
|
|
|
q_.SendTask(
|
2022-08-11 12:26:09 +02:00
|
|
|
[=] { video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
ExpectRelease();
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|