Sergey Silkin | 2e1a9a4 | 2022-12-15 10:15:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_TEST_VIDEO_CODEC_TESTER_H_ |
| 12 | #define API_TEST_VIDEO_CODEC_TESTER_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | #include "absl/functional/any_invocable.h" |
Sergey Silkin | 6c60f72 | 2023-02-02 11:49:13 +0100 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
| 18 | #include "api/test/video_codec_stats.h" |
Sergey Silkin | 2e1a9a4 | 2022-12-15 10:15:18 +0100 | [diff] [blame] | 19 | #include "api/video/encoded_image.h" |
| 20 | #include "api/video/resolution.h" |
| 21 | #include "api/video/video_frame.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | namespace test { |
| 25 | |
| 26 | // Interface for a video codec tester. The interface provides minimalistic set |
| 27 | // of data structures that enables implementation of decode-only, encode-only |
| 28 | // and encode-decode tests. |
| 29 | class VideoCodecTester { |
| 30 | public: |
| 31 | // Pacing settings for codec input. |
| 32 | struct PacingSettings { |
| 33 | enum PacingMode { |
| 34 | // Pacing is not used. Frames are sent to codec back-to-back. |
| 35 | kNoPacing, |
| 36 | // Pace with the rate equal to the target video frame rate. Pacing time is |
| 37 | // derived from RTP timestamp. |
| 38 | kRealTime, |
| 39 | // Pace with the explicitly provided rate. |
| 40 | kConstantRate, |
| 41 | }; |
| 42 | PacingMode mode = PacingMode::kNoPacing; |
| 43 | // Pacing rate for `kConstantRate` mode. |
| 44 | Frequency constant_rate = Frequency::Zero(); |
| 45 | }; |
| 46 | |
| 47 | struct DecoderSettings { |
| 48 | PacingSettings pacing; |
| 49 | }; |
| 50 | |
| 51 | struct EncoderSettings { |
| 52 | PacingSettings pacing; |
| 53 | }; |
| 54 | |
| 55 | virtual ~VideoCodecTester() = default; |
| 56 | |
| 57 | // Interface for a raw video frames source. |
| 58 | class RawVideoSource { |
| 59 | public: |
| 60 | virtual ~RawVideoSource() = default; |
| 61 | |
| 62 | // Returns next frame. If no more frames to pull, returns `absl::nullopt`. |
| 63 | // For analysis and pacing purposes, frame must have RTP timestamp set. The |
| 64 | // timestamp must represent the target video frame rate and be unique. |
| 65 | virtual absl::optional<VideoFrame> PullFrame() = 0; |
| 66 | |
| 67 | // Returns early pulled frame with RTP timestamp equal to `timestamp_rtp`. |
| 68 | virtual VideoFrame GetFrame(uint32_t timestamp_rtp, |
| 69 | Resolution resolution) = 0; |
| 70 | }; |
| 71 | |
| 72 | // Interface for a coded video frames source. |
| 73 | class CodedVideoSource { |
| 74 | public: |
| 75 | virtual ~CodedVideoSource() = default; |
| 76 | |
| 77 | // Returns next frame. If no more frames to pull, returns `absl::nullopt`. |
| 78 | // For analysis and pacing purposes, frame must have RTP timestamp set. The |
| 79 | // timestamp must represent the target video frame rate and be unique. |
| 80 | virtual absl::optional<EncodedImage> PullFrame() = 0; |
| 81 | }; |
| 82 | |
| 83 | // Interface for a video encoder. |
| 84 | class Encoder { |
| 85 | public: |
| 86 | using EncodeCallback = |
| 87 | absl::AnyInvocable<void(const EncodedImage& encoded_frame)>; |
| 88 | |
| 89 | virtual ~Encoder() = default; |
| 90 | |
| 91 | virtual void Encode(const VideoFrame& frame, EncodeCallback callback) = 0; |
| 92 | }; |
| 93 | |
| 94 | // Interface for a video decoder. |
| 95 | class Decoder { |
| 96 | public: |
| 97 | using DecodeCallback = |
| 98 | absl::AnyInvocable<void(const VideoFrame& decoded_frame)>; |
| 99 | |
| 100 | virtual ~Decoder() = default; |
| 101 | |
| 102 | virtual void Decode(const EncodedImage& frame, DecodeCallback callback) = 0; |
| 103 | }; |
| 104 | |
| 105 | // Pulls coded video frames from `video_source` and passes them to `decoder`. |
| 106 | // Returns `VideoCodecTestStats` object that contains collected per-frame |
| 107 | // metrics. |
Sergey Silkin | 6c60f72 | 2023-02-02 11:49:13 +0100 | [diff] [blame] | 108 | virtual std::unique_ptr<VideoCodecStats> RunDecodeTest( |
Sergey Silkin | c6ff4bc | 2023-02-03 13:32:24 +0100 | [diff] [blame] | 109 | CodedVideoSource* video_source, |
| 110 | Decoder* decoder, |
Sergey Silkin | 2e1a9a4 | 2022-12-15 10:15:18 +0100 | [diff] [blame] | 111 | const DecoderSettings& decoder_settings) = 0; |
| 112 | |
| 113 | // Pulls raw video frames from `video_source` and passes them to `encoder`. |
| 114 | // Returns `VideoCodecTestStats` object that contains collected per-frame |
| 115 | // metrics. |
Sergey Silkin | 6c60f72 | 2023-02-02 11:49:13 +0100 | [diff] [blame] | 116 | virtual std::unique_ptr<VideoCodecStats> RunEncodeTest( |
Sergey Silkin | c6ff4bc | 2023-02-03 13:32:24 +0100 | [diff] [blame] | 117 | RawVideoSource* video_source, |
| 118 | Encoder* encoder, |
Sergey Silkin | 2e1a9a4 | 2022-12-15 10:15:18 +0100 | [diff] [blame] | 119 | const EncoderSettings& encoder_settings) = 0; |
| 120 | |
| 121 | // Pulls raw video frames from `video_source`, passes them to `encoder` and |
| 122 | // then passes encoded frames to `decoder`. Returns `VideoCodecTestStats` |
| 123 | // object that contains collected per-frame metrics. |
Sergey Silkin | 6c60f72 | 2023-02-02 11:49:13 +0100 | [diff] [blame] | 124 | virtual std::unique_ptr<VideoCodecStats> RunEncodeDecodeTest( |
Sergey Silkin | c6ff4bc | 2023-02-03 13:32:24 +0100 | [diff] [blame] | 125 | RawVideoSource* video_source, |
| 126 | Encoder* encoder, |
| 127 | Decoder* decoder, |
Sergey Silkin | 2e1a9a4 | 2022-12-15 10:15:18 +0100 | [diff] [blame] | 128 | const EncoderSettings& encoder_settings, |
| 129 | const DecoderSettings& decoder_settings) = 0; |
| 130 | }; |
| 131 | |
| 132 | } // namespace test |
| 133 | } // namespace webrtc |
| 134 | |
| 135 | #endif // API_TEST_VIDEO_CODEC_TESTER_H_ |