blob: 5daec19449c7f53b97a02a45874124cb9175b850 [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>
aleloi440b6d92017-08-22 05:43:23 -070015#include <map>
16#include <string>
aleloi440b6d92017-08-22 05:43:23 -070017#include <vector>
18
Yves Gerey988cc082018-10-23 12:03:01 +020019#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/call/transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/crypto/crypto_options.h"
Niels Möller46879152019-01-07 15:54:47 +010022#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/rtp_parameters.h"
Yves Gerey988cc082018-10-23 12:03:01 +020024#include "api/video/video_content_type.h"
Niels Möller88be9722018-10-10 10:58:52 +020025#include "api/video/video_frame.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020026#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020027#include "api/video/video_source_interface.h"
Niels Möller213618e2018-07-24 09:29:58 +020028#include "api/video/video_stream_encoder_settings.h"
Niels Möller0a8f4352018-05-18 11:37:23 +020029#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "call/rtp_config.h"
Niels Möller53382cb2018-11-27 14:05:08 +010031#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010032#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070033
34namespace webrtc {
35
Benjamin Wright192eeec2018-10-17 17:27:25 -070036class FrameEncryptorInterface;
37
aleloi440b6d92017-08-22 05:43:23 -070038class 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;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +020071 uint32_t frames_dropped_by_capturer = 0;
72 uint32_t frames_dropped_by_encoder_queue = 0;
73 uint32_t frames_dropped_by_rate_limiter = 0;
74 uint32_t frames_dropped_by_encoder = 0;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020075 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070076 // Bitrate the encoder is currently configured to use due to bandwidth
77 // limitations.
78 int target_media_bitrate_bps = 0;
79 // Bitrate the encoder is actually producing.
80 int media_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -070081 bool suspended = false;
82 bool bw_limited_resolution = false;
83 bool cpu_limited_resolution = false;
84 bool bw_limited_framerate = false;
85 bool cpu_limited_framerate = false;
86 // Total number of times resolution as been requested to be changed due to
87 // CPU/quality adaptation.
88 int number_of_cpu_adapt_changes = 0;
89 int number_of_quality_adapt_changes = 0;
Åsa Perssonc3ed6302017-11-16 14:04:52 +010090 bool has_entered_low_resolution = false;
aleloi440b6d92017-08-22 05:43:23 -070091 std::map<uint32_t, StreamStats> substreams;
ilnik50864a82017-09-06 12:32:35 -070092 webrtc::VideoContentType content_type =
93 webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +010094 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -070095 };
96
97 struct Config {
98 public:
99 Config() = delete;
100 Config(Config&&);
Niels Möller46879152019-01-07 15:54:47 +0100101 Config(Transport* send_transport, MediaTransportInterface* media_transport);
aleloi440b6d92017-08-22 05:43:23 -0700102 explicit Config(Transport* send_transport);
103
104 Config& operator=(Config&&);
105 Config& operator=(const Config&) = delete;
106
107 ~Config();
108
109 // Mostly used by tests. Avoid creating copies if you can.
110 Config Copy() const { return Config(*this); }
111
112 std::string ToString() const;
113
Niels Möller213618e2018-07-24 09:29:58 +0200114 VideoStreamEncoderSettings encoder_settings;
aleloi440b6d92017-08-22 05:43:23 -0700115
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200116 RtpConfig rtp;
aleloi440b6d92017-08-22 05:43:23 -0700117
Jiawei Ou55718122018-11-09 13:17:39 -0800118 // Time interval between RTCP report for video
119 int rtcp_report_interval_ms = 1000;
Jiawei Ou3587b832018-01-31 22:08:26 -0800120
aleloi440b6d92017-08-22 05:43:23 -0700121 // Transport for outgoing packets.
122 Transport* send_transport = nullptr;
123
Niels Möller46879152019-01-07 15:54:47 +0100124 MediaTransportInterface* media_transport = nullptr;
125
aleloi440b6d92017-08-22 05:43:23 -0700126 // Expected delay needed by the renderer, i.e. the frame will be delivered
127 // this many milliseconds, if possible, earlier than expected render time.
128 // Only valid if |local_renderer| is set.
129 int render_delay_ms = 0;
130
131 // Target delay in milliseconds. A positive value indicates this stream is
132 // used for streaming instead of a real-time call.
133 int target_delay_ms = 0;
134
135 // True if the stream should be suspended when the available bitrate fall
136 // below the minimum configured bitrate. If this variable is false, the
137 // stream may send at a rate higher than the estimated available bitrate.
138 bool suspend_below_min_bitrate = false;
139
140 // Enables periodic bandwidth probing in application-limited region.
141 bool periodic_alr_bandwidth_probing = false;
142
Alex Narestb3944f02017-10-13 14:56:18 +0200143 // Track ID as specified during track creation.
144 std::string track_id;
145
Benjamin Wright192eeec2018-10-17 17:27:25 -0700146 // An optional custom frame encryptor that allows the entire frame to be
147 // encrypted in whatever way the caller chooses. This is not required by
148 // default.
149 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
150
151 // Per PeerConnection cryptography options.
152 CryptoOptions crypto_options;
153
aleloi440b6d92017-08-22 05:43:23 -0700154 private:
155 // Access to the copy constructor is private to force use of the Copy()
156 // method for those exceptional cases where we do use it.
157 Config(const Config&);
158 };
159
Seth Hampsoncc7125f2018-02-02 08:46:16 -0800160 // Updates the sending state for all simulcast layers that the video send
161 // stream owns. This can mean updating the activity one or for multiple
162 // layers. The ordering of active layers is the order in which the
163 // rtp modules are stored in the VideoSendStream.
164 // Note: This starts stream activity if it is inactive and one of the layers
165 // is active. This stops stream activity if it is active and all layers are
166 // inactive.
167 virtual void UpdateActiveSimulcastLayers(
168 const std::vector<bool> active_layers) = 0;
169
aleloi440b6d92017-08-22 05:43:23 -0700170 // Starts stream activity.
171 // When a stream is active, it can receive, process and deliver packets.
172 virtual void Start() = 0;
173 // Stops stream activity.
174 // When a stream is stopped, it can't receive, process or deliver packets.
175 virtual void Stop() = 0;
176
aleloi440b6d92017-08-22 05:43:23 -0700177 virtual void SetSource(
178 rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
179 const DegradationPreference& degradation_preference) = 0;
180
181 // Set which streams to send. Must have at least as many SSRCs as configured
182 // in the config. Encoder settings are passed on to the encoder instance along
183 // with the VideoStream settings.
184 virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
185
186 virtual Stats GetStats() = 0;
187
aleloi440b6d92017-08-22 05:43:23 -0700188 protected:
189 virtual ~VideoSendStream() {}
190};
191
192} // namespace webrtc
193
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200194#endif // CALL_VIDEO_SEND_STREAM_H_