blob: 5bf8a1a3834ff0623b759717e34e0e33bc4f8aa3 [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 Titovd57628f2019-03-22 12:34:25 +010019#include "api/test/stats_observer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010020#include "api/video/encoded_image.h"
21#include "api/video/video_frame.h"
22#include "api/video_codecs/video_encoder.h"
23
24namespace webrtc {
Artem Titov0b443142019-03-20 11:11:08 +010025namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010026
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.
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010055class VideoQualityAnalyzerInterface : public StatsObserverInterface {
Artem Titovb6c62012019-01-08 14:58:23 +010056 public:
Artem Titovd19513f2020-03-25 11:53:41 +010057 // Contains extra statistic provided by video encoder.
58 struct EncoderStats {
59 // TODO(hbos) https://crbug.com/webrtc/9547,
60 // https://crbug.com/webrtc/11443: improve stats API to make available
61 // there.
62 uint32_t target_encode_bitrate;
63 };
64 // Contains extra statistic provided by video decoder.
65 struct DecoderStats {
66 // Decode time provided by decoder itself. If decoder doesn’t produce such
67 // information can be omitted.
68 absl::optional<int32_t> decode_time_ms;
69 };
70
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010071 ~VideoQualityAnalyzerInterface() override = default;
Artem Titovb6c62012019-01-08 14:58:23 +010072
Artem Titov59835852019-02-27 17:44:13 +010073 // Will be called by framework before test.
74 // |test_case_name| is name of test case, that should be used to report all
75 // video metrics.
76 // |threads_count| is number of threads that analyzer can use for heavy
77 // calculations. Analyzer can perform simple calculations on the calling
78 // thread in each method, but should remember, that it is the same thread,
79 // that is used in video pipeline.
80 virtual void Start(std::string test_case_name, int max_threads_count) {}
Artem Titovb6c62012019-01-08 14:58:23 +010081
82 // Will be called when frame was generated from the input stream.
Artem Titov8a0284e2020-05-29 15:49:44 +020083 // |peer_name| is name of the peer on which side frame was captured.
Artem Titovb6c62012019-01-08 14:58:23 +010084 // Returns frame id, that will be set by framework to the frame.
Artem Titov8a0284e2020-05-29 15:49:44 +020085 virtual uint16_t OnFrameCaptured(absl::string_view peer_name,
86 const std::string& stream_label,
Artem Titovb6c62012019-01-08 14:58:23 +010087 const VideoFrame& frame) = 0;
Artem Titovebd97702019-01-09 17:55:36 +010088 // Will be called before calling the encoder.
Artem Titov8a0284e2020-05-29 15:49:44 +020089 // |peer_name| is name of the peer on which side frame came to encoder.
90 virtual void OnFramePreEncode(absl::string_view peer_name,
91 const VideoFrame& frame) {}
Artem Titovb6c62012019-01-08 14:58:23 +010092 // Will be called for each EncodedImage received from encoder. Single
93 // VideoFrame can produce multiple EncodedImages. Each encoded image will
94 // have id from VideoFrame.
Artem Titov8a0284e2020-05-29 15:49:44 +020095 // |peer_name| is name of the peer on which side frame was encoded.
96 virtual void OnFrameEncoded(absl::string_view peer_name,
97 uint16_t frame_id,
Artem Titovd19513f2020-03-25 11:53:41 +010098 const EncodedImage& encoded_image,
99 const EncoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100100 // Will be called for each frame dropped by encoder.
Artem Titov8a0284e2020-05-29 15:49:44 +0200101 // |peer_name| is name of the peer on which side frame drop was detected.
102 virtual void OnFrameDropped(absl::string_view peer_name,
103 EncodedImageCallback::DropReason reason) {}
Artem Titovebd97702019-01-09 17:55:36 +0100104 // Will be called before calling the decoder.
Artem Titov8a0284e2020-05-29 15:49:44 +0200105 // |peer_name| is name of the peer on which side frame was received.
106 virtual void OnFramePreDecode(absl::string_view peer_name,
107 uint16_t frame_id,
Johannes Kronc12db812019-09-19 13:20:01 +0200108 const EncodedImage& encoded_image) {}
Artem Titovd19513f2020-03-25 11:53:41 +0100109 // Will be called after decoding the frame.
Artem Titov8a0284e2020-05-29 15:49:44 +0200110 // |peer_name| is name of the peer on which side frame was decoded.
111 virtual void OnFrameDecoded(absl::string_view peer_name,
112 const VideoFrame& frame,
Artem Titovd19513f2020-03-25 11:53:41 +0100113 const DecoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100114 // Will be called when frame will be obtained from PeerConnection stack.
Artem Titov8a0284e2020-05-29 15:49:44 +0200115 // |peer_name| is name of the peer on which side frame was rendered.
116 virtual void OnFrameRendered(absl::string_view peer_name,
117 const VideoFrame& frame) {}
Artem Titovebd97702019-01-09 17:55:36 +0100118 // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
119 // All available codes are listed in
120 // modules/video_coding/include/video_error_codes.h
Artem Titov8a0284e2020-05-29 15:49:44 +0200121 // |peer_name| is name of the peer on which side error acquired.
122 virtual void OnEncoderError(absl::string_view peer_name,
123 const VideoFrame& frame,
124 int32_t error_code) {}
Artem Titovebd97702019-01-09 17:55:36 +0100125 // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
126 // All available codes are listed in
127 // modules/video_coding/include/video_error_codes.h
Artem Titov8a0284e2020-05-29 15:49:44 +0200128 // |peer_name| is name of the peer on which side error acquired.
129 virtual void OnDecoderError(absl::string_view peer_name,
130 uint16_t frame_id,
131 int32_t error_code) {}
Artem Titova8549212019-08-19 14:38:06 +0200132 // Will be called every time new stats reports are available for the
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100133 // Peer Connection identified by |pc_label|.
Mirko Bonadei60f14ce2019-05-08 10:52:52 +0200134 void OnStatsReports(const std::string& pc_label,
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100135 const StatsReports& stats_reports) override {}
Artem Titovb6c62012019-01-08 14:58:23 +0100136
Artem Titovebd97702019-01-09 17:55:36 +0100137 // Tells analyzer that analysis complete and it should calculate final
Artem Titovb6c62012019-01-08 14:58:23 +0100138 // statistics.
139 virtual void Stop() {}
Artem Titov32232e92019-02-20 21:13:14 +0100140
141 virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100142};
143
Artem Titov0b443142019-03-20 11:11:08 +0100144} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100145} // namespace webrtc
146
Artem Titovd57628f2019-03-22 12:34:25 +0100147#endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_