blob: 542027e95381be3651313d3acef48dfa1f1d075b [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
11#ifndef WEBRTC_CALL_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_CALL_VIDEO_RECEIVE_STREAM_H_
13
14#include <limits>
15#include <map>
16#include <string>
17#include <vector>
18
19#include "webrtc/api/call/transport.h"
Stefan Holmer1acbd682017-09-01 15:29:28 +020020#include "webrtc/api/rtpparameters.h"
21#include "webrtc/call/rtp_config.h"
aleloi440b6d92017-08-22 05:43:23 -070022#include "webrtc/common_types.h"
23#include "webrtc/common_video/include/frame_callback.h"
aleloi440b6d92017-08-22 05:43:23 -070024#include "webrtc/media/base/videosinkinterface.h"
25#include "webrtc/rtc_base/platform_file.h"
26
27namespace webrtc {
28
29class RtpPacketSinkInterface;
30class VideoDecoder;
31
32class VideoReceiveStream {
33 public:
34 // TODO(mflodman) Move all these settings to VideoDecoder and move the
35 // declaration to common_types.h.
36 struct Decoder {
37 Decoder();
38 Decoder(const Decoder&);
39 ~Decoder();
40 std::string ToString() const;
41
42 // The actual decoder instance.
43 VideoDecoder* decoder = nullptr;
44
45 // Received RTP packets with this payload type will be sent to this decoder
46 // instance.
47 int payload_type = 0;
48
49 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
50 // used to unpack incoming packets.
51 std::string payload_name;
52
53 // This map contains the codec specific parameters from SDP, i.e. the "fmtp"
54 // parameters. It is the same as cricket::CodecParameterMap used in
55 // cricket::VideoCodec.
56 std::map<std::string, std::string> codec_params;
57 };
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;
81 rtc::Optional<uint64_t> qp_sum;
82
83 int current_payload_type = -1;
84
85 int total_bitrate_bps = 0;
86 int discarded_packets = 0;
87
88 int width = 0;
89 int height = 0;
90
91 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'.
101 rtc::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
167 // See UlpfecConfig for description.
nisse5c0f6c62017-09-04 03:14:40 -0700168 // TODO(nisse): UlpfecConfig includes the field red_rtx_payload_type,
169 // which duplicates info in the rtx_associated_payload_types mapping. So
170 // delete the use of UlpfecConfig here, and replace by the values which
171 // make sense in this context, likely those are ulpfec_payload_type_ and
172 // red_payload_type_.
aleloi440b6d92017-08-22 05:43:23 -0700173 UlpfecConfig ulpfec;
174
175 // SSRC for retransmissions.
176 uint32_t rtx_ssrc = 0;
177
178 // Set if the stream is protected using FlexFEC.
179 bool protected_by_flexfec = false;
180
nisse26e3abb2017-08-25 04:44:25 -0700181 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700182 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700183 std::map<int, int> rtx_associated_payload_types;
Niels Möller23bdb672017-08-24 10:05:15 +0200184 // TODO(nisse): This is a temporary accessor function to enable
185 // reversing and renaming of the rtx_payload_types mapping.
186 void AddRtxBinding(int rtx_payload_type, int media_payload_type) {
nisse26e3abb2017-08-25 04:44:25 -0700187 rtx_associated_payload_types[rtx_payload_type] = media_payload_type;
Niels Möller23bdb672017-08-24 10:05:15 +0200188 }
nisse26e3abb2017-08-25 04:44:25 -0700189
aleloi440b6d92017-08-22 05:43:23 -0700190 // RTP header extensions used for the received stream.
191 std::vector<RtpExtension> extensions;
192 } rtp;
193
194 // Transport for outgoing packets (RTCP).
195 Transport* rtcp_send_transport = nullptr;
196
197 // Must not be 'nullptr' when the stream is started.
198 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
199
200 // Expected delay needed by the renderer, i.e. the frame will be delivered
201 // this many milliseconds, if possible, earlier than the ideal render time.
202 // Only valid if 'renderer' is set.
203 int render_delay_ms = 10;
204
205 // If set, pass frames on to the renderer as soon as they are
206 // available.
207 bool disable_prerenderer_smoothing = false;
208
209 // Identifier for an A/V synchronization group. Empty string to disable.
210 // TODO(pbos): Synchronize streams in a sync group, not just video streams
211 // to one of the audio streams.
212 std::string sync_group;
213
214 // Called for each incoming video frame, i.e. in encoded state. E.g. used
215 // when
216 // saving the stream to a file. 'nullptr' disables the callback.
217 EncodedFrameObserver* pre_decode_callback = nullptr;
218
219 // Target delay in milliseconds. A positive value indicates this stream is
220 // used for streaming instead of a real-time call.
221 int target_delay_ms = 0;
222 };
223
224 // Starts stream activity.
225 // When a stream is active, it can receive, process and deliver packets.
226 virtual void Start() = 0;
227 // Stops stream activity.
228 // When a stream is stopped, it can't receive, process or deliver packets.
229 virtual void Stop() = 0;
230
231 // TODO(pbos): Add info on currently-received codec to Stats.
232 virtual Stats GetStats() const = 0;
233
aleloi440b6d92017-08-22 05:43:23 -0700234 // Takes ownership of the file, is responsible for closing it later.
235 // Calling this method will close and finalize any current log.
236 // Giving rtc::kInvalidPlatformFileValue disables logging.
237 // If a frame to be written would make the log too large the write fails and
238 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
239 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
240 size_t byte_limit) = 0;
241 inline void DisableEncodedFrameRecording() {
242 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
243 }
244
245 // 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
252 protected:
253 virtual ~VideoReceiveStream() {}
254};
255
256} // namespace webrtc
257
258#endif // WEBRTC_CALL_VIDEO_RECEIVE_STREAM_H_