Add test::FakeEncodedFrame for testing

Change-Id: I1c8fabe5caf2c723487ec1cd71a379e922026a9d
Bug: webrtc:13996
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260001
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36654}
This commit is contained in:
Evan Shrubsole
2022-04-26 10:09:04 +02:00
committed by WebRTC LUCI CQ
parent 65dcc47b8b
commit a0ee64c57e
9 changed files with 602 additions and 414 deletions

View File

@ -14,6 +14,7 @@
#include "api/video/i420_buffer.h"
#include "api/video_codecs/video_decoder.h"
#include "test/fake_encoded_frame.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
@ -22,7 +23,6 @@
namespace webrtc {
namespace {
using ::testing::_;
using ::testing::ByMove;
using ::testing::NiceMock;
using ::testing::Return;
@ -127,35 +127,6 @@ class FakeVideoDecoderFactory : public VideoDecoderFactory {
NiceMock<StubVideoDecoder> av1_decoder_;
};
class FakeEncodedFrame : public EncodedFrame {
public:
int64_t ReceivedTime() const override { return 0; }
int64_t RenderTime() const override { return 0; }
// Setters for protected variables.
void SetPayloadType(int payload_type) { _payloadType = payload_type; }
};
class FrameBuilder {
public:
FrameBuilder() : frame_(std::make_unique<FakeEncodedFrame>()) {}
FrameBuilder& WithPayloadType(int payload_type) {
frame_->SetPayloadType(payload_type);
return *this;
}
FrameBuilder& WithPictureId(int picture_id) {
frame_->SetId(picture_id);
return *this;
}
std::unique_ptr<FakeEncodedFrame> Build() { return std::move(frame_); }
private:
std::unique_ptr<FakeEncodedFrame> frame_;
};
class VideoStreamDecoderImplTest : public ::testing::Test {
public:
VideoStreamDecoderImplTest()
@ -179,7 +150,8 @@ class VideoStreamDecoderImplTest : public ::testing::Test {
};
TEST_F(VideoStreamDecoderImplTest, InsertAndDecodeFrame) {
video_stream_decoder_.OnFrame(FrameBuilder().WithPayloadType(1).Build());
video_stream_decoder_.OnFrame(
test::FakeFrameBuilder().PayloadType(1).AsLast().Build());
EXPECT_CALL(callbacks_, OnDecodedFrame);
time_controller_.AdvanceTime(TimeDelta::Millis(1));
}
@ -190,7 +162,8 @@ TEST_F(VideoStreamDecoderImplTest, NonDecodableStateWaitingForKeyframe) {
}
TEST_F(VideoStreamDecoderImplTest, NonDecodableStateWaitingForDeltaFrame) {
video_stream_decoder_.OnFrame(FrameBuilder().WithPayloadType(1).Build());
video_stream_decoder_.OnFrame(
test::FakeFrameBuilder().PayloadType(1).AsLast().Build());
EXPECT_CALL(callbacks_, OnDecodedFrame);
time_controller_.AdvanceTime(TimeDelta::Millis(1));
EXPECT_CALL(callbacks_, OnNonDecodableState);
@ -198,7 +171,8 @@ TEST_F(VideoStreamDecoderImplTest, NonDecodableStateWaitingForDeltaFrame) {
}
TEST_F(VideoStreamDecoderImplTest, InsertAndDecodeFrameWithKeyframeRequest) {
video_stream_decoder_.OnFrame(FrameBuilder().WithPayloadType(1).Build());
video_stream_decoder_.OnFrame(
test::FakeFrameBuilder().PayloadType(1).AsLast().Build());
EXPECT_CALL(decoder_factory_.Vp8Decoder(), DecodeCall)
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME));
EXPECT_CALL(callbacks_, OnDecodedFrame);
@ -207,7 +181,12 @@ TEST_F(VideoStreamDecoderImplTest, InsertAndDecodeFrameWithKeyframeRequest) {
}
TEST_F(VideoStreamDecoderImplTest, FailToInitDecoder) {
video_stream_decoder_.OnFrame(FrameBuilder().WithPayloadType(1).Build());
video_stream_decoder_.OnFrame(
test::FakeFrameBuilder()
.ReceivedTime(time_controller_.GetClock()->CurrentTime())
.PayloadType(1)
.AsLast()
.Build());
ON_CALL(decoder_factory_.Vp8Decoder(), Configure)
.WillByDefault(Return(false));
EXPECT_CALL(callbacks_, OnNonDecodableState);
@ -215,7 +194,8 @@ TEST_F(VideoStreamDecoderImplTest, FailToInitDecoder) {
}
TEST_F(VideoStreamDecoderImplTest, FailToDecodeFrame) {
video_stream_decoder_.OnFrame(FrameBuilder().WithPayloadType(1).Build());
video_stream_decoder_.OnFrame(
test::FakeFrameBuilder().PayloadType(1).AsLast().Build());
ON_CALL(decoder_factory_.Vp8Decoder(), DecodeCall)
.WillByDefault(Return(WEBRTC_VIDEO_CODEC_ERROR));
EXPECT_CALL(callbacks_, OnNonDecodableState);
@ -225,13 +205,13 @@ TEST_F(VideoStreamDecoderImplTest, FailToDecodeFrame) {
TEST_F(VideoStreamDecoderImplTest, ChangeFramePayloadType) {
constexpr TimeDelta kFrameInterval = TimeDelta::Millis(1000 / 60);
video_stream_decoder_.OnFrame(
FrameBuilder().WithPayloadType(1).WithPictureId(0).Build());
test::FakeFrameBuilder().PayloadType(1).Id(0).AsLast().Build());
EXPECT_CALL(decoder_factory_.Vp8Decoder(), DecodeCall);
EXPECT_CALL(callbacks_, OnDecodedFrame);
time_controller_.AdvanceTime(kFrameInterval);
video_stream_decoder_.OnFrame(
FrameBuilder().WithPayloadType(2).WithPictureId(1).Build());
test::FakeFrameBuilder().PayloadType(2).Id(1).AsLast().Build());
EXPECT_CALL(decoder_factory_.Av1Decoder(), DecodeCall);
EXPECT_CALL(callbacks_, OnDecodedFrame);
time_controller_.AdvanceTime(kFrameInterval);