aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_VIDEO_SEND_STREAM_H_ |
| 12 | #define CALL_VIDEO_SEND_STREAM_H_ |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 16 | #include <map> |
| 17 | #include <string> |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "api/crypto/crypto_options.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/rtp_parameters.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 24 | #include "api/video/video_content_type.h" |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 25 | #include "api/video/video_frame.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 26 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 27 | #include "api/video/video_source_interface.h" |
Niels Möller | 213618e | 2018-07-24 09:29:58 +0200 | [diff] [blame] | 28 | #include "api/video/video_stream_encoder_settings.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 29 | #include "api/video_codecs/video_encoder_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "call/rtp_config.h" |
Henrik Boström | ce33b6a | 2019-05-28 17:42:38 +0200 | [diff] [blame] | 31 | #include "common_video/include/quality_limitation_reason.h" |
Henrik Boström | 87e3f9d | 2019-05-27 10:44:24 +0200 | [diff] [blame] | 32 | #include "modules/rtp_rtcp/include/report_block_data.h" |
Niels Möller | 53382cb | 2018-11-27 14:05:08 +0100 | [diff] [blame] | 33 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 34 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 35 | |
| 36 | namespace webrtc { |
| 37 | |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 38 | class FrameEncryptorInterface; |
| 39 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 40 | class VideoSendStream { |
| 41 | public: |
| 42 | struct StreamStats { |
| 43 | StreamStats(); |
| 44 | ~StreamStats(); |
| 45 | |
| 46 | std::string ToString() const; |
| 47 | |
| 48 | FrameCounts frame_counts; |
| 49 | bool is_rtx = false; |
| 50 | bool is_flexfec = false; |
| 51 | int width = 0; |
| 52 | int height = 0; |
| 53 | // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer. |
| 54 | int total_bitrate_bps = 0; |
| 55 | int retransmit_bitrate_bps = 0; |
| 56 | int avg_delay_ms = 0; |
| 57 | int max_delay_ms = 0; |
Henrik Boström | 9fe1834 | 2019-05-16 18:38:20 +0200 | [diff] [blame] | 58 | uint64_t total_packet_send_delay_ms = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 59 | StreamDataCounters rtp_stats; |
| 60 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 61 | RtcpStatistics rtcp_stats; |
Henrik Boström | 87e3f9d | 2019-05-27 10:44:24 +0200 | [diff] [blame] | 62 | // A snapshot of the most recent Report Block with additional data of |
| 63 | // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats. |
| 64 | absl::optional<ReportBlockData> report_block_data; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct Stats { |
| 68 | Stats(); |
| 69 | ~Stats(); |
| 70 | std::string ToString(int64_t time_ms) const; |
| 71 | std::string encoder_implementation_name = "unknown"; |
| 72 | int input_frame_rate = 0; |
| 73 | int encode_frame_rate = 0; |
| 74 | int avg_encode_time_ms = 0; |
| 75 | int encode_usage_percent = 0; |
| 76 | uint32_t frames_encoded = 0; |
Henrik Boström | 5684af5 | 2019-04-02 15:05:21 +0200 | [diff] [blame] | 77 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime |
| 78 | uint64_t total_encode_time_ms = 0; |
Henrik Boström | 23aff9b | 2019-05-20 15:15:38 +0200 | [diff] [blame] | 79 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget |
| 80 | uint64_t total_encoded_bytes_target = 0; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 81 | uint32_t frames_dropped_by_capturer = 0; |
| 82 | uint32_t frames_dropped_by_encoder_queue = 0; |
| 83 | uint32_t frames_dropped_by_rate_limiter = 0; |
| 84 | uint32_t frames_dropped_by_encoder = 0; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 85 | absl::optional<uint64_t> qp_sum; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 86 | // Bitrate the encoder is currently configured to use due to bandwidth |
| 87 | // limitations. |
| 88 | int target_media_bitrate_bps = 0; |
| 89 | // Bitrate the encoder is actually producing. |
| 90 | int media_bitrate_bps = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 91 | bool suspended = false; |
| 92 | bool bw_limited_resolution = false; |
| 93 | bool cpu_limited_resolution = false; |
| 94 | bool bw_limited_framerate = false; |
| 95 | bool cpu_limited_framerate = false; |
Henrik Boström | ce33b6a | 2019-05-28 17:42:38 +0200 | [diff] [blame] | 96 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason |
| 97 | QualityLimitationReason quality_limitation_reason = |
| 98 | QualityLimitationReason::kNone; |
| 99 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations |
| 100 | std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms; |
Evan Shrubsole | cc62b16 | 2019-09-09 11:26:45 +0200 | [diff] [blame] | 101 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges |
| 102 | uint32_t quality_limitation_resolution_changes = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 103 | // Total number of times resolution as been requested to be changed due to |
| 104 | // CPU/quality adaptation. |
| 105 | int number_of_cpu_adapt_changes = 0; |
| 106 | int number_of_quality_adapt_changes = 0; |
Åsa Persson | c3ed630 | 2017-11-16 14:04:52 +0100 | [diff] [blame] | 107 | bool has_entered_low_resolution = false; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 108 | std::map<uint32_t, StreamStats> substreams; |
ilnik | 50864a8 | 2017-09-06 12:32:35 -0700 | [diff] [blame] | 109 | webrtc::VideoContentType content_type = |
| 110 | webrtc::VideoContentType::UNSPECIFIED; |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 111 | uint32_t huge_frames_sent = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct Config { |
| 115 | public: |
| 116 | Config() = delete; |
| 117 | Config(Config&&); |
| 118 | explicit Config(Transport* send_transport); |
| 119 | |
| 120 | Config& operator=(Config&&); |
| 121 | Config& operator=(const Config&) = delete; |
| 122 | |
| 123 | ~Config(); |
| 124 | |
| 125 | // Mostly used by tests. Avoid creating copies if you can. |
| 126 | Config Copy() const { return Config(*this); } |
| 127 | |
| 128 | std::string ToString() const; |
| 129 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 130 | RtpConfig rtp; |
| 131 | |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 132 | VideoStreamEncoderSettings encoder_settings; |
| 133 | |
Jiawei Ou | 5571812 | 2018-11-09 13:17:39 -0800 | [diff] [blame] | 134 | // Time interval between RTCP report for video |
| 135 | int rtcp_report_interval_ms = 1000; |
Jiawei Ou | 3587b83 | 2018-01-31 22:08:26 -0800 | [diff] [blame] | 136 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 137 | // Transport for outgoing packets. |
| 138 | Transport* send_transport = nullptr; |
| 139 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 140 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 141 | // this many milliseconds, if possible, earlier than expected render time. |
| 142 | // Only valid if |local_renderer| is set. |
| 143 | int render_delay_ms = 0; |
| 144 | |
| 145 | // Target delay in milliseconds. A positive value indicates this stream is |
| 146 | // used for streaming instead of a real-time call. |
| 147 | int target_delay_ms = 0; |
| 148 | |
| 149 | // True if the stream should be suspended when the available bitrate fall |
| 150 | // below the minimum configured bitrate. If this variable is false, the |
| 151 | // stream may send at a rate higher than the estimated available bitrate. |
| 152 | bool suspend_below_min_bitrate = false; |
| 153 | |
| 154 | // Enables periodic bandwidth probing in application-limited region. |
| 155 | bool periodic_alr_bandwidth_probing = false; |
| 156 | |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 157 | // An optional custom frame encryptor that allows the entire frame to be |
| 158 | // encrypted in whatever way the caller chooses. This is not required by |
| 159 | // default. |
| 160 | rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor; |
| 161 | |
| 162 | // Per PeerConnection cryptography options. |
| 163 | CryptoOptions crypto_options; |
| 164 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 165 | private: |
| 166 | // Access to the copy constructor is private to force use of the Copy() |
| 167 | // method for those exceptional cases where we do use it. |
| 168 | Config(const Config&); |
| 169 | }; |
| 170 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 171 | // Updates the sending state for all simulcast layers that the video send |
| 172 | // stream owns. This can mean updating the activity one or for multiple |
| 173 | // layers. The ordering of active layers is the order in which the |
| 174 | // rtp modules are stored in the VideoSendStream. |
| 175 | // Note: This starts stream activity if it is inactive and one of the layers |
| 176 | // is active. This stops stream activity if it is active and all layers are |
| 177 | // inactive. |
| 178 | virtual void UpdateActiveSimulcastLayers( |
| 179 | const std::vector<bool> active_layers) = 0; |
| 180 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 181 | // Starts stream activity. |
| 182 | // When a stream is active, it can receive, process and deliver packets. |
| 183 | virtual void Start() = 0; |
| 184 | // Stops stream activity. |
| 185 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 186 | virtual void Stop() = 0; |
| 187 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 188 | virtual void SetSource( |
| 189 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source, |
| 190 | const DegradationPreference& degradation_preference) = 0; |
| 191 | |
| 192 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 193 | // in the config. Encoder settings are passed on to the encoder instance along |
| 194 | // with the VideoStream settings. |
| 195 | virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0; |
| 196 | |
| 197 | virtual Stats GetStats() = 0; |
| 198 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 199 | protected: |
| 200 | virtual ~VideoSendStream() {} |
| 201 | }; |
| 202 | |
| 203 | } // namespace webrtc |
| 204 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 205 | #endif // CALL_VIDEO_SEND_STREAM_H_ |