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