blob: 863cb2e088267b8dfabfb1fd98b187501c1faf02 [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +00001/*
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
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +000011#ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_VIDEO_RECEIVE_STREAM_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000013
asaperssonf8cdd182016-03-15 01:00:47 -070014#include <limits>
pbos@webrtc.orge02d4752014-01-20 14:43:55 +000015#include <map>
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000016#include <string>
17#include <vector>
18
aleloia8eb7562016-11-28 07:02:13 -080019#include "webrtc/api/call/transport.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000020#include "webrtc/common_types.h"
pbosa96b60b2016-04-18 21:12:48 -070021#include "webrtc/common_video/include/frame_callback.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000022#include "webrtc/config.h"
pbosa96b60b2016-04-18 21:12:48 -070023#include "webrtc/media/base/videosinkinterface.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020024#include "webrtc/rtc_base/platform_file.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000025
26namespace webrtc {
27
28class VideoDecoder;
29
pbos1ba8d392016-05-01 20:18:34 -070030class VideoReceiveStream {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000031 public:
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000032 // TODO(mflodman) Move all these settings to VideoDecoder and move the
33 // declaration to common_types.h.
34 struct Decoder {
pbos@webrtc.org32e85282015-01-15 10:09:39 +000035 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000036
37 // The actual decoder instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020038 VideoDecoder* decoder = nullptr;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000039
40 // Received RTP packets with this payload type will be sent to this decoder
41 // instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020042 int payload_type = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000043
44 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
45 // used to unpack incoming packets.
46 std::string payload_name;
johan3859c892016-08-05 09:19:25 -070047
magjed5dfac562016-11-25 03:56:37 -080048 // This map contains the codec specific parameters from SDP, i.e. the "fmtp"
49 // parameters. It is the same as cricket::CodecParameterMap used in
50 // cricket::VideoCodec.
51 std::map<std::string, std::string> codec_params;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000052 };
53
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000054 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -070055 std::string ToString(int64_t time_ms) const;
56
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000057 int network_frame_rate = 0;
58 int decode_frame_rate = 0;
59 int render_frame_rate = 0;
hbos50cfe1f2017-01-23 07:21:55 -080060 uint32_t frames_rendered = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000061
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000062 // Decoder stats.
Peter Boströmb7d9a972015-12-18 16:01:11 +010063 std::string decoder_implementation_name = "unknown";
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000064 FrameCounts frame_counts;
65 int decode_ms = 0;
66 int max_decode_ms = 0;
67 int current_delay_ms = 0;
68 int target_delay_ms = 0;
69 int jitter_buffer_ms = 0;
70 int min_playout_delay_ms = 0;
Peter Boströmc4188fd2015-04-24 15:16:03 +020071 int render_delay_ms = 10;
ilnikf04afde2017-07-07 01:26:24 -070072 uint64_t interframe_delay_sum_ms = 0;
sakale5ba44e2016-10-26 07:09:24 -070073 uint32_t frames_decoded = 0;
sakalcc452e12017-02-09 04:53:45 -080074 rtc::Optional<uint64_t> qp_sum;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000075
pbosf42376c2015-08-28 07:35:32 -070076 int current_payload_type = -1;
77
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000078 int total_bitrate_bps = 0;
79 int discarded_packets = 0;
80
asapersson2e5cfcd2016-08-11 08:41:18 -070081 int width = 0;
82 int height = 0;
83
asaperssonf8cdd182016-03-15 01:00:47 -070084 int sync_offset_ms = std::numeric_limits<int>::max();
85
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000086 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000087 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000088 StreamDataCounters rtp_stats;
89 RtcpPacketTypeCounter rtcp_packet_type_counts;
90 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000091 };
92
93 struct Config {
Tommi733b5472016-06-10 17:58:01 +020094 private:
95 // Access to the copy constructor is private to force use of the Copy()
96 // method for those exceptional cases where we do use it.
97 Config(const Config&) = default;
98
99 public:
solenberg4fbae2b2015-08-28 04:07:10 -0700100 Config() = delete;
Tommi733b5472016-06-10 17:58:01 +0200101 Config(Config&&) = default;
pbos2d566682015-09-28 09:59:31 -0700102 explicit Config(Transport* rtcp_send_transport)
solenberg4fbae2b2015-08-28 04:07:10 -0700103 : rtcp_send_transport(rtcp_send_transport) {}
104
Tommi733b5472016-06-10 17:58:01 +0200105 Config& operator=(Config&&) = default;
106 Config& operator=(const Config&) = delete;
107
108 // Mostly used by tests. Avoid creating copies if you can.
109 Config Copy() const { return Config(*this); }
110
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000111 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000112
113 // Decoders for every payload that we can receive.
114 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000115
116 // Receive-stream specific RTP settings.
117 struct Rtp {
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000118 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000119
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000120 // Synchronization source (stream identifier) to be received.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200121 uint32_t remote_ssrc = 0;
brandtr14742122017-01-27 04:53:07 -0800122
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000123 // Sender SSRC used for sending RTCP (such as receiver reports).
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200124 uint32_t local_ssrc = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000125
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000126 // See RtcpMode for description.
pbosda903ea2015-10-02 02:36:56 -0700127 RtcpMode rtcp_mode = RtcpMode::kCompound;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000128
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000129 // Extended RTCP settings.
130 struct RtcpXr {
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000131 // True if RTCP Receiver Reference Time Report Block extension
132 // (RFC 3611) should be enabled.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200133 bool receiver_reference_time_report = false;
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000134 } rtcp_xr;
135
nisse05843312017-04-18 23:38:35 -0700136 // TODO(nisse): This remb setting is currently set but never
137 // applied. REMB logic is now the responsibility of
138 // PacketRouter, and it will generate REMB feedback if
139 // OnReceiveBitrateChanged is used, which depends on how the
140 // estimators belonging to the ReceiveSideCongestionController
141 // are configured. Decide if this setting should be deleted, and
142 // if it needs to be replaced by a setting in PacketRouter to
143 // disable REMB feedback.
144
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000145 // See draft-alvestrand-rmcat-remb for information.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200146 bool remb = false;
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000147
stefan43edf0f2015-11-20 18:05:48 -0800148 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
149 bool transport_cc = false;
150
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000151 // See NackConfig for description.
152 NackConfig nack;
153
brandtrb5f2c3f2016-10-04 23:28:39 -0700154 // See UlpfecConfig for description.
155 UlpfecConfig ulpfec;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000156
brandtr14742122017-01-27 04:53:07 -0800157 // SSRC for retransmissions.
158 uint32_t rtx_ssrc = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000159
nissec69385d2017-03-09 06:13:20 -0800160 // Set if the stream is protected using FlexFEC.
161 bool protected_by_flexfec = false;
162
brandtr14742122017-01-27 04:53:07 -0800163 // Map from video payload type (apt) -> RTX payload type (pt).
164 // For RTX to be enabled, both an SSRC and this mapping are needed.
165 std::map<int, int> rtx_payload_types;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000166
167 // RTP header extensions used for the received stream.
168 std::vector<RtpExtension> extensions;
169 } rtp;
170
solenberg4fbae2b2015-08-28 04:07:10 -0700171 // Transport for outgoing packets (RTCP).
pbos2d566682015-09-28 09:59:31 -0700172 Transport* rtcp_send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -0700173
sakal55d932b2016-09-30 06:19:08 -0700174 // Must not be 'nullptr' when the stream is started.
nisse7ade7b32016-03-23 04:48:10 -0700175 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000176
177 // Expected delay needed by the renderer, i.e. the frame will be delivered
178 // this many milliseconds, if possible, earlier than the ideal render time.
179 // Only valid if 'renderer' is set.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200180 int render_delay_ms = 10;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000181
nisse7ade7b32016-03-23 04:48:10 -0700182 // If set, pass frames on to the renderer as soon as they are
183 // available.
184 bool disable_prerenderer_smoothing = false;
185
pbos8fc7fa72015-07-15 08:02:58 -0700186 // Identifier for an A/V synchronization group. Empty string to disable.
187 // TODO(pbos): Synchronize streams in a sync group, not just video streams
188 // to one of the audio streams.
189 std::string sync_group;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000190
191 // Called for each incoming video frame, i.e. in encoded state. E.g. used
192 // when
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200193 // saving the stream to a file. 'nullptr' disables the callback.
194 EncodedFrameObserver* pre_decode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000195
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000196 // Target delay in milliseconds. A positive value indicates this stream is
197 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200198 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000199 };
200
pbos1ba8d392016-05-01 20:18:34 -0700201 // Starts stream activity.
202 // When a stream is active, it can receive, process and deliver packets.
203 virtual void Start() = 0;
204 // Stops stream activity.
205 // When a stream is stopped, it can't receive, process or deliver packets.
206 virtual void Stop() = 0;
207
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000208 // TODO(pbos): Add info on currently-received codec to Stats.
209 virtual Stats GetStats() const = 0;
pbos1ba8d392016-05-01 20:18:34 -0700210
ilnik2edc6842017-07-06 03:06:50 -0700211 virtual rtc::Optional<TimingFrameInfo> GetAndResetTimingFrameInfo() = 0;
212
palmkviste75f2042016-09-28 06:19:48 -0700213 // Takes ownership of the file, is responsible for closing it later.
214 // Calling this method will close and finalize any current log.
215 // Giving rtc::kInvalidPlatformFileValue disables logging.
216 // If a frame to be written would make the log too large the write fails and
217 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
218 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
219 size_t byte_limit) = 0;
220 inline void DisableEncodedFrameRecording() {
221 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
222 }
223
pbos1ba8d392016-05-01 20:18:34 -0700224 protected:
225 virtual ~VideoReceiveStream() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000226};
227
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000228} // namespace webrtc
229
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000230#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_