blob: affc256eb2ec19a7b5caaf1075e850f8e3f758d0 [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>
16#include <string>
17#include <vector>
18
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/call/transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/crypto_options.h"
Niels Möller46879152019-01-07 15:54:47 +010021#include "api/media_transport_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020022#include "api/rtp_headers.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/rtp_parameters.h"
24#include "api/rtp_receiver_interface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010025#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020026#include "api/video/video_sink_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020027#include "api/video/video_timing.h"
Niels Möllercb7e1d22018-09-11 15:56:04 +020028#include "api/video_codecs/sdp_video_format.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "call/rtp_config.h"
Niels Möller53382cb2018-11-27 14:05:08 +010030#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010031#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070032
33namespace webrtc {
34
Benjamin Wright192eeec2018-10-17 17:27:25 -070035class FrameDecryptorInterface;
aleloi440b6d92017-08-22 05:43:23 -070036class RtpPacketSinkInterface;
Niels Möllercbcbc222018-09-28 09:07:24 +020037class VideoDecoderFactory;
aleloi440b6d92017-08-22 05:43:23 -070038
39class VideoReceiveStream {
40 public:
41 // TODO(mflodman) Move all these settings to VideoDecoder and move the
42 // declaration to common_types.h.
43 struct Decoder {
44 Decoder();
45 Decoder(const Decoder&);
46 ~Decoder();
47 std::string ToString() const;
48
Niels Möllercbcbc222018-09-28 09:07:24 +020049 // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection).
50 // TODO(nisse): Move one level out, to VideoReceiveStream::Config, and later
51 // to the configuration of VideoStreamDecoder.
52 VideoDecoderFactory* decoder_factory = nullptr;
Niels Möllercb7e1d22018-09-11 15:56:04 +020053 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 05:43:23 -070054
55 // Received RTP packets with this payload type will be sent to this decoder
56 // instance.
57 int payload_type = 0;
aleloi440b6d92017-08-22 05:43:23 -070058 };
59
60 struct Stats {
61 Stats();
62 ~Stats();
63 std::string ToString(int64_t time_ms) const;
64
65 int network_frame_rate = 0;
66 int decode_frame_rate = 0;
67 int render_frame_rate = 0;
68 uint32_t frames_rendered = 0;
69
70 // Decoder stats.
71 std::string decoder_implementation_name = "unknown";
72 FrameCounts frame_counts;
73 int decode_ms = 0;
74 int max_decode_ms = 0;
75 int current_delay_ms = 0;
76 int target_delay_ms = 0;
77 int jitter_buffer_ms = 0;
78 int min_playout_delay_ms = 0;
79 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -070080 int64_t interframe_delay_max_ms = -1;
aleloi440b6d92017-08-22 05:43:23 -070081 uint32_t frames_decoded = 0;
Benjamin Wright514f0842018-12-10 09:55:17 -080082 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020083 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070084
85 int current_payload_type = -1;
86
87 int total_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -070088
89 int width = 0;
90 int height = 0;
91
Sergey Silkin02371062019-01-31 16:45:42 +010092 uint32_t freeze_count = 0;
93 uint32_t pause_count = 0;
94 uint32_t total_freezes_duration_ms = 0;
95 uint32_t total_pauses_duration_ms = 0;
96 uint32_t total_frames_duration_ms = 0;
97 double sum_squared_frame_durations = 0.0;
98
ilnik2e1b40b2017-09-04 07:57:17 -070099 VideoContentType content_type = VideoContentType::UNSPECIFIED;
100
aleloi440b6d92017-08-22 05:43:23 -0700101 int sync_offset_ms = std::numeric_limits<int>::max();
102
103 uint32_t ssrc = 0;
104 std::string c_name;
105 StreamDataCounters rtp_stats;
106 RtcpPacketTypeCounter rtcp_packet_type_counts;
107 RtcpStatistics rtcp_stats;
ilnik75204c52017-09-04 03:35:40 -0700108
109 // Timing frame info: all important timestamps for a full lifetime of a
110 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200111 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700112 };
113
114 struct Config {
115 private:
116 // Access to the copy constructor is private to force use of the Copy()
117 // method for those exceptional cases where we do use it.
118 Config(const Config&);
119
120 public:
121 Config() = delete;
122 Config(Config&&);
Niels Möller46879152019-01-07 15:54:47 +0100123 Config(Transport* rtcp_send_transport,
124 MediaTransportInterface* media_transport);
aleloi440b6d92017-08-22 05:43:23 -0700125 explicit Config(Transport* rtcp_send_transport);
126 Config& operator=(Config&&);
127 Config& operator=(const Config&) = delete;
128 ~Config();
129
130 // Mostly used by tests. Avoid creating copies if you can.
131 Config Copy() const { return Config(*this); }
132
133 std::string ToString() const;
134
135 // Decoders for every payload that we can receive.
136 std::vector<Decoder> decoders;
137
138 // Receive-stream specific RTP settings.
139 struct Rtp {
140 Rtp();
141 Rtp(const Rtp&);
142 ~Rtp();
143 std::string ToString() const;
144
145 // Synchronization source (stream identifier) to be received.
146 uint32_t remote_ssrc = 0;
147
148 // Sender SSRC used for sending RTCP (such as receiver reports).
149 uint32_t local_ssrc = 0;
150
151 // See RtcpMode for description.
152 RtcpMode rtcp_mode = RtcpMode::kCompound;
153
154 // Extended RTCP settings.
155 struct RtcpXr {
156 // True if RTCP Receiver Reference Time Report Block extension
157 // (RFC 3611) should be enabled.
158 bool receiver_reference_time_report = false;
159 } rtcp_xr;
160
161 // TODO(nisse): This remb setting is currently set but never
162 // applied. REMB logic is now the responsibility of
163 // PacketRouter, and it will generate REMB feedback if
164 // OnReceiveBitrateChanged is used, which depends on how the
165 // estimators belonging to the ReceiveSideCongestionController
166 // are configured. Decide if this setting should be deleted, and
167 // if it needs to be replaced by a setting in PacketRouter to
168 // disable REMB feedback.
169
170 // See draft-alvestrand-rmcat-remb for information.
171 bool remb = false;
172
173 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
174 bool transport_cc = false;
175
176 // See NackConfig for description.
177 NackConfig nack;
178
nisse3b3622f2017-09-26 02:49:21 -0700179 // Payload types for ULPFEC and RED, respectively.
180 int ulpfec_payload_type = -1;
181 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700182
183 // SSRC for retransmissions.
184 uint32_t rtx_ssrc = 0;
185
186 // Set if the stream is protected using FlexFEC.
187 bool protected_by_flexfec = false;
188
nisse26e3abb2017-08-25 04:44:25 -0700189 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700190 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700191 std::map<int, int> rtx_associated_payload_types;
nisse26e3abb2017-08-25 04:44:25 -0700192
aleloi440b6d92017-08-22 05:43:23 -0700193 // RTP header extensions used for the received stream.
194 std::vector<RtpExtension> extensions;
195 } rtp;
196
197 // Transport for outgoing packets (RTCP).
198 Transport* rtcp_send_transport = nullptr;
199
Niels Möller46879152019-01-07 15:54:47 +0100200 MediaTransportInterface* media_transport = nullptr;
201
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100202 // Must always be set.
aleloi440b6d92017-08-22 05:43:23 -0700203 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
204
205 // Expected delay needed by the renderer, i.e. the frame will be delivered
206 // this many milliseconds, if possible, earlier than the ideal render time.
aleloi440b6d92017-08-22 05:43:23 -0700207 int render_delay_ms = 10;
208
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100209 // If false, pass frames on to the renderer as soon as they are
aleloi440b6d92017-08-22 05:43:23 -0700210 // available.
Rasmus Brandt1e27fec2019-01-23 09:47:50 +0100211 bool enable_prerenderer_smoothing = true;
aleloi440b6d92017-08-22 05:43:23 -0700212
213 // Identifier for an A/V synchronization group. Empty string to disable.
214 // TODO(pbos): Synchronize streams in a sync group, not just video streams
215 // to one of the audio streams.
216 std::string sync_group;
217
aleloi440b6d92017-08-22 05:43:23 -0700218 // Target delay in milliseconds. A positive value indicates this stream is
219 // used for streaming instead of a real-time call.
220 int target_delay_ms = 0;
Niels Möllercbcbc222018-09-28 09:07:24 +0200221
222 // TODO(nisse): Used with VideoDecoderFactory::LegacyCreateVideoDecoder.
223 // Delete when that method is retired.
224 std::string stream_id;
Benjamin Wright192eeec2018-10-17 17:27:25 -0700225
226 // An optional custom frame decryptor that allows the entire frame to be
227 // decrypted in whatever way the caller choses. This is not required by
228 // default.
229 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
230
231 // Per PeerConnection cryptography options.
232 CryptoOptions crypto_options;
aleloi440b6d92017-08-22 05:43:23 -0700233 };
234
235 // Starts stream activity.
236 // When a stream is active, it can receive, process and deliver packets.
237 virtual void Start() = 0;
238 // Stops stream activity.
239 // When a stream is stopped, it can't receive, process or deliver packets.
240 virtual void Stop() = 0;
241
242 // TODO(pbos): Add info on currently-received codec to Stats.
243 virtual Stats GetStats() const = 0;
244
aleloi440b6d92017-08-22 05:43:23 -0700245 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
246 // sinks, such as FlexFEC, might wish to be informed of all of the packets
247 // a given sink receives (or any set of sinks). They may do so by registering
248 // themselves as secondary sinks.
249 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
250 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
251
Jonas Oreland49ac5952018-09-26 16:04:32 +0200252 virtual std::vector<RtpSource> GetSources() const = 0;
253
Ruslan Burakov493a6502019-02-27 15:32:48 +0100254 // Sets a base minimum for the playout delay. Base minimum delay sets lower
255 // bound on minimum delay value determining lower bound on playout delay.
256 //
257 // Returns true if value was successfully set, false overwise.
258 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
259
260 // Returns current value of base minimum delay in milliseconds.
261 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
262
Benjamin Wrighta5564482019-04-03 10:44:18 -0700263 // Allows a FrameDecryptor to be attached to a VideoReceiveStream after
264 // creation without resetting the decoder state.
265 virtual void SetFrameDecryptor(
266 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) = 0;
267
aleloi440b6d92017-08-22 05:43:23 -0700268 protected:
269 virtual ~VideoReceiveStream() {}
270};
271
272} // namespace webrtc
273
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200274#endif // CALL_VIDEO_RECEIVE_STREAM_H_