blob: c5370a7089ef53da7ea1f7613f0d3a35924a4e37 [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 {
Artem Titov0b443142019-03-20 11:11:08 +010026namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010027
Artem Titovd57628f2019-03-22 12:34:25 +010028// API is in development and can be changed without notice.
29
Artem Titovebd97702019-01-09 17:55:36 +010030// Base interface for video quality analyzer for peer connection level end-2-end
31// tests. Interface has only one abstract method, which have to return frame id.
32// Other methods have empty implementation by default, so user can override only
33// required parts.
34//
35// VideoQualityAnalyzerInterface will be injected into WebRTC pipeline on both
36// sides of the call. Here is video data flow in WebRTC pipeline
37//
38// Alice:
39// ___________ ________ _________
40// | | | | | |
41// | Frame |-(A)→| WebRTC |-(B)→| Video |-(C)┐
42// | Generator | | Stack | | Decoder | |
43// ¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯ |
44// __↓________
45// | Transport |
46// | & |
47// | Network |
48// ¯¯|¯¯¯¯¯¯¯¯
49// Bob: |
50// _______ ________ _________ |
51// | | | | | | |
52// | Video |←(F)-| WebRTC |←(E)-| Video |←(D)----┘
53// | Sink | | Stack | | Decoder |
54// ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯
55// The analyzer will be injected in all points from A to F.
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010056class VideoQualityAnalyzerInterface : public 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 {
60 // TODO(hbos) https://crbug.com/webrtc/9547,
61 // https://crbug.com/webrtc/11443: improve stats API to make available
62 // there.
63 uint32_t target_encode_bitrate;
64 };
65 // Contains extra statistic provided by video decoder.
66 struct DecoderStats {
67 // Decode time provided by decoder itself. If decoder doesn’t produce such
68 // information can be omitted.
69 absl::optional<int32_t> decode_time_ms;
70 };
71
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010072 ~VideoQualityAnalyzerInterface() override = default;
Artem Titovb6c62012019-01-08 14:58:23 +010073
Artem Titov59835852019-02-27 17:44:13 +010074 // Will be called by framework before test.
75 // |test_case_name| is name of test case, that should be used to report all
76 // video metrics.
77 // |threads_count| is number of threads that analyzer can use for heavy
78 // calculations. Analyzer can perform simple calculations on the calling
79 // thread in each method, but should remember, that it is the same thread,
80 // that is used in video pipeline.
Artem Titov3b641672020-06-02 17:18:17 +020081 virtual void Start(std::string test_case_name,
82 rtc::ArrayView<const std::string> peer_names,
83 int max_threads_count) {}
Artem Titovb6c62012019-01-08 14:58:23 +010084
85 // Will be called when frame was generated from the input stream.
Artem Titov8a0284e2020-05-29 15:49:44 +020086 // |peer_name| is name of the peer on which side frame was captured.
Artem Titovb6c62012019-01-08 14:58:23 +010087 // Returns frame id, that will be set by framework to the frame.
Andrey Logvin8dbbd642020-12-02 18:42:34 +000088 virtual uint16_t OnFrameCaptured(absl::string_view peer_name,
89 const std::string& stream_label,
90 const VideoFrame& frame) = 0;
Artem Titovebd97702019-01-09 17:55:36 +010091 // Will be called before calling the encoder.
Artem Titov8a0284e2020-05-29 15:49:44 +020092 // |peer_name| is name of the peer on which side frame came to encoder.
93 virtual void OnFramePreEncode(absl::string_view peer_name,
94 const VideoFrame& frame) {}
Artem Titovb6c62012019-01-08 14:58:23 +010095 // Will be called for each EncodedImage received from encoder. Single
96 // VideoFrame can produce multiple EncodedImages. Each encoded image will
97 // have id from VideoFrame.
Artem Titov8a0284e2020-05-29 15:49:44 +020098 // |peer_name| is name of the peer on which side frame was encoded.
99 virtual void OnFrameEncoded(absl::string_view peer_name,
100 uint16_t frame_id,
Artem Titovd19513f2020-03-25 11:53:41 +0100101 const EncodedImage& encoded_image,
102 const EncoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100103 // Will be called for each frame dropped by encoder.
Artem Titov8a0284e2020-05-29 15:49:44 +0200104 // |peer_name| is name of the peer on which side frame drop was detected.
105 virtual void OnFrameDropped(absl::string_view peer_name,
106 EncodedImageCallback::DropReason reason) {}
Artem Titovebd97702019-01-09 17:55:36 +0100107 // Will be called before calling the decoder.
Artem Titov8a0284e2020-05-29 15:49:44 +0200108 // |peer_name| is name of the peer on which side frame was received.
109 virtual void OnFramePreDecode(absl::string_view peer_name,
110 uint16_t frame_id,
Johannes Kronc12db812019-09-19 13:20:01 +0200111 const EncodedImage& encoded_image) {}
Artem Titovd19513f2020-03-25 11:53:41 +0100112 // Will be called after decoding the frame.
Artem Titov8a0284e2020-05-29 15:49:44 +0200113 // |peer_name| is name of the peer on which side frame was decoded.
114 virtual void OnFrameDecoded(absl::string_view peer_name,
115 const VideoFrame& frame,
Artem Titovd19513f2020-03-25 11:53:41 +0100116 const DecoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100117 // Will be called when frame will be obtained from PeerConnection stack.
Artem Titov8a0284e2020-05-29 15:49:44 +0200118 // |peer_name| is name of the peer on which side frame was rendered.
119 virtual void OnFrameRendered(absl::string_view peer_name,
120 const VideoFrame& frame) {}
Artem Titovebd97702019-01-09 17:55:36 +0100121 // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
122 // All available codes are listed in
123 // modules/video_coding/include/video_error_codes.h
Artem Titov8a0284e2020-05-29 15:49:44 +0200124 // |peer_name| is name of the peer on which side error acquired.
125 virtual void OnEncoderError(absl::string_view peer_name,
126 const VideoFrame& frame,
127 int32_t error_code) {}
Artem Titovebd97702019-01-09 17:55:36 +0100128 // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
129 // All available codes are listed in
130 // modules/video_coding/include/video_error_codes.h
Artem Titov8a0284e2020-05-29 15:49:44 +0200131 // |peer_name| is name of the peer on which side error acquired.
132 virtual void OnDecoderError(absl::string_view peer_name,
133 uint16_t frame_id,
134 int32_t error_code) {}
Artem Titova8549212019-08-19 14:38:06 +0200135 // Will be called every time new stats reports are available for the
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100136 // Peer Connection identified by |pc_label|.
Andrey Logvin9b526182020-06-15 16:14:07 +0000137 void OnStatsReports(
138 absl::string_view pc_label,
139 const rtc::scoped_refptr<const RTCStatsReport>& report) override {}
Artem Titovb6c62012019-01-08 14:58:23 +0100140
Artem Titovebd97702019-01-09 17:55:36 +0100141 // Tells analyzer that analysis complete and it should calculate final
Artem Titovb6c62012019-01-08 14:58:23 +0100142 // statistics.
143 virtual void Stop() {}
Artem Titov32232e92019-02-20 21:13:14 +0100144
145 virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100146};
147
Artem Titov0b443142019-03-20 11:11:08 +0100148} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100149} // namespace webrtc
150
Artem Titovd57628f2019-03-22 12:34:25 +0100151#endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_