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