blob: 0adcf3fc0d4cd3f499ae562dbd91ffbcfb03a21b [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
19#include "webrtc/common_types.h"
pbosa96b60b2016-04-18 21:12:48 -070020#include "webrtc/common_video/include/frame_callback.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000021#include "webrtc/config.h"
pbosa96b60b2016-04-18 21:12:48 -070022#include "webrtc/media/base/videosinkinterface.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000023#include "webrtc/transport.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000024
25namespace webrtc {
26
27class VideoDecoder;
28
pbos1ba8d392016-05-01 20:18:34 -070029class VideoReceiveStream {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000030 public:
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000031 // TODO(mflodman) Move all these settings to VideoDecoder and move the
32 // declaration to common_types.h.
33 struct Decoder {
pbos@webrtc.org32e85282015-01-15 10:09:39 +000034 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000035
36 // The actual decoder instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020037 VideoDecoder* decoder = nullptr;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000038
39 // Received RTP packets with this payload type will be sent to this decoder
40 // instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020041 int payload_type = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000042
43 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
44 // used to unpack incoming packets.
45 std::string payload_name;
johan3859c892016-08-05 09:19:25 -070046
47 DecoderSpecificSettings decoder_specific;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000048 };
49
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000050 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -070051 std::string ToString(int64_t time_ms) const;
52
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000053 int network_frame_rate = 0;
54 int decode_frame_rate = 0;
55 int render_frame_rate = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000056
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000057 // Decoder stats.
Peter Boströmb7d9a972015-12-18 16:01:11 +010058 std::string decoder_implementation_name = "unknown";
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000059 FrameCounts frame_counts;
60 int decode_ms = 0;
61 int max_decode_ms = 0;
62 int current_delay_ms = 0;
63 int target_delay_ms = 0;
64 int jitter_buffer_ms = 0;
65 int min_playout_delay_ms = 0;
Peter Boströmc4188fd2015-04-24 15:16:03 +020066 int render_delay_ms = 10;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000067
pbosf42376c2015-08-28 07:35:32 -070068 int current_payload_type = -1;
69
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000070 int total_bitrate_bps = 0;
71 int discarded_packets = 0;
72
asapersson2e5cfcd2016-08-11 08:41:18 -070073 int width = 0;
74 int height = 0;
75
asaperssonf8cdd182016-03-15 01:00:47 -070076 int sync_offset_ms = std::numeric_limits<int>::max();
77
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000078 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000079 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000080 StreamDataCounters rtp_stats;
81 RtcpPacketTypeCounter rtcp_packet_type_counts;
82 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000083 };
84
85 struct Config {
Tommi733b5472016-06-10 17:58:01 +020086 private:
87 // Access to the copy constructor is private to force use of the Copy()
88 // method for those exceptional cases where we do use it.
89 Config(const Config&) = default;
90
91 public:
solenberg4fbae2b2015-08-28 04:07:10 -070092 Config() = delete;
Tommi733b5472016-06-10 17:58:01 +020093 Config(Config&&) = default;
pbos2d566682015-09-28 09:59:31 -070094 explicit Config(Transport* rtcp_send_transport)
solenberg4fbae2b2015-08-28 04:07:10 -070095 : rtcp_send_transport(rtcp_send_transport) {}
96
Tommi733b5472016-06-10 17:58:01 +020097 Config& operator=(Config&&) = default;
98 Config& operator=(const Config&) = delete;
99
100 // Mostly used by tests. Avoid creating copies if you can.
101 Config Copy() const { return Config(*this); }
102
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000103 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000104
105 // Decoders for every payload that we can receive.
106 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000107
108 // Receive-stream specific RTP settings.
109 struct Rtp {
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000110 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000111
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000112 // Synchronization source (stream identifier) to be received.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200113 uint32_t remote_ssrc = 0;
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000114 // Sender SSRC used for sending RTCP (such as receiver reports).
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200115 uint32_t local_ssrc = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000116
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000117 // See RtcpMode for description.
pbosda903ea2015-10-02 02:36:56 -0700118 RtcpMode rtcp_mode = RtcpMode::kCompound;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000119
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000120 // Extended RTCP settings.
121 struct RtcpXr {
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000122 // True if RTCP Receiver Reference Time Report Block extension
123 // (RFC 3611) should be enabled.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200124 bool receiver_reference_time_report = false;
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000125 } rtcp_xr;
126
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000127 // See draft-alvestrand-rmcat-remb for information.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200128 bool remb = false;
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000129
stefan43edf0f2015-11-20 18:05:48 -0800130 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
131 bool transport_cc = false;
132
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000133 // See NackConfig for description.
134 NackConfig nack;
135
136 // See FecConfig for description.
137 FecConfig fec;
138
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000139 // RTX settings for incoming video payloads that may be received. RTX is
140 // disabled if there's no config present.
141 struct Rtx {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000142 // SSRCs to use for the RTX streams.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200143 uint32_t ssrc = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000144
145 // Payload type to use for the RTX stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200146 int payload_type = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000147 };
148
149 // Map from video RTP payload type -> RTX config.
150 typedef std::map<int, Rtx> RtxMap;
151 RtxMap rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000152
noahric65220a72015-10-14 11:29:49 -0700153 // If set to true, the RTX payload type mapping supplied in |rtx| will be
154 // used when restoring RTX packets. Without it, RTX packets will always be
155 // restored to the last non-RTX packet payload type received.
156 bool use_rtx_payload_mapping_on_restore = false;
157
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000158 // RTP header extensions used for the received stream.
159 std::vector<RtpExtension> extensions;
160 } rtp;
161
solenberg4fbae2b2015-08-28 04:07:10 -0700162 // Transport for outgoing packets (RTCP).
pbos2d566682015-09-28 09:59:31 -0700163 Transport* rtcp_send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -0700164
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200165 // VideoRenderer will be called for each decoded frame. 'nullptr' disables
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000166 // rendering of this stream.
nisse7ade7b32016-03-23 04:48:10 -0700167 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000168
169 // Expected delay needed by the renderer, i.e. the frame will be delivered
170 // this many milliseconds, if possible, earlier than the ideal render time.
171 // Only valid if 'renderer' is set.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200172 int render_delay_ms = 10;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000173
nisse7ade7b32016-03-23 04:48:10 -0700174 // If set, pass frames on to the renderer as soon as they are
175 // available.
176 bool disable_prerenderer_smoothing = false;
177
pbos8fc7fa72015-07-15 08:02:58 -0700178 // Identifier for an A/V synchronization group. Empty string to disable.
179 // TODO(pbos): Synchronize streams in a sync group, not just video streams
180 // to one of the audio streams.
181 std::string sync_group;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000182
183 // Called for each incoming video frame, i.e. in encoded state. E.g. used
184 // when
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200185 // saving the stream to a file. 'nullptr' disables the callback.
186 EncodedFrameObserver* pre_decode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000187
188 // Called for each decoded frame. E.g. used when adding effects to the
189 // decoded
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200190 // stream. 'nullptr' disables the callback.
Tommibd3380f2016-06-10 17:38:17 +0200191 // TODO(tommi): This seems to be only used by a test or two. Consider
192 // removing it (and use an appropriate alternative in the tests) as well
193 // as the associated code in VideoStreamDecoder.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200194 I420FrameCallback* pre_render_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
211 protected:
212 virtual ~VideoReceiveStream() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000213};
214
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000215} // namespace webrtc
216
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000217#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_