blob: de6f71290182a4f8f8069698b44c89cd91984153 [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"
20#include "api/rtpparameters.h"
21#include "call/rtp_config.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020022#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "common_video/include/frame_callback.h"
24#include "media/base/videosinkinterface.h"
25#include "rtc_base/platform_file.h"
aleloi440b6d92017-08-22 05:43:23 -070026
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
ilnik2e1b40b2017-09-04 07:57:17 -070091 VideoContentType content_type = VideoContentType::UNSPECIFIED;
92
aleloi440b6d92017-08-22 05:43:23 -070093 int sync_offset_ms = std::numeric_limits<int>::max();
94
95 uint32_t ssrc = 0;
96 std::string c_name;
97 StreamDataCounters rtp_stats;
98 RtcpPacketTypeCounter rtcp_packet_type_counts;
99 RtcpStatistics rtcp_stats;
ilnik75204c52017-09-04 03:35:40 -0700100
101 // Timing frame info: all important timestamps for a full lifetime of a
102 // single 'timing frame'.
103 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
aleloi440b6d92017-08-22 05:43:23 -0700104 };
105
106 struct Config {
107 private:
108 // Access to the copy constructor is private to force use of the Copy()
109 // method for those exceptional cases where we do use it.
110 Config(const Config&);
111
112 public:
113 Config() = delete;
114 Config(Config&&);
115 explicit Config(Transport* rtcp_send_transport);
116 Config& operator=(Config&&);
117 Config& operator=(const Config&) = delete;
118 ~Config();
119
120 // Mostly used by tests. Avoid creating copies if you can.
121 Config Copy() const { return Config(*this); }
122
123 std::string ToString() const;
124
125 // Decoders for every payload that we can receive.
126 std::vector<Decoder> decoders;
127
128 // Receive-stream specific RTP settings.
129 struct Rtp {
130 Rtp();
131 Rtp(const Rtp&);
132 ~Rtp();
133 std::string ToString() const;
134
135 // Synchronization source (stream identifier) to be received.
136 uint32_t remote_ssrc = 0;
137
138 // Sender SSRC used for sending RTCP (such as receiver reports).
139 uint32_t local_ssrc = 0;
140
141 // See RtcpMode for description.
142 RtcpMode rtcp_mode = RtcpMode::kCompound;
143
144 // Extended RTCP settings.
145 struct RtcpXr {
146 // True if RTCP Receiver Reference Time Report Block extension
147 // (RFC 3611) should be enabled.
148 bool receiver_reference_time_report = false;
149 } rtcp_xr;
150
151 // TODO(nisse): This remb setting is currently set but never
152 // applied. REMB logic is now the responsibility of
153 // PacketRouter, and it will generate REMB feedback if
154 // OnReceiveBitrateChanged is used, which depends on how the
155 // estimators belonging to the ReceiveSideCongestionController
156 // are configured. Decide if this setting should be deleted, and
157 // if it needs to be replaced by a setting in PacketRouter to
158 // disable REMB feedback.
159
160 // See draft-alvestrand-rmcat-remb for information.
161 bool remb = false;
162
163 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
164 bool transport_cc = false;
165
166 // See NackConfig for description.
167 NackConfig nack;
168
nisse3b3622f2017-09-26 02:49:21 -0700169 // Payload types for ULPFEC and RED, respectively.
170 int ulpfec_payload_type = -1;
171 int red_payload_type = -1;
aleloi440b6d92017-08-22 05:43:23 -0700172
173 // SSRC for retransmissions.
174 uint32_t rtx_ssrc = 0;
175
176 // Set if the stream is protected using FlexFEC.
177 bool protected_by_flexfec = false;
178
nisse26e3abb2017-08-25 04:44:25 -0700179 // Map from rtx payload type -> media payload type.
aleloi440b6d92017-08-22 05:43:23 -0700180 // For RTX to be enabled, both an SSRC and this mapping are needed.
nisse26e3abb2017-08-25 04:44:25 -0700181 std::map<int, int> rtx_associated_payload_types;
Niels Möller23bdb672017-08-24 10:05:15 +0200182 // TODO(nisse): This is a temporary accessor function to enable
183 // reversing and renaming of the rtx_payload_types mapping.
184 void AddRtxBinding(int rtx_payload_type, int media_payload_type) {
nisse26e3abb2017-08-25 04:44:25 -0700185 rtx_associated_payload_types[rtx_payload_type] = media_payload_type;
Niels Möller23bdb672017-08-24 10:05:15 +0200186 }
nisse26e3abb2017-08-25 04:44:25 -0700187
aleloi440b6d92017-08-22 05:43:23 -0700188 // RTP header extensions used for the received stream.
189 std::vector<RtpExtension> extensions;
190 } rtp;
191
192 // Transport for outgoing packets (RTCP).
193 Transport* rtcp_send_transport = nullptr;
194
195 // Must not be 'nullptr' when the stream is started.
196 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
197
198 // Expected delay needed by the renderer, i.e. the frame will be delivered
199 // this many milliseconds, if possible, earlier than the ideal render time.
200 // Only valid if 'renderer' is set.
201 int render_delay_ms = 10;
202
203 // If set, pass frames on to the renderer as soon as they are
204 // available.
205 bool disable_prerenderer_smoothing = false;
206
207 // Identifier for an A/V synchronization group. Empty string to disable.
208 // TODO(pbos): Synchronize streams in a sync group, not just video streams
209 // to one of the audio streams.
210 std::string sync_group;
211
212 // Called for each incoming video frame, i.e. in encoded state. E.g. used
213 // when
214 // saving the stream to a file. 'nullptr' disables the callback.
215 EncodedFrameObserver* pre_decode_callback = nullptr;
216
217 // Target delay in milliseconds. A positive value indicates this stream is
218 // used for streaming instead of a real-time call.
219 int target_delay_ms = 0;
220 };
221
222 // Starts stream activity.
223 // When a stream is active, it can receive, process and deliver packets.
224 virtual void Start() = 0;
225 // Stops stream activity.
226 // When a stream is stopped, it can't receive, process or deliver packets.
227 virtual void Stop() = 0;
228
229 // TODO(pbos): Add info on currently-received codec to Stats.
230 virtual Stats GetStats() const = 0;
231
aleloi440b6d92017-08-22 05:43:23 -0700232 // Takes ownership of the file, is responsible for closing it later.
233 // Calling this method will close and finalize any current log.
234 // Giving rtc::kInvalidPlatformFileValue disables logging.
235 // If a frame to be written would make the log too large the write fails and
236 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
237 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
238 size_t byte_limit) = 0;
239 inline void DisableEncodedFrameRecording() {
240 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
241 }
242
243 // RtpDemuxer only forwards a given RTP packet to one sink. However, some
244 // sinks, such as FlexFEC, might wish to be informed of all of the packets
245 // a given sink receives (or any set of sinks). They may do so by registering
246 // themselves as secondary sinks.
247 virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
248 virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
249
250 protected:
251 virtual ~VideoReceiveStream() {}
252};
253
254} // namespace webrtc
255
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200256#endif // CALL_VIDEO_RECEIVE_STREAM_H_