blob: fa37fe895f3ff29e2355ab9f567010f4151b4f98 [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_RECEIVE_STREAM_H_
12#define CALL_VIDEO_RECEIVE_STREAM_H_
aleloi440b6d92017-08-22 05:43:23 -070013
14#include <limits>
15#include <map>
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +020016#include <set>
aleloi440b6d92017-08-22 05:43:23 -070017#include <string>
18#include <vector>
19
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"
Anton Sukhanov4f08faa2019-05-21 11:12:57 -070022#include "api/media_transport_config.h"
Niels Möller46879152019-01-07 15:54:47 +010023#include "api/media_transport_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020024#include "api/rtp_headers.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/rtp_parameters.h"
26#include "api/rtp_receiver_interface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010027#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020028#include "api/video/video_sink_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020029#include "api/video/video_timing.h"
Niels Möllercb7e1d22018-09-11 15:56:04 +020030#include "api/video_codecs/sdp_video_format.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "call/rtp_config.h"
Niels Möller53382cb2018-11-27 14:05:08 +010032#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010033#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070034
35namespace webrtc {
36
Benjamin Wright192eeec2018-10-17 17:27:25 -070037class FrameDecryptorInterface;
aleloi440b6d92017-08-22 05:43:23 -070038class RtpPacketSinkInterface;
Niels Möllercbcbc222018-09-28 09:07:24 +020039class VideoDecoderFactory;
aleloi440b6d92017-08-22 05:43:23 -070040
41class VideoReceiveStream {
42 public:
43 // TODO(mflodman) Move all these settings to VideoDecoder and move the
44 // declaration to common_types.h.
45 struct Decoder {
46 Decoder();
47 Decoder(const Decoder&);
48 ~Decoder();
49 std::string ToString() const;
50
Niels Möllercbcbc222018-09-28 09:07:24 +020051 // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection).
52 // TODO(nisse): Move one level out, to VideoReceiveStream::Config, and later
53 // to the configuration of VideoStreamDecoder.
54 VideoDecoderFactory* decoder_factory = nullptr;
Niels Möllercb7e1d22018-09-11 15:56:04 +020055 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 05:43:23 -070056
57 // Received RTP packets with this payload type will be sent to this decoder
58 // instance.
59 int payload_type = 0;
aleloi440b6d92017-08-22 05:43:23 -070060 };
61
62 struct Stats {
63 Stats();
64 ~Stats();
65 std::string ToString(int64_t time_ms) const;
66
67 int network_frame_rate = 0;
68 int decode_frame_rate = 0;
69 int render_frame_rate = 0;
70 uint32_t frames_rendered = 0;
71
72 // Decoder stats.
73 std::string decoder_implementation_name = "unknown";
74 FrameCounts frame_counts;
75 int decode_ms = 0;
76 int max_decode_ms = 0;
77 int current_delay_ms = 0;
78 int target_delay_ms = 0;
79 int jitter_buffer_ms = 0;
Guido Urdaneta67378412019-05-28 17:38:08 +020080 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferdelay
81 double jitter_buffer_delay_seconds = 0;
82 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferemittedcount
83 uint64_t jitter_buffer_emitted_count = 0;
aleloi440b6d92017-08-22 05:43:23 -070084 int min_playout_delay_ms = 0;
85 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -070086 int64_t interframe_delay_max_ms = -1;
Johannes Kron0c141c52019-08-26 15:04:43 +020087 // Frames dropped due to decoding failures or if the system is too slow.
88 // https://www.w3.org/TR/webrtc-stats/#dom-rtcvideoreceiverstats-framesdropped
89 uint32_t frames_dropped = 0;
aleloi440b6d92017-08-22 05:43:23 -070090 uint32_t frames_decoded = 0;
Johannes Kronbfd343b2019-07-01 10:07:50 +020091 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime
92 uint64_t total_decode_time_ms = 0;
Benjamin Wright514f0842018-12-10 09:55:17 -080093 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020094 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070095
96 int current_payload_type = -1;
97
98 int total_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -070099
100 int width = 0;
101 int height = 0;
102
Sergey Silkin02371062019-01-31 16:45:42 +0100103 uint32_t freeze_count = 0;
104 uint32_t pause_count = 0;
105 uint32_t total_freezes_duration_ms = 0;
106 uint32_t total_pauses_duration_ms = 0;
107 uint32_t total_frames_duration_ms = 0;
108 double sum_squared_frame_durations = 0.0;
109
ilnik2e1b40b2017-09-04 07:57:17 -0700110 VideoContentType content_type = VideoContentType::UNSPECIFIED;
111
aleloi440b6d92017-08-22 05:43:23 -0700112 int sync_offset_ms = std::numeric_limits<int>::max();
113
114 uint32_t ssrc = 0;
115 std::string c_name;
Niels Möllerd77cc242019-08-22 09:40:25 +0200116 RtpReceiveStats rtp_stats;
aleloi440b6d92017-08-22 05:43:23 -0700117 RtcpPacketTypeCounter rtcp_packet_type_counts;
ilnik75204c52017-09-04 03:35:40 -0700118
119 // Timing frame info: all important timestamps for a full lifetime of a
120 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200121 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700122 };
123
124 struct Config {
125 private:
126 // Access to the copy constructor is private to force use of the Copy()
127 // method for those exceptional cases where we do use it.
128 Config(const Config&);
129
130 public:
131 Config() = delete;
132 Config(Config&&);
Niels Möller46879152019-01-07 15:54:47 +0100133 Config(Transport* rtcp_send_transport,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700134 MediaTransportConfig media_transport_config);
aleloi440b6d92017-08-22 05:43:23 -0700135 explicit Config(Transport* rtcp_send_transport);
136 Config& operator=(Config&&);
137 Config& operator=(const Config&) = delete;
138 ~Config();
139
140 // Mostly used by tests. Avoid creating copies if you can.
141 Config Copy() const { return Config(*this); }
142
143 std::string ToString() const;
144
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700145 MediaTransportInterface* media_transport() const {
146 return media_transport_config.media_transport;
147 }
148
aleloi440b6d92017-08-22 05:43:23 -0700149 // Decoders for every payload that we can receive.
150 std::vector<Decoder> decoders;
151
152 // Receive-stream specific RTP settings.
153 struct Rtp {
154 Rtp();
155 Rtp(const Rtp&);
156 ~Rtp();
157 std::string ToString() const;
158
159 // Synchronization source (stream identifier) to be received.
160 uint32_t remote_ssrc = 0;
161
162 // Sender SSRC used for sending RTCP (such as receiver reports).
163 uint32_t local_ssrc = 0;
164
165 // See RtcpMode for description.
166 RtcpMode rtcp_mode = RtcpMode::kCompound;
167
168 // Extended RTCP settings.
169 struct RtcpXr {
170 // True if RTCP Receiver Reference Time Report Block extension
171 // (RFC 3611) should be enabled.
172 bool receiver_reference_time_report = false;
173 } rtcp_xr;
174
175 // TODO(nisse): This remb setting is currently set but never
176 // applied. REMB logic is now the responsibility of
177 // PacketRouter, and it will generate REMB feedback if
178 // OnReceiveBitrateChanged is used, which depends on how the
179 // estimators belonging to the ReceiveSideCongestionController
180 // are configured. Decide if this setting should be deleted, and
181 // if it needs to be replaced by a setting in PacketRouter to
182 // disable REMB feedback.
183
184 // See draft-alvestrand-rmcat-remb for information.
185 bool remb = false;
186
187 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
188 bool transport_cc = false;
189
Elad Alonfadb1812019-05-24 13:40:02 +0200190 // See LntfConfig for description.
191 LntfConfig lntf;
192
aleloi440b6d92017-08-22 05:43:23 -0700193 // See NackConfig for description.
194 NackConfig nack;
195
nisse3b3622f2017-09-26 02:49:21 -0700196 // Payload types for ULPFEC and RED, respectively.
197 int ulpfec_payload_type = -1;
198 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700199
200 // SSRC for retransmissions.
201 uint32_t rtx_ssrc = 0;
202
203 // Set if the stream is protected using FlexFEC.
204 bool protected_by_flexfec = false;
205
nisse26e3abb2017-08-25 04:44:25 -0700206 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700207 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700208 std::map<int, int> rtx_associated_payload_types;
nisse26e3abb2017-08-25 04:44:25 -0700209
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +0200210 // Payload types that should be depacketized using raw depacketizer
211 // (payload header will not be parsed and must not be present, additional
212 // meta data is expected to be present in generic frame descriptor
213 // RTP header extension).
214 std::set<int> raw_payload_types;
215
aleloi440b6d92017-08-22 05:43:23 -0700216 // RTP header extensions used for the received stream.
217 std::vector<RtpExtension> extensions;
218 } rtp;
219
220 // Transport for outgoing packets (RTCP).
221 Transport* rtcp_send_transport = nullptr;
222
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700223 MediaTransportConfig media_transport_config;
Niels Möller46879152019-01-07 15:54:47 +0100224
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100225 // Must always be set.
aleloi440b6d92017-08-22 05:43:23 -0700226 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
227
228 // Expected delay needed by the renderer, i.e. the frame will be delivered
229 // this many milliseconds, if possible, earlier than the ideal render time.
aleloi440b6d92017-08-22 05:43:23 -0700230 int render_delay_ms = 10;
231
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100232 // If false, pass frames on to the renderer as soon as they are
aleloi440b6d92017-08-22 05:43:23 -0700233 // available.
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100234 bool enable_prerenderer_smoothing = true;
aleloi440b6d92017-08-22 05:43:23 -0700235
236 // Identifier for an A/V synchronization group. Empty string to disable.
237 // TODO(pbos): Synchronize streams in a sync group, not just video streams
238 // to one of the audio streams.
239 std::string sync_group;
240
aleloi440b6d92017-08-22 05:43:23 -0700241 // Target delay in milliseconds. A positive value indicates this stream is
242 // used for streaming instead of a real-time call.
243 int target_delay_ms = 0;
Niels Möllercbcbc222018-09-28 09:07:24 +0200244
245 // TODO(nisse): Used with VideoDecoderFactory::LegacyCreateVideoDecoder.
246 // Delete when that method is retired.
247 std::string stream_id;
Benjamin Wright192eeec2018-10-17 17:27:25 -0700248
249 // An optional custom frame decryptor that allows the entire frame to be
250 // decrypted in whatever way the caller choses. This is not required by
251 // default.
252 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
253
254 // Per PeerConnection cryptography options.
255 CryptoOptions crypto_options;
aleloi440b6d92017-08-22 05:43:23 -0700256 };
257
258 // Starts stream activity.
259 // When a stream is active, it can receive, process and deliver packets.
260 virtual void Start() = 0;
261 // Stops stream activity.
262 // When a stream is stopped, it can't receive, process or deliver packets.
263 virtual void Stop() = 0;
264
265 // TODO(pbos): Add info on currently-received codec to Stats.
266 virtual Stats GetStats() const = 0;
267
aleloi440b6d92017-08-22 05:43:23 -0700268 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
269 // sinks, such as FlexFEC, might wish to be informed of all of the packets
270 // a given sink receives (or any set of sinks). They may do so by registering
271 // themselves as secondary sinks.
272 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
273 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
274
Jonas Oreland49ac5952018-09-26 16:04:32 +0200275 virtual std::vector<RtpSource> GetSources() const = 0;
276
Ruslan Burakov493a6502019-02-27 15:32:48 +0100277 // Sets a base minimum for the playout delay. Base minimum delay sets lower
278 // bound on minimum delay value determining lower bound on playout delay.
279 //
280 // Returns true if value was successfully set, false overwise.
281 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
282
283 // Returns current value of base minimum delay in milliseconds.
284 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
285
Benjamin Wrighta5564482019-04-03 10:44:18 -0700286 // Allows a FrameDecryptor to be attached to a VideoReceiveStream after
287 // creation without resetting the decoder state.
288 virtual void SetFrameDecryptor(
289 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) = 0;
290
aleloi440b6d92017-08-22 05:43:23 -0700291 protected:
292 virtual ~VideoReceiveStream() {}
293};
294
295} // namespace webrtc
296
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200297#endif // CALL_VIDEO_RECEIVE_STREAM_H_