mflodman@webrtc.org | 06e8026 | 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 | 5e0cbcf | 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 | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 13 | |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 | [diff] [blame] | 14 | #include <map> |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 15 | #include <string> |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 16 | |
| 17 | #include "webrtc/common_types.h" |
pbos@webrtc.org | 24e2089 | 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 | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class VideoEncoder; |
| 25 | |
mflodman@webrtc.org | 06e8026 | 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 | c33d37c | 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. |
pbos@webrtc.org | c33d37c | 2013-12-11 16:26:16 | [diff] [blame] | 32 | virtual void SwapFrame(I420VideoFrame* video_frame) = 0; |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 33 | |
| 34 | protected: |
| 35 | virtual ~VideoSendStreamInput() {} |
| 36 | }; |
| 37 | |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 38 | class VideoSendStream { |
| 39 | public: |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 40 | struct Stats { |
| 41 | Stats() |
| 42 | : input_frame_rate(0), |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 | [diff] [blame] | 43 | encode_frame_rate(0), |
stefan@webrtc.org | 5232267 | 2014-11-05 14:05:29 | [diff] [blame] | 44 | media_bitrate_bps(0), |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 | [diff] [blame] | 45 | suspended(false) {} |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 | [diff] [blame] | 46 | int input_frame_rate; |
| 47 | int encode_frame_rate; |
stefan@webrtc.org | 5232267 | 2014-11-05 14:05:29 | [diff] [blame] | 48 | int media_bitrate_bps; |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 | [diff] [blame] | 49 | bool suspended; |
stefan@webrtc.org | 5232267 | 2014-11-05 14:05:29 | [diff] [blame] | 50 | std::map<uint32_t, SsrcStats> substreams; |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct Config { |
| 54 | Config() |
| 55 | : pre_encode_callback(NULL), |
sprang@webrtc.org | 2e98d45 | 2013-11-26 11:41:59 | [diff] [blame] | 56 | post_encode_callback(NULL), |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 57 | local_renderer(NULL), |
| 58 | render_delay_ms(0), |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 59 | target_delay_ms(0), |
henrik.lundin@webrtc.org | 4590177 | 2013-11-18 12:18:43 | [diff] [blame] | 60 | suspend_below_min_bitrate(false) {} |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 61 | std::string ToString() const; |
| 62 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 | [diff] [blame] | 63 | struct EncoderSettings { |
pbos@webrtc.org | bdfcddf | 2014-06-06 10:49:19 | [diff] [blame] | 64 | EncoderSettings() : payload_type(-1), encoder(NULL) {} |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 65 | |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 66 | std::string ToString() const; |
| 67 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 | [diff] [blame] | 68 | std::string payload_name; |
| 69 | int payload_type; |
| 70 | |
| 71 | // Uninitialized VideoEncoder instance to be used for encoding. Will be |
| 72 | // initialized from inside the VideoSendStream. |
pbos@webrtc.org | f076e17 | 2015-01-15 10:09:39 | [diff] [blame] | 73 | VideoEncoder* encoder; |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 | [diff] [blame] | 74 | } encoder_settings; |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 75 | |
sprang@webrtc.org | 44bb62a | 2013-10-16 13:29:14 | [diff] [blame] | 76 | static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4. |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 77 | struct Rtp { |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 78 | Rtp() : max_packet_size(kDefaultMaxPacketSize) {} |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 79 | std::string ToString() const; |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 80 | |
| 81 | std::vector<uint32_t> ssrcs; |
| 82 | |
| 83 | // Max RTP packet size delivered to send transport from VideoEngine. |
| 84 | size_t max_packet_size; |
| 85 | |
| 86 | // RTP header extensions to use for this send stream. |
| 87 | std::vector<RtpExtension> extensions; |
| 88 | |
| 89 | // See NackConfig for description. |
| 90 | NackConfig nack; |
| 91 | |
| 92 | // See FecConfig for description. |
| 93 | FecConfig fec; |
| 94 | |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 | [diff] [blame] | 95 | // Settings for RTP retransmission payload format, see RFC 4588 for |
| 96 | // details. |
| 97 | struct Rtx { |
stefan@webrtc.org | 7c8ebe8 | 2014-12-19 15:33:17 | [diff] [blame] | 98 | Rtx() : payload_type(-1) {} |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 99 | std::string ToString() const; |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 | [diff] [blame] | 100 | // SSRCs to use for the RTX streams. |
| 101 | std::vector<uint32_t> ssrcs; |
| 102 | |
| 103 | // Payload type to use for the RTX stream. |
| 104 | int payload_type; |
| 105 | } rtx; |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 106 | |
| 107 | // RTCP CNAME, see RFC 3550. |
| 108 | std::string c_name; |
| 109 | } rtp; |
| 110 | |
| 111 | // Called for each I420 frame before encoding the frame. Can be used for |
| 112 | // effects, snapshots etc. 'NULL' disables the callback. |
| 113 | I420FrameCallback* pre_encode_callback; |
| 114 | |
| 115 | // Called for each encoded frame, e.g. used for file storage. 'NULL' |
| 116 | // disables the callback. |
sprang@webrtc.org | 2e98d45 | 2013-11-26 11:41:59 | [diff] [blame] | 117 | EncodedFrameObserver* post_encode_callback; |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 118 | |
| 119 | // Renderer for local preview. The local renderer will be called even if |
| 120 | // sending hasn't started. 'NULL' disables local rendering. |
| 121 | VideoRenderer* local_renderer; |
| 122 | |
| 123 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 124 | // this many milliseconds, if possible, earlier than expected render time. |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 125 | // Only valid if |local_renderer| is set. |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 126 | int render_delay_ms; |
| 127 | |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 128 | // Target delay in milliseconds. A positive value indicates this stream is |
| 129 | // used for streaming instead of a real-time call. |
| 130 | int target_delay_ms; |
| 131 | |
henrik.lundin@webrtc.org | 4590177 | 2013-11-18 12:18:43 | [diff] [blame] | 132 | // True if the stream should be suspended when the available bitrate fall |
| 133 | // below the minimum configured bitrate. If this variable is false, the |
| 134 | // stream may send at a rate higher than the estimated available bitrate. |
| 135 | bool suspend_below_min_bitrate; |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 | [diff] [blame] | 136 | }; |
| 137 | |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 138 | // Gets interface used to insert captured frames. Valid as long as the |
| 139 | // VideoSendStream is valid. |
| 140 | virtual VideoSendStreamInput* Input() = 0; |
| 141 | |
pbos@webrtc.org | 16a058a | 2014-04-24 11:13:21 | [diff] [blame] | 142 | virtual void Start() = 0; |
| 143 | virtual void Stop() = 0; |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 144 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 | [diff] [blame] | 145 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 146 | // in the config. Encoder settings are passed on to the encoder instance along |
| 147 | // with the VideoStream settings. |
pbos@webrtc.org | 58b5140 | 2014-09-19 12:30:25 | [diff] [blame] | 148 | virtual bool ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0; |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 149 | |
pbos@webrtc.org | ee9497c | 2014-12-01 15:23:21 | [diff] [blame] | 150 | virtual Stats GetStats() = 0; |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 | [diff] [blame] | 151 | |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 152 | protected: |
| 153 | virtual ~VideoSendStream() {} |
| 154 | }; |
| 155 | |
mflodman@webrtc.org | 06e8026 | 2013-04-18 12:02:52 | [diff] [blame] | 156 | } // namespace webrtc |
| 157 | |
mflodman@webrtc.org | 5e0cbcf | 2013-12-18 09:46:22 | [diff] [blame] | 158 | #endif // WEBRTC_VIDEO_SEND_STREAM_H_ |