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