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@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 18 | #include "webrtc/config.h" |
| 19 | #include "webrtc/frame_callback.h" |
| 20 | #include "webrtc/video_renderer.h" |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class VideoEncoder; |
| 25 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 26 | // Class to deliver captured frame to the video send stream. |
| 27 | class VideoSendStreamInput { |
| 28 | public: |
pbos@webrtc.org | 724947b | 2013-12-11 16:26:16 | [diff] [blame] | 29 | // These methods do not lock internally and must be called sequentially. |
| 30 | // If your application switches input sources synchronization must be done |
| 31 | // externally to make sure that any old frames are not delivered concurrently. |
Miguel Casas-Sanchez | 4765070 | 2015-05-30 00:21:40 | [diff] [blame] | 32 | virtual void IncomingCapturedFrame(const VideoFrame& video_frame) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 33 | |
| 34 | protected: |
| 35 | virtual ~VideoSendStreamInput() {} |
| 36 | }; |
| 37 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 38 | class VideoSendStream { |
| 39 | public: |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 | [diff] [blame] | 40 | struct StreamStats { |
| 41 | FrameCounts frame_counts; |
| 42 | int width = 0; |
| 43 | int height = 0; |
| 44 | // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer. |
| 45 | int total_bitrate_bps = 0; |
| 46 | int retransmit_bitrate_bps = 0; |
| 47 | int avg_delay_ms = 0; |
| 48 | int max_delay_ms = 0; |
| 49 | StreamDataCounters rtp_stats; |
| 50 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 51 | RtcpStatistics rtcp_stats; |
| 52 | }; |
| 53 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 54 | struct Stats { |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 55 | int input_frame_rate = 0; |
| 56 | int encode_frame_rate = 0; |
| 57 | int avg_encode_time_ms = 0; |
| 58 | int encode_usage_percent = 0; |
| 59 | int target_media_bitrate_bps = 0; |
| 60 | int media_bitrate_bps = 0; |
| 61 | bool suspended = false; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 | [diff] [blame] | 62 | std::map<uint32_t, StreamStats> substreams; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct Config { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 66 | std::string ToString() const; |
| 67 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 68 | struct EncoderSettings { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 69 | std::string ToString() const; |
| 70 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 71 | std::string payload_name; |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 72 | int payload_type = -1; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 73 | |
| 74 | // Uninitialized VideoEncoder instance to be used for encoding. Will be |
| 75 | // initialized from inside the VideoSendStream. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 76 | VideoEncoder* encoder = nullptr; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 77 | } encoder_settings; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 78 | |
sprang@webrtc.org | 25fce9a | 2013-10-16 13:29:14 | [diff] [blame] | 79 | static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4. |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 80 | struct Rtp { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 81 | std::string ToString() const; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 82 | |
| 83 | std::vector<uint32_t> ssrcs; |
| 84 | |
| 85 | // Max RTP packet size delivered to send transport from VideoEngine. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 86 | size_t max_packet_size = kDefaultMaxPacketSize; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 87 | |
| 88 | // RTP header extensions to use for this send stream. |
| 89 | std::vector<RtpExtension> extensions; |
| 90 | |
| 91 | // See NackConfig for description. |
| 92 | NackConfig nack; |
| 93 | |
| 94 | // See FecConfig for description. |
| 95 | FecConfig fec; |
| 96 | |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 97 | // Settings for RTP retransmission payload format, see RFC 4588 for |
| 98 | // details. |
| 99 | struct Rtx { |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 100 | std::string ToString() const; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 101 | // SSRCs to use for the RTX streams. |
| 102 | std::vector<uint32_t> ssrcs; |
| 103 | |
| 104 | // Payload type to use for the RTX stream. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 105 | int payload_type = -1; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 106 | } rtx; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 107 | |
| 108 | // RTCP CNAME, see RFC 3550. |
| 109 | std::string c_name; |
| 110 | } rtp; |
| 111 | |
| 112 | // Called for each I420 frame before encoding the frame. Can be used for |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 113 | // effects, snapshots etc. 'nullptr' disables the callback. |
| 114 | I420FrameCallback* pre_encode_callback = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 115 | |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 116 | // Called for each encoded frame, e.g. used for file storage. 'nullptr' |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 117 | // disables the callback. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 118 | EncodedFrameObserver* post_encode_callback = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 119 | |
| 120 | // Renderer for local preview. The local renderer will be called even if |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 121 | // sending hasn't started. 'nullptr' disables local rendering. |
| 122 | VideoRenderer* local_renderer = nullptr; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 123 | |
| 124 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 125 | // this many milliseconds, if possible, earlier than expected render time. |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 126 | // Only valid if |local_renderer| is set. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 127 | int render_delay_ms = 0; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 128 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 129 | // Target delay in milliseconds. A positive value indicates this stream is |
| 130 | // used for streaming instead of a real-time call. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 131 | int target_delay_ms = 0; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 132 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 | [diff] [blame] | 133 | // True if the stream should be suspended when the available bitrate fall |
| 134 | // below the minimum configured bitrate. If this variable is false, the |
| 135 | // stream may send at a rate higher than the estimated available bitrate. |
Fredrik Solenberg | 78fb3b3 | 2015-06-11 10:38:38 | [diff] [blame] | 136 | bool suspend_below_min_bitrate = false; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 137 | }; |
| 138 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 139 | // Gets interface used to insert captured frames. Valid as long as the |
| 140 | // VideoSendStream is valid. |
| 141 | virtual VideoSendStreamInput* Input() = 0; |
| 142 | |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 | [diff] [blame] | 143 | virtual void Start() = 0; |
| 144 | virtual void Stop() = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 145 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 146 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 147 | // in the config. Encoder settings are passed on to the encoder instance along |
| 148 | // with the VideoStream settings. |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 | [diff] [blame] | 149 | virtual bool ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 150 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 | [diff] [blame] | 151 | virtual Stats GetStats() = 0; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 | [diff] [blame] | 152 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 153 | protected: |
| 154 | virtual ~VideoSendStream() {} |
| 155 | }; |
| 156 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 157 | } // namespace webrtc |
| 158 | |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 | [diff] [blame] | 159 | #endif // WEBRTC_VIDEO_SEND_STREAM_H_ |