blob: 0d3f44153484f922ffa78b74a035f6bb8e40716b [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
17#include "absl/types/optional.h"
Artem Titovd57628f2019-03-22 12:34:25 +010018#include "api/test/stats_observer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010019#include "api/video/encoded_image.h"
20#include "api/video/video_frame.h"
21#include "api/video_codecs/video_encoder.h"
22
23namespace webrtc {
Artem Titov0b443142019-03-20 11:11:08 +010024namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010025
Artem Titovd57628f2019-03-22 12:34:25 +010026// API is in development and can be changed without notice.
27
Artem Titovebd97702019-01-09 17:55:36 +010028// Base interface for video quality analyzer for peer connection level end-2-end
29// tests. Interface has only one abstract method, which have to return frame id.
30// Other methods have empty implementation by default, so user can override only
31// required parts.
32//
33// VideoQualityAnalyzerInterface will be injected into WebRTC pipeline on both
34// sides of the call. Here is video data flow in WebRTC pipeline
35//
36// Alice:
37// ___________ ________ _________
38// | | | | | |
39// | Frame |-(A)→| WebRTC |-(B)→| Video |-(C)┐
40// | Generator | | Stack | | Decoder | |
41// ¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯ |
42// __↓________
43// | Transport |
44// | & |
45// | Network |
46// ¯¯|¯¯¯¯¯¯¯¯
47// Bob: |
48// _______ ________ _________ |
49// | | | | | | |
50// | Video |←(F)-| WebRTC |←(E)-| Video |←(D)----┘
51// | Sink | | Stack | | Decoder |
52// ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯
53// The analyzer will be injected in all points from A to F.
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010054class VideoQualityAnalyzerInterface : public StatsObserverInterface {
Artem Titovb6c62012019-01-08 14:58:23 +010055 public:
Artem Titovd19513f2020-03-25 11:53:41 +010056 // Contains extra statistic provided by video encoder.
57 struct EncoderStats {
58 // TODO(hbos) https://crbug.com/webrtc/9547,
59 // https://crbug.com/webrtc/11443: improve stats API to make available
60 // there.
61 uint32_t target_encode_bitrate;
62 };
63 // Contains extra statistic provided by video decoder.
64 struct DecoderStats {
65 // Decode time provided by decoder itself. If decoder doesn’t produce such
66 // information can be omitted.
67 absl::optional<int32_t> decode_time_ms;
68 };
69
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010070 ~VideoQualityAnalyzerInterface() override = default;
Artem Titovb6c62012019-01-08 14:58:23 +010071
Artem Titov59835852019-02-27 17:44:13 +010072 // Will be called by framework before test.
73 // |test_case_name| is name of test case, that should be used to report all
74 // video metrics.
75 // |threads_count| is number of threads that analyzer can use for heavy
76 // calculations. Analyzer can perform simple calculations on the calling
77 // thread in each method, but should remember, that it is the same thread,
78 // that is used in video pipeline.
79 virtual void Start(std::string test_case_name, int max_threads_count) {}
Artem Titovb6c62012019-01-08 14:58:23 +010080
81 // Will be called when frame was generated from the input stream.
82 // Returns frame id, that will be set by framework to the frame.
Artem Titovebd97702019-01-09 17:55:36 +010083 virtual uint16_t OnFrameCaptured(const std::string& stream_label,
Artem Titovb6c62012019-01-08 14:58:23 +010084 const VideoFrame& frame) = 0;
Artem Titovebd97702019-01-09 17:55:36 +010085 // Will be called before calling the encoder.
Artem Titovb6c62012019-01-08 14:58:23 +010086 virtual void OnFramePreEncode(const VideoFrame& frame) {}
87 // Will be called for each EncodedImage received from encoder. Single
88 // VideoFrame can produce multiple EncodedImages. Each encoded image will
89 // have id from VideoFrame.
90 virtual void OnFrameEncoded(uint16_t frame_id,
Artem Titovd19513f2020-03-25 11:53:41 +010091 const EncodedImage& encoded_image,
92 const EncoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +010093 // Will be called for each frame dropped by encoder.
94 virtual void OnFrameDropped(EncodedImageCallback::DropReason reason) {}
Artem Titovebd97702019-01-09 17:55:36 +010095 // Will be called before calling the decoder.
Johannes Kronc12db812019-09-19 13:20:01 +020096 virtual void OnFramePreDecode(uint16_t frame_id,
97 const EncodedImage& encoded_image) {}
Artem Titovd19513f2020-03-25 11:53:41 +010098 // Will be called after decoding the frame.
Artem Titovb6c62012019-01-08 14:58:23 +010099 virtual void OnFrameDecoded(const VideoFrame& frame,
Artem Titovd19513f2020-03-25 11:53:41 +0100100 const DecoderStats& stats) {}
Artem Titovb6c62012019-01-08 14:58:23 +0100101 // Will be called when frame will be obtained from PeerConnection stack.
102 virtual void OnFrameRendered(const VideoFrame& frame) {}
Artem Titovebd97702019-01-09 17:55:36 +0100103 // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
104 // All available codes are listed in
105 // modules/video_coding/include/video_error_codes.h
Artem Titovb6c62012019-01-08 14:58:23 +0100106 virtual void OnEncoderError(const VideoFrame& frame, int32_t error_code) {}
Artem Titovebd97702019-01-09 17:55:36 +0100107 // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
108 // All available codes are listed in
109 // modules/video_coding/include/video_error_codes.h
Artem Titovb6c62012019-01-08 14:58:23 +0100110 virtual void OnDecoderError(uint16_t frame_id, int32_t error_code) {}
Artem Titova8549212019-08-19 14:38:06 +0200111 // Will be called every time new stats reports are available for the
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100112 // Peer Connection identified by |pc_label|.
Mirko Bonadei60f14ce2019-05-08 10:52:52 +0200113 void OnStatsReports(const std::string& pc_label,
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100114 const StatsReports& stats_reports) override {}
Artem Titovb6c62012019-01-08 14:58:23 +0100115
Artem Titovebd97702019-01-09 17:55:36 +0100116 // Tells analyzer that analysis complete and it should calculate final
Artem Titovb6c62012019-01-08 14:58:23 +0100117 // statistics.
118 virtual void Stop() {}
Artem Titov32232e92019-02-20 21:13:14 +0100119
120 virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100121};
122
Artem Titov0b443142019-03-20 11:11:08 +0100123} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100124} // namespace webrtc
125
Artem Titovd57628f2019-03-22 12:34:25 +0100126#endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_