blob: 990548af9ee50c32562c652cf6d0dce4a39deb37 [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:
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010056 ~VideoQualityAnalyzerInterface() override = default;
Artem Titovb6c62012019-01-08 14:58:23 +010057
Artem Titov59835852019-02-27 17:44:13 +010058 // Will be called by framework before test.
59 // |test_case_name| is name of test case, that should be used to report all
60 // video metrics.
61 // |threads_count| is number of threads that analyzer can use for heavy
62 // calculations. Analyzer can perform simple calculations on the calling
63 // thread in each method, but should remember, that it is the same thread,
64 // that is used in video pipeline.
65 virtual void Start(std::string test_case_name, int max_threads_count) {}
Artem Titovb6c62012019-01-08 14:58:23 +010066
67 // Will be called when frame was generated from the input stream.
68 // Returns frame id, that will be set by framework to the frame.
Artem Titovebd97702019-01-09 17:55:36 +010069 virtual uint16_t OnFrameCaptured(const std::string& stream_label,
Artem Titovb6c62012019-01-08 14:58:23 +010070 const VideoFrame& frame) = 0;
Artem Titovebd97702019-01-09 17:55:36 +010071 // Will be called before calling the encoder.
Artem Titovb6c62012019-01-08 14:58:23 +010072 virtual void OnFramePreEncode(const VideoFrame& frame) {}
73 // Will be called for each EncodedImage received from encoder. Single
74 // VideoFrame can produce multiple EncodedImages. Each encoded image will
75 // have id from VideoFrame.
76 virtual void OnFrameEncoded(uint16_t frame_id,
77 const EncodedImage& encoded_image) {}
78 // Will be called for each frame dropped by encoder.
79 virtual void OnFrameDropped(EncodedImageCallback::DropReason reason) {}
Artem Titovebd97702019-01-09 17:55:36 +010080 // Will be called before calling the decoder.
Johannes Kronc12db812019-09-19 13:20:01 +020081 virtual void OnFramePreDecode(uint16_t frame_id,
82 const EncodedImage& encoded_image) {}
Artem Titovb6c62012019-01-08 14:58:23 +010083 // Will be called after decoding the frame. |decode_time_ms| is a decode
84 // time provided by decoder itself. If decoder doesn’t produce such
85 // information can be omitted.
86 virtual void OnFrameDecoded(const VideoFrame& frame,
87 absl::optional<int32_t> decode_time_ms,
88 absl::optional<uint8_t> qp) {}
89 // Will be called when frame will be obtained from PeerConnection stack.
90 virtual void OnFrameRendered(const VideoFrame& frame) {}
Artem Titovebd97702019-01-09 17:55:36 +010091 // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
92 // All available codes are listed in
93 // modules/video_coding/include/video_error_codes.h
Artem Titovb6c62012019-01-08 14:58:23 +010094 virtual void OnEncoderError(const VideoFrame& frame, int32_t error_code) {}
Artem Titovebd97702019-01-09 17:55:36 +010095 // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
96 // All available codes are listed in
97 // modules/video_coding/include/video_error_codes.h
Artem Titovb6c62012019-01-08 14:58:23 +010098 virtual void OnDecoderError(uint16_t frame_id, int32_t error_code) {}
Artem Titova8549212019-08-19 14:38:06 +020099 // Will be called every time new stats reports are available for the
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100100 // Peer Connection identified by |pc_label|.
Mirko Bonadei60f14ce2019-05-08 10:52:52 +0200101 void OnStatsReports(const std::string& pc_label,
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100102 const StatsReports& stats_reports) override {}
Artem Titovb6c62012019-01-08 14:58:23 +0100103
Artem Titovebd97702019-01-09 17:55:36 +0100104 // Tells analyzer that analysis complete and it should calculate final
Artem Titovb6c62012019-01-08 14:58:23 +0100105 // statistics.
106 virtual void Stop() {}
Artem Titov32232e92019-02-20 21:13:14 +0100107
108 virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100109};
110
Artem Titov0b443142019-03-20 11:11:08 +0100111} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100112} // namespace webrtc
113
Artem Titovd57628f2019-03-22 12:34:25 +0100114#endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_