blob: b5c1649aa9c6a7cd41103aa69d1b9eee9d3f1d52 [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"
Yves Gerey665174f2018-06-19 15:03:05 +020020#include "api/rtp_headers.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/rtpparameters.h"
Jonas Oreland49ac5952018-09-26 16:04:32 +020022#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010023#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020024#include "api/video/video_sink_interface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020025#include "api/video/video_timing.h"
Niels Möllercb7e1d22018-09-11 15:56:04 +020026#include "api/video_codecs/sdp_video_format.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "call/rtp_config.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020028#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "common_video/include/frame_callback.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010030#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_base/platform_file.h"
aleloi440b6d92017-08-22 05:43:23 -070032
33namespace webrtc {
34
35class RtpPacketSinkInterface;
36class VideoDecoder;
37
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
48 // The actual decoder instance.
49 VideoDecoder* decoder = nullptr;
Niels Möllercb7e1d22018-09-11 15:56:04 +020050 SdpVideoFormat video_format;
aleloi440b6d92017-08-22 05:43:23 -070051
52 // Received RTP packets with this payload type will be sent to this decoder
53 // instance.
54 int payload_type = 0;
aleloi440b6d92017-08-22 05:43:23 -070055 };
56
57 struct Stats {
58 Stats();
59 ~Stats();
60 std::string ToString(int64_t time_ms) const;
61
62 int network_frame_rate = 0;
63 int decode_frame_rate = 0;
64 int render_frame_rate = 0;
65 uint32_t frames_rendered = 0;
66
67 // Decoder stats.
68 std::string decoder_implementation_name = "unknown";
69 FrameCounts frame_counts;
70 int decode_ms = 0;
71 int max_decode_ms = 0;
72 int current_delay_ms = 0;
73 int target_delay_ms = 0;
74 int jitter_buffer_ms = 0;
75 int min_playout_delay_ms = 0;
76 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -070077 int64_t interframe_delay_max_ms = -1;
aleloi440b6d92017-08-22 05:43:23 -070078 uint32_t frames_decoded = 0;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020079 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -070080
81 int current_payload_type = -1;
82
83 int total_bitrate_bps = 0;
84 int discarded_packets = 0;
85
86 int width = 0;
87 int height = 0;
88
ilnik2e1b40b2017-09-04 07:57:17 -070089 VideoContentType content_type = VideoContentType::UNSPECIFIED;
90
aleloi440b6d92017-08-22 05:43:23 -070091 int sync_offset_ms = std::numeric_limits<int>::max();
92
93 uint32_t ssrc = 0;
94 std::string c_name;
95 StreamDataCounters rtp_stats;
96 RtcpPacketTypeCounter rtcp_packet_type_counts;
97 RtcpStatistics rtcp_stats;
ilnik75204c52017-09-04 03:35:40 -070098
99 // Timing frame info: all important timestamps for a full lifetime of a
100 // single 'timing frame'.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200101 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700102 };
103
104 struct Config {
105 private:
106 // Access to the copy constructor is private to force use of the Copy()
107 // method for those exceptional cases where we do use it.
108 Config(const Config&);
109
110 public:
111 Config() = delete;
112 Config(Config&&);
113 explicit Config(Transport* rtcp_send_transport);
114 Config& operator=(Config&&);
115 Config& operator=(const Config&) = delete;
116 ~Config();
117
118 // Mostly used by tests. Avoid creating copies if you can.
119 Config Copy() const { return Config(*this); }
120
121 std::string ToString() const;
122
123 // Decoders for every payload that we can receive.
124 std::vector<Decoder> decoders;
125
126 // Receive-stream specific RTP settings.
127 struct Rtp {
128 Rtp();
129 Rtp(const Rtp&);
130 ~Rtp();
131 std::string ToString() const;
132
133 // Synchronization source (stream identifier) to be received.
134 uint32_t remote_ssrc = 0;
135
136 // Sender SSRC used for sending RTCP (such as receiver reports).
137 uint32_t local_ssrc = 0;
138
139 // See RtcpMode for description.
140 RtcpMode rtcp_mode = RtcpMode::kCompound;
141
142 // Extended RTCP settings.
143 struct RtcpXr {
144 // True if RTCP Receiver Reference Time Report Block extension
145 // (RFC 3611) should be enabled.
146 bool receiver_reference_time_report = false;
147 } rtcp_xr;
148
149 // TODO(nisse): This remb setting is currently set but never
150 // applied. REMB logic is now the responsibility of
151 // PacketRouter, and it will generate REMB feedback if
152 // OnReceiveBitrateChanged is used, which depends on how the
153 // estimators belonging to the ReceiveSideCongestionController
154 // are configured. Decide if this setting should be deleted, and
155 // if it needs to be replaced by a setting in PacketRouter to
156 // disable REMB feedback.
157
158 // See draft-alvestrand-rmcat-remb for information.
159 bool remb = false;
160
161 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
162 bool transport_cc = false;
163
164 // See NackConfig for description.
165 NackConfig nack;
166
nisse3b3622f2017-09-26 02:49:21 -0700167 // Payload types for ULPFEC and RED, respectively.
168 int ulpfec_payload_type = -1;
169 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700170
171 // SSRC for retransmissions.
172 uint32_t rtx_ssrc = 0;
173
174 // Set if the stream is protected using FlexFEC.
175 bool protected_by_flexfec = false;
176
nisse26e3abb2017-08-25 04:44:25 -0700177 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700178 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700179 std::map<int, int> rtx_associated_payload_types;
Niels Möller23bdb672017-08-24 10:05:15 +0200180 // TODO(nisse): This is a temporary accessor function to enable
181 // reversing and renaming of the rtx_payload_types mapping.
182 void AddRtxBinding(int rtx_payload_type, int media_payload_type) {
nisse26e3abb2017-08-25 04:44:25 -0700183 rtx_associated_payload_types[rtx_payload_type] = media_payload_type;
Niels Möller23bdb672017-08-24 10:05:15 +0200184 }
nisse26e3abb2017-08-25 04:44:25 -0700185
aleloi440b6d92017-08-22 05:43:23 -0700186 // RTP header extensions used for the received stream.
187 std::vector<RtpExtension> extensions;
188 } rtp;
189
190 // Transport for outgoing packets (RTCP).
191 Transport* rtcp_send_transport = nullptr;
192
193 // Must not be 'nullptr' when the stream is started.
194 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
195
196 // Expected delay needed by the renderer, i.e. the frame will be delivered
197 // this many milliseconds, if possible, earlier than the ideal render time.
198 // Only valid if 'renderer' is set.
199 int render_delay_ms = 10;
200
201 // If set, pass frames on to the renderer as soon as they are
202 // available.
203 bool disable_prerenderer_smoothing = false;
204
205 // Identifier for an A/V synchronization group. Empty string to disable.
206 // TODO(pbos): Synchronize streams in a sync group, not just video streams
207 // to one of the audio streams.
208 std::string sync_group;
209
aleloi440b6d92017-08-22 05:43:23 -0700210 // Target delay in milliseconds. A positive value indicates this stream is
211 // used for streaming instead of a real-time call.
212 int target_delay_ms = 0;
213 };
214
215 // Starts stream activity.
216 // When a stream is active, it can receive, process and deliver packets.
217 virtual void Start() = 0;
218 // Stops stream activity.
219 // When a stream is stopped, it can't receive, process or deliver packets.
220 virtual void Stop() = 0;
221
222 // TODO(pbos): Add info on currently-received codec to Stats.
223 virtual Stats GetStats() const = 0;
224
aleloi440b6d92017-08-22 05:43:23 -0700225 // Takes ownership of the file, is responsible for closing it later.
226 // Calling this method will close and finalize any current log.
227 // Giving rtc::kInvalidPlatformFileValue disables logging.
228 // If a frame to be written would make the log too large the write fails and
229 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
230 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
231 size_t byte_limit) = 0;
232 inline void DisableEncodedFrameRecording() {
233 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
234 }
235
236 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
237 // sinks, such as FlexFEC, might wish to be informed of all of the packets
238 // a given sink receives (or any set of sinks). They may do so by registering
239 // themselves as secondary sinks.
240 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
241 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
242
Jonas Oreland49ac5952018-09-26 16:04:32 +0200243 virtual std::vector<RtpSource> GetSources() const = 0;
244
aleloi440b6d92017-08-22 05:43:23 -0700245 protected:
246 virtual ~VideoReceiveStream() {}
247};
248
249} // namespace webrtc
250
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200251#endif // CALL_VIDEO_RECEIVE_STREAM_H_