mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [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 | [diff] [blame] | 11 | #ifndef WEBRTC_VIDEO_SEND_STREAM_H_ |
| 12 | #define WEBRTC_VIDEO_SEND_STREAM_H_ |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 13 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 | [diff] [blame] | 14 | #include <map> |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 15 | #include <string> |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 16 | |
| 17 | #include "webrtc/common_types.h" |
pbos | a96b60b | 2016-04-19 04:12:48 | [diff] [blame] | 18 | #include "webrtc/common_video/include/frame_callback.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 19 | #include "webrtc/config.h" |
nisse | d30a111 | 2016-04-18 12:15:22 | [diff] [blame] | 20 | #include "webrtc/media/base/videosinkinterface.h" |
solenberg | 4fbae2b | 2015-08-28 11:07:10 | [diff] [blame] | 21 | #include "webrtc/transport.h" |
nisse | 7ade7b3 | 2016-03-23 11:48:10 | [diff] [blame] | 22 | #include "webrtc/media/base/videosinkinterface.h" |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
solenberg | e526974 | 2015-09-08 12:13:22 | [diff] [blame] | 26 | class LoadObserver; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 27 | class VideoEncoder; |
| 28 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 29 | // Class to deliver captured frame to the video send stream. |
Peter Boström | 4b91bd0 | 2015-06-26 04:58:16 | [diff] [blame] | 30 | class VideoCaptureInput { |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 31 | public: |
pbos@webrtc.org | 724947b | 2013-12-11 16:26:16 | [diff] [blame] | 32 | // These methods do not lock internally and must be called sequentially. |
| 33 | // If your application switches input sources synchronization must be done |
| 34 | // externally to make sure that any old frames are not delivered concurrently. |
Miguel Casas-Sanchez | 4765070 | 2015-05-30 00:21:40 | [diff] [blame] | 35 | virtual void IncomingCapturedFrame(const VideoFrame& video_frame) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 36 | |
| 37 | protected: |
Peter Boström | 4b91bd0 | 2015-06-26 04:58:16 | [diff] [blame] | 38 | virtual ~VideoCaptureInput() {} |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 39 | }; |
| 40 | |
pbos | 1ba8d39 | 2016-05-02 03:18:34 | [diff] [blame] | 41 | class VideoSendStream { |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 42 | public: |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 | [diff] [blame] | 43 | struct StreamStats { |
| 44 | FrameCounts frame_counts; |
| 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 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 57 | struct Stats { |
Peter Boström | b7d9a97 | 2015-12-18 15:01:11 | [diff] [blame] | 58 | std::string encoder_implementation_name = "unknown"; |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 59 | int input_frame_rate = 0; |
| 60 | int encode_frame_rate = 0; |
| 61 | int avg_encode_time_ms = 0; |
| 62 | int encode_usage_percent = 0; |
| 63 | int target_media_bitrate_bps = 0; |
| 64 | int media_bitrate_bps = 0; |
| 65 | bool suspended = false; |
asapersson | 17821db | 2015-12-14 10:08:12 | [diff] [blame] | 66 | bool bw_limited_resolution = false; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 | [diff] [blame] | 67 | std::map<uint32_t, StreamStats> substreams; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | struct Config { |
solenberg | 4fbae2b | 2015-08-28 11:07:10 | [diff] [blame] | 71 | Config() = delete; |
pbos | 2d56668 | 2015-09-28 16:59:31 | [diff] [blame] | 72 | explicit Config(Transport* send_transport) |
solenberg | 4fbae2b | 2015-08-28 11:07:10 | [diff] [blame] | 73 | : send_transport(send_transport) {} |
| 74 | |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 75 | std::string ToString() const; |
| 76 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 77 | struct EncoderSettings { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 78 | std::string ToString() const; |
| 79 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 80 | std::string payload_name; |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 81 | int payload_type = -1; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 82 | |
sophiechang | 47d78cc | 2015-09-04 01:24:44 | [diff] [blame] | 83 | // TODO(sophiechang): Delete this field when no one is using internal |
| 84 | // sources anymore. |
| 85 | bool internal_source = false; |
| 86 | |
Peter Boström | e449915 | 2016-02-05 10:13:28 | [diff] [blame] | 87 | // Allow 100% encoder utilization. Used for HW encoders where CPU isn't |
| 88 | // expected to be the limiting factor, but a chip could be running at |
| 89 | // 30fps (for example) exactly. |
| 90 | bool full_overuse_time = false; |
| 91 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 92 | // Uninitialized VideoEncoder instance to be used for encoding. Will be |
| 93 | // initialized from inside the VideoSendStream. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 94 | VideoEncoder* encoder = nullptr; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 95 | } encoder_settings; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 96 | |
sprang@webrtc.org | 25fce9a | 2013-10-16 13:29:14 | [diff] [blame] | 97 | static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4. |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 98 | struct Rtp { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 99 | std::string ToString() const; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 100 | |
| 101 | std::vector<uint32_t> ssrcs; |
| 102 | |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 103 | // See RtcpMode for description. |
| 104 | RtcpMode rtcp_mode = RtcpMode::kCompound; |
| 105 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 106 | // Max RTP packet size delivered to send transport from VideoEngine. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 107 | size_t max_packet_size = kDefaultMaxPacketSize; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 108 | |
| 109 | // RTP header extensions to use for this send stream. |
| 110 | std::vector<RtpExtension> extensions; |
| 111 | |
| 112 | // See NackConfig for description. |
| 113 | NackConfig nack; |
| 114 | |
| 115 | // See FecConfig for description. |
| 116 | FecConfig fec; |
| 117 | |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 118 | // Settings for RTP retransmission payload format, see RFC 4588 for |
| 119 | // details. |
| 120 | struct Rtx { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 121 | std::string ToString() const; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 122 | // SSRCs to use for the RTX streams. |
| 123 | std::vector<uint32_t> ssrcs; |
| 124 | |
| 125 | // Payload type to use for the RTX stream. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 126 | int payload_type = -1; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 127 | } rtx; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 128 | |
| 129 | // RTCP CNAME, see RFC 3550. |
| 130 | std::string c_name; |
| 131 | } rtp; |
| 132 | |
solenberg | 4fbae2b | 2015-08-28 11:07:10 | [diff] [blame] | 133 | // Transport for outgoing packets. |
pbos | 2d56668 | 2015-09-28 16:59:31 | [diff] [blame] | 134 | Transport* send_transport = nullptr; |
solenberg | 4fbae2b | 2015-08-28 11:07:10 | [diff] [blame] | 135 | |
solenberg | e526974 | 2015-09-08 12:13:22 | [diff] [blame] | 136 | // Callback for overuse and normal usage based on the jitter of incoming |
| 137 | // captured frames. 'nullptr' disables the callback. |
| 138 | LoadObserver* overuse_callback = nullptr; |
| 139 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 140 | // Called for each I420 frame before encoding the frame. Can be used for |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 141 | // effects, snapshots etc. 'nullptr' disables the callback. |
nisse | d30a111 | 2016-04-18 12:15:22 | [diff] [blame] | 142 | rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 143 | |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 144 | // Called for each encoded frame, e.g. used for file storage. 'nullptr' |
Peter Boström | e449915 | 2016-02-05 10:13:28 | [diff] [blame] | 145 | // disables the callback. Also measures timing and passes the time |
| 146 | // spent on encoding. This timing will not fire if encoding takes longer |
| 147 | // than the measuring window, since the sample data will have been dropped. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 148 | EncodedFrameObserver* post_encode_callback = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 149 | |
| 150 | // Renderer for local preview. The local renderer will be called even if |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 151 | // sending hasn't started. 'nullptr' disables local rendering. |
nisse | 7ade7b3 | 2016-03-23 11:48:10 | [diff] [blame] | 152 | rtc::VideoSinkInterface<VideoFrame>* local_renderer = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 153 | |
| 154 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 155 | // this many milliseconds, if possible, earlier than expected render time. |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 156 | // Only valid if |local_renderer| is set. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 157 | int render_delay_ms = 0; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 158 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 159 | // Target delay in milliseconds. A positive value indicates this stream is |
| 160 | // used for streaming instead of a real-time call. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 161 | int target_delay_ms = 0; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 162 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 | [diff] [blame] | 163 | // True if the stream should be suspended when the available bitrate fall |
| 164 | // below the minimum configured bitrate. If this variable is false, the |
| 165 | // stream may send at a rate higher than the estimated available bitrate. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 166 | bool suspend_below_min_bitrate = false; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 167 | }; |
| 168 | |
pbos | 1ba8d39 | 2016-05-02 03:18:34 | [diff] [blame] | 169 | // Starts stream activity. |
| 170 | // When a stream is active, it can receive, process and deliver packets. |
| 171 | virtual void Start() = 0; |
| 172 | // Stops stream activity. |
| 173 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 174 | virtual void Stop() = 0; |
| 175 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 176 | // Gets interface used to insert captured frames. Valid as long as the |
| 177 | // VideoSendStream is valid. |
Peter Boström | 4b91bd0 | 2015-06-26 04:58:16 | [diff] [blame] | 178 | virtual VideoCaptureInput* Input() = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 179 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 180 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 181 | // in the config. Encoder settings are passed on to the encoder instance along |
| 182 | // with the VideoStream settings. |
Peter Boström | 905f8e7 | 2016-03-02 15:59:56 | [diff] [blame] | 183 | virtual void ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 184 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 | [diff] [blame] | 185 | virtual Stats GetStats() = 0; |
pbos | 1ba8d39 | 2016-05-02 03:18:34 | [diff] [blame] | 186 | |
| 187 | protected: |
| 188 | virtual ~VideoSendStream() {} |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 189 | }; |
| 190 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 191 | } // namespace webrtc |
| 192 | |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 | [diff] [blame] | 193 | #endif // WEBRTC_VIDEO_SEND_STREAM_H_ |