* 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 <string>
#include "absl/functional/any_invocable.h"
#include "absl/types/optional.h"
#include "api/test/video_codec_stats.h"
#include "api/video/encoded_image.h"
#include "api/video/resolution.h"
#include "api/video/video_frame.h"
namespace webrtc {
namespace test {
class VideoCodecTester {
public:
struct PacingSettings {
enum PacingMode {
kNoPacing,
kRealTime,
kConstantRate,
};
PacingMode mode = PacingMode::kNoPacing;
Frequency constant_rate = Frequency::Zero();
};
struct DecoderSettings {
PacingSettings pacing;
absl::optional<std::string> decoder_input_base_path;
absl::optional<std::string> decoder_output_base_path;
};
struct EncoderSettings {
PacingSettings pacing;
absl::optional<std::string> encoder_input_base_path;
absl::optional<std::string> encoder_output_base_path;
};
virtual ~VideoCodecTester() = default;
class RawVideoSource {
public:
virtual ~RawVideoSource() = default;
virtual absl::optional<VideoFrame> PullFrame() = 0;
virtual VideoFrame GetFrame(uint32_t timestamp_rtp,
Resolution resolution) = 0;
};
class CodedVideoSource {
public:
virtual ~CodedVideoSource() = default;
virtual absl::optional<EncodedImage> PullFrame() = 0;
};
class Encoder {
public:
using EncodeCallback =
absl::AnyInvocable<void(const EncodedImage& encoded_frame)>;
virtual ~Encoder() = default;
virtual void Initialize() = 0;
virtual void Encode(const VideoFrame& frame, EncodeCallback callback) = 0;
virtual void Flush() = 0;
};
class Decoder {
public:
using DecodeCallback =
absl::AnyInvocable<void(const VideoFrame& decoded_frame)>;
virtual ~Decoder() = default;
virtual void Initialize() = 0;
virtual void Decode(const EncodedImage& frame, DecodeCallback callback) = 0;
virtual void Flush() = 0;
};
virtual std::unique_ptr<VideoCodecStats> RunDecodeTest(
CodedVideoSource* video_source,
Decoder* decoder,
const DecoderSettings& decoder_settings) = 0;
virtual std::unique_ptr<VideoCodecStats> RunEncodeTest(
RawVideoSource* video_source,
Encoder* encoder,
const EncoderSettings& encoder_settings) = 0;
virtual std::unique_ptr<VideoCodecStats> RunEncodeDecodeTest(
RawVideoSource* video_source,
Encoder* encoder,
Decoder* decoder,
const EncoderSettings& encoder_settings,
const DecoderSettings& decoder_settings) = 0;
};
}
}
#endif