Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 1 | /* |
| 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 Titov | d57628f | 2019-03-22 12:34:25 +0100 | [diff] [blame] | 11 | #ifndef API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_ |
| 12 | #define API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_ |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | |
| 17 | #include "absl/types/optional.h" |
Artem Titov | d57628f | 2019-03-22 12:34:25 +0100 | [diff] [blame] | 18 | #include "api/test/stats_observer_interface.h" |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 19 | #include "api/video/encoded_image.h" |
| 20 | #include "api/video/video_frame.h" |
| 21 | #include "api/video_codecs/video_encoder.h" |
| 22 | |
| 23 | namespace webrtc { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 24 | namespace webrtc_pc_e2e { |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 25 | |
Artem Titov | d57628f | 2019-03-22 12:34:25 +0100 | [diff] [blame] | 26 | // API is in development and can be changed without notice. |
| 27 | |
Artem Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 28 | // 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 Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 54 | class VideoQualityAnalyzerInterface : public StatsObserverInterface { |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 55 | public: |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 56 | ~VideoQualityAnalyzerInterface() override = default; |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 57 | |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 58 | // 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 Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 66 | |
| 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 Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 69 | virtual uint16_t OnFrameCaptured(const std::string& stream_label, |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 70 | const VideoFrame& frame) = 0; |
Artem Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 71 | // Will be called before calling the encoder. |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 72 | 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 Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 80 | // Will be called before calling the decoder. |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 81 | virtual void OnFrameReceived(uint16_t frame_id, |
| 82 | const EncodedImage& encoded_image) {} |
| 83 | // 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 Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 91 | // 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 Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 94 | virtual void OnEncoderError(const VideoFrame& frame, int32_t error_code) {} |
Artem Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 95 | // 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 Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 98 | virtual void OnDecoderError(uint16_t frame_id, int32_t error_code) {} |
Artem Titov | a854921 | 2019-08-19 14:38:06 +0200 | [diff] [blame] | 99 | // Will be called every time new stats reports are available for the |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 100 | // Peer Connection identified by |pc_label|. |
Mirko Bonadei | 60f14ce | 2019-05-08 10:52:52 +0200 | [diff] [blame] | 101 | void OnStatsReports(const std::string& pc_label, |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 102 | const StatsReports& stats_reports) override {} |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 103 | |
Artem Titov | ebd9770 | 2019-01-09 17:55:36 +0100 | [diff] [blame] | 104 | // Tells analyzer that analysis complete and it should calculate final |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 105 | // statistics. |
| 106 | virtual void Stop() {} |
Artem Titov | 32232e9 | 2019-02-20 21:13:14 +0100 | [diff] [blame] | 107 | |
| 108 | virtual std::string GetStreamLabel(uint16_t frame_id) = 0; |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 111 | } // namespace webrtc_pc_e2e |
Artem Titov | b6c6201 | 2019-01-08 14:58:23 +0100 | [diff] [blame] | 112 | } // namespace webrtc |
| 113 | |
Artem Titov | d57628f | 2019-03-22 12:34:25 +0100 | [diff] [blame] | 114 | #endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_ |