blob: b33f3893476dbb6c5de81e83f1fa68fad60e2639 [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +00001/*
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:22 +000011#ifndef WEBRTC_VIDEO_SEND_STREAM_H_
12#define WEBRTC_VIDEO_SEND_STREAM_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000013
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000014#include <map>
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000015#include <string>
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000016
17#include "webrtc/common_types.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000018#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/video_renderer.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000021
22namespace webrtc {
23
24class VideoEncoder;
25
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026// Class to deliver captured frame to the video send stream.
27class VideoSendStreamInput {
28 public:
pbos@webrtc.org724947b2013-12-11 16:26:16 +000029 // 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.org724947b2013-12-11 16:26:16 +000032 virtual void SwapFrame(I420VideoFrame* video_frame) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000033
34 protected:
35 virtual ~VideoSendStreamInput() {}
36};
37
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000038class VideoSendStream {
39 public:
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000040 struct Stats {
41 Stats()
42 : input_frame_rate(0),
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000043 encode_frame_rate(0),
44 avg_delay_ms(0),
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +000045 max_delay_ms(0),
46 suspended(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000047
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000048 int input_frame_rate;
49 int encode_frame_rate;
50 int avg_delay_ms;
51 int max_delay_ms;
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +000052 bool suspended;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000053 std::string c_name;
54 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000055 };
56
57 struct Config {
58 Config()
59 : pre_encode_callback(NULL),
sprang@webrtc.org40709352013-11-26 11:41:59 +000060 post_encode_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000061 local_renderer(NULL),
62 render_delay_ms(0),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000063 target_delay_ms(0),
stefan@webrtc.org360e3762013-08-22 09:29:56 +000064 pacing(false),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +000065 suspend_below_min_bitrate(false) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000066 std::string ToString() const;
67
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000068 struct EncoderSettings {
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +000069 EncoderSettings() : payload_type(-1), encoder(NULL) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000070 std::string ToString() const;
71
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000072 std::string payload_name;
73 int payload_type;
74
75 // Uninitialized VideoEncoder instance to be used for encoding. Will be
76 // initialized from inside the VideoSendStream.
77 webrtc::VideoEncoder* encoder;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000078 } encoder_settings;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000079
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000080 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000081 struct Rtp {
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000082 Rtp()
83 : max_packet_size(kDefaultMaxPacketSize),
pbos@webrtc.org709e2972014-03-19 10:59:52 +000084 min_transmit_bitrate_bps(0) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000085 std::string ToString() const;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000086
87 std::vector<uint32_t> ssrcs;
88
89 // Max RTP packet size delivered to send transport from VideoEngine.
90 size_t max_packet_size;
91
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000092 // Padding will be used up to this bitrate regardless of the bitrate
93 // produced by the encoder. Padding above what's actually produced by the
94 // encoder helps maintaining a higher bitrate estimate.
pbos@webrtc.org709e2972014-03-19 10:59:52 +000095 int min_transmit_bitrate_bps;
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000096
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000097 // RTP header extensions to use for this send stream.
98 std::vector<RtpExtension> extensions;
99
100 // See NackConfig for description.
101 NackConfig nack;
102
103 // See FecConfig for description.
104 FecConfig fec;
105
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000106 // Settings for RTP retransmission payload format, see RFC 4588 for
107 // details.
108 struct Rtx {
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000109 Rtx() : payload_type(-1) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000110 std::string ToString() const;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000111 // SSRCs to use for the RTX streams.
112 std::vector<uint32_t> ssrcs;
113
114 // Payload type to use for the RTX stream.
115 int payload_type;
116 } rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000117
118 // RTCP CNAME, see RFC 3550.
119 std::string c_name;
120 } rtp;
121
122 // Called for each I420 frame before encoding the frame. Can be used for
123 // effects, snapshots etc. 'NULL' disables the callback.
124 I420FrameCallback* pre_encode_callback;
125
126 // Called for each encoded frame, e.g. used for file storage. 'NULL'
127 // disables the callback.
sprang@webrtc.org40709352013-11-26 11:41:59 +0000128 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000129
130 // Renderer for local preview. The local renderer will be called even if
131 // sending hasn't started. 'NULL' disables local rendering.
132 VideoRenderer* local_renderer;
133
134 // Expected delay needed by the renderer, i.e. the frame will be delivered
135 // this many milliseconds, if possible, earlier than expected render time.
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000136 // Only valid if |local_renderer| is set.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000137 int render_delay_ms;
138
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000139 // Target delay in milliseconds. A positive value indicates this stream is
140 // used for streaming instead of a real-time call.
141 int target_delay_ms;
142
stefan@webrtc.org360e3762013-08-22 09:29:56 +0000143 // True if network a send-side packet buffer should be used to pace out
144 // packets onto the network.
145 bool pacing;
146
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000147 // True if the stream should be suspended when the available bitrate fall
148 // below the minimum configured bitrate. If this variable is false, the
149 // stream may send at a rate higher than the estimated available bitrate.
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000150 // |suspend_below_min_bitrate| requires |pacing| to be enabled as well.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000151 bool suspend_below_min_bitrate;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000152 };
153
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000154 // Gets interface used to insert captured frames. Valid as long as the
155 // VideoSendStream is valid.
156 virtual VideoSendStreamInput* Input() = 0;
157
pbos@webrtc.orga5c8d2c2014-04-24 11:13:21 +0000158 virtual void Start() = 0;
159 virtual void Stop() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000160
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000161 // Set which streams to send. Must have at least as many SSRCs as configured
162 // in the config. Encoder settings are passed on to the encoder instance along
163 // with the VideoStream settings.
164 virtual bool ReconfigureVideoEncoder(const std::vector<VideoStream>& streams,
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000165 const void* encoder_settings) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000166
sprang@webrtc.orgccd42842014-01-07 09:54:34 +0000167 virtual Stats GetStats() const = 0;
168
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000169 protected:
170 virtual ~VideoSendStream() {}
171};
172
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000173} // namespace webrtc
174
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000175#endif // WEBRTC_VIDEO_SEND_STREAM_H_