blob: 8279c052a506929a7625cf2d99c49a4a33c78bdd [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.
32 virtual void PutFrame(const I420VideoFrame& video_frame) = 0;
33 virtual void SwapFrame(I420VideoFrame* video_frame) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000034
35 protected:
36 virtual ~VideoSendStreamInput() {}
37};
38
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000039class VideoSendStream {
40 public:
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000041 struct Stats {
42 Stats()
43 : input_frame_rate(0),
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000044 encode_frame_rate(0),
45 avg_delay_ms(0),
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +000046 max_delay_ms(0),
47 suspended(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000048
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000049 int input_frame_rate;
50 int encode_frame_rate;
51 int avg_delay_ms;
52 int max_delay_ms;
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +000053 bool suspended;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000054 std::string c_name;
55 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000056 };
57
58 struct Config {
59 Config()
60 : pre_encode_callback(NULL),
sprang@webrtc.org40709352013-11-26 11:41:59 +000061 post_encode_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000062 local_renderer(NULL),
63 render_delay_ms(0),
64 encoder(NULL),
65 internal_source(false),
66 target_delay_ms(0),
stefan@webrtc.org360e3762013-08-22 09:29:56 +000067 pacing(false),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +000068 suspend_below_min_bitrate(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000069 VideoCodec codec;
70
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000071 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000072 struct Rtp {
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000073 Rtp()
74 : max_packet_size(kDefaultMaxPacketSize),
75 min_transmit_bitrate_kbps(0) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000076
77 std::vector<uint32_t> ssrcs;
78
79 // Max RTP packet size delivered to send transport from VideoEngine.
80 size_t max_packet_size;
81
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000082 // Padding will be used up to this bitrate regardless of the bitrate
83 // produced by the encoder. Padding above what's actually produced by the
84 // encoder helps maintaining a higher bitrate estimate.
85 int min_transmit_bitrate_kbps;
86
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000087 // RTP header extensions to use for this send stream.
88 std::vector<RtpExtension> extensions;
89
90 // See NackConfig for description.
91 NackConfig nack;
92
93 // See FecConfig for description.
94 FecConfig fec;
95
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +000096 // Settings for RTP retransmission payload format, see RFC 4588 for
97 // details.
98 struct Rtx {
99 Rtx() : payload_type(0) {}
100 // SSRCs to use for the RTX streams.
101 std::vector<uint32_t> ssrcs;
102
103 // Payload type to use for the RTX stream.
104 int payload_type;
105 } rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000106
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.org40709352013-11-26 11:41:59 +0000117 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000118
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.org360e3762013-08-22 09:29:56 +0000139 // True if network a send-side packet buffer should be used to pace out
140 // packets onto the network.
141 bool pacing;
142
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000143 // True if the stream should be suspended when the available bitrate fall
144 // below the minimum configured bitrate. If this variable is false, the
145 // stream may send at a rate higher than the estimated available bitrate.
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +0000146 // Enabling suspend_below_min_bitrate will also enable pacing and padding,
147 // otherwise, the video will be unable to recover from suspension.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000148 bool suspend_below_min_bitrate;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000149 };
150
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000151 // Gets interface used to insert captured frames. Valid as long as the
152 // VideoSendStream is valid.
153 virtual VideoSendStreamInput* Input() = 0;
154
pbos@webrtc.org53c85732013-11-20 11:36:47 +0000155 virtual void StartSending() = 0;
156 virtual void StopSending() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000157
pbos@webrtc.org64887612013-11-14 08:58:14 +0000158 virtual bool SetCodec(const VideoCodec& codec) = 0;
159 virtual VideoCodec GetCodec() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000160
sprang@webrtc.orgccd42842014-01-07 09:54:34 +0000161 virtual Stats GetStats() const = 0;
162
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000163 protected:
164 virtual ~VideoSendStream() {}
165};
166
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000167} // namespace webrtc
168
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000169#endif // WEBRTC_VIDEO_SEND_STREAM_H_