video_quality_analyzer_interface.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #ifndef API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_
  11. #define API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_
  12. #include <memory>
  13. #include <string>
  14. #include "absl/strings/string_view.h"
  15. #include "absl/types/optional.h"
  16. #include "api/array_view.h"
  17. #include "api/test/stats_observer_interface.h"
  18. #include "api/video/encoded_image.h"
  19. #include "api/video/video_frame.h"
  20. #include "api/video_codecs/video_encoder.h"
  21. namespace webrtc {
  22. namespace webrtc_pc_e2e {
  23. // API is in development and can be changed without notice.
  24. // Base interface for video quality analyzer for peer connection level end-2-end
  25. // tests. Interface has only one abstract method, which have to return frame id.
  26. // Other methods have empty implementation by default, so user can override only
  27. // required parts.
  28. //
  29. // VideoQualityAnalyzerInterface will be injected into WebRTC pipeline on both
  30. // sides of the call. Here is video data flow in WebRTC pipeline
  31. //
  32. // Alice:
  33. // ___________ ________ _________
  34. // | | | | | |
  35. // | Frame |-(A)→| WebRTC |-(B)→| Video |-(C)┐
  36. // | Generator | | Stack | | Decoder | |
  37. // ¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯ |
  38. // __↓________
  39. // | Transport |
  40. // | & |
  41. // | Network |
  42. // ¯¯|¯¯¯¯¯¯¯¯
  43. // Bob: |
  44. // _______ ________ _________ |
  45. // | | | | | | |
  46. // | Video |←(F)-| WebRTC |←(E)-| Video |←(D)----┘
  47. // | Sink | | Stack | | Decoder |
  48. // ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯
  49. // The analyzer will be injected in all points from A to F.
  50. class VideoQualityAnalyzerInterface : public StatsObserverInterface {
  51. public:
  52. // Contains extra statistic provided by video encoder.
  53. struct EncoderStats {
  54. // TODO(hbos) https://crbug.com/webrtc/9547,
  55. // https://crbug.com/webrtc/11443: improve stats API to make available
  56. // there.
  57. uint32_t target_encode_bitrate;
  58. };
  59. // Contains extra statistic provided by video decoder.
  60. struct DecoderStats {
  61. // Decode time provided by decoder itself. If decoder doesn’t produce such
  62. // information can be omitted.
  63. absl::optional<int32_t> decode_time_ms;
  64. };
  65. ~VideoQualityAnalyzerInterface() override = default;
  66. // Will be called by framework before test.
  67. // |test_case_name| is name of test case, that should be used to report all
  68. // video metrics.
  69. // |threads_count| is number of threads that analyzer can use for heavy
  70. // calculations. Analyzer can perform simple calculations on the calling
  71. // thread in each method, but should remember, that it is the same thread,
  72. // that is used in video pipeline.
  73. virtual void Start(std::string test_case_name,
  74. rtc::ArrayView<const std::string> peer_names,
  75. int max_threads_count) {}
  76. // Will be called when frame was generated from the input stream.
  77. // |peer_name| is name of the peer on which side frame was captured.
  78. // Returns frame id, that will be set by framework to the frame.
  79. virtual uint16_t OnFrameCaptured(absl::string_view peer_name,
  80. const std::string& stream_label,
  81. const VideoFrame& frame) = 0;
  82. // Will be called before calling the encoder.
  83. // |peer_name| is name of the peer on which side frame came to encoder.
  84. virtual void OnFramePreEncode(absl::string_view peer_name,
  85. const VideoFrame& frame) {}
  86. // Will be called for each EncodedImage received from encoder. Single
  87. // VideoFrame can produce multiple EncodedImages. Each encoded image will
  88. // have id from VideoFrame.
  89. // |peer_name| is name of the peer on which side frame was encoded.
  90. virtual void OnFrameEncoded(absl::string_view peer_name,
  91. uint16_t frame_id,
  92. const EncodedImage& encoded_image,
  93. const EncoderStats& stats) {}
  94. // Will be called for each frame dropped by encoder.
  95. // |peer_name| is name of the peer on which side frame drop was detected.
  96. virtual void OnFrameDropped(absl::string_view peer_name,
  97. EncodedImageCallback::DropReason reason) {}
  98. // Will be called before calling the decoder.
  99. // |peer_name| is name of the peer on which side frame was received.
  100. virtual void OnFramePreDecode(absl::string_view peer_name,
  101. uint16_t frame_id,
  102. const EncodedImage& encoded_image) {}
  103. // Will be called after decoding the frame.
  104. // |peer_name| is name of the peer on which side frame was decoded.
  105. virtual void OnFrameDecoded(absl::string_view peer_name,
  106. const VideoFrame& frame,
  107. const DecoderStats& stats) {}
  108. // Will be called when frame will be obtained from PeerConnection stack.
  109. // |peer_name| is name of the peer on which side frame was rendered.
  110. virtual void OnFrameRendered(absl::string_view peer_name,
  111. const VideoFrame& frame) {}
  112. // Will be called if encoder return not WEBRTC_VIDEO_CODEC_OK.
  113. // All available codes are listed in
  114. // modules/video_coding/include/video_error_codes.h
  115. // |peer_name| is name of the peer on which side error acquired.
  116. virtual void OnEncoderError(absl::string_view peer_name,
  117. const VideoFrame& frame,
  118. int32_t error_code) {}
  119. // Will be called if decoder return not WEBRTC_VIDEO_CODEC_OK.
  120. // All available codes are listed in
  121. // modules/video_coding/include/video_error_codes.h
  122. // |peer_name| is name of the peer on which side error acquired.
  123. virtual void OnDecoderError(absl::string_view peer_name,
  124. uint16_t frame_id,
  125. int32_t error_code) {}
  126. // Will be called every time new stats reports are available for the
  127. // Peer Connection identified by |pc_label|.
  128. void OnStatsReports(
  129. absl::string_view pc_label,
  130. const rtc::scoped_refptr<const RTCStatsReport>& report) override {}
  131. // Tells analyzer that analysis complete and it should calculate final
  132. // statistics.
  133. virtual void Stop() {}
  134. virtual std::string GetStreamLabel(uint16_t frame_id) = 0;
  135. };
  136. } // namespace webrtc_pc_e2e
  137. } // namespace webrtc
  138. #endif // API_TEST_VIDEO_QUALITY_ANALYZER_INTERFACE_H_