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