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-08-07 03:36:54 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/i420_buffer.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2018-04-13 14:25:22 +02:00
|
|
|
#include "media/base/mediaconstants.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/codecs/test/videoprocessor.h"
|
|
|
|
|
#include "modules/video_coding/include/mock/mock_video_codec_interface.h"
|
|
|
|
|
#include "modules/video_coding/include/video_coding.h"
|
2018-02-07 13:56:16 +01:00
|
|
|
#include "rtc_base/event.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/ptr_util.h"
|
2018-02-07 13:56:16 +01:00
|
|
|
#include "rtc_base/task_queue.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"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
using ::testing::_;
|
2017-08-30 06:29:51 -07:00
|
|
|
using ::testing::Property;
|
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;
|
|
|
|
|
const int kFrameSize = kWidth * kHeight * 3 / 2; // I420.
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2018-02-07 13:56:16 +01:00
|
|
|
#define DO_SYNC(q, block) \
|
|
|
|
|
{ \
|
|
|
|
|
rtc::Event event(false, false); \
|
|
|
|
|
q.PostTask([&, this] { \
|
|
|
|
|
block; \
|
|
|
|
|
event.Set(); \
|
|
|
|
|
}); \
|
|
|
|
|
RTC_CHECK(event.Wait(rtc::Event::kForever)); \
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-21 03:04:49 -08: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,
|
|
|
|
|
false, 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();
|
2017-08-07 03:36:54 -07:00
|
|
|
EXPECT_CALL(frame_reader_mock_, FrameLength())
|
|
|
|
|
.WillRepeatedly(Return(kFrameSize));
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, {
|
|
|
|
|
video_processor_ = rtc::MakeUnique<VideoProcessor>(
|
|
|
|
|
&encoder_mock_, &decoders_, &frame_reader_mock_, config_, &stats_,
|
|
|
|
|
nullptr /* encoded_frame_writer */,
|
|
|
|
|
nullptr /* decoded_frame_writer */);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~VideoProcessorTest() {
|
|
|
|
|
DO_SYNC(q_, { video_processor_.reset(); });
|
2012-02-08 07:09:32 +00:00
|
|
|
}
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
void ExpectInit() {
|
2015-12-21 03:04:49 -08:00
|
|
|
EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1);
|
2017-08-30 06:29:51 -07:00
|
|
|
EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1);
|
2018-02-01 13:25:17 +01:00
|
|
|
EXPECT_CALL(*decoder_mock_, InitDecode(_, _)).Times(1);
|
|
|
|
|
EXPECT_CALL(*decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
|
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
|
|
|
|
2018-02-07 13:56:16 +01:00
|
|
|
rtc::TaskQueue q_;
|
|
|
|
|
|
2017-08-08 08:35:53 -07:00
|
|
|
TestConfig config_;
|
|
|
|
|
|
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-02-20 09:48:26 +01:00
|
|
|
Stats stats_;
|
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;
|
2017-10-24 16:03:39 +02:00
|
|
|
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kFramerateFps))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(0));
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
2016-09-30 04:14:07 -07:00
|
|
|
EXPECT_CALL(frame_reader_mock_, ReadFrame())
|
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_,
|
|
|
|
|
Encode(Property(&VideoFrame::timestamp, 1 * 90000 / kFramerateFps), _, _))
|
|
|
|
|
.Times(1);
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
EXPECT_CALL(
|
|
|
|
|
encoder_mock_,
|
|
|
|
|
Encode(Property(&VideoFrame::timestamp, 2 * 90000 / kFramerateFps), _, _))
|
|
|
|
|
.Times(1);
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { 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;
|
2017-10-24 16:03:39 +02:00
|
|
|
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kStartFramerateFps))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(0));
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_,
|
|
|
|
|
{ video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
EXPECT_CALL(frame_reader_mock_, ReadFrame())
|
|
|
|
|
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
|
2018-01-24 17:20:18 +01:00
|
|
|
EXPECT_CALL(encoder_mock_,
|
|
|
|
|
Encode(Property(&VideoFrame::timestamp, kStartTimestamp), _, _))
|
2017-08-07 03:36:54 -07:00
|
|
|
.Times(1);
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
2017-08-07 03:36:54 -07:00
|
|
|
|
2017-08-30 06:29:51 -07:00
|
|
|
const int kNewFramerateFps = 13;
|
2017-10-24 16:03:39 +02:00
|
|
|
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kNewFramerateFps))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(0));
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { 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),
|
|
|
|
|
_, _))
|
2017-08-07 03:36:54 -07:00
|
|
|
.Times(1);
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
ExpectRelease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoProcessorTest, SetRates) {
|
|
|
|
|
const int kBitrateKbps = 123;
|
|
|
|
|
const int kFramerateFps = 17;
|
|
|
|
|
EXPECT_CALL(encoder_mock_,
|
|
|
|
|
SetRateAllocation(
|
2018-04-23 12:32:22 +02:00
|
|
|
Property(&VideoBitrateAllocation::get_sum_kbps, kBitrateKbps),
|
2017-08-30 06:29:51 -07:00
|
|
|
kFramerateFps))
|
|
|
|
|
.Times(1);
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
2017-08-30 06:29:51 -07:00
|
|
|
|
|
|
|
|
const int kNewBitrateKbps = 456;
|
|
|
|
|
const int kNewFramerateFps = 34;
|
|
|
|
|
EXPECT_CALL(encoder_mock_,
|
2018-04-23 12:32:22 +02:00
|
|
|
SetRateAllocation(Property(&VideoBitrateAllocation::get_sum_kbps,
|
|
|
|
|
kNewBitrateKbps),
|
|
|
|
|
kNewFramerateFps))
|
2017-08-30 06:29:51 -07:00
|
|
|
.Times(1);
|
2018-02-07 13:56:16 +01:00
|
|
|
DO_SYNC(q_,
|
|
|
|
|
{ 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
|