blob: 18e904d076489fdddf99b667d6f37dd90c163fb2 [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"
20#include "webrtc/common_types.h"
21#include "webrtc/common_video/include/frame_callback.h"
22#include "webrtc/config.h"
23#include "webrtc/media/base/videosinkinterface.h"
24#include "webrtc/rtc_base/platform_file.h"
25
26namespace webrtc {
27
28class RtpPacketSinkInterface;
29class VideoDecoder;
30
31class VideoReceiveStream {
32 public:
33 // TODO(mflodman) Move all these settings to VideoDecoder and move the
34 // declaration to common_types.h.
35 struct Decoder {
36 Decoder();
37 Decoder(const Decoder&);
38 ~Decoder();
39 std::string ToString() const;
40
41 // The actual decoder instance.
42 VideoDecoder* decoder = nullptr;
43
44 // Received RTP packets with this payload type will be sent to this decoder
45 // instance.
46 int payload_type = 0;
47
48 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
49 // used to unpack incoming packets.
50 std::string payload_name;
51
52 // This map contains the codec specific parameters from SDP, i.e. the "fmtp"
53 // parameters. It is the same as cricket::CodecParameterMap used in
54 // cricket::VideoCodec.
55 std::map<std::string, std::string> codec_params;
56 };
57
58 struct Stats {
59 Stats();
60 ~Stats();
61 std::string ToString(int64_t time_ms) const;
62
63 int network_frame_rate = 0;
64 int decode_frame_rate = 0;
65 int render_frame_rate = 0;
66 uint32_t frames_rendered = 0;
67
68 // Decoder stats.
69 std::string decoder_implementation_name = "unknown";
70 FrameCounts frame_counts;
71 int decode_ms = 0;
72 int max_decode_ms = 0;
73 int current_delay_ms = 0;
74 int target_delay_ms = 0;
75 int jitter_buffer_ms = 0;
76 int min_playout_delay_ms = 0;
77 int render_delay_ms = 10;
ilnika79cc282017-08-23 05:24:10 -070078 int64_t interframe_delay_max_ms = -1;
aleloi440b6d92017-08-22 05:43:23 -070079 uint32_t frames_decoded = 0;
80 rtc::Optional<uint64_t> qp_sum;
81
82 int current_payload_type = -1;
83
84 int total_bitrate_bps = 0;
85 int discarded_packets = 0;
86
87 int width = 0;
88 int height = 0;
89
90 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;
97 };
98
99 struct Config {
100 private:
101 // Access to the copy constructor is private to force use of the Copy()
102 // method for those exceptional cases where we do use it.
103 Config(const Config&);
104
105 public:
106 Config() = delete;
107 Config(Config&&);
108 explicit Config(Transport* rtcp_send_transport);
109 Config& operator=(Config&&);
110 Config& operator=(const Config&) = delete;
111 ~Config();
112
113 // Mostly used by tests. Avoid creating copies if you can.
114 Config Copy() const { return Config(*this); }
115
116 std::string ToString() const;
117
118 // Decoders for every payload that we can receive.
119 std::vector<Decoder> decoders;
120
121 // Receive-stream specific RTP settings.
122 struct Rtp {
123 Rtp();
124 Rtp(const Rtp&);
125 ~Rtp();
126 std::string ToString() const;
127
128 // Synchronization source (stream identifier) to be received.
129 uint32_t remote_ssrc = 0;
130
131 // Sender SSRC used for sending RTCP (such as receiver reports).
132 uint32_t local_ssrc = 0;
133
134 // See RtcpMode for description.
135 RtcpMode rtcp_mode = RtcpMode::kCompound;
136
137 // Extended RTCP settings.
138 struct RtcpXr {
139 // True if RTCP Receiver Reference Time Report Block extension
140 // (RFC 3611) should be enabled.
141 bool receiver_reference_time_report = false;
142 } rtcp_xr;
143
144 // TODO(nisse): This remb setting is currently set but never
145 // applied. REMB logic is now the responsibility of
146 // PacketRouter, and it will generate REMB feedback if
147 // OnReceiveBitrateChanged is used, which depends on how the
148 // estimators belonging to the ReceiveSideCongestionController
149 // are configured. Decide if this setting should be deleted, and
150 // if it needs to be replaced by a setting in PacketRouter to
151 // disable REMB feedback.
152
153 // See draft-alvestrand-rmcat-remb for information.
154 bool remb = false;
155
156 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
157 bool transport_cc = false;
158
159 // See NackConfig for description.
160 NackConfig nack;
161
162 // See UlpfecConfig for description.
163 UlpfecConfig ulpfec;
164
165 // SSRC for retransmissions.
166 uint32_t rtx_ssrc = 0;
167
168 // Set if the stream is protected using FlexFEC.
169 bool protected_by_flexfec = false;
170
nisse26e3abb2017-08-25 04:44:25 -0700171 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700172 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700173 std::map<int, int> rtx_associated_payload_types;
Niels Möller23bdb672017-08-24 10:05:15 +0200174 // TODO(nisse): This is a temporary accessor function to enable
175 // reversing and renaming of the rtx_payload_types mapping.
176 void AddRtxBinding(int rtx_payload_type, int media_payload_type) {
nisse26e3abb2017-08-25 04:44:25 -0700177 rtx_associated_payload_types[rtx_payload_type] = media_payload_type;
Niels Möller23bdb672017-08-24 10:05:15 +0200178 }
nisse26e3abb2017-08-25 04:44:25 -0700179
aleloi440b6d92017-08-22 05:43:23 -0700180 // RTP header extensions used for the received stream.
181 std::vector<RtpExtension> extensions;
182 } rtp;
183
184 // Transport for outgoing packets (RTCP).
185 Transport* rtcp_send_transport = nullptr;
186
187 // Must not be 'nullptr' when the stream is started.
188 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
189
190 // Expected delay needed by the renderer, i.e. the frame will be delivered
191 // this many milliseconds, if possible, earlier than the ideal render time.
192 // Only valid if 'renderer' is set.
193 int render_delay_ms = 10;
194
195 // If set, pass frames on to the renderer as soon as they are
196 // available.
197 bool disable_prerenderer_smoothing = false;
198
199 // Identifier for an A/V synchronization group. Empty string to disable.
200 // TODO(pbos): Synchronize streams in a sync group, not just video streams
201 // to one of the audio streams.
202 std::string sync_group;
203
204 // Called for each incoming video frame, i.e. in encoded state. E.g. used
205 // when
206 // saving the stream to a file. 'nullptr' disables the callback.
207 EncodedFrameObserver* pre_decode_callback = nullptr;
208
209 // 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
224 virtual rtc::Optional<TimingFrameInfo> GetAndResetTimingFrameInfo() = 0;
225
226 // Takes ownership of the file, is responsible for closing it later.
227 // Calling this method will close and finalize any current log.
228 // Giving rtc::kInvalidPlatformFileValue disables logging.
229 // If a frame to be written would make the log too large the write fails and
230 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
231 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
232 size_t byte_limit) = 0;
233 inline void DisableEncodedFrameRecording() {
234 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
235 }
236
237 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
238 // sinks, such as FlexFEC, might wish to be informed of all of the packets
239 // a given sink receives (or any set of sinks). They may do so by registering
240 // themselves as secondary sinks.
241 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
242 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
243
244 protected:
245 virtual ~VideoReceiveStream() {}
246};
247
248} // namespace webrtc
249
250#endif // WEBRTC_CALL_VIDEO_RECEIVE_STREAM_H_