blob: d1c17264c276852ad96c3e94294ffdc0f1f5decd [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),
46 max_delay_ms(0) {}
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;
52 std::string c_name;
53 std::map<uint32_t, StreamStats> substreams;
54
55 bool operator==(const Stats& other) const {
56 if (input_frame_rate != other.input_frame_rate ||
57 encode_frame_rate != other.encode_frame_rate ||
58 avg_delay_ms != other.avg_delay_ms ||
59 max_delay_ms != other.max_delay_ms || c_name != other.c_name ||
60 substreams.size() != other.substreams.size()) {
61 return false;
62 }
63 return std::equal(
64 substreams.begin(), substreams.end(), other.substreams.begin());
65 }
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000066 };
67
68 struct Config {
69 Config()
70 : pre_encode_callback(NULL),
sprang@webrtc.org40709352013-11-26 11:41:59 +000071 post_encode_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000072 local_renderer(NULL),
73 render_delay_ms(0),
74 encoder(NULL),
75 internal_source(false),
76 target_delay_ms(0),
stefan@webrtc.org360e3762013-08-22 09:29:56 +000077 pacing(false),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +000078 suspend_below_min_bitrate(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000079 VideoCodec codec;
80
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000081 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000082 struct Rtp {
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000083 Rtp() : max_packet_size(kDefaultMaxPacketSize) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000084
85 std::vector<uint32_t> ssrcs;
86
87 // Max RTP packet size delivered to send transport from VideoEngine.
88 size_t max_packet_size;
89
90 // RTP header extensions to use for this send stream.
91 std::vector<RtpExtension> extensions;
92
93 // See NackConfig for description.
94 NackConfig nack;
95
96 // See FecConfig for description.
97 FecConfig fec;
98
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +000099 // Settings for RTP retransmission payload format, see RFC 4588 for
100 // details.
101 struct Rtx {
102 Rtx() : payload_type(0) {}
103 // SSRCs to use for the RTX streams.
104 std::vector<uint32_t> ssrcs;
105
106 // Payload type to use for the RTX stream.
107 int payload_type;
108 } rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000109
110 // RTCP CNAME, see RFC 3550.
111 std::string c_name;
112 } rtp;
113
114 // Called for each I420 frame before encoding the frame. Can be used for
115 // effects, snapshots etc. 'NULL' disables the callback.
116 I420FrameCallback* pre_encode_callback;
117
118 // Called for each encoded frame, e.g. used for file storage. 'NULL'
119 // disables the callback.
sprang@webrtc.org40709352013-11-26 11:41:59 +0000120 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000121
122 // Renderer for local preview. The local renderer will be called even if
123 // sending hasn't started. 'NULL' disables local rendering.
124 VideoRenderer* local_renderer;
125
126 // Expected delay needed by the renderer, i.e. the frame will be delivered
127 // this many milliseconds, if possible, earlier than expected render time.
128 // Only valid if |renderer| is set.
129 int render_delay_ms;
130
131 // TODO(mflodman) Move VideoEncoder to common_types.h and redefine.
132 // External encoding. 'encoder' is the external encoder instance and
133 // 'internal_source' is set to true if the encoder also captures the video
134 // frames.
135 VideoEncoder* encoder;
136 bool internal_source;
137
138 // Target delay in milliseconds. A positive value indicates this stream is
139 // used for streaming instead of a real-time call.
140 int target_delay_ms;
141
stefan@webrtc.org360e3762013-08-22 09:29:56 +0000142 // True if network a send-side packet buffer should be used to pace out
143 // packets onto the network.
144 bool pacing;
145
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000146 // 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.org331d4402013-11-21 14:05:40 +0000149 // 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.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.org53c85732013-11-20 11:36:47 +0000158 virtual void StartSending() = 0;
159 virtual void StopSending() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000160
pbos@webrtc.org64887612013-11-14 08:58:14 +0000161 virtual bool SetCodec(const VideoCodec& codec) = 0;
162 virtual VideoCodec GetCodec() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000163
sprang@webrtc.orgccd42842014-01-07 09:54:34 +0000164 virtual Stats GetStats() const = 0;
165
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000166 protected:
167 virtual ~VideoSendStream() {}
168};
169
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000170} // namespace webrtc
171
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000172#endif // WEBRTC_VIDEO_SEND_STREAM_H_