aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_VIDEO_RECEIVE_STREAM_H_ |
| 12 | #define CALL_VIDEO_RECEIVE_STREAM_H_ |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 13 | |
| 14 | #include <limits> |
| 15 | #include <map> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 19 | #include "api/rtp_headers.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "api/call/transport.h" |
| 21 | #include "api/rtpparameters.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 22 | #include "api/video/video_content_type.h" |
| 23 | #include "api/video/video_timing.h" |
Patrik Höglund | be214a2 | 2018-01-04 12:14:35 +0100 | [diff] [blame] | 24 | #include "api/videosinkinterface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "call/rtp_config.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 26 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "common_video/include/frame_callback.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 28 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "rtc_base/platform_file.h" |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | |
| 33 | class RtpPacketSinkInterface; |
| 34 | class VideoDecoder; |
| 35 | |
| 36 | class VideoReceiveStream { |
| 37 | public: |
| 38 | // TODO(mflodman) Move all these settings to VideoDecoder and move the |
| 39 | // declaration to common_types.h. |
| 40 | struct Decoder { |
| 41 | Decoder(); |
| 42 | Decoder(const Decoder&); |
| 43 | ~Decoder(); |
| 44 | std::string ToString() const; |
| 45 | |
| 46 | // The actual decoder instance. |
| 47 | VideoDecoder* decoder = nullptr; |
| 48 | |
| 49 | // Received RTP packets with this payload type will be sent to this decoder |
| 50 | // instance. |
| 51 | int payload_type = 0; |
| 52 | |
| 53 | // Name of the decoded payload (such as VP8). Maps back to the depacketizer |
| 54 | // used to unpack incoming packets. |
| 55 | std::string payload_name; |
| 56 | |
| 57 | // This map contains the codec specific parameters from SDP, i.e. the "fmtp" |
| 58 | // parameters. It is the same as cricket::CodecParameterMap used in |
| 59 | // cricket::VideoCodec. |
| 60 | std::map<std::string, std::string> codec_params; |
| 61 | }; |
| 62 | |
| 63 | struct Stats { |
| 64 | Stats(); |
| 65 | ~Stats(); |
| 66 | std::string ToString(int64_t time_ms) const; |
| 67 | |
| 68 | int network_frame_rate = 0; |
| 69 | int decode_frame_rate = 0; |
| 70 | int render_frame_rate = 0; |
| 71 | uint32_t frames_rendered = 0; |
| 72 | |
| 73 | // Decoder stats. |
| 74 | std::string decoder_implementation_name = "unknown"; |
| 75 | FrameCounts frame_counts; |
| 76 | int decode_ms = 0; |
| 77 | int max_decode_ms = 0; |
| 78 | int current_delay_ms = 0; |
| 79 | int target_delay_ms = 0; |
| 80 | int jitter_buffer_ms = 0; |
| 81 | int min_playout_delay_ms = 0; |
| 82 | int render_delay_ms = 10; |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 83 | int64_t interframe_delay_max_ms = -1; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 84 | uint32_t frames_decoded = 0; |
| 85 | rtc::Optional<uint64_t> qp_sum; |
| 86 | |
| 87 | int current_payload_type = -1; |
| 88 | |
| 89 | int total_bitrate_bps = 0; |
| 90 | int discarded_packets = 0; |
| 91 | |
| 92 | int width = 0; |
| 93 | int height = 0; |
| 94 | |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 95 | VideoContentType content_type = VideoContentType::UNSPECIFIED; |
| 96 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 97 | int sync_offset_ms = std::numeric_limits<int>::max(); |
| 98 | |
| 99 | uint32_t ssrc = 0; |
| 100 | std::string c_name; |
| 101 | StreamDataCounters rtp_stats; |
| 102 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 103 | RtcpStatistics rtcp_stats; |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 104 | |
| 105 | // Timing frame info: all important timestamps for a full lifetime of a |
| 106 | // single 'timing frame'. |
| 107 | rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct Config { |
| 111 | private: |
| 112 | // Access to the copy constructor is private to force use of the Copy() |
| 113 | // method for those exceptional cases where we do use it. |
| 114 | Config(const Config&); |
| 115 | |
| 116 | public: |
| 117 | Config() = delete; |
| 118 | Config(Config&&); |
| 119 | explicit Config(Transport* rtcp_send_transport); |
| 120 | Config& operator=(Config&&); |
| 121 | Config& operator=(const Config&) = delete; |
| 122 | ~Config(); |
| 123 | |
| 124 | // Mostly used by tests. Avoid creating copies if you can. |
| 125 | Config Copy() const { return Config(*this); } |
| 126 | |
| 127 | std::string ToString() const; |
| 128 | |
| 129 | // Decoders for every payload that we can receive. |
| 130 | std::vector<Decoder> decoders; |
| 131 | |
| 132 | // Receive-stream specific RTP settings. |
| 133 | struct Rtp { |
| 134 | Rtp(); |
| 135 | Rtp(const Rtp&); |
| 136 | ~Rtp(); |
| 137 | std::string ToString() const; |
| 138 | |
| 139 | // Synchronization source (stream identifier) to be received. |
| 140 | uint32_t remote_ssrc = 0; |
| 141 | |
| 142 | // Sender SSRC used for sending RTCP (such as receiver reports). |
| 143 | uint32_t local_ssrc = 0; |
| 144 | |
| 145 | // See RtcpMode for description. |
| 146 | RtcpMode rtcp_mode = RtcpMode::kCompound; |
| 147 | |
| 148 | // Extended RTCP settings. |
| 149 | struct RtcpXr { |
| 150 | // True if RTCP Receiver Reference Time Report Block extension |
| 151 | // (RFC 3611) should be enabled. |
| 152 | bool receiver_reference_time_report = false; |
| 153 | } rtcp_xr; |
| 154 | |
| 155 | // TODO(nisse): This remb setting is currently set but never |
| 156 | // applied. REMB logic is now the responsibility of |
| 157 | // PacketRouter, and it will generate REMB feedback if |
| 158 | // OnReceiveBitrateChanged is used, which depends on how the |
| 159 | // estimators belonging to the ReceiveSideCongestionController |
| 160 | // are configured. Decide if this setting should be deleted, and |
| 161 | // if it needs to be replaced by a setting in PacketRouter to |
| 162 | // disable REMB feedback. |
| 163 | |
| 164 | // See draft-alvestrand-rmcat-remb for information. |
| 165 | bool remb = false; |
| 166 | |
| 167 | // See draft-holmer-rmcat-transport-wide-cc-extensions for details. |
| 168 | bool transport_cc = false; |
| 169 | |
| 170 | // See NackConfig for description. |
| 171 | NackConfig nack; |
| 172 | |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 173 | // Payload types for ULPFEC and RED, respectively. |
| 174 | int ulpfec_payload_type = -1; |
| 175 | int red_payload_type = -1; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 176 | |
| 177 | // SSRC for retransmissions. |
| 178 | uint32_t rtx_ssrc = 0; |
| 179 | |
| 180 | // Set if the stream is protected using FlexFEC. |
| 181 | bool protected_by_flexfec = false; |
| 182 | |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 183 | // Map from rtx payload type -> media payload type. |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 184 | // For RTX to be enabled, both an SSRC and this mapping are needed. |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 185 | std::map<int, int> rtx_associated_payload_types; |
Niels Möller | 23bdb67 | 2017-08-24 10:05:15 +0200 | [diff] [blame] | 186 | // TODO(nisse): This is a temporary accessor function to enable |
| 187 | // reversing and renaming of the rtx_payload_types mapping. |
| 188 | void AddRtxBinding(int rtx_payload_type, int media_payload_type) { |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 189 | rtx_associated_payload_types[rtx_payload_type] = media_payload_type; |
Niels Möller | 23bdb67 | 2017-08-24 10:05:15 +0200 | [diff] [blame] | 190 | } |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 191 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 192 | // RTP header extensions used for the received stream. |
| 193 | std::vector<RtpExtension> extensions; |
| 194 | } rtp; |
| 195 | |
| 196 | // Transport for outgoing packets (RTCP). |
| 197 | Transport* rtcp_send_transport = nullptr; |
| 198 | |
| 199 | // Must not be 'nullptr' when the stream is started. |
| 200 | rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
| 201 | |
| 202 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 203 | // this many milliseconds, if possible, earlier than the ideal render time. |
| 204 | // Only valid if 'renderer' is set. |
| 205 | int render_delay_ms = 10; |
| 206 | |
| 207 | // If set, pass frames on to the renderer as soon as they are |
| 208 | // available. |
| 209 | bool disable_prerenderer_smoothing = false; |
| 210 | |
| 211 | // Identifier for an A/V synchronization group. Empty string to disable. |
| 212 | // TODO(pbos): Synchronize streams in a sync group, not just video streams |
| 213 | // to one of the audio streams. |
| 214 | std::string sync_group; |
| 215 | |
| 216 | // Called for each incoming video frame, i.e. in encoded state. E.g. used |
| 217 | // when |
| 218 | // saving the stream to a file. 'nullptr' disables the callback. |
| 219 | EncodedFrameObserver* pre_decode_callback = nullptr; |
| 220 | |
| 221 | // Target delay in milliseconds. A positive value indicates this stream is |
| 222 | // used for streaming instead of a real-time call. |
| 223 | int target_delay_ms = 0; |
| 224 | }; |
| 225 | |
| 226 | // Starts stream activity. |
| 227 | // When a stream is active, it can receive, process and deliver packets. |
| 228 | virtual void Start() = 0; |
| 229 | // Stops stream activity. |
| 230 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 231 | virtual void Stop() = 0; |
| 232 | |
| 233 | // TODO(pbos): Add info on currently-received codec to Stats. |
| 234 | virtual Stats GetStats() const = 0; |
| 235 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 236 | // Takes ownership of the file, is responsible for closing it later. |
| 237 | // Calling this method will close and finalize any current log. |
| 238 | // Giving rtc::kInvalidPlatformFileValue disables logging. |
| 239 | // If a frame to be written would make the log too large the write fails and |
| 240 | // the log is closed and finalized. A |byte_limit| of 0 means no limit. |
| 241 | virtual void EnableEncodedFrameRecording(rtc::PlatformFile file, |
| 242 | size_t byte_limit) = 0; |
| 243 | inline void DisableEncodedFrameRecording() { |
| 244 | EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0); |
| 245 | } |
| 246 | |
| 247 | // RtpDemuxer only forwards a given RTP packet to one sink. However, some |
| 248 | // sinks, such as FlexFEC, might wish to be informed of all of the packets |
| 249 | // a given sink receives (or any set of sinks). They may do so by registering |
| 250 | // themselves as secondary sinks. |
| 251 | virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0; |
| 252 | virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0; |
| 253 | |
| 254 | protected: |
| 255 | virtual ~VideoReceiveStream() {} |
| 256 | }; |
| 257 | |
| 258 | } // namespace webrtc |
| 259 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 260 | #endif // CALL_VIDEO_RECEIVE_STREAM_H_ |