blob: bd4b9976f698729c9337be38d38592379daa9527 [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
171 // Map from video payload type (apt) -> RTX payload type (pt).
172 // For RTX to be enabled, both an SSRC and this mapping are needed.
173 std::map<int, int> rtx_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) {
177 rtx_payload_types[media_payload_type] = rtx_payload_type;
178 }
aleloi440b6d92017-08-22 05:43:23 -0700179 // RTP header extensions used for the received stream.
180 std::vector<RtpExtension> extensions;
181 } rtp;
182
183 // Transport for outgoing packets (RTCP).
184 Transport* rtcp_send_transport = nullptr;
185
186 // Must not be 'nullptr' when the stream is started.
187 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
188
189 // Expected delay needed by the renderer, i.e. the frame will be delivered
190 // this many milliseconds, if possible, earlier than the ideal render time.
191 // Only valid if 'renderer' is set.
192 int render_delay_ms = 10;
193
194 // If set, pass frames on to the renderer as soon as they are
195 // available.
196 bool disable_prerenderer_smoothing = false;
197
198 // Identifier for an A/V synchronization group. Empty string to disable.
199 // TODO(pbos): Synchronize streams in a sync group, not just video streams
200 // to one of the audio streams.
201 std::string sync_group;
202
203 // Called for each incoming video frame, i.e. in encoded state. E.g. used
204 // when
205 // saving the stream to a file. 'nullptr' disables the callback.
206 EncodedFrameObserver* pre_decode_callback = nullptr;
207
208 // Target delay in milliseconds. A positive value indicates this stream is
209 // used for streaming instead of a real-time call.
210 int target_delay_ms = 0;
211 };
212
213 // Starts stream activity.
214 // When a stream is active, it can receive, process and deliver packets.
215 virtual void Start() = 0;
216 // Stops stream activity.
217 // When a stream is stopped, it can't receive, process or deliver packets.
218 virtual void Stop() = 0;
219
220 // TODO(pbos): Add info on currently-received codec to Stats.
221 virtual Stats GetStats() const = 0;
222
223 virtual rtc::Optional<TimingFrameInfo> GetAndResetTimingFrameInfo() = 0;
224
225 // 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
243 protected:
244 virtual ~VideoReceiveStream() {}
245};
246
247} // namespace webrtc
248
249#endif // WEBRTC_CALL_VIDEO_RECEIVE_STREAM_H_