blob: 962578d60b27ca6b9cd67fbd219e2ee1ddc69ee5 [file] [log] [blame]
aleloi440b6d92017-08-22 05:43:23 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef CALL_VIDEO_SEND_STREAM_H_
12#define CALL_VIDEO_SEND_STREAM_H_
aleloi440b6d92017-08-22 05:43:23 -070013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
aleloi440b6d92017-08-22 05:43:23 -070016#include <map>
17#include <string>
aleloi440b6d92017-08-22 05:43:23 -070018#include <vector>
19
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/call/transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/crypto/crypto_options.h"
Marina Cioceae77912b2020-02-27 16:16:55 +010023#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/rtp_parameters.h"
Yves Gerey988cc082018-10-23 12:03:01 +020025#include "api/video/video_content_type.h"
Niels Möller88be9722018-10-10 10:58:52 +020026#include "api/video/video_frame.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020027#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020028#include "api/video/video_source_interface.h"
Niels Möller213618e2018-07-24 09:29:58 +020029#include "api/video/video_stream_encoder_settings.h"
Niels Möller0a8f4352018-05-18 11:37:23 +020030#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "call/rtp_config.h"
Henrik Boströmce33b6a2019-05-28 17:42:38 +020032#include "common_video/include/quality_limitation_reason.h"
Henrik Boström87e3f9d2019-05-27 10:44:24 +020033#include "modules/rtp_rtcp/include/report_block_data.h"
Niels Möller53382cb2018-11-27 14:05:08 +010034#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010035#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070036
37namespace webrtc {
38
Benjamin Wright192eeec2018-10-17 17:27:25 -070039class FrameEncryptorInterface;
40
aleloi440b6d92017-08-22 05:43:23 -070041class VideoSendStream {
42 public:
43 struct StreamStats {
44 StreamStats();
45 ~StreamStats();
46
47 std::string ToString() const;
48
49 FrameCounts frame_counts;
50 bool is_rtx = false;
51 bool is_flexfec = false;
52 int width = 0;
53 int height = 0;
54 // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
55 int total_bitrate_bps = 0;
56 int retransmit_bitrate_bps = 0;
57 int avg_delay_ms = 0;
58 int max_delay_ms = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +020059 uint64_t total_packet_send_delay_ms = 0;
aleloi440b6d92017-08-22 05:43:23 -070060 StreamDataCounters rtp_stats;
61 RtcpPacketTypeCounter rtcp_packet_type_counts;
62 RtcpStatistics rtcp_stats;
Henrik Boström87e3f9d2019-05-27 10:44:24 +020063 // A snapshot of the most recent Report Block with additional data of
64 // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats.
65 absl::optional<ReportBlockData> report_block_data;
aleloi440b6d92017-08-22 05:43:23 -070066 };
67
68 struct Stats {
69 Stats();
70 ~Stats();
71 std::string ToString(int64_t time_ms) const;
72 std::string encoder_implementation_name = "unknown";
73 int input_frame_rate = 0;
74 int encode_frame_rate = 0;
75 int avg_encode_time_ms = 0;
76 int encode_usage_percent = 0;
77 uint32_t frames_encoded = 0;
Henrik Boström5684af52019-04-02 15:05:21 +020078 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
79 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +020080 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
81 uint64_t total_encoded_bytes_target = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +020082 uint32_t frames_dropped_by_capturer = 0;
83 uint32_t frames_dropped_by_encoder_queue = 0;
84 uint32_t frames_dropped_by_rate_limiter = 0;
Ying Wang9b881ab2020-02-07 14:29:32 +010085 uint32_t frames_dropped_by_congestion_window = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +020086 uint32_t frames_dropped_by_encoder = 0;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020087 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070088 // Bitrate the encoder is currently configured to use due to bandwidth
89 // limitations.
90 int target_media_bitrate_bps = 0;
91 // Bitrate the encoder is actually producing.
92 int media_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -070093 bool suspended = false;
94 bool bw_limited_resolution = false;
95 bool cpu_limited_resolution = false;
96 bool bw_limited_framerate = false;
97 bool cpu_limited_framerate = false;
Henrik Boströmce33b6a2019-05-28 17:42:38 +020098 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
99 QualityLimitationReason quality_limitation_reason =
100 QualityLimitationReason::kNone;
101 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
102 std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms;
Evan Shrubsolecc62b162019-09-09 11:26:45 +0200103 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
104 uint32_t quality_limitation_resolution_changes = 0;
aleloi440b6d92017-08-22 05:43:23 -0700105 // Total number of times resolution as been requested to be changed due to
106 // CPU/quality adaptation.
107 int number_of_cpu_adapt_changes = 0;
108 int number_of_quality_adapt_changes = 0;
Åsa Perssonc3ed6302017-11-16 14:04:52 +0100109 bool has_entered_low_resolution = false;
aleloi440b6d92017-08-22 05:43:23 -0700110 std::map<uint32_t, StreamStats> substreams;
ilnik50864a82017-09-06 12:32:35 -0700111 webrtc::VideoContentType content_type =
112 webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100113 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -0700114 };
115
116 struct Config {
117 public:
118 Config() = delete;
119 Config(Config&&);
120 explicit Config(Transport* send_transport);
121
122 Config& operator=(Config&&);
123 Config& operator=(const Config&) = delete;
124
125 ~Config();
126
127 // Mostly used by tests. Avoid creating copies if you can.
128 Config Copy() const { return Config(*this); }
129
130 std::string ToString() const;
131
Philip Eliasson49d661a2019-06-11 11:55:47 +0000132 RtpConfig rtp;
133
Elad Alon370f93a2019-06-11 14:57:57 +0200134 VideoStreamEncoderSettings encoder_settings;
135
Jiawei Ou55718122018-11-09 13:17:39 -0800136 // Time interval between RTCP report for video
137 int rtcp_report_interval_ms = 1000;
Jiawei Ou3587b832018-01-31 22:08:26 -0800138
aleloi440b6d92017-08-22 05:43:23 -0700139 // Transport for outgoing packets.
140 Transport* send_transport = nullptr;
141
aleloi440b6d92017-08-22 05:43:23 -0700142 // Expected delay needed by the renderer, i.e. the frame will be delivered
143 // this many milliseconds, if possible, earlier than expected render time.
144 // Only valid if |local_renderer| is set.
145 int render_delay_ms = 0;
146
147 // Target delay in milliseconds. A positive value indicates this stream is
148 // used for streaming instead of a real-time call.
149 int target_delay_ms = 0;
150
151 // True if the stream should be suspended when the available bitrate fall
152 // below the minimum configured bitrate. If this variable is false, the
153 // stream may send at a rate higher than the estimated available bitrate.
154 bool suspend_below_min_bitrate = false;
155
156 // Enables periodic bandwidth probing in application-limited region.
157 bool periodic_alr_bandwidth_probing = false;
158
Benjamin Wright192eeec2018-10-17 17:27:25 -0700159 // An optional custom frame encryptor that allows the entire frame to be
160 // encrypted in whatever way the caller chooses. This is not required by
161 // default.
162 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
163
164 // Per PeerConnection cryptography options.
165 CryptoOptions crypto_options;
166
Marina Cioceae77912b2020-02-27 16:16:55 +0100167 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
168
aleloi440b6d92017-08-22 05:43:23 -0700169 private:
170 // Access to the copy constructor is private to force use of the Copy()
171 // method for those exceptional cases where we do use it.
172 Config(const Config&);
173 };
174
Seth Hampsoncc7125f2018-02-02 08:46:16 -0800175 // Updates the sending state for all simulcast layers that the video send
176 // stream owns. This can mean updating the activity one or for multiple
177 // layers. The ordering of active layers is the order in which the
178 // rtp modules are stored in the VideoSendStream.
179 // Note: This starts stream activity if it is inactive and one of the layers
180 // is active. This stops stream activity if it is active and all layers are
181 // inactive.
182 virtual void UpdateActiveSimulcastLayers(
183 const std::vector<bool> active_layers) = 0;
184
aleloi440b6d92017-08-22 05:43:23 -0700185 // Starts stream activity.
186 // When a stream is active, it can receive, process and deliver packets.
187 virtual void Start() = 0;
188 // Stops stream activity.
189 // When a stream is stopped, it can't receive, process or deliver packets.
190 virtual void Stop() = 0;
191
aleloi440b6d92017-08-22 05:43:23 -0700192 virtual void SetSource(
193 rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
194 const DegradationPreference& degradation_preference) = 0;
195
196 // Set which streams to send. Must have at least as many SSRCs as configured
197 // in the config. Encoder settings are passed on to the encoder instance along
198 // with the VideoStream settings.
199 virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
200
201 virtual Stats GetStats() = 0;
202
aleloi440b6d92017-08-22 05:43:23 -0700203 protected:
204 virtual ~VideoSendStream() {}
205};
206
207} // namespace webrtc
208
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200209#endif // CALL_VIDEO_SEND_STREAM_H_