blob: 8bd9982bf45b88d02cf433ea142705f0f918890f [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;
aleloi440b6d92017-08-22 05:43:23 -070087 uint32_t frames_decoded = 0;
Benjamin Wright514f0842018-12-10 09:55:17 -080088 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020089 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070090
91 int current_payload_type = -1;
92
93 int total_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -070094
95 int width = 0;
96 int height = 0;
97
Sergey Silkin02371062019-01-31 16:45:42 +010098 uint32_t freeze_count = 0;
99 uint32_t pause_count = 0;
100 uint32_t total_freezes_duration_ms = 0;
101 uint32_t total_pauses_duration_ms = 0;
102 uint32_t total_frames_duration_ms = 0;
103 double sum_squared_frame_durations = 0.0;
104
ilnik2e1b40b2017-09-04 07:57:17 -0700105 VideoContentType content_type = VideoContentType::UNSPECIFIED;
106
aleloi440b6d92017-08-22 05:43:23 -0700107 int sync_offset_ms = std::numeric_limits<int>::max();
108
109 uint32_t ssrc = 0;
110 std::string c_name;
111 StreamDataCounters rtp_stats;
112 RtcpPacketTypeCounter rtcp_packet_type_counts;
113 RtcpStatistics rtcp_stats;
ilnik75204c52017-09-04 03:35:40 -0700114
115 // Timing frame info: all important timestamps for a full lifetime of a
116 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200117 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700118 };
119
120 struct Config {
121 private:
122 // Access to the copy constructor is private to force use of the Copy()
123 // method for those exceptional cases where we do use it.
124 Config(const Config&);
125
126 public:
127 Config() = delete;
128 Config(Config&&);
Niels Möller46879152019-01-07 15:54:47 +0100129 Config(Transport* rtcp_send_transport,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700130 MediaTransportConfig media_transport_config);
aleloi440b6d92017-08-22 05:43:23 -0700131 explicit Config(Transport* rtcp_send_transport);
132 Config& operator=(Config&&);
133 Config& operator=(const Config&) = delete;
134 ~Config();
135
136 // Mostly used by tests. Avoid creating copies if you can.
137 Config Copy() const { return Config(*this); }
138
139 std::string ToString() const;
140
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700141 MediaTransportInterface* media_transport() const {
142 return media_transport_config.media_transport;
143 }
144
aleloi440b6d92017-08-22 05:43:23 -0700145 // Decoders for every payload that we can receive.
146 std::vector<Decoder> decoders;
147
148 // Receive-stream specific RTP settings.
149 struct Rtp {
150 Rtp();
151 Rtp(const Rtp&);
152 ~Rtp();
153 std::string ToString() const;
154
155 // Synchronization source (stream identifier) to be received.
156 uint32_t remote_ssrc = 0;
157
158 // Sender SSRC used for sending RTCP (such as receiver reports).
159 uint32_t local_ssrc = 0;
160
161 // See RtcpMode for description.
162 RtcpMode rtcp_mode = RtcpMode::kCompound;
163
164 // Extended RTCP settings.
165 struct RtcpXr {
166 // True if RTCP Receiver Reference Time Report Block extension
167 // (RFC 3611) should be enabled.
168 bool receiver_reference_time_report = false;
169 } rtcp_xr;
170
171 // TODO(nisse): This remb setting is currently set but never
172 // applied. REMB logic is now the responsibility of
173 // PacketRouter, and it will generate REMB feedback if
174 // OnReceiveBitrateChanged is used, which depends on how the
175 // estimators belonging to the ReceiveSideCongestionController
176 // are configured. Decide if this setting should be deleted, and
177 // if it needs to be replaced by a setting in PacketRouter to
178 // disable REMB feedback.
179
180 // See draft-alvestrand-rmcat-remb for information.
181 bool remb = false;
182
183 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
184 bool transport_cc = false;
185
Elad Alonfadb1812019-05-24 13:40:02 +0200186 // See LntfConfig for description.
187 LntfConfig lntf;
188
aleloi440b6d92017-08-22 05:43:23 -0700189 // See NackConfig for description.
190 NackConfig nack;
191
nisse3b3622f2017-09-26 02:49:21 -0700192 // Payload types for ULPFEC and RED, respectively.
193 int ulpfec_payload_type = -1;
194 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700195
196 // SSRC for retransmissions.
197 uint32_t rtx_ssrc = 0;
198
199 // Set if the stream is protected using FlexFEC.
200 bool protected_by_flexfec = false;
201
nisse26e3abb2017-08-25 04:44:25 -0700202 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700203 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700204 std::map<int, int> rtx_associated_payload_types;
nisse26e3abb2017-08-25 04:44:25 -0700205
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +0200206 // Payload types that should be depacketized using raw depacketizer
207 // (payload header will not be parsed and must not be present, additional
208 // meta data is expected to be present in generic frame descriptor
209 // RTP header extension).
210 std::set<int> raw_payload_types;
211
aleloi440b6d92017-08-22 05:43:23 -0700212 // RTP header extensions used for the received stream.
213 std::vector<RtpExtension> extensions;
214 } rtp;
215
216 // Transport for outgoing packets (RTCP).
217 Transport* rtcp_send_transport = nullptr;
218
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700219 MediaTransportConfig media_transport_config;
Niels Möller46879152019-01-07 15:54:47 +0100220
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100221 // Must always be set.
aleloi440b6d92017-08-22 05:43:23 -0700222 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
223
224 // Expected delay needed by the renderer, i.e. the frame will be delivered
225 // this many milliseconds, if possible, earlier than the ideal render time.
aleloi440b6d92017-08-22 05:43:23 -0700226 int render_delay_ms = 10;
227
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100228 // If false, pass frames on to the renderer as soon as they are
aleloi440b6d92017-08-22 05:43:23 -0700229 // available.
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100230 bool enable_prerenderer_smoothing = true;
aleloi440b6d92017-08-22 05:43:23 -0700231
232 // Identifier for an A/V synchronization group. Empty string to disable.
233 // TODO(pbos): Synchronize streams in a sync group, not just video streams
234 // to one of the audio streams.
235 std::string sync_group;
236
aleloi440b6d92017-08-22 05:43:23 -0700237 // Target delay in milliseconds. A positive value indicates this stream is
238 // used for streaming instead of a real-time call.
239 int target_delay_ms = 0;
Niels Möllercbcbc222018-09-28 09:07:24 +0200240
241 // TODO(nisse): Used with VideoDecoderFactory::LegacyCreateVideoDecoder.
242 // Delete when that method is retired.
243 std::string stream_id;
Benjamin Wright192eeec2018-10-17 17:27:25 -0700244
245 // An optional custom frame decryptor that allows the entire frame to be
246 // decrypted in whatever way the caller choses. This is not required by
247 // default.
248 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
249
250 // Per PeerConnection cryptography options.
251 CryptoOptions crypto_options;
aleloi440b6d92017-08-22 05:43:23 -0700252 };
253
254 // Starts stream activity.
255 // When a stream is active, it can receive, process and deliver packets.
256 virtual void Start() = 0;
257 // Stops stream activity.
258 // When a stream is stopped, it can't receive, process or deliver packets.
259 virtual void Stop() = 0;
260
261 // TODO(pbos): Add info on currently-received codec to Stats.
262 virtual Stats GetStats() const = 0;
263
aleloi440b6d92017-08-22 05:43:23 -0700264 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
265 // sinks, such as FlexFEC, might wish to be informed of all of the packets
266 // a given sink receives (or any set of sinks). They may do so by registering
267 // themselves as secondary sinks.
268 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
269 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
270
Jonas Oreland49ac5952018-09-26 16:04:32 +0200271 virtual std::vector<RtpSource> GetSources() const = 0;
272
Ruslan Burakov493a6502019-02-27 15:32:48 +0100273 // Sets a base minimum for the playout delay. Base minimum delay sets lower
274 // bound on minimum delay value determining lower bound on playout delay.
275 //
276 // Returns true if value was successfully set, false overwise.
277 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
278
279 // Returns current value of base minimum delay in milliseconds.
280 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
281
Benjamin Wrighta5564482019-04-03 10:44:18 -0700282 // Allows a FrameDecryptor to be attached to a VideoReceiveStream after
283 // creation without resetting the decoder state.
284 virtual void SetFrameDecryptor(
285 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) = 0;
286
aleloi440b6d92017-08-22 05:43:23 -0700287 protected:
288 virtual ~VideoReceiveStream() {}
289};
290
291} // namespace webrtc
292
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200293#endif // CALL_VIDEO_RECEIVE_STREAM_H_