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 | |
| 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 | 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. |
| 32 | virtual void PutFrame(const I420VideoFrame& video_frame) = 0; |
| 33 | virtual void SwapFrame(I420VideoFrame* video_frame) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | virtual ~VideoSendStreamInput() {} |
| 37 | }; |
| 38 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 39 | class VideoSendStream { |
| 40 | public: |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 41 | struct Stats { |
| 42 | Stats() |
| 43 | : input_frame_rate(0), |
| 44 | encode_frame(0), |
| 45 | key_frames(0), |
| 46 | delta_frames(0), |
| 47 | video_packets(0), |
| 48 | retransmitted_packets(0), |
| 49 | fec_packets(0), |
| 50 | padding_packets(0), |
| 51 | send_bitrate_bps(0), |
| 52 | delay_ms(0) {} |
| 53 | RtpStatistics rtp; |
| 54 | int input_frame_rate; |
| 55 | int encode_frame; |
| 56 | uint32_t key_frames; |
| 57 | uint32_t delta_frames; |
| 58 | uint32_t video_packets; |
| 59 | uint32_t retransmitted_packets; |
| 60 | uint32_t fec_packets; |
| 61 | uint32_t padding_packets; |
| 62 | int32_t send_bitrate_bps; |
| 63 | int delay_ms; |
| 64 | }; |
| 65 | |
| 66 | class StatsCallback { |
| 67 | public: |
| 68 | virtual ~StatsCallback() {} |
| 69 | virtual void ReceiveStats(const std::vector<Stats>& stats) = 0; |
| 70 | }; |
| 71 | |
| 72 | struct Config { |
| 73 | Config() |
| 74 | : pre_encode_callback(NULL), |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 | [diff] [blame] | 75 | post_encode_callback(NULL), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 76 | local_renderer(NULL), |
| 77 | render_delay_ms(0), |
| 78 | encoder(NULL), |
| 79 | internal_source(false), |
| 80 | target_delay_ms(0), |
stefan@webrtc.org | 360e376 | 2013-08-22 09:29:56 | [diff] [blame] | 81 | pacing(false), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 82 | stats_callback(NULL), |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 | [diff] [blame] | 83 | suspend_below_min_bitrate(false) {} |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 84 | VideoCodec codec; |
| 85 | |
sprang@webrtc.org | 25fce9a | 2013-10-16 13:29:14 | [diff] [blame] | 86 | static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4. |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 87 | struct Rtp { |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 | [diff] [blame] | 88 | Rtp() : max_packet_size(kDefaultMaxPacketSize) {} |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 89 | |
| 90 | std::vector<uint32_t> ssrcs; |
| 91 | |
| 92 | // Max RTP packet size delivered to send transport from VideoEngine. |
| 93 | size_t max_packet_size; |
| 94 | |
| 95 | // RTP header extensions to use for this send stream. |
| 96 | std::vector<RtpExtension> extensions; |
| 97 | |
| 98 | // See NackConfig for description. |
| 99 | NackConfig nack; |
| 100 | |
| 101 | // See FecConfig for description. |
| 102 | FecConfig fec; |
| 103 | |
| 104 | // See RtxConfig for description. |
| 105 | RtxConfig rtx; |
| 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 | 4070935 | 2013-11-26 11:41:59 | [diff] [blame] | 117 | EncodedFrameObserver* post_encode_callback; |
pbos@webrtc.org | 025f4f1 | 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. |
| 125 | // Only valid if |renderer| is set. |
| 126 | int render_delay_ms; |
| 127 | |
| 128 | // TODO(mflodman) Move VideoEncoder to common_types.h and redefine. |
| 129 | // External encoding. 'encoder' is the external encoder instance and |
| 130 | // 'internal_source' is set to true if the encoder also captures the video |
| 131 | // frames. |
| 132 | VideoEncoder* encoder; |
| 133 | bool internal_source; |
| 134 | |
| 135 | // Target delay in milliseconds. A positive value indicates this stream is |
| 136 | // used for streaming instead of a real-time call. |
| 137 | int target_delay_ms; |
| 138 | |
stefan@webrtc.org | 360e376 | 2013-08-22 09:29:56 | [diff] [blame] | 139 | // True if network a send-side packet buffer should be used to pace out |
| 140 | // packets onto the network. |
| 141 | bool pacing; |
| 142 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 143 | // Callback for periodically receiving send stats. |
| 144 | StatsCallback* stats_callback; |
| 145 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 | [diff] [blame] | 146 | // True if the stream should be suspended when the available bitrate fall |
| 147 | // below the minimum configured bitrate. If this variable is false, the |
| 148 | // stream may send at a rate higher than the estimated available bitrate. |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 | [diff] [blame] | 149 | // Enabling suspend_below_min_bitrate will also enable pacing and padding, |
| 150 | // otherwise, the video will be unable to recover from suspension. |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 | [diff] [blame] | 151 | bool suspend_below_min_bitrate; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 | [diff] [blame] | 152 | }; |
| 153 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 154 | // Gets interface used to insert captured frames. Valid as long as the |
| 155 | // VideoSendStream is valid. |
| 156 | virtual VideoSendStreamInput* Input() = 0; |
| 157 | |
pbos@webrtc.org | 53c8573 | 2013-11-20 11:36:47 | [diff] [blame] | 158 | virtual void StartSending() = 0; |
| 159 | virtual void StopSending() = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 160 | |
pbos@webrtc.org | 6488761 | 2013-11-14 08:58:14 | [diff] [blame] | 161 | virtual bool SetCodec(const VideoCodec& codec) = 0; |
| 162 | virtual VideoCodec GetCodec() = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 163 | |
| 164 | protected: |
| 165 | virtual ~VideoSendStream() {} |
| 166 | }; |
| 167 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 | [diff] [blame] | 168 | } // namespace webrtc |
| 169 | |
| 170 | #endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_ |