blob: def103f195ca0216f218f9b1d973d8bbbdc12be9 [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
palmkviste75f2042016-09-28 06:19:48 -070019#include "webrtc/base/platform_file.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"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000024#include "webrtc/transport.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
48 DecoderSpecificSettings decoder_specific;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000049 };
50
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000051 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -070052 std::string ToString(int64_t time_ms) const;
53
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000054 int network_frame_rate = 0;
55 int decode_frame_rate = 0;
56 int render_frame_rate = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000057
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000058 // Decoder stats.
Peter Boströmb7d9a972015-12-18 16:01:11 +010059 std::string decoder_implementation_name = "unknown";
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000060 FrameCounts frame_counts;
61 int decode_ms = 0;
62 int max_decode_ms = 0;
63 int current_delay_ms = 0;
64 int target_delay_ms = 0;
65 int jitter_buffer_ms = 0;
66 int min_playout_delay_ms = 0;
Peter Boströmc4188fd2015-04-24 15:16:03 +020067 int render_delay_ms = 10;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000068
pbosf42376c2015-08-28 07:35:32 -070069 int current_payload_type = -1;
70
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000071 int total_bitrate_bps = 0;
72 int discarded_packets = 0;
73
asapersson2e5cfcd2016-08-11 08:41:18 -070074 int width = 0;
75 int height = 0;
76
asaperssonf8cdd182016-03-15 01:00:47 -070077 int sync_offset_ms = std::numeric_limits<int>::max();
78
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000079 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000080 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000081 StreamDataCounters rtp_stats;
82 RtcpPacketTypeCounter rtcp_packet_type_counts;
83 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000084 };
85
86 struct Config {
Tommi733b5472016-06-10 17:58:01 +020087 private:
88 // Access to the copy constructor is private to force use of the Copy()
89 // method for those exceptional cases where we do use it.
90 Config(const Config&) = default;
91
92 public:
solenberg4fbae2b2015-08-28 04:07:10 -070093 Config() = delete;
Tommi733b5472016-06-10 17:58:01 +020094 Config(Config&&) = default;
pbos2d566682015-09-28 09:59:31 -070095 explicit Config(Transport* rtcp_send_transport)
solenberg4fbae2b2015-08-28 04:07:10 -070096 : rtcp_send_transport(rtcp_send_transport) {}
97
Tommi733b5472016-06-10 17:58:01 +020098 Config& operator=(Config&&) = default;
99 Config& operator=(const Config&) = delete;
100
101 // Mostly used by tests. Avoid creating copies if you can.
102 Config Copy() const { return Config(*this); }
103
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000104 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000105
106 // Decoders for every payload that we can receive.
107 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000108
109 // Receive-stream specific RTP settings.
110 struct Rtp {
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000111 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000112
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000113 // Synchronization source (stream identifier) to be received.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200114 uint32_t remote_ssrc = 0;
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000115 // Sender SSRC used for sending RTCP (such as receiver reports).
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200116 uint32_t local_ssrc = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000117
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000118 // See RtcpMode for description.
pbosda903ea2015-10-02 02:36:56 -0700119 RtcpMode rtcp_mode = RtcpMode::kCompound;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000120
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000121 // Extended RTCP settings.
122 struct RtcpXr {
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000123 // True if RTCP Receiver Reference Time Report Block extension
124 // (RFC 3611) should be enabled.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200125 bool receiver_reference_time_report = false;
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000126 } rtcp_xr;
127
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000128 // See draft-alvestrand-rmcat-remb for information.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200129 bool remb = false;
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000130
stefan43edf0f2015-11-20 18:05:48 -0800131 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
132 bool transport_cc = false;
133
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000134 // See NackConfig for description.
135 NackConfig nack;
136
137 // See FecConfig for description.
138 FecConfig fec;
139
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000140 // RTX settings for incoming video payloads that may be received. RTX is
141 // disabled if there's no config present.
142 struct Rtx {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000143 // SSRCs to use for the RTX streams.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200144 uint32_t ssrc = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000145
146 // Payload type to use for the RTX stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200147 int payload_type = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000148 };
149
150 // Map from video RTP payload type -> RTX config.
151 typedef std::map<int, Rtx> RtxMap;
152 RtxMap rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000153
noahric65220a72015-10-14 11:29:49 -0700154 // If set to true, the RTX payload type mapping supplied in |rtx| will be
155 // used when restoring RTX packets. Without it, RTX packets will always be
156 // restored to the last non-RTX packet payload type received.
157 bool use_rtx_payload_mapping_on_restore = false;
158
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000159 // RTP header extensions used for the received stream.
160 std::vector<RtpExtension> extensions;
161 } rtp;
162
solenberg4fbae2b2015-08-28 04:07:10 -0700163 // Transport for outgoing packets (RTCP).
pbos2d566682015-09-28 09:59:31 -0700164 Transport* rtcp_send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -0700165
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200166 // VideoRenderer will be called for each decoded frame. 'nullptr' disables
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000167 // rendering of this stream.
nisse7ade7b32016-03-23 04:48:10 -0700168 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000169
170 // Expected delay needed by the renderer, i.e. the frame will be delivered
171 // this many milliseconds, if possible, earlier than the ideal render time.
172 // Only valid if 'renderer' is set.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200173 int render_delay_ms = 10;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000174
nisse7ade7b32016-03-23 04:48:10 -0700175 // If set, pass frames on to the renderer as soon as they are
176 // available.
177 bool disable_prerenderer_smoothing = false;
178
pbos8fc7fa72015-07-15 08:02:58 -0700179 // Identifier for an A/V synchronization group. Empty string to disable.
180 // TODO(pbos): Synchronize streams in a sync group, not just video streams
181 // to one of the audio streams.
182 std::string sync_group;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000183
184 // Called for each incoming video frame, i.e. in encoded state. E.g. used
185 // when
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200186 // saving the stream to a file. 'nullptr' disables the callback.
187 EncodedFrameObserver* pre_decode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000188
189 // Called for each decoded frame. E.g. used when adding effects to the
190 // decoded
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200191 // stream. 'nullptr' disables the callback.
Tommibd3380f2016-06-10 17:38:17 +0200192 // TODO(tommi): This seems to be only used by a test or two. Consider
193 // removing it (and use an appropriate alternative in the tests) as well
194 // as the associated code in VideoStreamDecoder.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200195 I420FrameCallback* pre_render_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000196
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000197 // Target delay in milliseconds. A positive value indicates this stream is
198 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200199 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000200 };
201
pbos1ba8d392016-05-01 20:18:34 -0700202 // Starts stream activity.
203 // When a stream is active, it can receive, process and deliver packets.
204 virtual void Start() = 0;
205 // Stops stream activity.
206 // When a stream is stopped, it can't receive, process or deliver packets.
207 virtual void Stop() = 0;
208
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000209 // TODO(pbos): Add info on currently-received codec to Stats.
210 virtual Stats GetStats() const = 0;
pbos1ba8d392016-05-01 20:18:34 -0700211
palmkviste75f2042016-09-28 06:19:48 -0700212 // Takes ownership of the file, is responsible for closing it later.
213 // Calling this method will close and finalize any current log.
214 // Giving rtc::kInvalidPlatformFileValue disables logging.
215 // If a frame to be written would make the log too large the write fails and
216 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
217 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
218 size_t byte_limit) = 0;
219 inline void DisableEncodedFrameRecording() {
220 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
221 }
222
pbos1ba8d392016-05-01 20:18:34 -0700223 protected:
224 virtual ~VideoReceiveStream() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000225};
226
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000227} // namespace webrtc
228
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000229#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_