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_SEND_STREAM_H_ |
| 12 | #define CALL_VIDEO_SEND_STREAM_H_ |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <string> |
| 16 | #include <utility> |
| 17 | #include <vector> |
| 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/call/transport.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 20 | #include "api/rtp_headers.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 21 | #include "api/rtpparameters.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 22 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 23 | #include "api/video/video_source_interface.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 24 | #include "api/video_codecs/video_encoder_config.h" |
Niels Möller | 88614b0 | 2018-03-27 16:39:01 +0200 | [diff] [blame] | 25 | #include "api/video_codecs/video_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "call/rtp_config.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 27 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "common_video/include/frame_callback.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 29 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "rtc_base/platform_file.h" |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 31 | |
| 32 | namespace webrtc { |
| 33 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 34 | class VideoSendStream { |
| 35 | public: |
| 36 | struct StreamStats { |
| 37 | StreamStats(); |
| 38 | ~StreamStats(); |
| 39 | |
| 40 | std::string ToString() const; |
| 41 | |
| 42 | FrameCounts frame_counts; |
| 43 | bool is_rtx = false; |
| 44 | bool is_flexfec = false; |
| 45 | int width = 0; |
| 46 | int height = 0; |
| 47 | // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer. |
| 48 | int total_bitrate_bps = 0; |
| 49 | int retransmit_bitrate_bps = 0; |
| 50 | int avg_delay_ms = 0; |
| 51 | int max_delay_ms = 0; |
| 52 | StreamDataCounters rtp_stats; |
| 53 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 54 | RtcpStatistics rtcp_stats; |
| 55 | }; |
| 56 | |
| 57 | struct Stats { |
| 58 | Stats(); |
| 59 | ~Stats(); |
| 60 | std::string ToString(int64_t time_ms) const; |
| 61 | std::string encoder_implementation_name = "unknown"; |
| 62 | int input_frame_rate = 0; |
| 63 | int encode_frame_rate = 0; |
| 64 | int avg_encode_time_ms = 0; |
| 65 | int encode_usage_percent = 0; |
| 66 | uint32_t frames_encoded = 0; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 67 | uint32_t frames_dropped_by_capturer = 0; |
| 68 | uint32_t frames_dropped_by_encoder_queue = 0; |
| 69 | uint32_t frames_dropped_by_rate_limiter = 0; |
| 70 | uint32_t frames_dropped_by_encoder = 0; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 71 | absl::optional<uint64_t> qp_sum; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 72 | // Bitrate the encoder is currently configured to use due to bandwidth |
| 73 | // limitations. |
| 74 | int target_media_bitrate_bps = 0; |
| 75 | // Bitrate the encoder is actually producing. |
| 76 | int media_bitrate_bps = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 77 | bool suspended = false; |
| 78 | bool bw_limited_resolution = false; |
| 79 | bool cpu_limited_resolution = false; |
| 80 | bool bw_limited_framerate = false; |
| 81 | bool cpu_limited_framerate = false; |
| 82 | // Total number of times resolution as been requested to be changed due to |
| 83 | // CPU/quality adaptation. |
| 84 | int number_of_cpu_adapt_changes = 0; |
| 85 | int number_of_quality_adapt_changes = 0; |
Åsa Persson | c3ed630 | 2017-11-16 14:04:52 +0100 | [diff] [blame] | 86 | bool has_entered_low_resolution = false; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 87 | std::map<uint32_t, StreamStats> substreams; |
ilnik | 50864a8 | 2017-09-06 12:32:35 -0700 | [diff] [blame] | 88 | webrtc::VideoContentType content_type = |
| 89 | webrtc::VideoContentType::UNSPECIFIED; |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 90 | uint32_t huge_frames_sent = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | struct Config { |
| 94 | public: |
| 95 | Config() = delete; |
| 96 | Config(Config&&); |
| 97 | explicit Config(Transport* send_transport); |
| 98 | |
| 99 | Config& operator=(Config&&); |
| 100 | Config& operator=(const Config&) = delete; |
| 101 | |
| 102 | ~Config(); |
| 103 | |
| 104 | // Mostly used by tests. Avoid creating copies if you can. |
| 105 | Config Copy() const { return Config(*this); } |
| 106 | |
| 107 | std::string ToString() const; |
| 108 | |
| 109 | struct EncoderSettings { |
| 110 | EncoderSettings() = default; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 111 | std::string ToString() const; |
| 112 | |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 113 | // Enables the new method to estimate the cpu load from encoding, used for |
| 114 | // cpu adaptation. |
| 115 | bool experiment_cpu_load_estimator = false; |
| 116 | |
Niels Möller | 88614b0 | 2018-03-27 16:39:01 +0200 | [diff] [blame] | 117 | // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection). |
| 118 | VideoEncoderFactory* encoder_factory = nullptr; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 119 | } encoder_settings; |
| 120 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 121 | RtpConfig rtp; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 122 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 123 | RtcpConfig rtcp; |
Jiawei Ou | 3587b83 | 2018-01-31 22:08:26 -0800 | [diff] [blame] | 124 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 125 | // Transport for outgoing packets. |
| 126 | Transport* send_transport = nullptr; |
| 127 | |
| 128 | // Called for each I420 frame before encoding the frame. Can be used for |
| 129 | // effects, snapshots etc. 'nullptr' disables the callback. |
| 130 | rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback = nullptr; |
| 131 | |
| 132 | // Called for each encoded frame, e.g. used for file storage. 'nullptr' |
| 133 | // disables the callback. Also measures timing and passes the time |
| 134 | // spent on encoding. This timing will not fire if encoding takes longer |
| 135 | // than the measuring window, since the sample data will have been dropped. |
| 136 | EncodedFrameObserver* post_encode_callback = nullptr; |
| 137 | |
| 138 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 139 | // this many milliseconds, if possible, earlier than expected render time. |
| 140 | // Only valid if |local_renderer| is set. |
| 141 | int render_delay_ms = 0; |
| 142 | |
| 143 | // Target delay in milliseconds. A positive value indicates this stream is |
| 144 | // used for streaming instead of a real-time call. |
| 145 | int target_delay_ms = 0; |
| 146 | |
| 147 | // True if the stream should be suspended when the available bitrate fall |
| 148 | // below the minimum configured bitrate. If this variable is false, the |
| 149 | // stream may send at a rate higher than the estimated available bitrate. |
| 150 | bool suspend_below_min_bitrate = false; |
| 151 | |
| 152 | // Enables periodic bandwidth probing in application-limited region. |
| 153 | bool periodic_alr_bandwidth_probing = false; |
| 154 | |
Alex Narest | b3944f0 | 2017-10-13 14:56:18 +0200 | [diff] [blame] | 155 | // Track ID as specified during track creation. |
| 156 | std::string track_id; |
| 157 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 158 | private: |
| 159 | // Access to the copy constructor is private to force use of the Copy() |
| 160 | // method for those exceptional cases where we do use it. |
| 161 | Config(const Config&); |
| 162 | }; |
| 163 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 164 | // Updates the sending state for all simulcast layers that the video send |
| 165 | // stream owns. This can mean updating the activity one or for multiple |
| 166 | // layers. The ordering of active layers is the order in which the |
| 167 | // rtp modules are stored in the VideoSendStream. |
| 168 | // Note: This starts stream activity if it is inactive and one of the layers |
| 169 | // is active. This stops stream activity if it is active and all layers are |
| 170 | // inactive. |
| 171 | virtual void UpdateActiveSimulcastLayers( |
| 172 | const std::vector<bool> active_layers) = 0; |
| 173 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 174 | // Starts stream activity. |
| 175 | // When a stream is active, it can receive, process and deliver packets. |
| 176 | virtual void Start() = 0; |
| 177 | // Stops stream activity. |
| 178 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 179 | virtual void Stop() = 0; |
| 180 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 181 | virtual void SetSource( |
| 182 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source, |
| 183 | const DegradationPreference& degradation_preference) = 0; |
| 184 | |
| 185 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 186 | // in the config. Encoder settings are passed on to the encoder instance along |
| 187 | // with the VideoStream settings. |
| 188 | virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0; |
| 189 | |
| 190 | virtual Stats GetStats() = 0; |
| 191 | |
| 192 | // Takes ownership of each file, is responsible for closing them later. |
| 193 | // Calling this method will close and finalize any current logs. |
| 194 | // Some codecs produce multiple streams (VP8 only at present), each of these |
| 195 | // streams will log to a separate file. kMaxSimulcastStreams in common_types.h |
| 196 | // gives the max number of such streams. If there is no file for a stream, or |
| 197 | // the file is rtc::kInvalidPlatformFileValue, frames from that stream will |
| 198 | // not be logged. |
| 199 | // If a frame to be written would make the log too large the write fails and |
| 200 | // the log is closed and finalized. A |byte_limit| of 0 means no limit. |
| 201 | virtual void EnableEncodedFrameRecording( |
| 202 | const std::vector<rtc::PlatformFile>& files, |
| 203 | size_t byte_limit) = 0; |
| 204 | inline void DisableEncodedFrameRecording() { |
| 205 | EnableEncodedFrameRecording(std::vector<rtc::PlatformFile>(), 0); |
| 206 | } |
| 207 | |
| 208 | protected: |
| 209 | virtual ~VideoSendStream() {} |
| 210 | }; |
| 211 | |
| 212 | } // namespace webrtc |
| 213 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 214 | #endif // CALL_VIDEO_SEND_STREAM_H_ |