blob: 2959f67c0deacd2f7e894635e3d0ff6d66612523 [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"
Niels Möllera8370302019-09-02 15:16:49 +020022#include "api/crypto/frame_decryptor_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020023#include "api/rtp_headers.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/rtp_parameters.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020025#include "api/transport/media/media_transport_config.h"
26#include "api/transport/media/media_transport_interface.h"
Niels Möllera8370302019-09-02 15:16:49 +020027#include "api/transport/rtp/rtp_source.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010028#include "api/video/video_content_type.h"
Niels Möllera8370302019-09-02 15:16:49 +020029#include "api/video/video_frame.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020030#include "api/video/video_sink_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020031#include "api/video/video_timing.h"
Niels Möllercb7e1d22018-09-11 15:56:04 +020032#include "api/video_codecs/sdp_video_format.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "call/rtp_config.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
39class RtpPacketSinkInterface;
Niels Möllercbcbc222018-09-28 09:07:24 +020040class VideoDecoderFactory;
aleloi440b6d92017-08-22 05:43:23 -070041
42class VideoReceiveStream {
43 public:
44 // TODO(mflodman) Move all these settings to VideoDecoder and move the
45 // declaration to common_types.h.
46 struct Decoder {
47 Decoder();
48 Decoder(const Decoder&);
49 ~Decoder();
50 std::string ToString() const;
51
Niels Möllercbcbc222018-09-28 09:07:24 +020052 // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection).
53 // TODO(nisse): Move one level out, to VideoReceiveStream::Config, and later
54 // to the configuration of VideoStreamDecoder.
55 VideoDecoderFactory* decoder_factory = nullptr;
Niels Möllercb7e1d22018-09-11 15:56:04 +020056 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 05:43:23 -070057
58 // Received RTP packets with this payload type will be sent to this decoder
59 // instance.
60 int payload_type = 0;
aleloi440b6d92017-08-22 05:43:23 -070061 };
62
63 struct Stats {
64 Stats();
65 ~Stats();
66 std::string ToString(int64_t time_ms) const;
67
68 int network_frame_rate = 0;
69 int decode_frame_rate = 0;
70 int render_frame_rate = 0;
71 uint32_t frames_rendered = 0;
72
73 // Decoder stats.
74 std::string decoder_implementation_name = "unknown";
75 FrameCounts frame_counts;
76 int decode_ms = 0;
77 int max_decode_ms = 0;
78 int current_delay_ms = 0;
79 int target_delay_ms = 0;
80 int jitter_buffer_ms = 0;
Guido Urdaneta67378412019-05-28 17:38:08 +020081 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferdelay
82 double jitter_buffer_delay_seconds = 0;
83 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferemittedcount
84 uint64_t jitter_buffer_emitted_count = 0;
aleloi440b6d92017-08-22 05:43:23 -070085 int min_playout_delay_ms = 0;
86 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -070087 int64_t interframe_delay_max_ms = -1;
Johannes Kron0c141c52019-08-26 15:04:43 +020088 // Frames dropped due to decoding failures or if the system is too slow.
89 // https://www.w3.org/TR/webrtc-stats/#dom-rtcvideoreceiverstats-framesdropped
90 uint32_t frames_dropped = 0;
aleloi440b6d92017-08-22 05:43:23 -070091 uint32_t frames_decoded = 0;
Johannes Kronbfd343b2019-07-01 10:07:50 +020092 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime
93 uint64_t total_decode_time_ms = 0;
Johannes Kron00376e12019-11-25 10:25:42 +010094 // Total inter frame delay in seconds.
95 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalinterframedelay
96 double total_inter_frame_delay = 0;
97 // Total squared inter frame delay in seconds^2.
98 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalsqauredinterframedelay
99 double total_squared_inter_frame_delay = 0;
Benjamin Wright514f0842018-12-10 09:55:17 -0800100 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200101 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -0700102
103 int current_payload_type = -1;
104
105 int total_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -0700106
107 int width = 0;
108 int height = 0;
109
Sergey Silkin02371062019-01-31 16:45:42 +0100110 uint32_t freeze_count = 0;
111 uint32_t pause_count = 0;
112 uint32_t total_freezes_duration_ms = 0;
113 uint32_t total_pauses_duration_ms = 0;
114 uint32_t total_frames_duration_ms = 0;
115 double sum_squared_frame_durations = 0.0;
116
ilnik2e1b40b2017-09-04 07:57:17 -0700117 VideoContentType content_type = VideoContentType::UNSPECIFIED;
118
Åsa Perssonfcf79cc2019-10-22 15:23:44 +0200119 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
120 absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
aleloi440b6d92017-08-22 05:43:23 -0700121 int sync_offset_ms = std::numeric_limits<int>::max();
122
123 uint32_t ssrc = 0;
124 std::string c_name;
Niels Möllerd77cc242019-08-22 09:40:25 +0200125 RtpReceiveStats rtp_stats;
aleloi440b6d92017-08-22 05:43:23 -0700126 RtcpPacketTypeCounter rtcp_packet_type_counts;
ilnik75204c52017-09-04 03:35:40 -0700127
128 // Timing frame info: all important timestamps for a full lifetime of a
129 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200130 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700131 };
132
133 struct Config {
134 private:
135 // Access to the copy constructor is private to force use of the Copy()
136 // method for those exceptional cases where we do use it.
137 Config(const Config&);
138
139 public:
140 Config() = delete;
141 Config(Config&&);
Niels Möller46879152019-01-07 15:54:47 +0100142 Config(Transport* rtcp_send_transport,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700143 MediaTransportConfig media_transport_config);
aleloi440b6d92017-08-22 05:43:23 -0700144 explicit Config(Transport* rtcp_send_transport);
145 Config& operator=(Config&&);
146 Config& operator=(const Config&) = delete;
147 ~Config();
148
149 // Mostly used by tests. Avoid creating copies if you can.
150 Config Copy() const { return Config(*this); }
151
152 std::string ToString() const;
153
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700154 MediaTransportInterface* media_transport() const {
155 return media_transport_config.media_transport;
156 }
157
aleloi440b6d92017-08-22 05:43:23 -0700158 // Decoders for every payload that we can receive.
159 std::vector<Decoder> decoders;
160
161 // Receive-stream specific RTP settings.
162 struct Rtp {
163 Rtp();
164 Rtp(const Rtp&);
165 ~Rtp();
166 std::string ToString() const;
167
168 // Synchronization source (stream identifier) to be received.
169 uint32_t remote_ssrc = 0;
170
171 // Sender SSRC used for sending RTCP (such as receiver reports).
172 uint32_t local_ssrc = 0;
173
174 // See RtcpMode for description.
175 RtcpMode rtcp_mode = RtcpMode::kCompound;
176
177 // Extended RTCP settings.
178 struct RtcpXr {
179 // True if RTCP Receiver Reference Time Report Block extension
180 // (RFC 3611) should be enabled.
181 bool receiver_reference_time_report = false;
182 } rtcp_xr;
183
aleloi440b6d92017-08-22 05:43:23 -0700184 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
185 bool transport_cc = false;
186
Elad Alonfadb1812019-05-24 13:40:02 +0200187 // See LntfConfig for description.
188 LntfConfig lntf;
189
aleloi440b6d92017-08-22 05:43:23 -0700190 // See NackConfig for description.
191 NackConfig nack;
192
nisse3b3622f2017-09-26 02:49:21 -0700193 // Payload types for ULPFEC and RED, respectively.
194 int ulpfec_payload_type = -1;
195 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700196
197 // SSRC for retransmissions.
198 uint32_t rtx_ssrc = 0;
199
200 // Set if the stream is protected using FlexFEC.
201 bool protected_by_flexfec = false;
202
nisse26e3abb2017-08-25 04:44:25 -0700203 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700204 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700205 std::map<int, int> rtx_associated_payload_types;
nisse26e3abb2017-08-25 04:44:25 -0700206
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +0200207 // Payload types that should be depacketized using raw depacketizer
208 // (payload header will not be parsed and must not be present, additional
209 // meta data is expected to be present in generic frame descriptor
210 // RTP header extension).
211 std::set<int> raw_payload_types;
212
aleloi440b6d92017-08-22 05:43:23 -0700213 // RTP header extensions used for the received stream.
214 std::vector<RtpExtension> extensions;
215 } rtp;
216
217 // Transport for outgoing packets (RTCP).
218 Transport* rtcp_send_transport = nullptr;
219
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700220 MediaTransportConfig media_transport_config;
Niels Möller46879152019-01-07 15:54:47 +0100221
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100222 // Must always be set.
aleloi440b6d92017-08-22 05:43:23 -0700223 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
224
225 // Expected delay needed by the renderer, i.e. the frame will be delivered
226 // this many milliseconds, if possible, earlier than the ideal render time.
aleloi440b6d92017-08-22 05:43:23 -0700227 int render_delay_ms = 10;
228
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100229 // If false, pass frames on to the renderer as soon as they are
aleloi440b6d92017-08-22 05:43:23 -0700230 // available.
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100231 bool enable_prerenderer_smoothing = true;
aleloi440b6d92017-08-22 05:43:23 -0700232
233 // Identifier for an A/V synchronization group. Empty string to disable.
234 // TODO(pbos): Synchronize streams in a sync group, not just video streams
235 // to one of the audio streams.
236 std::string sync_group;
237
aleloi440b6d92017-08-22 05:43:23 -0700238 // Target delay in milliseconds. A positive value indicates this stream is
239 // used for streaming instead of a real-time call.
240 int target_delay_ms = 0;
Niels Möllercbcbc222018-09-28 09:07:24 +0200241
242 // TODO(nisse): Used with VideoDecoderFactory::LegacyCreateVideoDecoder.
243 // Delete when that method is retired.
244 std::string stream_id;
Benjamin Wright192eeec2018-10-17 17:27:25 -0700245
246 // An optional custom frame decryptor that allows the entire frame to be
247 // decrypted in whatever way the caller choses. This is not required by
248 // default.
249 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
250
251 // Per PeerConnection cryptography options.
252 CryptoOptions crypto_options;
aleloi440b6d92017-08-22 05:43:23 -0700253 };
254
255 // Starts stream activity.
256 // When a stream is active, it can receive, process and deliver packets.
257 virtual void Start() = 0;
258 // Stops stream activity.
259 // When a stream is stopped, it can't receive, process or deliver packets.
260 virtual void Stop() = 0;
261
262 // TODO(pbos): Add info on currently-received codec to Stats.
263 virtual Stats GetStats() const = 0;
264
aleloi440b6d92017-08-22 05:43:23 -0700265 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
266 // sinks, such as FlexFEC, might wish to be informed of all of the packets
267 // a given sink receives (or any set of sinks). They may do so by registering
268 // themselves as secondary sinks.
269 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
270 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
271
Jonas Oreland49ac5952018-09-26 16:04:32 +0200272 virtual std::vector<RtpSource> GetSources() const = 0;
273
Ruslan Burakov493a6502019-02-27 15:32:48 +0100274 // Sets a base minimum for the playout delay. Base minimum delay sets lower
275 // bound on minimum delay value determining lower bound on playout delay.
276 //
277 // Returns true if value was successfully set, false overwise.
278 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
279
280 // Returns current value of base minimum delay in milliseconds.
281 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
282
Benjamin Wrighta5564482019-04-03 10:44:18 -0700283 // Allows a FrameDecryptor to be attached to a VideoReceiveStream after
284 // creation without resetting the decoder state.
285 virtual void SetFrameDecryptor(
286 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) = 0;
287
aleloi440b6d92017-08-22 05:43:23 -0700288 protected:
289 virtual ~VideoReceiveStream() {}
290};
291
292} // namespace webrtc
293
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200294#endif // CALL_VIDEO_RECEIVE_STREAM_H_