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