mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 1 | /* |
| 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.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_ |
| 12 | #define WEBRTC_VIDEO_RECEIVE_STREAM_H_ |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 13 | |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 14 | #include <limits> |
pbos@webrtc.org | e02d475 | 2014-01-20 14:43:55 +0000 | [diff] [blame] | 15 | #include <map> |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "webrtc/common_types.h" |
pbos | a96b60b | 2016-04-18 21:12:48 -0700 | [diff] [blame] | 20 | #include "webrtc/common_video/include/frame_callback.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 21 | #include "webrtc/config.h" |
pbos | a96b60b | 2016-04-18 21:12:48 -0700 | [diff] [blame] | 22 | #include "webrtc/media/base/videosinkinterface.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 23 | #include "webrtc/transport.h" |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | class VideoDecoder; |
| 28 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 29 | class VideoReceiveStream { |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 30 | public: |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 31 | // TODO(mflodman) Move all these settings to VideoDecoder and move the |
| 32 | // declaration to common_types.h. |
| 33 | struct Decoder { |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 34 | std::string ToString() const; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 35 | |
| 36 | // The actual decoder instance. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 37 | VideoDecoder* decoder = nullptr; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 38 | |
| 39 | // Received RTP packets with this payload type will be sent to this decoder |
| 40 | // instance. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 41 | int payload_type = 0; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 42 | |
| 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; |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 46 | |
| 47 | DecoderSpecificSettings decoder_specific; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 50 | struct Stats { |
| 51 | int network_frame_rate = 0; |
| 52 | int decode_frame_rate = 0; |
| 53 | int render_frame_rate = 0; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 54 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 55 | // Decoder stats. |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 56 | std::string decoder_implementation_name = "unknown"; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 57 | FrameCounts frame_counts; |
| 58 | int decode_ms = 0; |
| 59 | int max_decode_ms = 0; |
| 60 | int current_delay_ms = 0; |
| 61 | int target_delay_ms = 0; |
| 62 | int jitter_buffer_ms = 0; |
| 63 | int min_playout_delay_ms = 0; |
Peter Boström | c4188fd | 2015-04-24 15:16:03 +0200 | [diff] [blame] | 64 | int render_delay_ms = 10; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 65 | |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 66 | int current_payload_type = -1; |
| 67 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 68 | int total_bitrate_bps = 0; |
| 69 | int discarded_packets = 0; |
| 70 | |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 71 | int sync_offset_ms = std::numeric_limits<int>::max(); |
| 72 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 73 | uint32_t ssrc = 0; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 74 | std::string c_name; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 75 | StreamDataCounters rtp_stats; |
| 76 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 77 | RtcpStatistics rtcp_stats; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct Config { |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 81 | private: |
| 82 | // Access to the copy constructor is private to force use of the Copy() |
| 83 | // method for those exceptional cases where we do use it. |
| 84 | Config(const Config&) = default; |
| 85 | |
| 86 | public: |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 87 | Config() = delete; |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 88 | Config(Config&&) = default; |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 89 | explicit Config(Transport* rtcp_send_transport) |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 90 | : rtcp_send_transport(rtcp_send_transport) {} |
| 91 | |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 92 | Config& operator=(Config&&) = default; |
| 93 | Config& operator=(const Config&) = delete; |
| 94 | |
| 95 | // Mostly used by tests. Avoid creating copies if you can. |
| 96 | Config Copy() const { return Config(*this); } |
| 97 | |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 98 | std::string ToString() const; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 99 | |
| 100 | // Decoders for every payload that we can receive. |
| 101 | std::vector<Decoder> decoders; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 102 | |
| 103 | // Receive-stream specific RTP settings. |
| 104 | struct Rtp { |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 105 | std::string ToString() const; |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 106 | |
pbos@webrtc.org | b613b5a | 2013-12-03 10:13:04 +0000 | [diff] [blame] | 107 | // Synchronization source (stream identifier) to be received. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 108 | uint32_t remote_ssrc = 0; |
pbos@webrtc.org | b613b5a | 2013-12-03 10:13:04 +0000 | [diff] [blame] | 109 | // Sender SSRC used for sending RTCP (such as receiver reports). |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 110 | uint32_t local_ssrc = 0; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 111 | |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 112 | // See RtcpMode for description. |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 113 | RtcpMode rtcp_mode = RtcpMode::kCompound; |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 114 | |
asapersson@webrtc.org | efaeda0 | 2014-01-20 08:34:49 +0000 | [diff] [blame] | 115 | // Extended RTCP settings. |
| 116 | struct RtcpXr { |
asapersson@webrtc.org | efaeda0 | 2014-01-20 08:34:49 +0000 | [diff] [blame] | 117 | // True if RTCP Receiver Reference Time Report Block extension |
| 118 | // (RFC 3611) should be enabled. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 119 | bool receiver_reference_time_report = false; |
asapersson@webrtc.org | efaeda0 | 2014-01-20 08:34:49 +0000 | [diff] [blame] | 120 | } rtcp_xr; |
| 121 | |
mflodman@webrtc.org | 92c2793 | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 122 | // See draft-alvestrand-rmcat-remb for information. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 123 | bool remb = false; |
mflodman@webrtc.org | 92c2793 | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 124 | |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 125 | // See draft-holmer-rmcat-transport-wide-cc-extensions for details. |
| 126 | bool transport_cc = false; |
| 127 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 128 | // See NackConfig for description. |
| 129 | NackConfig nack; |
| 130 | |
| 131 | // See FecConfig for description. |
| 132 | FecConfig fec; |
| 133 | |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 134 | // RTX settings for incoming video payloads that may be received. RTX is |
| 135 | // disabled if there's no config present. |
| 136 | struct Rtx { |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 137 | // SSRCs to use for the RTX streams. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 138 | uint32_t ssrc = 0; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 139 | |
| 140 | // Payload type to use for the RTX stream. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 141 | int payload_type = 0; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | // Map from video RTP payload type -> RTX config. |
| 145 | typedef std::map<int, Rtx> RtxMap; |
| 146 | RtxMap rtx; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 147 | |
noahric | 65220a7 | 2015-10-14 11:29:49 -0700 | [diff] [blame] | 148 | // If set to true, the RTX payload type mapping supplied in |rtx| will be |
| 149 | // used when restoring RTX packets. Without it, RTX packets will always be |
| 150 | // restored to the last non-RTX packet payload type received. |
| 151 | bool use_rtx_payload_mapping_on_restore = false; |
| 152 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 153 | // RTP header extensions used for the received stream. |
| 154 | std::vector<RtpExtension> extensions; |
| 155 | } rtp; |
| 156 | |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 157 | // Transport for outgoing packets (RTCP). |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 158 | Transport* rtcp_send_transport = nullptr; |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 159 | |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 160 | // VideoRenderer will be called for each decoded frame. 'nullptr' disables |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 161 | // rendering of this stream. |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 162 | rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 163 | |
| 164 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 165 | // this many milliseconds, if possible, earlier than the ideal render time. |
| 166 | // Only valid if 'renderer' is set. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 167 | int render_delay_ms = 10; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 168 | |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 169 | // If set, pass frames on to the renderer as soon as they are |
| 170 | // available. |
| 171 | bool disable_prerenderer_smoothing = false; |
| 172 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 173 | // Identifier for an A/V synchronization group. Empty string to disable. |
| 174 | // TODO(pbos): Synchronize streams in a sync group, not just video streams |
| 175 | // to one of the audio streams. |
| 176 | std::string sync_group; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 177 | |
| 178 | // Called for each incoming video frame, i.e. in encoded state. E.g. used |
| 179 | // when |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 180 | // saving the stream to a file. 'nullptr' disables the callback. |
| 181 | EncodedFrameObserver* pre_decode_callback = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 182 | |
| 183 | // Called for each decoded frame. E.g. used when adding effects to the |
| 184 | // decoded |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 185 | // stream. 'nullptr' disables the callback. |
Tommi | bd3380f | 2016-06-10 17:38:17 +0200 | [diff] [blame] | 186 | // TODO(tommi): This seems to be only used by a test or two. Consider |
| 187 | // removing it (and use an appropriate alternative in the tests) as well |
| 188 | // as the associated code in VideoStreamDecoder. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 189 | I420FrameCallback* pre_render_callback = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 190 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 191 | // Target delay in milliseconds. A positive value indicates this stream is |
| 192 | // used for streaming instead of a real-time call. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 12:38:38 +0200 | [diff] [blame] | 193 | int target_delay_ms = 0; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 196 | // Starts stream activity. |
| 197 | // When a stream is active, it can receive, process and deliver packets. |
| 198 | virtual void Start() = 0; |
| 199 | // Stops stream activity. |
| 200 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 201 | virtual void Stop() = 0; |
| 202 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 203 | // TODO(pbos): Add info on currently-received codec to Stats. |
| 204 | virtual Stats GetStats() const = 0; |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 205 | |
| 206 | protected: |
| 207 | virtual ~VideoReceiveStream() {} |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 208 | }; |
| 209 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 210 | } // namespace webrtc |
| 211 | |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 212 | #endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_ |