blob: 8388356f3570957e6c2c0b348ec95945357cf36b [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"
Benjamin Wright192eeec2018-10-17 17:27:25 -070020#include "api/crypto/cryptooptions.h"
Yves Gerey665174f2018-06-19 15:03:05 +020021#include "api/rtp_headers.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/rtpparameters.h"
Jonas Oreland49ac5952018-09-26 16:04:32 +020023#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010024#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020025#include "api/video/video_sink_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020026#include "api/video/video_timing.h"
Niels Möllercb7e1d22018-09-11 15:56:04 +020027#include "api/video_codecs/sdp_video_format.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "call/rtp_config.h"
Niels Möller53382cb2018-11-27 14:05:08 +010029#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010030#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070031
32namespace webrtc {
33
Benjamin Wright192eeec2018-10-17 17:27:25 -070034class FrameDecryptorInterface;
aleloi440b6d92017-08-22 05:43:23 -070035class RtpPacketSinkInterface;
Niels Möllercbcbc222018-09-28 09:07:24 +020036class VideoDecoderFactory;
aleloi440b6d92017-08-22 05:43:23 -070037
38class VideoReceiveStream {
39 public:
40 // TODO(mflodman) Move all these settings to VideoDecoder and move the
41 // declaration to common_types.h.
42 struct Decoder {
43 Decoder();
44 Decoder(const Decoder&);
45 ~Decoder();
46 std::string ToString() const;
47
Niels Möllercbcbc222018-09-28 09:07:24 +020048 // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection).
49 // TODO(nisse): Move one level out, to VideoReceiveStream::Config, and later
50 // to the configuration of VideoStreamDecoder.
51 VideoDecoderFactory* decoder_factory = nullptr;
Niels Möllercb7e1d22018-09-11 15:56:04 +020052 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 05:43:23 -070053
54 // Received RTP packets with this payload type will be sent to this decoder
55 // instance.
56 int payload_type = 0;
aleloi440b6d92017-08-22 05:43:23 -070057 };
58
59 struct Stats {
60 Stats();
61 ~Stats();
62 std::string ToString(int64_t time_ms) const;
63
64 int network_frame_rate = 0;
65 int decode_frame_rate = 0;
66 int render_frame_rate = 0;
67 uint32_t frames_rendered = 0;
68
69 // Decoder stats.
70 std::string decoder_implementation_name = "unknown";
71 FrameCounts frame_counts;
72 int decode_ms = 0;
73 int max_decode_ms = 0;
74 int current_delay_ms = 0;
75 int target_delay_ms = 0;
76 int jitter_buffer_ms = 0;
77 int min_playout_delay_ms = 0;
78 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -070079 int64_t interframe_delay_max_ms = -1;
aleloi440b6d92017-08-22 05:43:23 -070080 uint32_t frames_decoded = 0;
Benjamin Wright514f0842018-12-10 09:55:17 -080081 int64_t first_frame_received_to_decoded_ms = -1;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020082 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070083
84 int current_payload_type = -1;
85
86 int total_bitrate_bps = 0;
87 int discarded_packets = 0;
88
89 int width = 0;
90 int height = 0;
91
ilnik2e1b40b2017-09-04 07:57:17 -070092 VideoContentType content_type = VideoContentType::UNSPECIFIED;
93
aleloi440b6d92017-08-22 05:43:23 -070094 int sync_offset_ms = std::numeric_limits<int>::max();
95
96 uint32_t ssrc = 0;
97 std::string c_name;
98 StreamDataCounters rtp_stats;
99 RtcpPacketTypeCounter rtcp_packet_type_counts;
100 RtcpStatistics rtcp_stats;
ilnik75204c52017-09-04 03:35:40 -0700101
102 // Timing frame info: all important timestamps for a full lifetime of a
103 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200104 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700105 };
106
107 struct Config {
108 private:
109 // Access to the copy constructor is private to force use of the Copy()
110 // method for those exceptional cases where we do use it.
111 Config(const Config&);
112
113 public:
114 Config() = delete;
115 Config(Config&&);
116 explicit Config(Transport* rtcp_send_transport);
117 Config& operator=(Config&&);
118 Config& operator=(const Config&) = delete;
119 ~Config();
120
121 // Mostly used by tests. Avoid creating copies if you can.
122 Config Copy() const { return Config(*this); }
123
124 std::string ToString() const;
125
126 // Decoders for every payload that we can receive.
127 std::vector<Decoder> decoders;
128
129 // Receive-stream specific RTP settings.
130 struct Rtp {
131 Rtp();
132 Rtp(const Rtp&);
133 ~Rtp();
134 std::string ToString() const;
135
136 // Synchronization source (stream identifier) to be received.
137 uint32_t remote_ssrc = 0;
138
139 // Sender SSRC used for sending RTCP (such as receiver reports).
140 uint32_t local_ssrc = 0;
141
142 // See RtcpMode for description.
143 RtcpMode rtcp_mode = RtcpMode::kCompound;
144
145 // Extended RTCP settings.
146 struct RtcpXr {
147 // True if RTCP Receiver Reference Time Report Block extension
148 // (RFC 3611) should be enabled.
149 bool receiver_reference_time_report = false;
150 } rtcp_xr;
151
152 // TODO(nisse): This remb setting is currently set but never
153 // applied. REMB logic is now the responsibility of
154 // PacketRouter, and it will generate REMB feedback if
155 // OnReceiveBitrateChanged is used, which depends on how the
156 // estimators belonging to the ReceiveSideCongestionController
157 // are configured. Decide if this setting should be deleted, and
158 // if it needs to be replaced by a setting in PacketRouter to
159 // disable REMB feedback.
160
161 // See draft-alvestrand-rmcat-remb for information.
162 bool remb = false;
163
164 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
165 bool transport_cc = false;
166
167 // See NackConfig for description.
168 NackConfig nack;
169
nisse3b3622f2017-09-26 02:49:21 -0700170 // Payload types for ULPFEC and RED, respectively.
171 int ulpfec_payload_type = -1;
172 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700173
174 // SSRC for retransmissions.
175 uint32_t rtx_ssrc = 0;
176
177 // Set if the stream is protected using FlexFEC.
178 bool protected_by_flexfec = false;
179
nisse26e3abb2017-08-25 04:44:25 -0700180 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700181 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700182 std::map<int, int> rtx_associated_payload_types;
Niels Möller23bdb672017-08-24 10:05:15 +0200183 // TODO(nisse): This is a temporary accessor function to enable
184 // reversing and renaming of the rtx_payload_types mapping.
185 void AddRtxBinding(int rtx_payload_type, int media_payload_type) {
nisse26e3abb2017-08-25 04:44:25 -0700186 rtx_associated_payload_types[rtx_payload_type] = media_payload_type;
Niels Möller23bdb672017-08-24 10:05:15 +0200187 }
nisse26e3abb2017-08-25 04:44:25 -0700188
aleloi440b6d92017-08-22 05:43:23 -0700189 // RTP header extensions used for the received stream.
190 std::vector<RtpExtension> extensions;
191 } rtp;
192
193 // Transport for outgoing packets (RTCP).
194 Transport* rtcp_send_transport = nullptr;
195
196 // Must not be 'nullptr' when the stream is started.
197 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
198
199 // Expected delay needed by the renderer, i.e. the frame will be delivered
200 // this many milliseconds, if possible, earlier than the ideal render time.
201 // Only valid if 'renderer' is set.
202 int render_delay_ms = 10;
203
204 // If set, pass frames on to the renderer as soon as they are
205 // available.
206 bool disable_prerenderer_smoothing = false;
207
208 // Identifier for an A/V synchronization group. Empty string to disable.
209 // TODO(pbos): Synchronize streams in a sync group, not just video streams
210 // to one of the audio streams.
211 std::string sync_group;
212
aleloi440b6d92017-08-22 05:43:23 -0700213 // Target delay in milliseconds. A positive value indicates this stream is
214 // used for streaming instead of a real-time call.
215 int target_delay_ms = 0;
Niels Möllercbcbc222018-09-28 09:07:24 +0200216
217 // TODO(nisse): Used with VideoDecoderFactory::LegacyCreateVideoDecoder.
218 // Delete when that method is retired.
219 std::string stream_id;
Benjamin Wright192eeec2018-10-17 17:27:25 -0700220
221 // An optional custom frame decryptor that allows the entire frame to be
222 // decrypted in whatever way the caller choses. This is not required by
223 // default.
224 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
225
226 // Per PeerConnection cryptography options.
227 CryptoOptions crypto_options;
aleloi440b6d92017-08-22 05:43:23 -0700228 };
229
230 // Starts stream activity.
231 // When a stream is active, it can receive, process and deliver packets.
232 virtual void Start() = 0;
233 // Stops stream activity.
234 // When a stream is stopped, it can't receive, process or deliver packets.
235 virtual void Stop() = 0;
236
237 // TODO(pbos): Add info on currently-received codec to Stats.
238 virtual Stats GetStats() const = 0;
239
aleloi440b6d92017-08-22 05:43:23 -0700240 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
241 // sinks, such as FlexFEC, might wish to be informed of all of the packets
242 // a given sink receives (or any set of sinks). They may do so by registering
243 // themselves as secondary sinks.
244 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
245 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
246
Jonas Oreland49ac5952018-09-26 16:04:32 +0200247 virtual std::vector<RtpSource> GetSources() const = 0;
248
aleloi440b6d92017-08-22 05:43:23 -0700249 protected:
250 virtual ~VideoReceiveStream() {}
251};
252
253} // namespace webrtc
254
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200255#endif // CALL_VIDEO_RECEIVE_STREAM_H_