blob: 33d779d9b39444ab09a53d8457e879034dcf41f2 [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:521/*
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:2211#ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_VIDEO_RECEIVE_STREAM_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:5213
asaperssonf8cdd182016-03-15 08:00:4714#include <limits>
pbos@webrtc.orge02d4752014-01-20 14:43:5515#include <map>
mflodman@webrtc.org65f995a2013-04-18 12:02:5216#include <string>
17#include <vector>
18
aleloia8eb7562016-11-28 15:02:1319#include "webrtc/api/call/transport.h"
palmkviste75f2042016-09-28 13:19:4820#include "webrtc/base/platform_file.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:5221#include "webrtc/common_types.h"
pbosa96b60b2016-04-19 04:12:4822#include "webrtc/common_video/include/frame_callback.h"
pbos@webrtc.org16e03b72013-10-28 16:32:0123#include "webrtc/config.h"
pbosa96b60b2016-04-19 04:12:4824#include "webrtc/media/base/videosinkinterface.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:5225
26namespace webrtc {
27
28class VideoDecoder;
29
pbos1ba8d392016-05-02 03:18:3430class VideoReceiveStream {
mflodman@webrtc.org65f995a2013-04-18 12:02:5231 public:
pbos@webrtc.org776e6f22014-10-29 15:28:3932 // 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:3935 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:3936
37 // The actual decoder instance.
Fredrik Solenberg78fb3b32015-06-11 10:38:3838 VideoDecoder* decoder = nullptr;
pbos@webrtc.org776e6f22014-10-29 15:28:3939
40 // Received RTP packets with this payload type will be sent to this decoder
41 // instance.
Fredrik Solenberg78fb3b32015-06-11 10:38:3842 int payload_type = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:3943
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 16:19:2547
magjed5dfac562016-11-25 11:56:3748 // 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:3952 };
53
pbos@webrtc.org09c77b92015-02-25 10:42:1654 struct Stats {
asapersson2e5cfcd2016-08-11 15:41:1855 std::string ToString(int64_t time_ms) const;
56
pbos@webrtc.org09c77b92015-02-25 10:42:1657 int network_frame_rate = 0;
58 int decode_frame_rate = 0;
59 int render_frame_rate = 0;
hbos50cfe1f2017-01-23 15:21:5560 uint32_t frames_rendered = 0;
sprang@webrtc.org09315702014-02-07 12:06:2961
pbos@webrtc.org09c77b92015-02-25 10:42:1662 // Decoder stats.
Peter Boströmb7d9a972015-12-18 15:01:1163 std::string decoder_implementation_name = "unknown";
pbos@webrtc.org09c77b92015-02-25 10:42:1664 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 13:16:0371 int render_delay_ms = 10;
sakale5ba44e2016-10-26 14:09:2472 uint32_t frames_decoded = 0;
sakalcc452e12017-02-09 12:53:4573 rtc::Optional<uint64_t> qp_sum;
pbos@webrtc.org09c77b92015-02-25 10:42:1674
pbosf42376c2015-08-28 14:35:3275 int current_payload_type = -1;
76
pbos@webrtc.org09c77b92015-02-25 10:42:1677 int total_bitrate_bps = 0;
78 int discarded_packets = 0;
79
asapersson2e5cfcd2016-08-11 15:41:1880 int width = 0;
81 int height = 0;
82
asaperssonf8cdd182016-03-15 08:00:4783 int sync_offset_ms = std::numeric_limits<int>::max();
84
pbos@webrtc.org09c77b92015-02-25 10:42:1685 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:2986 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:1687 StreamDataCounters rtp_stats;
88 RtcpPacketTypeCounter rtcp_packet_type_counts;
89 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:2190 };
91
92 struct Config {
Tommi733b5472016-06-10 15:58:0193 private:
94 // Access to the copy constructor is private to force use of the Copy()
95 // method for those exceptional cases where we do use it.
96 Config(const Config&) = default;
97
98 public:
solenberg4fbae2b2015-08-28 11:07:1099 Config() = delete;
Tommi733b5472016-06-10 15:58:01100 Config(Config&&) = default;
pbos2d566682015-09-28 16:59:31101 explicit Config(Transport* rtcp_send_transport)
solenberg4fbae2b2015-08-28 11:07:10102 : rtcp_send_transport(rtcp_send_transport) {}
103
Tommi733b5472016-06-10 15:58:01104 Config& operator=(Config&&) = default;
105 Config& operator=(const Config&) = delete;
106
107 // Mostly used by tests. Avoid creating copies if you can.
108 Config Copy() const { return Config(*this); }
109
pbos@webrtc.org32e85282015-01-15 10:09:39110 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39111
112 // Decoders for every payload that we can receive.
113 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21114
115 // Receive-stream specific RTP settings.
116 struct Rtp {
pbos@webrtc.org32e85282015-01-15 10:09:39117 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42118
pbos@webrtc.orgb613b5a2013-12-03 10:13:04119 // Synchronization source (stream identifier) to be received.
Fredrik Solenberg78fb3b32015-06-11 10:38:38120 uint32_t remote_ssrc = 0;
brandtr14742122017-01-27 12:53:07121
pbos@webrtc.orgb613b5a2013-12-03 10:13:04122 // Sender SSRC used for sending RTCP (such as receiver reports).
Fredrik Solenberg78fb3b32015-06-11 10:38:38123 uint32_t local_ssrc = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21124
pbos@webrtc.orgc11148b2013-10-17 14:14:42125 // See RtcpMode for description.
pbosda903ea2015-10-02 09:36:56126 RtcpMode rtcp_mode = RtcpMode::kCompound;
pbos@webrtc.orgc11148b2013-10-17 14:14:42127
asapersson@webrtc.orgefaeda02014-01-20 08:34:49128 // Extended RTCP settings.
129 struct RtcpXr {
asapersson@webrtc.orgefaeda02014-01-20 08:34:49130 // True if RTCP Receiver Reference Time Report Block extension
131 // (RFC 3611) should be enabled.
Fredrik Solenberg78fb3b32015-06-11 10:38:38132 bool receiver_reference_time_report = false;
asapersson@webrtc.orgefaeda02014-01-20 08:34:49133 } rtcp_xr;
134
mflodman@webrtc.org92c27932013-12-13 16:36:28135 // See draft-alvestrand-rmcat-remb for information.
Fredrik Solenberg78fb3b32015-06-11 10:38:38136 bool remb = false;
mflodman@webrtc.org92c27932013-12-13 16:36:28137
stefan43edf0f2015-11-21 02:05:48138 // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
139 bool transport_cc = false;
140
pbos@webrtc.org025f4f12013-06-05 11:33:21141 // See NackConfig for description.
142 NackConfig nack;
143
brandtrb5f2c3f2016-10-05 06:28:39144 // See UlpfecConfig for description.
145 UlpfecConfig ulpfec;
pbos@webrtc.org025f4f12013-06-05 11:33:21146
brandtr14742122017-01-27 12:53:07147 // SSRC for retransmissions.
148 uint32_t rtx_ssrc = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53149
nissec69385d2017-03-09 14:13:20150 // Set if the stream is protected using FlexFEC.
151 bool protected_by_flexfec = false;
152
brandtr14742122017-01-27 12:53:07153 // Map from video payload type (apt) -> RTX payload type (pt).
154 // For RTX to be enabled, both an SSRC and this mapping are needed.
155 std::map<int, int> rtx_payload_types;
pbos@webrtc.org025f4f12013-06-05 11:33:21156
157 // RTP header extensions used for the received stream.
158 std::vector<RtpExtension> extensions;
159 } rtp;
160
solenberg4fbae2b2015-08-28 11:07:10161 // Transport for outgoing packets (RTCP).
pbos2d566682015-09-28 16:59:31162 Transport* rtcp_send_transport = nullptr;
solenberg4fbae2b2015-08-28 11:07:10163
sakal55d932b2016-09-30 13:19:08164 // Must not be 'nullptr' when the stream is started.
nisse7ade7b32016-03-23 11:48:10165 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21166
167 // Expected delay needed by the renderer, i.e. the frame will be delivered
168 // this many milliseconds, if possible, earlier than the ideal render time.
169 // Only valid if 'renderer' is set.
Fredrik Solenberg78fb3b32015-06-11 10:38:38170 int render_delay_ms = 10;
pbos@webrtc.org025f4f12013-06-05 11:33:21171
nisse7ade7b32016-03-23 11:48:10172 // If set, pass frames on to the renderer as soon as they are
173 // available.
174 bool disable_prerenderer_smoothing = false;
175
pbos8fc7fa72015-07-15 15:02:58176 // Identifier for an A/V synchronization group. Empty string to disable.
177 // TODO(pbos): Synchronize streams in a sync group, not just video streams
178 // to one of the audio streams.
179 std::string sync_group;
pbos@webrtc.org025f4f12013-06-05 11:33:21180
181 // Called for each incoming video frame, i.e. in encoded state. E.g. used
182 // when
Fredrik Solenberg78fb3b32015-06-11 10:38:38183 // saving the stream to a file. 'nullptr' disables the callback.
184 EncodedFrameObserver* pre_decode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21185
pbos@webrtc.org025f4f12013-06-05 11:33:21186 // Target delay in milliseconds. A positive value indicates this stream is
187 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 10:38:38188 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21189 };
190
pbos1ba8d392016-05-02 03:18:34191 // Starts stream activity.
192 // When a stream is active, it can receive, process and deliver packets.
193 virtual void Start() = 0;
194 // Stops stream activity.
195 // When a stream is stopped, it can't receive, process or deliver packets.
196 virtual void Stop() = 0;
197
pbos@webrtc.org776e6f22014-10-29 15:28:39198 // TODO(pbos): Add info on currently-received codec to Stats.
199 virtual Stats GetStats() const = 0;
pbos1ba8d392016-05-02 03:18:34200
palmkviste75f2042016-09-28 13:19:48201 // Takes ownership of the file, is responsible for closing it later.
202 // Calling this method will close and finalize any current log.
203 // Giving rtc::kInvalidPlatformFileValue disables logging.
204 // If a frame to be written would make the log too large the write fails and
205 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
206 virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
207 size_t byte_limit) = 0;
208 inline void DisableEncodedFrameRecording() {
209 EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
210 }
211
pbos1ba8d392016-05-02 03:18:34212 protected:
213 virtual ~VideoReceiveStream() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52214};
215
mflodman@webrtc.org65f995a2013-04-18 12:02:52216} // namespace webrtc
217
mflodman@webrtc.orgb429e512013-12-18 09:46:22218#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_