blob: 1a94121dcc87ecea42aa35611f8d93c247444a36 [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:521/*
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.orgb429e512013-12-18 09:46:2211#ifndef WEBRTC_VIDEO_SEND_STREAM_H_
12#define WEBRTC_VIDEO_SEND_STREAM_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:5213
sprang@webrtc.orgccd42842014-01-07 09:54:3414#include <map>
mflodman@webrtc.org65f995a2013-04-18 12:02:5215#include <string>
mflodman@webrtc.org65f995a2013-04-18 12:02:5216
17#include "webrtc/common_types.h"
pbos@webrtc.org16e03b72013-10-28 16:32:0118#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/video_renderer.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:5221
22namespace webrtc {
23
24class VideoEncoder;
25
mflodman@webrtc.org65f995a2013-04-18 12:02:5226// Class to deliver captured frame to the video send stream.
27class VideoSendStreamInput {
28 public:
pbos@webrtc.org724947b2013-12-11 16:26:1629 // 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.org65f995a2013-04-18 12:02:5234
35 protected:
36 virtual ~VideoSendStreamInput() {}
37};
38
mflodman@webrtc.org65f995a2013-04-18 12:02:5239class VideoSendStream {
40 public:
pbos@webrtc.org025f4f12013-06-05 11:33:2141 struct Stats {
42 Stats()
43 : input_frame_rate(0),
sprang@webrtc.orgccd42842014-01-07 09:54:3444 encode_frame_rate(0),
45 avg_delay_ms(0),
henrik.lundin@webrtc.orgb10363f32014-03-13 13:31:2146 max_delay_ms(0),
47 suspended(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:2148
sprang@webrtc.orgccd42842014-01-07 09:54:3449 int input_frame_rate;
50 int encode_frame_rate;
51 int avg_delay_ms;
52 int max_delay_ms;
henrik.lundin@webrtc.orgb10363f32014-03-13 13:31:2153 bool suspended;
sprang@webrtc.orgccd42842014-01-07 09:54:3454 std::string c_name;
55 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org025f4f12013-06-05 11:33:2156 };
57
58 struct Config {
59 Config()
60 : pre_encode_callback(NULL),
sprang@webrtc.org40709352013-11-26 11:41:5961 post_encode_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:2162 local_renderer(NULL),
63 render_delay_ms(0),
pbos@webrtc.org025f4f12013-06-05 11:33:2164 target_delay_ms(0),
stefan@webrtc.org360e3762013-08-22 09:29:5665 pacing(false),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:4366 suspend_below_min_bitrate(false) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:0667 std::string ToString() const;
68
pbos@webrtc.orgf577ae92014-03-19 08:43:5769 struct EncoderSettings {
70 EncoderSettings()
71 : payload_type(-1), encoder(NULL), encoder_settings(NULL) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:0672 std::string ToString() const;
73
pbos@webrtc.orgf577ae92014-03-19 08:43:5774 std::string payload_name;
75 int payload_type;
76
77 // Uninitialized VideoEncoder instance to be used for encoding. Will be
78 // initialized from inside the VideoSendStream.
79 webrtc::VideoEncoder* encoder;
80 // TODO(pbos): Wire up encoder-specific settings.
81 // Encoder-specific settings, will be passed to the encoder during
82 // initialization.
83 void* encoder_settings;
84
85 // List of stream settings to encode (resolution, bitrates, framerate).
86 std::vector<VideoStream> streams;
87 } encoder_settings;
pbos@webrtc.org025f4f12013-06-05 11:33:2188
sprang@webrtc.org25fce9a2013-10-16 13:29:1489 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:2190 struct Rtp {
pbos@webrtc.org3349ae02014-03-13 12:52:2791 Rtp()
92 : max_packet_size(kDefaultMaxPacketSize),
pbos@webrtc.org709e2972014-03-19 10:59:5293 min_transmit_bitrate_bps(0) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:0694 std::string ToString() const;
pbos@webrtc.org025f4f12013-06-05 11:33:2195
96 std::vector<uint32_t> ssrcs;
97
98 // Max RTP packet size delivered to send transport from VideoEngine.
99 size_t max_packet_size;
100
pbos@webrtc.org3349ae02014-03-13 12:52:27101 // Padding will be used up to this bitrate regardless of the bitrate
102 // produced by the encoder. Padding above what's actually produced by the
103 // encoder helps maintaining a higher bitrate estimate.
pbos@webrtc.org709e2972014-03-19 10:59:52104 int min_transmit_bitrate_bps;
pbos@webrtc.org3349ae02014-03-13 12:52:27105
pbos@webrtc.org025f4f12013-06-05 11:33:21106 // RTP header extensions to use for this send stream.
107 std::vector<RtpExtension> extensions;
108
109 // See NackConfig for description.
110 NackConfig nack;
111
112 // See FecConfig for description.
113 FecConfig fec;
114
pbos@webrtc.orgc279a5d2014-01-24 09:30:53115 // Settings for RTP retransmission payload format, see RFC 4588 for
116 // details.
117 struct Rtx {
118 Rtx() : payload_type(0) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06119 std::string ToString() const;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53120 // SSRCs to use for the RTX streams.
121 std::vector<uint32_t> ssrcs;
122
123 // Payload type to use for the RTX stream.
124 int payload_type;
125 } rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21126
127 // RTCP CNAME, see RFC 3550.
128 std::string c_name;
129 } rtp;
130
131 // Called for each I420 frame before encoding the frame. Can be used for
132 // effects, snapshots etc. 'NULL' disables the callback.
133 I420FrameCallback* pre_encode_callback;
134
135 // Called for each encoded frame, e.g. used for file storage. 'NULL'
136 // disables the callback.
sprang@webrtc.org40709352013-11-26 11:41:59137 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21138
139 // Renderer for local preview. The local renderer will be called even if
140 // sending hasn't started. 'NULL' disables local rendering.
141 VideoRenderer* local_renderer;
142
143 // Expected delay needed by the renderer, i.e. the frame will be delivered
144 // this many milliseconds, if possible, earlier than expected render time.
pbos@webrtc.org1e92b0a2014-05-15 09:35:06145 // Only valid if |local_renderer| is set.
pbos@webrtc.org025f4f12013-06-05 11:33:21146 int render_delay_ms;
147
pbos@webrtc.org025f4f12013-06-05 11:33:21148 // Target delay in milliseconds. A positive value indicates this stream is
149 // used for streaming instead of a real-time call.
150 int target_delay_ms;
151
stefan@webrtc.org360e3762013-08-22 09:29:56152 // True if network a send-side packet buffer should be used to pace out
153 // packets onto the network.
154 bool pacing;
155
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43156 // True if the stream should be suspended when the available bitrate fall
157 // below the minimum configured bitrate. If this variable is false, the
158 // stream may send at a rate higher than the estimated available bitrate.
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40159 // Enabling suspend_below_min_bitrate will also enable pacing and padding,
160 // otherwise, the video will be unable to recover from suspension.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43161 bool suspend_below_min_bitrate;
pbos@webrtc.org025f4f12013-06-05 11:33:21162 };
163
mflodman@webrtc.org65f995a2013-04-18 12:02:52164 // Gets interface used to insert captured frames. Valid as long as the
165 // VideoSendStream is valid.
166 virtual VideoSendStreamInput* Input() = 0;
167
pbos@webrtc.orga5c8d2c2014-04-24 11:13:21168 virtual void Start() = 0;
169 virtual void Stop() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52170
pbos@webrtc.orgf577ae92014-03-19 08:43:57171 // Set which streams to send. Must have at least as many SSRCs as configured
172 // in the config. Encoder settings are passed on to the encoder instance along
173 // with the VideoStream settings.
174 virtual bool ReconfigureVideoEncoder(const std::vector<VideoStream>& streams,
175 void* encoder_settings) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52176
sprang@webrtc.orgccd42842014-01-07 09:54:34177 virtual Stats GetStats() const = 0;
178
mflodman@webrtc.org65f995a2013-04-18 12:02:52179 protected:
180 virtual ~VideoSendStream() {}
181};
182
mflodman@webrtc.org65f995a2013-04-18 12:02:52183} // namespace webrtc
184
mflodman@webrtc.orgb429e512013-12-18 09:46:22185#endif // WEBRTC_VIDEO_SEND_STREAM_H_