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