blob: 49f4dd1ff3ac58ddeea3cfa00158eba12940e83f [file] [log] [blame]
Artem Titovb6c62012019-01-08 14:58:23 +01001/*
2 * Copyright (c) 2018 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
Artem Titovd57628f2019-03-22 12:34:25 +010011#ifndef API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_
12#define API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_
Artem Titovb6c62012019-01-08 14:58:23 +010013
14#include <memory>
15#include <string>
16
Artem Titov8a0284e2020-05-29 15:49:44 +020017#include "absl/strings/string_view.h"
Artem Titovb6c62012019-01-08 14:58:23 +010018#include "absl/types/optional.h"
Artem Titov3b641672020-06-02 17:18:17 +020019#include "api/array_view.h"
Artem Titovd57628f2019-03-22 12:34:25 +010020#include "api/test/stats_observer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010021#include "api/video/encoded_image.h"
22#include "api/video/video_frame.h"
23#include "api/video_codecs/video_encoder.h"
24
25namespace webrtc {
26
Artem Titovd57628f2019-03-22 12:34:25 +010027// API is in development and can be changed without notice.
28
Artem Titovebd97702019-01-09 17:55:36 +010029// Base interface for video quality analyzer for peer connection level end-2-end
30// tests. Interface has only one abstract method, which have to return frame id.
31// Other methods have empty implementation by default, so user can override only
32// required parts.
33//
34// VideoQualityAnalyzerInterface will be injected into WebRTC pipeline on both
35// sides of the call. Here is video data flow in WebRTC pipeline
36//
37// Alice:
38// ___________ ________ _________
39// | | | | | |
40// | Frame |-(A)→| WebRTC |-(B)→| Video |-(C)┐
41// | Generator | | Stack | | Decoder | |
42// ¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯ |
43// __↓________
44// | Transport |
45// | & |
46// | Network |
47// ¯¯|¯¯¯¯¯¯¯¯
48// Bob: |
49// _______ ________ _________ |
50// | | | | | | |
51// | Video |←(F)-| WebRTC |←(E)-| Video |←(D)----┘
52// | Sink | | Stack | | Decoder |
53// ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯
54// The analyzer will be injected in all points from A to F.
Artem Titov4c4c7442021-08-19 22:11:33 +020055class VideoQualityAnalyzerInterface
56 : public webrtc_pc_e2e::StatsObserverInterface {
Artem Titovb6c62012019-01-08 14:58:23 +010057 public:
Artem Titovd19513f2020-03-25 11:53:41 +010058 // Contains extra statistic provided by video encoder.
59 struct EncoderStats {
Artem Titov647d3262021-08-11 18:27:36 +020060 std::string encoder_name = "unknown";
Artem Titovd19513f2020-03-25 11:53:41 +010061 // TODO(hbos) https://crbug.com/webrtc/9547,
62 // https://crbug.com/webrtc/11443: improve stats API to make available
63 // there.
Artem Titov647d3262021-08-11 18:27:36 +020064 uint32_t target_encode_bitrate = 0;
Artem Titovd19513f2020-03-25 11:53:41 +010065 };
66 // Contains extra statistic provided by video decoder.
67 struct DecoderStats {
Artem Titov647d3262021-08-11 18:27:36 +020068 std::string decoder_name = "unknown";
Artem Titovd19513f2020-03-25 11:53:41 +010069 // Decode time provided by decoder itself. If decoder doesn’t produce such
70 // information can be omitted.
Artem Titov647d3262021-08-11 18:27:36 +020071 absl::optional<int32_t> decode_time_ms = absl::nullopt;
Artem Titovd19513f2020-03-25 11:53:41 +010072 };
73
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010074 ~VideoQualityAnalyzerInterface() override = default;
Artem Titovb6c62012019-01-08 14:58:23 +010075
Artem Titov59835852019-02-27 17:44:13 +010076 // Will be called by framework before test.
Artem Titov0e61fdd2021-07-25 21:50:14 +020077 // `test_case_name` is name of test case, that should be used to report all
Artem Titov59835852019-02-27 17:44:13 +010078 // video metrics.
Artem Titov0e61fdd2021-07-25 21:50:14 +020079 // `threads_count` is number of threads that analyzer can use for heavy
Artem Titov59835852019-02-27 17:44:13 +010080 // calculations. Analyzer can perform simple calculations on the calling
81 // thread in each method, but should remember, that it is the same thread,
82 // that is used in video pipeline.
Artem Titov3b641672020-06-02 17:18:17 +020083 virtual void Start(std::string test_case_name,
84 rtc::ArrayView<const std::string> peer_names,
85 int max_threads_count) {}
Artem Titovb6c62012019-01-08 14:58:23 +010086
87 // Will be called when frame was generated from the input stream.
Artem Titov0e61fdd2021-07-25 21:50:14 +020088 // `peer_name` is name of the peer on which side frame was captured.
Artem Titovb6c62012019-01-08 14:58:23 +010089 // Returns frame id, that will be set by framework to the frame.
Andrey Logvin8dbbd642020-12-02 18:42:34 +000090 virtual uint16_t OnFrameCaptured(absl::string_view peer_name,
91 const std::string& stream_label,
92 const VideoFrame& frame) = 0;
Artem Titovebd97702019-01-09 17:55:36 +010093 // Will be called before calling the encoder.
Artem Titov0e61fdd2021-07-25 21:50:14 +020094 // `peer_name` is name of the peer on which side frame came to encoder.
Artem Titov8a0284e2020-05-29 15:49:44 +020095 virtual void OnFramePreEncode(absl::string_view peer_name,
96 const VideoFrame& frame) {}
Artem Titovb6c62012019-01-08 14:58:23 +010097 // Will be called for each EncodedImage received from encoder. Single
98 // VideoFrame can produce multiple EncodedImages. Each encoded image will
99 // have id from VideoFrame.
Artem Titov0e61fdd2021-07-25 21:50:14 +0200100 // `peer_name` is name of the peer on which side frame was encoded.
Artem Titov8a0284e2020-05-29 15:49:44 +0200101 virtual void OnFrameEncoded(absl::string_view peer_name,
102 uint16_t frame_id,
Artem Titovd19513f2020-03-25 11:53:41 +0100103 const EncodedImage& encoded_image,
104 const EncoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100105 // Will be called for each frame dropped by encoder.
Artem Titov0e61fdd2021-07-25 21:50:14 +0200106 // `peer_name` is name of the peer on which side frame drop was detected.
Artem Titov8a0284e2020-05-29 15:49:44 +0200107 virtual void OnFrameDropped(absl::string_view peer_name,
108 EncodedImageCallback::DropReason reason) {}
Artem Titovebd97702019-01-09 17:55:36 +0100109 // Will be called before calling the decoder.
Artem Titov0e61fdd2021-07-25 21:50:14 +0200110 // `peer_name` is name of the peer on which side frame was received.
Artem Titov8a0284e2020-05-29 15:49:44 +0200111 virtual void OnFramePreDecode(absl::string_view peer_name,
112 uint16_t frame_id,
Johannes Kronc12db812019-09-19 13:20:01 +0200113 const EncodedImage& encoded_image) {}
Artem Titovd19513f2020-03-25 11:53:41 +0100114 // Will be called after decoding the frame.
Artem Titov0e61fdd2021-07-25 21:50:14 +0200115 // `peer_name` is name of the peer on which side frame was decoded.
Artem Titov8a0284e2020-05-29 15:49:44 +0200116 virtual void OnFrameDecoded(absl::string_view peer_name,
117 const VideoFrame& frame,
Artem Titovd19513f2020-03-25 11:53:41 +0100118 const DecoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100119 // Will be called when frame will be obtained from PeerConnection stack.
Artem Titov0e61fdd2021-07-25 21:50:14 +0200120 // `peer_name` is name of the peer on which side frame was rendered.
Artem Titov8a0284e2020-05-29 15:49:44 +0200121 virtual void OnFrameRendered(absl::string_view peer_name,
122 const VideoFrame& frame) {}
Artem Titovebd97702019-01-09 17:55:36 +0100123 // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
124 // All available codes are listed in
125 // modules/video_coding/include/video_error_codes.h
Artem Titov0e61fdd2021-07-25 21:50:14 +0200126 // `peer_name` is name of the peer on which side error acquired.
Artem Titov8a0284e2020-05-29 15:49:44 +0200127 virtual void OnEncoderError(absl::string_view peer_name,
128 const VideoFrame& frame,
129 int32_t error_code) {}
Artem Titovebd97702019-01-09 17:55:36 +0100130 // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
131 // All available codes are listed in
132 // modules/video_coding/include/video_error_codes.h
Artem Titov0e61fdd2021-07-25 21:50:14 +0200133 // `peer_name` is name of the peer on which side error acquired.
Artem Titov8a0284e2020-05-29 15:49:44 +0200134 virtual void OnDecoderError(absl::string_view peer_name,
135 uint16_t frame_id,
136 int32_t error_code) {}
Artem Titova8549212019-08-19 14:38:06 +0200137 // Will be called every time new stats reports are available for the
Artem Titov0e61fdd2021-07-25 21:50:14 +0200138 // Peer Connection identified by `pc_label`.
Andrey Logvin9b526182020-06-15 16:14:07 +0000139 void OnStatsReports(
140 absl::string_view pc_label,
141 const rtc::scoped_refptr<const RTCStatsReport>& report) override {}
Artem Titovb6c62012019-01-08 14:58:23 +0100142
Andrey Logvind7808f12020-12-08 15:21:27 +0000143 // Will be called before test adds new participant in the middle of a call.
144 virtual void RegisterParticipantInCall(absl::string_view peer_name) {}
Artem Titov86ebbdb2022-06-21 00:24:41 +0200145 // Will be called after test removed existing participant in the middle of the
146 // call.
147 virtual void UnregisterParticipantInCall(absl::string_view peer_name) {}
Andrey Logvind7808f12020-12-08 15:21:27 +0000148
Artem Titovebd97702019-01-09 17:55:36 +0100149 // Tells analyzer that analysis complete and it should calculate final
Artem Titovb6c62012019-01-08 14:58:23 +0100150 // statistics.
151 virtual void Stop() {}
Artem Titov32232e92019-02-20 21:13:14 +0100152
Artem Titovbe9c40f2021-11-17 11:56:43 +0100153 // Returns the last stream where this frame was captured. It means that if
154 // frame ids space wraps around, then stream label for frame id may change.
155 // It will crash, if the specified `frame_id` wasn't captured.
Artem Titov32232e92019-02-20 21:13:14 +0100156 virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100157};
158
Artem Titovb6c62012019-01-08 14:58:23 +0100159} // namespace webrtc
160
Artem Titovd57628f2019-03-22 12:34:25 +0100161#endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_