webrtc/modules/video_coding/codecs/test/video_codec_analyzer.h
Sergey Silkin 5dd493b3da Do not use PostDelayedTask in video codec tester's pacer
PostDelayedTask doesn't guarantee task execution order. For example,
if you post two tasks, A and B, back-to-back using the same delay
there is no guarantee that A will be executed before B.

Re-implemented pacing using sleep(). Changed pacer to compute task
scheduled time instead of delay. Sleep time is calculated right before
task start. This provides better accuracy by accounting for any delays
that may happen after pacing time is computed and before task queue is
ready to run the task.

It is tricky to implement pacer tests using simulated clocks. The test
use system time which make them flacky on low performance bots. Keep
the test disabled by default.

Bug: b/261160916, webrtc:14852
Change-Id: I88e1a2001e6d33cf3bb7fe16730ec28abf90acc8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291804
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39302}
2023-02-13 15:07:16 +00:00

76 lines
2.3 KiB
C++

/*
* 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 MODULES_VIDEO_CODING_CODECS_TEST_VIDEO_CODEC_ANALYZER_H_
#define MODULES_VIDEO_CODING_CODECS_TEST_VIDEO_CODEC_ANALYZER_H_
#include <map>
#include <memory>
#include "absl/types/optional.h"
#include "api/sequence_checker.h"
#include "api/test/video_codec_tester.h"
#include "api/video/encoded_image.h"
#include "api/video/resolution.h"
#include "api/video/video_frame.h"
#include "modules/video_coding/codecs/test/video_codec_stats_impl.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/no_unique_address.h"
#include "rtc_base/task_queue_for_test.h"
namespace webrtc {
namespace test {
// Analyzer measures and collects metrics necessary for evaluation of video
// codec quality and performance. This class is thread-safe.
class VideoCodecAnalyzer {
public:
// An interface that provides reference frames for spatial quality analysis.
class ReferenceVideoSource {
public:
virtual ~ReferenceVideoSource() = default;
virtual VideoFrame GetFrame(uint32_t timestamp_rtp,
Resolution resolution) = 0;
};
explicit VideoCodecAnalyzer(
ReferenceVideoSource* reference_video_source = nullptr);
void StartEncode(const VideoFrame& frame);
void FinishEncode(const EncodedImage& frame);
void StartDecode(const EncodedImage& frame);
void FinishDecode(const VideoFrame& frame, int spatial_idx);
std::unique_ptr<VideoCodecStats> GetStats();
protected:
TaskQueueForTest task_queue_;
ReferenceVideoSource* const reference_video_source_;
VideoCodecStatsImpl stats_ RTC_GUARDED_BY(sequence_checker_);
// Map from RTP timestamp to frame number.
std::map<uint32_t, int> frame_num_ RTC_GUARDED_BY(sequence_checker_);
// Processed frames counter.
int num_frames_ RTC_GUARDED_BY(sequence_checker_);
RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
};
} // namespace test
} // namespace webrtc
#endif // MODULES_VIDEO_CODING_CODECS_TEST_VIDEO_CODEC_ANALYZER_H_