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