Skip to content

Commit

Permalink
Add video codec tester.
Browse files Browse the repository at this point in the history
This tester is an improved version of VideoProcessor and VideoCodecTestFixture and will eventually replace them.

The tester provides better separation between codecs and testing logic. Its knowledge about codecs is limited to frame encode/decode calls and frame ready callbacks. Instantiation and configuration of codecs are the test responsibilities.

Other differences:
- Run encoding and decoding in separate threads
- Run quality analysis in a separate thread
- Reference frame buffering is moved into video source (which re-read frames from the file).
- Make it possible to run decode-only tests

This CL is MVP implementation: it adds only 1 test (video_codec_test.cc, ConstantRate/EncodeDecodeTest) and the test is disabled for now.

Bug: b/261160916
Change-Id: Ida24a2fca1b1496237fa695c812084877c76379f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/283525
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38901}
  • Loading branch information
Sergey Silkin authored and WebRTC LUCI CQ committed Dec 15, 2022
1 parent aa5897d commit 2e1a9a4
Show file tree
Hide file tree
Showing 16 changed files with 1,836 additions and 16 deletions.
47 changes: 44 additions & 3 deletions api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -985,22 +985,50 @@ if (rtc_include_tests) {
]
}

rtc_library("videocodec_test_fixture_api") {
rtc_library("videocodec_test_stats_api") {
visibility = [ "*" ]
testonly = true
sources = [
"test/videocodec_test_fixture.h",
"test/videocodec_test_stats.cc",
"test/videocodec_test_stats.h",
]
deps = [
"../modules/video_coding:video_codec_interface",
"../api/units:data_rate",
"../api/units:frequency",
"../rtc_base:stringutils",
"video:video_frame_type",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}

rtc_library("videocodec_test_fixture_api") {
visibility = [ "*" ]
testonly = true
sources = [ "test/videocodec_test_fixture.h" ]
deps = [
":videocodec_test_stats_api",
"../modules/video_coding:video_codec_interface",
"video_codecs:video_codecs_api",
]
}

rtc_library("video_codec_tester_api") {
visibility = [ "*" ]
testonly = true
sources = [ "test/video_codec_tester.h" ]
deps = [
":videocodec_test_stats_api",
"../modules/video_coding/svc:scalability_mode_util",
"video:encoded_image",
"video:resolution",
"video:video_frame",
]
absl_deps = [
"//third_party/abseil-cpp/absl/functional:any_invocable",
"//third_party/abseil-cpp/absl/types:optional",
]
}

rtc_library("create_videocodec_test_fixture_api") {
visibility = [ "*" ]
testonly = true
Expand All @@ -1016,6 +1044,19 @@ if (rtc_include_tests) {
]
}

rtc_library("create_video_codec_tester_api") {
visibility = [ "*" ]
testonly = true
sources = [
"test/create_video_codec_tester.cc",
"test/create_video_codec_tester.h",
]
deps = [
":video_codec_tester_api",
"../modules/video_coding:videocodec_test_impl",
]
}

rtc_source_set("mock_audio_mixer") {
visibility = [ "*" ]
testonly = true
Expand Down
27 changes: 27 additions & 0 deletions api/test/create_video_codec_tester.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/

#include "api/test/create_video_codec_tester.h"

#include <memory>
#include <utility>

#include "api/test/video_codec_tester.h"
#include "modules/video_coding/codecs/test/video_codec_tester_impl.h"

namespace webrtc {
namespace test {

std::unique_ptr<VideoCodecTester> CreateVideoCodecTester() {
return std::make_unique<VideoCodecTesterImpl>();
}

} // namespace test
} // namespace webrtc
26 changes: 26 additions & 0 deletions api/test/create_video_codec_tester.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/

#ifndef API_TEST_CREATE_VIDEO_CODEC_TESTER_H_
#define API_TEST_CREATE_VIDEO_CODEC_TESTER_H_

#include <memory>

#include "api/test/video_codec_tester.h"

namespace webrtc {
namespace test {

std::unique_ptr<VideoCodecTester> CreateVideoCodecTester();

} // namespace test
} // namespace webrtc

#endif // API_TEST_CREATE_VIDEO_CODEC_TESTER_H_
134 changes: 134 additions & 0 deletions api/test/video_codec_tester.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/

#ifndef API_TEST_VIDEO_CODEC_TESTER_H_
#define API_TEST_VIDEO_CODEC_TESTER_H_

#include <memory>

#include "absl/functional/any_invocable.h"
#include "api/test/videocodec_test_stats.h"
#include "api/video/encoded_image.h"
#include "api/video/resolution.h"
#include "api/video/video_frame.h"

namespace webrtc {
namespace test {

// Interface for a video codec tester. The interface provides minimalistic set
// of data structures that enables implementation of decode-only, encode-only
// and encode-decode tests.
class VideoCodecTester {
public:
// Pacing settings for codec input.
struct PacingSettings {
enum PacingMode {
// Pacing is not used. Frames are sent to codec back-to-back.
kNoPacing,
// Pace with the rate equal to the target video frame rate. Pacing time is
// derived from RTP timestamp.
kRealTime,
// Pace with the explicitly provided rate.
kConstantRate,
};
PacingMode mode = PacingMode::kNoPacing;
// Pacing rate for `kConstantRate` mode.
Frequency constant_rate = Frequency::Zero();
};

struct DecoderSettings {
PacingSettings pacing;
};

struct EncoderSettings {
PacingSettings pacing;
};

virtual ~VideoCodecTester() = default;

// Interface for a raw video frames source.
class RawVideoSource {
public:
virtual ~RawVideoSource() = default;

// Returns next frame. If no more frames to pull, returns `absl::nullopt`.
// For analysis and pacing purposes, frame must have RTP timestamp set. The
// timestamp must represent the target video frame rate and be unique.
virtual absl::optional<VideoFrame> PullFrame() = 0;

// Returns early pulled frame with RTP timestamp equal to `timestamp_rtp`.
virtual VideoFrame GetFrame(uint32_t timestamp_rtp,
Resolution resolution) = 0;
};

// Interface for a coded video frames source.
class CodedVideoSource {
public:
virtual ~CodedVideoSource() = default;

// Returns next frame. If no more frames to pull, returns `absl::nullopt`.
// For analysis and pacing purposes, frame must have RTP timestamp set. The
// timestamp must represent the target video frame rate and be unique.
virtual absl::optional<EncodedImage> PullFrame() = 0;
};

// Interface for a video encoder.
class Encoder {
public:
using EncodeCallback =
absl::AnyInvocable<void(const EncodedImage& encoded_frame)>;

virtual ~Encoder() = default;

virtual void Encode(const VideoFrame& frame, EncodeCallback callback) = 0;
};

// Interface for a video decoder.
class Decoder {
public:
using DecodeCallback =
absl::AnyInvocable<void(const VideoFrame& decoded_frame)>;

virtual ~Decoder() = default;

virtual void Decode(const EncodedImage& frame, DecodeCallback callback) = 0;
};

// Pulls coded video frames from `video_source` and passes them to `decoder`.
// Returns `VideoCodecTestStats` object that contains collected per-frame
// metrics.
virtual std::unique_ptr<VideoCodecTestStats> RunDecodeTest(
std::unique_ptr<CodedVideoSource> video_source,
std::unique_ptr<Decoder> decoder,
const DecoderSettings& decoder_settings) = 0;

// Pulls raw video frames from `video_source` and passes them to `encoder`.
// Returns `VideoCodecTestStats` object that contains collected per-frame
// metrics.
virtual std::unique_ptr<VideoCodecTestStats> RunEncodeTest(
std::unique_ptr<RawVideoSource> video_source,
std::unique_ptr<Encoder> encoder,
const EncoderSettings& encoder_settings) = 0;

// Pulls raw video frames from `video_source`, passes them to `encoder` and
// then passes encoded frames to `decoder`. Returns `VideoCodecTestStats`
// object that contains collected per-frame metrics.
virtual std::unique_ptr<VideoCodecTestStats> RunEncodeDecodeTest(
std::unique_ptr<RawVideoSource> video_source,
std::unique_ptr<Encoder> encoder,
std::unique_ptr<Decoder> decoder,
const EncoderSettings& encoder_settings,
const DecoderSettings& decoder_settings) = 0;
};

} // namespace test
} // namespace webrtc

#endif // API_TEST_VIDEO_CODEC_TESTER_H_
10 changes: 9 additions & 1 deletion api/test/videocodec_test_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <string>
#include <vector>

#include "absl/types/optional.h"
#include "api/units/data_rate.h"
#include "api/units/frequency.h"
#include "api/video/video_frame_type.h"

namespace webrtc {
Expand Down Expand Up @@ -135,11 +138,16 @@ class VideoCodecTestStats {

virtual ~VideoCodecTestStats() = default;

virtual std::vector<FrameStatistics> GetFrameStatistics() = 0;
virtual std::vector<FrameStatistics> GetFrameStatistics() const = 0;

virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
size_t first_frame_num,
size_t last_frame_num) = 0;

virtual VideoStatistics CalcVideoStatistic(size_t first_frame,
size_t last_frame,
DataRate target_bitrate,
Frequency target_framerate) = 0;
};

} // namespace test
Expand Down
Loading

0 comments on commit 2e1a9a4

Please sign in to comment.