blob: 8ed93a1f1d6d67310deca2670b4a295a33e5696a [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;
98 };
99
100 struct Config {
101 private:
102 // Access to the copy constructor is private to force use of the Copy()
103 // method for those exceptional cases where we do use it.
104 Config(const Config&);
105
106 public:
107 Config() = delete;
108 Config(Config&&);
109 explicit Config(Transport* rtcp_send_transport);
110 Config& operator=(Config&&);
111 Config& operator=(const Config&) = delete;
112 ~Config();
113
114 // Mostly used by tests. Avoid creating copies if you can.
115 Config Copy() const { return Config(*this); }
116
117 std::string ToString() const;
118
119 // Decoders for every payload that we can receive.
120 std::vector<Decoder> decoders;
121
122 // Receive-stream specific RTP settings.
123 struct Rtp {
124 Rtp();
125 Rtp(const Rtp&);
126 ~Rtp();
127 std::string ToString() const;
128
129 // Synchronization source (stream identifier) to be received.
130 uint32_t remote_ssrc = 0;
131
132 // Sender SSRC used for sending RTCP (such as receiver reports).
133 uint32_t local_ssrc = 0;
134
135 // See RtcpMode for description.
136 RtcpMode rtcp_mode = RtcpMode::kCompound;
137
138 // Extended RTCP settings.
139 struct RtcpXr {
140 // True if RTCP Receiver Reference Time Report Block extension
141 // (RFC 3611) should be enabled.
142 bool receiver_reference_time_report = false;
143 } rtcp_xr;
144
145 // TODO(nisse): This remb setting is currently set but never
146 // applied. REMB logic is now the responsibility of
147 // PacketRouter, and it will generate REMB feedback if
148 // OnReceiveBitrateChanged is used, which depends on how the
149 // estimators belonging to the ReceiveSideCongestionController
150 // are configured. Decide if this setting should be deleted, and
151 // if it needs to be replaced by a setting in PacketRouter to
152 // disable REMB feedback.
153
154 // See draft-alvestrand-rmcat-remb for information.
155 bool remb = false;
156
157 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
158 bool transport_cc = false;
159
160 // See NackConfig for description.
161 NackConfig nack;
162
163 // See UlpfecConfig for description.
164 UlpfecConfig ulpfec;
165
166 // SSRC for retransmissions.
167 uint32_t rtx_ssrc = 0;
168
169 // Set if the stream is protected using FlexFEC.
170 bool protected_by_flexfec = false;
171
nisse26e3abb2017-08-25 04:44:25 -0700172 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700173 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700174 std::map<int, int> rtx_associated_payload_types;
Niels Möller23bdb672017-08-24 10:05:15 +0200175 // TODO(nisse): This is a temporary accessor function to enable
176 // reversing and renaming of the rtx_payload_types mapping.
177 void AddRtxBinding(int rtx_payload_type, int media_payload_type) {
nisse26e3abb2017-08-25 04:44:25 -0700178 rtx_associated_payload_types[rtx_payload_type] = media_payload_type;
Niels Möller23bdb672017-08-24 10:05:15 +0200179 }
nisse26e3abb2017-08-25 04:44:25 -0700180
aleloi440b6d92017-08-22 05:43:23 -0700181 // RTP header extensions used for the received stream.
182 std::vector<RtpExtension> extensions;
183 } rtp;
184
185 // Transport for outgoing packets (RTCP).
186 Transport* rtcp_send_transport = nullptr;
187
188 // Must not be 'nullptr' when the stream is started.
189 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
190
191 // Expected delay needed by the renderer, i.e. the frame will be delivered
192 // this many milliseconds, if possible, earlier than the ideal render time.
193 // Only valid if 'renderer' is set.
194 int render_delay_ms = 10;
195
196 // If set, pass frames on to the renderer as soon as they are
197 // available.
198 bool disable_prerenderer_smoothing = false;
199
200 // Identifier for an A/V synchronization group. Empty string to disable.
201 // TODO(pbos): Synchronize streams in a sync group, not just video streams
202 // to one of the audio streams.
203 std::string sync_group;
204
205 // Called for each incoming video frame, i.e. in encoded state. E.g. used
206 // when
207 // saving the stream to a file. 'nullptr' disables the callback.
208 EncodedFrameObserver* pre_decode_callback = nullptr;
209
210 // 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
225 virtual rtc::Optional<TimingFrameInfo> GetAndResetTimingFrameInfo() = 0;
226
227 // Takes ownership of the file, is responsible for closing it later.
228 // Calling this method will close and finalize any current log.
229 // Giving rtc::kInvalidPlatformFileValue disables logging.
230 // If a frame to be written would make the log too large the write fails and
231 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
232 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
233 size_t byte_limit) = 0;
234 inline void DisableEncodedFrameRecording() {
235 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
236 }
237
238 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
239 // sinks, such as FlexFEC, might wish to be informed of all of the packets
240 // a given sink receives (or any set of sinks). They may do so by registering
241 // themselves as secondary sinks.
242 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
243 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
244
245 protected:
246 virtual ~VideoReceiveStream() {}
247};
248
249} // namespace webrtc
250
251#endif // WEBRTC_CALL_VIDEO_RECEIVE_STREAM_H_