blob: d83d16040a768dc41c05016d6084f3ef967eaa26 [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
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010017#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:
Mirko Bonadei12ae4f42019-02-26 15:19:07 +010057 ~VideoQualityAnalyzerInterface() override = default;
Artem Titovb6c62012019-01-08 14:58:23 +010058
Artem Titov59835852019-02-27 17:44:13 +010059 // Will be called by framework before test.
60 // |test_case_name| is name of test case, that should be used to report all
61 // video metrics.
62 // |threads_count| is number of threads that analyzer can use for heavy
63 // calculations. Analyzer can perform simple calculations on the calling
64 // thread in each method, but should remember, that it is the same thread,
65 // that is used in video pipeline.
66 virtual void Start(std::string test_case_name, int max_threads_count) {}
Artem Titovb6c62012019-01-08 14:58:23 +010067
68 // Will be called when frame was generated from the input stream.
69 // Returns frame id, that will be set by framework to the frame.
Artem Titovebd97702019-01-09 17:55:36 +010070 virtual uint16_t OnFrameCaptured(const std::string& stream_label,
Artem Titovb6c62012019-01-08 14:58:23 +010071 const VideoFrame& frame) = 0;
Artem Titovebd97702019-01-09 17:55:36 +010072 // Will be called before calling the encoder.
Artem Titovb6c62012019-01-08 14:58:23 +010073 virtual void OnFramePreEncode(const VideoFrame& frame) {}
74 // Will be called for each EncodedImage received from encoder. Single
75 // VideoFrame can produce multiple EncodedImages. Each encoded image will
76 // have id from VideoFrame.
77 virtual void OnFrameEncoded(uint16_t frame_id,
78 const EncodedImage& encoded_image) {}
79 // Will be called for each frame dropped by encoder.
80 virtual void OnFrameDropped(EncodedImageCallback::DropReason reason) {}
Artem Titovebd97702019-01-09 17:55:36 +010081 // Will be called before calling the decoder.
Artem Titovb6c62012019-01-08 14:58:23 +010082 virtual void OnFrameReceived(uint16_t frame_id,
83 const EncodedImage& encoded_image) {}
84 // Will be called after decoding the frame. |decode_time_ms| is a decode
85 // time provided by decoder itself. If decoder doesn’t produce such
86 // information can be omitted.
87 virtual void OnFrameDecoded(const VideoFrame& frame,
88 absl::optional<int32_t> decode_time_ms,
89 absl::optional<uint8_t> qp) {}
90 // Will be called when frame will be obtained from PeerConnection stack.
91 virtual void OnFrameRendered(const VideoFrame& frame) {}
Artem Titovebd97702019-01-09 17:55:36 +010092 // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
93 // All available codes are listed in
94 // modules/video_coding/include/video_error_codes.h
Artem Titovb6c62012019-01-08 14:58:23 +010095 virtual void OnEncoderError(const VideoFrame& frame, int32_t error_code) {}
Artem Titovebd97702019-01-09 17:55:36 +010096 // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
97 // All available codes are listed in
98 // modules/video_coding/include/video_error_codes.h
Artem Titovb6c62012019-01-08 14:58:23 +010099 virtual void OnDecoderError(uint16_t frame_id, int32_t error_code) {}
Mirko Bonadei12ae4f42019-02-26 15:19:07 +0100100 // Will be called everytime new stats reports are available for the
101 // Peer Connection identified by |pc_label|.
102 void OnStatsReports(absl::string_view pc_label,
103 const StatsReports& stats_reports) override {}
Artem Titovb6c62012019-01-08 14:58:23 +0100104
Artem Titovebd97702019-01-09 17:55:36 +0100105 // Tells analyzer that analysis complete and it should calculate final
Artem Titovb6c62012019-01-08 14:58:23 +0100106 // statistics.
107 virtual void Stop() {}
Artem Titov32232e92019-02-20 21:13:14 +0100108
109 virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100110};
111
Artem Titov0b443142019-03-20 11:11:08 +0100112} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100113} // namespace webrtc
114
Artem Titovd57628f2019-03-22 12:34:25 +0100115#endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_