blob: 3dbf66e1b14c8541ef8268081552176f21d14bc6 [file] [log] [blame]
aleloi440b6d92017-08-22 12:43:231/*
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 04:47:3111#ifndef CALL_VIDEO_RECEIVE_STREAM_H_
12#define CALL_VIDEO_RECEIVE_STREAM_H_
aleloi440b6d92017-08-22 12:43:2313
14#include <limits>
15#include <map>
Mirta Dvornicicfe68daa2019-05-23 11:21:1216#include <set>
aleloi440b6d92017-08-22 12:43:2317#include <string>
Markus Handell269ac812019-12-03 13:31:4518#include <utility>
aleloi440b6d92017-08-22 12:43:2319#include <vector>
20
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "api/call/transport.h"
Steve Anton10542f22019-01-11 17:11:0022#include "api/crypto/crypto_options.h"
Yves Gerey665174f2018-06-19 13:03:0523#include "api/rtp_headers.h"
Steve Anton10542f22019-01-11 17:11:0024#include "api/rtp_parameters.h"
Markus Handell269ac812019-12-03 13:31:4525#include "api/video/recordable_encoded_frame.h"
Patrik Höglund3e113432017-12-15 13:40:1026#include "api/video/video_content_type.h"
Niels Möllera8370302019-09-02 13:16:4927#include "api/video/video_frame.h"
Niels Möllerc6ce9c52018-05-11 09:15:3028#include "api/video/video_sink_interface.h"
Yves Gerey665174f2018-06-19 13:03:0529#include "api/video/video_timing.h"
Niels Möllercb7e1d22018-09-11 13:56:0430#include "api/video_codecs/sdp_video_format.h"
Tommi1c1f5402021-06-14 08:54:2031#include "call/receive_stream.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3132#include "call/rtp_config.h"
Niels Möllera8327d42020-08-25 08:28:5033#include "common_video/frame_counts.h"
Niels Möller53382cb2018-11-27 13:05:0834#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 13:40:1035#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 12:43:2336
37namespace webrtc {
38
39class RtpPacketSinkInterface;
Niels Möllercbcbc222018-09-28 07:07:2440class VideoDecoderFactory;
aleloi440b6d92017-08-22 12:43:2341
Tommif6f45432022-05-20 13:21:2042class VideoReceiveStreamInterface : public MediaReceiveStreamInterface {
aleloi440b6d92017-08-22 12:43:2343 public:
Markus Handell269ac812019-12-03 13:31:4544 // 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
Tommif6f45432022-05-20 13:21:2051 // Callback stored from the VideoReceiveStreamInterface. The
52 // VideoReceiveStreamInterface client should not interpret the attribute.
Markus Handell269ac812019-12-03 13:31:4553 std::function<void(const RecordableEncodedFrame&)> callback;
Tommif6f45432022-05-20 13:21:2054 // Memento of when a keyframe request was last sent. The
55 // VideoReceiveStreamInterface client should not interpret the attribute.
Markus Handell269ac812019-12-03 13:31:4556 absl::optional<int64_t> last_keyframe_request_ms;
57 };
58
aleloi440b6d92017-08-22 12:43:2359 // TODO(mflodman) Move all these settings to VideoDecoder and move the
60 // declaration to common_types.h.
61 struct Decoder {
Tommib42ced42021-07-01 10:21:2162 Decoder(SdpVideoFormat video_format, int payload_type);
aleloi440b6d92017-08-22 12:43:2363 Decoder();
64 Decoder(const Decoder&);
65 ~Decoder();
Tommib42ced42021-07-01 10:21:2166
67 bool operator==(const Decoder& other) const;
68
aleloi440b6d92017-08-22 12:43:2369 std::string ToString() const;
70
Niels Möllercb7e1d22018-09-11 13:56:0471 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 12:43:2372
73 // Received RTP packets with this payload type will be sent to this decoder
74 // instance.
75 int payload_type = 0;
aleloi440b6d92017-08-22 12:43:2376 };
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 15:38:0896 // 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 12:43:23100 int min_playout_delay_ms = 0;
101 int render_delay_ms = 10;
ilnika79cc282017-08-23 12:24:10102 int64_t interframe_delay_max_ms = -1;
Johannes Kron0c141c52019-08-26 13:04:43103 // 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 12:43:23106 uint32_t frames_decoded = 0;
Johannes Kronbfd343b2019-07-01 08:07:50107 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime
Philipp Hanckea204ad22022-07-08 16:43:25108 TimeDelta total_decode_time = TimeDelta::Zero();
Philipp Hanckea16a6a62022-04-25 10:21:30109 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalprocessingdelay
Philipp Hanckea204ad22022-07-08 16:43:25110 TimeDelta total_processing_delay = TimeDelta::Zero();
Philipp Hancke0359ba22022-05-05 13:55:36111 // TODO(bugs.webrtc.org/13986): standardize
Philipp Hanckea204ad22022-07-08 16:43:25112 TimeDelta total_assembly_time = TimeDelta::Zero();
Philipp Hancke0359ba22022-05-05 13:55:36113 uint32_t frames_assembled_from_multiple_packets = 0;
Johannes Kron00376e12019-11-25 09:25:42114 // Total inter frame delay in seconds.
115 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalinterframedelay
116 double total_inter_frame_delay = 0;
117 // Total squared inter frame delay in seconds^2.
118 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalsqauredinterframedelay
119 double total_squared_inter_frame_delay = 0;
Benjamin Wright514f0842018-12-10 17:55:17120 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 10:28:07121 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 12:43:23122
123 int current_payload_type = -1;
124
125 int total_bitrate_bps = 0;
aleloi440b6d92017-08-22 12:43:23126
127 int width = 0;
128 int height = 0;
129
Sergey Silkin02371062019-01-31 15:45:42130 uint32_t freeze_count = 0;
131 uint32_t pause_count = 0;
132 uint32_t total_freezes_duration_ms = 0;
133 uint32_t total_pauses_duration_ms = 0;
134 uint32_t total_frames_duration_ms = 0;
135 double sum_squared_frame_durations = 0.0;
136
ilnik2e1b40b2017-09-04 14:57:17137 VideoContentType content_type = VideoContentType::UNSPECIFIED;
138
Åsa Perssonfcf79cc2019-10-22 13:23:44139 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
140 absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
aleloi440b6d92017-08-22 12:43:23141 int sync_offset_ms = std::numeric_limits<int>::max();
142
143 uint32_t ssrc = 0;
144 std::string c_name;
Niels Möllerd77cc242019-08-22 07:40:25145 RtpReceiveStats rtp_stats;
aleloi440b6d92017-08-22 12:43:23146 RtcpPacketTypeCounter rtcp_packet_type_counts;
ilnik75204c52017-09-04 10:35:40147
148 // Timing frame info: all important timestamps for a full lifetime of a
149 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 10:28:07150 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 12:43:23151 };
152
153 struct Config {
154 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 public:
160 Config() = delete;
161 Config(Config&&);
Tommi9e2b3152021-06-21 20:15:39162 Config(Transport* rtcp_send_transport,
163 VideoDecoderFactory* decoder_factory = nullptr);
aleloi440b6d92017-08-22 12:43:23164 Config& operator=(Config&&);
165 Config& operator=(const Config&) = delete;
166 ~Config();
167
168 // Mostly used by tests. Avoid creating copies if you can.
169 Config Copy() const { return Config(*this); }
170
171 std::string ToString() const;
172
173 // Decoders for every payload that we can receive.
174 std::vector<Decoder> decoders;
175
Philip Eliasson2b068ce2020-08-03 15:55:10176 // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection).
177 VideoDecoderFactory* decoder_factory = nullptr;
178
aleloi440b6d92017-08-22 12:43:23179 // Receive-stream specific RTP settings.
Tommi7a15ff32022-05-09 18:54:02180 struct Rtp : public ReceiveStreamRtpConfig {
aleloi440b6d92017-08-22 12:43:23181 Rtp();
182 Rtp(const Rtp&);
183 ~Rtp();
184 std::string ToString() const;
185
Tommi1c1f5402021-06-14 08:54:20186 // See NackConfig for description.
187 NackConfig nack;
aleloi440b6d92017-08-22 12:43:23188
189 // See RtcpMode for description.
190 RtcpMode rtcp_mode = RtcpMode::kCompound;
191
192 // Extended RTCP settings.
193 struct RtcpXr {
194 // True if RTCP Receiver Reference Time Report Block extension
195 // (RFC 3611) should be enabled.
196 bool receiver_reference_time_report = false;
197 } rtcp_xr;
198
Nico Grunbauma36f10b2021-12-09 04:59:31199 // How to request keyframes from a remote sender. Applies only if lntf is
200 // disabled.
201 KeyFrameReqMethod keyframe_method = KeyFrameReqMethod::kPliRtcp;
202
Elad Alonfadb1812019-05-24 11:40:02203 // See LntfConfig for description.
204 LntfConfig lntf;
205
nisse3b3622f2017-09-26 09:49:21206 // Payload types for ULPFEC and RED, respectively.
207 int ulpfec_payload_type = -1;
208 int red_payload_type = -1;
aleloi440b6d92017-08-22 12:43:23209
210 // SSRC for retransmissions.
211 uint32_t rtx_ssrc = 0;
212
213 // Set if the stream is protected using FlexFEC.
214 bool protected_by_flexfec = false;
215
Philipp Hancke1c951ec2022-05-25 08:44:22216 // Optional callback sink to support additional packet handlers such as
Tomas Gunnarsson8408c992021-02-14 13:19:12217 // FlexFec.
218 RtpPacketSinkInterface* packet_sink_ = nullptr;
219
nisse26e3abb2017-08-25 11:44:25220 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 12:43:23221 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 11:44:25222 std::map<int, int> rtx_associated_payload_types;
nisse26e3abb2017-08-25 11:44:25223
Mirta Dvornicicfe68daa2019-05-23 11:21:12224 // Payload types that should be depacketized using raw depacketizer
225 // (payload header will not be parsed and must not be present, additional
226 // meta data is expected to be present in generic frame descriptor
227 // RTP header extension).
228 std::set<int> raw_payload_types;
aleloi440b6d92017-08-22 12:43:23229 } rtp;
230
231 // Transport for outgoing packets (RTCP).
232 Transport* rtcp_send_transport = nullptr;
233
Rasmus Brandt1e27fec2019-01-23 08:47:50234 // Must always be set.
aleloi440b6d92017-08-22 12:43:23235 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
236
237 // Expected delay needed by the renderer, i.e. the frame will be delivered
238 // this many milliseconds, if possible, earlier than the ideal render time.
aleloi440b6d92017-08-22 12:43:23239 int render_delay_ms = 10;
240
Rasmus Brandt1e27fec2019-01-23 08:47:50241 // If false, pass frames on to the renderer as soon as they are
aleloi440b6d92017-08-22 12:43:23242 // available.
Rasmus Brandt1e27fec2019-01-23 08:47:50243 bool enable_prerenderer_smoothing = true;
aleloi440b6d92017-08-22 12:43:23244
245 // Identifier for an A/V synchronization group. Empty string to disable.
246 // TODO(pbos): Synchronize streams in a sync group, not just video streams
247 // to one of the audio streams.
248 std::string sync_group;
249
Benjamin Wright192eeec2018-10-18 00:27:25250 // An optional custom frame decryptor that allows the entire frame to be
251 // decrypted in whatever way the caller choses. This is not required by
252 // default.
253 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
254
255 // Per PeerConnection cryptography options.
256 CryptoOptions crypto_options;
Marina Ciocea412a31b2020-02-28 15:02:06257
258 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
aleloi440b6d92017-08-22 12:43:23259 };
260
aleloi440b6d92017-08-22 12:43:23261 // TODO(pbos): Add info on currently-received codec to Stats.
262 virtual Stats GetStats() const = 0;
263
Ruslan Burakov493a6502019-02-27 14:32:48264 // Sets a base minimum for the playout delay. Base minimum delay sets lower
265 // bound on minimum delay value determining lower bound on playout delay.
266 //
267 // Returns true if value was successfully set, false overwise.
268 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
269
270 // Returns current value of base minimum delay in milliseconds.
271 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
272
Markus Handell269ac812019-12-03 13:31:45273 // Sets and returns recording state. The old state is moved out
Artem Titovea240272021-07-26 10:40:21274 // of the video receive stream and returned to the caller, and `state`
Markus Handell269ac812019-12-03 13:31:45275 // is moved in. If the state's callback is set, it will be called with
276 // recordable encoded frames as they arrive.
Artem Titovea240272021-07-26 10:40:21277 // If `generate_key_frame` is true, the method will generate a key frame.
Markus Handell269ac812019-12-03 13:31:45278 // When the function returns, it's guaranteed that all old callouts
279 // to the returned callback has ceased.
280 // Note: the client should not interpret the returned state's attributes, but
281 // instead treat it as opaque data.
282 virtual RecordingState SetAndGetRecordingState(RecordingState state,
283 bool generate_key_frame) = 0;
284
285 // Cause eventual generation of a key frame from the sender.
286 virtual void GenerateKeyFrame() = 0;
287
Tommiaeb44122022-07-14 16:33:42288 virtual void SetRtcpMode(RtcpMode mode) = 0;
289
Tommi185f10c2022-08-02 09:51:20290 // Sets or clears a flexfec RTP sink. This affects `rtp.packet_sink_` and
291 // `rtp.protected_by_flexfec` parts of the configuration. Must be called on
292 // the packet delivery thread.
293 // TODO(bugs.webrtc.org/11993): Packet delivery thread today means `worker
294 // thread` but will be `network thread`.
295 virtual void SetFlexFecProtection(RtpPacketSinkInterface* flexfec_sink) = 0;
296
Tommie644a4b2022-08-03 14:13:53297 // Turns on/off loss notifications. Must be called on the packet delivery
298 // thread.
299 virtual void SetLossNotificationEnabled(bool enabled) = 0;
300
Tommi3900f212022-08-05 14:21:54301 // Modify `rtp.nack.rtp_history_ms` post construction. Setting this value
302 // to 0 disables nack.
303 // Must be called on the packet delivery thread.
304 virtual void SetNackHistory(TimeDelta history) = 0;
305
Tommie1bd8332022-08-13 08:44:10306 virtual void SetProtectionPayloadTypes(int red_payload_type,
307 int ulpfec_payload_type) = 0;
Tommi1c5f3172022-08-13 08:43:59308
Tommi2e809362022-08-12 20:06:20309 virtual void SetRtcpXr(Config::Rtp::RtcpXr rtcp_xr) = 0;
310
Tommi13b9f812022-08-16 08:23:47311 virtual void SetAssociatedPayloadTypes(
312 std::map<int, int> associated_payload_types) = 0;
313
aleloi440b6d92017-08-22 12:43:23314 protected:
Tommif6f45432022-05-20 13:21:20315 virtual ~VideoReceiveStreamInterface() {}
aleloi440b6d92017-08-22 12:43:23316};
317
318} // namespace webrtc
319
Mirko Bonadei92ea95e2017-09-15 04:47:31320#endif // CALL_VIDEO_RECEIVE_STREAM_H_