blob: 86e5052151a5fed82b28ab4eefb0fa666b24b3d7 [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>
Markus Handell269ac812019-12-03 14:31:45 +010018#include <utility>
aleloi440b6d92017-08-22 05:43:23 -070019#include <vector>
20
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"
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"
Markus Handell269ac812019-12-03 14:31:45 +010025#include "api/video/recordable_encoded_frame.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010026#include "api/video/video_content_type.h"
Niels Möllera8370302019-09-02 15:16:49 +020027#include "api/video/video_frame.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"
Tommi1c1f5402021-06-14 10:54:20 +020031#include "call/receive_stream.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "call/rtp_config.h"
Niels Möllera8327d42020-08-25 10:28:50 +020033#include "common_video/frame_counts.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
Tommi1c1f5402021-06-14 10:54:20 +020042class VideoReceiveStream : public MediaReceiveStream {
aleloi440b6d92017-08-22 05:43:23 -070043 public:
Markus Handell269ac812019-12-03 14:31:45 +010044 // Class for handling moving in/out recording state.
45 struct RecordingState {
46 RecordingState() = default;
47 explicit RecordingState(
48 std::function<void(const RecordableEncodedFrame&)> callback)
49 : callback(std::move(callback)) {}
50
51 // Callback stored from the VideoReceiveStream. The VideoReceiveStream
52 // client should not interpret the attribute.
53 std::function<void(const RecordableEncodedFrame&)> callback;
Markus Handell269ac812019-12-03 14:31:45 +010054 // Memento of when a keyframe request was last sent. The VideoReceiveStream
55 // client should not interpret the attribute.
56 absl::optional<int64_t> last_keyframe_request_ms;
57 };
58
aleloi440b6d92017-08-22 05:43:23 -070059 // TODO(mflodman) Move all these settings to VideoDecoder and move the
60 // declaration to common_types.h.
61 struct Decoder {
Tommib42ced42021-07-01 12:21:21 +020062 Decoder(SdpVideoFormat video_format, int payload_type);
aleloi440b6d92017-08-22 05:43:23 -070063 Decoder();
64 Decoder(const Decoder&);
65 ~Decoder();
Tommib42ced42021-07-01 12:21:21 +020066
67 bool operator==(const Decoder& other) const;
68
aleloi440b6d92017-08-22 05:43:23 -070069 std::string ToString() const;
70
Niels Möllercb7e1d22018-09-11 15:56:04 +020071 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 05:43:23 -070072
73 // Received RTP packets with this payload type will be sent to this decoder
74 // instance.
75 int payload_type = 0;
aleloi440b6d92017-08-22 05:43:23 -070076 };
77
78 struct Stats {
79 Stats();
80 ~Stats();
81 std::string ToString(int64_t time_ms) const;
82
83 int network_frame_rate = 0;
84 int decode_frame_rate = 0;
85 int render_frame_rate = 0;
86 uint32_t frames_rendered = 0;
87
88 // Decoder stats.
89 std::string decoder_implementation_name = "unknown";
90 FrameCounts frame_counts;
91 int decode_ms = 0;
92 int max_decode_ms = 0;
93 int current_delay_ms = 0;
94 int target_delay_ms = 0;
95 int jitter_buffer_ms = 0;
Guido Urdaneta67378412019-05-28 17:38:08 +020096 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferdelay
97 double jitter_buffer_delay_seconds = 0;
98 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferemittedcount
99 uint64_t jitter_buffer_emitted_count = 0;
aleloi440b6d92017-08-22 05:43:23 -0700100 int min_playout_delay_ms = 0;
101 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -0700102 int64_t interframe_delay_max_ms = -1;
Johannes Kron0c141c52019-08-26 15:04:43 +0200103 // Frames dropped due to decoding failures or if the system is too slow.
104 // https://www.w3.org/TR/webrtc-stats/#dom-rtcvideoreceiverstats-framesdropped
105 uint32_t frames_dropped = 0;
aleloi440b6d92017-08-22 05:43:23 -0700106 uint32_t frames_decoded = 0;
Johannes Kronbfd343b2019-07-01 10:07:50 +0200107 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime
108 uint64_t total_decode_time_ms = 0;
Johannes Kron00376e12019-11-25 10:25:42 +0100109 // Total inter frame delay in seconds.
110 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalinterframedelay
111 double total_inter_frame_delay = 0;
112 // Total squared inter frame delay in seconds^2.
113 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalsqauredinterframedelay
114 double total_squared_inter_frame_delay = 0;
Benjamin Wright514f0842018-12-10 09:55:17 -0800115 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200116 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -0700117
118 int current_payload_type = -1;
119
120 int total_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -0700121
122 int width = 0;
123 int height = 0;
124
Sergey Silkin02371062019-01-31 16:45:42 +0100125 uint32_t freeze_count = 0;
126 uint32_t pause_count = 0;
127 uint32_t total_freezes_duration_ms = 0;
128 uint32_t total_pauses_duration_ms = 0;
129 uint32_t total_frames_duration_ms = 0;
130 double sum_squared_frame_durations = 0.0;
131
ilnik2e1b40b2017-09-04 07:57:17 -0700132 VideoContentType content_type = VideoContentType::UNSPECIFIED;
133
Åsa Perssonfcf79cc2019-10-22 15:23:44 +0200134 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
135 absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
aleloi440b6d92017-08-22 05:43:23 -0700136 int sync_offset_ms = std::numeric_limits<int>::max();
137
138 uint32_t ssrc = 0;
139 std::string c_name;
Niels Möllerd77cc242019-08-22 09:40:25 +0200140 RtpReceiveStats rtp_stats;
aleloi440b6d92017-08-22 05:43:23 -0700141 RtcpPacketTypeCounter rtcp_packet_type_counts;
ilnik75204c52017-09-04 03:35:40 -0700142
143 // Timing frame info: all important timestamps for a full lifetime of a
144 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200145 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700146 };
147
148 struct Config {
149 private:
150 // Access to the copy constructor is private to force use of the Copy()
151 // method for those exceptional cases where we do use it.
152 Config(const Config&);
153
154 public:
155 Config() = delete;
156 Config(Config&&);
Tommi9e2b3152021-06-21 22:15:39 +0200157 Config(Transport* rtcp_send_transport,
158 VideoDecoderFactory* decoder_factory = nullptr);
aleloi440b6d92017-08-22 05:43:23 -0700159 Config& operator=(Config&&);
160 Config& operator=(const Config&) = delete;
161 ~Config();
162
163 // Mostly used by tests. Avoid creating copies if you can.
164 Config Copy() const { return Config(*this); }
165
166 std::string ToString() const;
167
168 // Decoders for every payload that we can receive.
169 std::vector<Decoder> decoders;
170
Philip Eliasson2b068ce2020-08-03 15:55:10 +0000171 // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection).
172 VideoDecoderFactory* decoder_factory = nullptr;
173
aleloi440b6d92017-08-22 05:43:23 -0700174 // Receive-stream specific RTP settings.
Tommi1c1f5402021-06-14 10:54:20 +0200175 struct Rtp : public RtpConfig {
aleloi440b6d92017-08-22 05:43:23 -0700176 Rtp();
177 Rtp(const Rtp&);
178 ~Rtp();
179 std::string ToString() const;
180
Tommi1c1f5402021-06-14 10:54:20 +0200181 // See NackConfig for description.
182 NackConfig nack;
aleloi440b6d92017-08-22 05:43:23 -0700183
184 // See RtcpMode for description.
185 RtcpMode rtcp_mode = RtcpMode::kCompound;
186
187 // Extended RTCP settings.
188 struct RtcpXr {
189 // True if RTCP Receiver Reference Time Report Block extension
190 // (RFC 3611) should be enabled.
191 bool receiver_reference_time_report = false;
192 } rtcp_xr;
193
Elad Alonfadb1812019-05-24 13:40:02 +0200194 // See LntfConfig for description.
195 LntfConfig lntf;
196
nisse3b3622f2017-09-26 02:49:21 -0700197 // Payload types for ULPFEC and RED, respectively.
198 int ulpfec_payload_type = -1;
199 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700200
201 // SSRC for retransmissions.
202 uint32_t rtx_ssrc = 0;
203
204 // Set if the stream is protected using FlexFEC.
205 bool protected_by_flexfec = false;
206
Tomas Gunnarsson8408c992021-02-14 14:19:12 +0100207 // Optional callback sink to support additional packet handlsers such as
208 // FlexFec.
209 RtpPacketSinkInterface* packet_sink_ = nullptr;
210
nisse26e3abb2017-08-25 04:44:25 -0700211 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700212 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700213 std::map<int, int> rtx_associated_payload_types;
nisse26e3abb2017-08-25 04:44:25 -0700214
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +0200215 // Payload types that should be depacketized using raw depacketizer
216 // (payload header will not be parsed and must not be present, additional
217 // meta data is expected to be present in generic frame descriptor
218 // RTP header extension).
219 std::set<int> raw_payload_types;
aleloi440b6d92017-08-22 05:43:23 -0700220 } rtp;
221
222 // Transport for outgoing packets (RTCP).
223 Transport* rtcp_send_transport = nullptr;
224
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
Benjamin Wright192eeec2018-10-17 17:27:25 -0700245 // 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;
Marina Ciocea412a31b2020-02-28 16:02:06 +0100252
253 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
aleloi440b6d92017-08-22 05:43:23 -0700254 };
255
aleloi440b6d92017-08-22 05:43:23 -0700256 // TODO(pbos): Add info on currently-received codec to Stats.
257 virtual Stats GetStats() const = 0;
258
Ruslan Burakov493a6502019-02-27 15:32:48 +0100259 // Sets a base minimum for the playout delay. Base minimum delay sets lower
260 // bound on minimum delay value determining lower bound on playout delay.
261 //
262 // Returns true if value was successfully set, false overwise.
263 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
264
265 // Returns current value of base minimum delay in milliseconds.
266 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
267
Markus Handell269ac812019-12-03 14:31:45 +0100268 // Sets and returns recording state. The old state is moved out
269 // of the video receive stream and returned to the caller, and |state|
270 // is moved in. If the state's callback is set, it will be called with
271 // recordable encoded frames as they arrive.
272 // If |generate_key_frame| is true, the method will generate a key frame.
273 // When the function returns, it's guaranteed that all old callouts
274 // to the returned callback has ceased.
275 // Note: the client should not interpret the returned state's attributes, but
276 // instead treat it as opaque data.
277 virtual RecordingState SetAndGetRecordingState(RecordingState state,
278 bool generate_key_frame) = 0;
279
280 // Cause eventual generation of a key frame from the sender.
281 virtual void GenerateKeyFrame() = 0;
282
aleloi440b6d92017-08-22 05:43:23 -0700283 protected:
284 virtual ~VideoReceiveStream() {}
285};
286
Tomas Gunnarsson8408c992021-02-14 14:19:12 +0100287class DEPRECATED_VideoReceiveStream : public VideoReceiveStream {
288 public:
289 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
290 // sinks, such as FlexFEC, might wish to be informed of all of the packets
291 // a given sink receives (or any set of sinks). They may do so by registering
292 // themselves as secondary sinks.
293 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
294 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
295};
296
aleloi440b6d92017-08-22 05:43:23 -0700297} // namespace webrtc
298
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200299#endif // CALL_VIDEO_RECEIVE_STREAM_H_