webrtc/api/test/video_codec_stats.h
Sergey Silkin 26d1b26277 Log metrics even if test failed
Set of codecs for testing is hardcoded to AV1, VP8, VP9, H264, H265. Some codecs may not be available due to lack of support on the platform or due to some issue in our code which would be a regression. Reporting zero metrics for failed tests would allow the perf tool to detect such a regression.

This also enables codec tests by default. The tests should not run on bots since video_codec_perf_tests binary is not included in any test suits yet.

Bug: webrtc:14852
Change-Id: I967160069055036f93e595d328c4d5f1ca483be9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300868
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39840}
2023-04-13 08:49:37 +00:00

120 lines
3.3 KiB
C++

/*
* Copyright (c) 2023 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_STATS_H_
#define API_TEST_VIDEO_CODEC_STATS_H_
#include <map>
#include <string>
#include <vector>
#include "absl/types/optional.h"
#include "api/numerics/samples_stats_counter.h"
#include "api/test/metrics/metric.h"
#include "api/test/metrics/metrics_logger.h"
#include "api/units/data_rate.h"
#include "api/units/data_size.h"
#include "api/units/frequency.h"
namespace webrtc {
namespace test {
// Interface for encoded and/or decoded video frame and stream statistics.
class VideoCodecStats {
public:
// Filter for slicing frames.
struct Filter {
absl::optional<int> first_frame;
absl::optional<int> last_frame;
absl::optional<int> spatial_idx;
absl::optional<int> temporal_idx;
};
struct Frame {
int frame_num = 0;
uint32_t timestamp_rtp = 0;
int spatial_idx = 0;
int temporal_idx = 0;
int width = 0;
int height = 0;
DataSize frame_size = DataSize::Zero();
bool keyframe = false;
absl::optional<int> qp;
absl::optional<int> base_spatial_idx;
Timestamp encode_start = Timestamp::Zero();
TimeDelta encode_time = TimeDelta::Zero();
Timestamp decode_start = Timestamp::Zero();
TimeDelta decode_time = TimeDelta::Zero();
struct Psnr {
double y = 0.0;
double u = 0.0;
double v = 0.0;
};
absl::optional<Psnr> psnr;
absl::optional<DataRate> target_bitrate;
absl::optional<Frequency> target_framerate;
bool encoded = false;
bool decoded = false;
};
struct Stream {
SamplesStatsCounter width;
SamplesStatsCounter height;
SamplesStatsCounter frame_size_bytes;
SamplesStatsCounter keyframe;
SamplesStatsCounter qp;
SamplesStatsCounter encode_time_ms;
SamplesStatsCounter decode_time_ms;
SamplesStatsCounter target_bitrate_kbps;
SamplesStatsCounter target_framerate_fps;
SamplesStatsCounter encoded_bitrate_kbps;
SamplesStatsCounter encoded_framerate_fps;
SamplesStatsCounter bitrate_mismatch_pct;
SamplesStatsCounter framerate_mismatch_pct;
SamplesStatsCounter transmission_time_ms;
struct Psnr {
SamplesStatsCounter y;
SamplesStatsCounter u;
SamplesStatsCounter v;
} psnr;
// Logs `Stream` metrics to provided `MetricsLogger`.
void LogMetrics(MetricsLogger* logger,
std::string test_case_name,
std::map<std::string, std::string> metadata = {}) const;
};
virtual ~VideoCodecStats() = default;
// Returns frames from interval, spatial and temporal layer specified by given
// `filter`.
virtual std::vector<Frame> Slice(
absl::optional<Filter> filter = absl::nullopt) const = 0;
// Returns video statistics aggregated for given `frames`.
virtual Stream Aggregate(const std::vector<Frame>& frames) const = 0;
};
} // namespace test
} // namespace webrtc
#endif // API_TEST_VIDEO_CODEC_STATS_H_