blob: aa027b0effeaa7edebeffe037fd048633b5f7675 [file] [log] [blame]
mflodman@webrtc.org69b0d2c2013-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.org2a4595a2013-12-18 09:46:22 +000011#ifndef WEBRTC_VIDEO_SEND_STREAM_H_
12#define WEBRTC_VIDEO_SEND_STREAM_H_
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000013
sprang@webrtc.orgca723002014-01-07 09:54:34 +000014#include <map>
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000015#include <string>
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000016
17#include "webrtc/common_types.h"
pbos@webrtc.orgb581c902013-10-28 16:32:01 +000018#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/video_renderer.h"
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000021
22namespace webrtc {
23
24class VideoEncoder;
25
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000026// Class to deliver captured frame to the video send stream.
27class VideoSendStreamInput {
28 public:
pbos@webrtc.org7123a802013-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.org69b0d2c2013-04-18 12:02:52 +000034
35 protected:
36 virtual ~VideoSendStreamInput() {}
37};
38
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000039class VideoSendStream {
40 public:
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000041 struct Stats {
42 Stats()
43 : input_frame_rate(0),
sprang@webrtc.orgca723002014-01-07 09:54:34 +000044 encode_frame_rate(0),
45 avg_delay_ms(0),
henrik.lundin@webrtc.org15cf7172014-03-13 13:31:21 +000046 max_delay_ms(0),
47 suspended(false) {}
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000048
sprang@webrtc.orgca723002014-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.org15cf7172014-03-13 13:31:21 +000053 bool suspended;
sprang@webrtc.orgca723002014-01-07 09:54:34 +000054 std::string c_name;
55 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000056 };
57
58 struct Config {
59 Config()
60 : pre_encode_callback(NULL),
sprang@webrtc.org4a9843f2013-11-26 11:41:59 +000061 post_encode_callback(NULL),
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000062 local_renderer(NULL),
63 render_delay_ms(0),
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000064 target_delay_ms(0),
stefan@webrtc.orga0a91d82013-08-22 09:29:56 +000065 pacing(false),
henrik.lundin@webrtc.org8fdf1912013-11-18 12:18:43 +000066 suspend_below_min_bitrate(false) {}
pbos@webrtc.orgf39df522014-03-19 08:43:57 +000067 struct EncoderSettings {
68 EncoderSettings()
69 : payload_type(-1), encoder(NULL), encoder_settings(NULL) {}
70 std::string payload_name;
71 int payload_type;
72
73 // Uninitialized VideoEncoder instance to be used for encoding. Will be
74 // initialized from inside the VideoSendStream.
75 webrtc::VideoEncoder* encoder;
76 // TODO(pbos): Wire up encoder-specific settings.
77 // Encoder-specific settings, will be passed to the encoder during
78 // initialization.
79 void* encoder_settings;
80
81 // List of stream settings to encode (resolution, bitrates, framerate).
82 std::vector<VideoStream> streams;
83 } encoder_settings;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000084
sprang@webrtc.org6133dd52013-10-16 13:29:14 +000085 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000086 struct Rtp {
pbos@webrtc.org9420a1f2014-03-13 12:52:27 +000087 Rtp()
88 : max_packet_size(kDefaultMaxPacketSize),
pbos@webrtc.orgbef6e622014-03-19 10:59:52 +000089 min_transmit_bitrate_bps(0) {}
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000090
91 std::vector<uint32_t> ssrcs;
92
93 // Max RTP packet size delivered to send transport from VideoEngine.
94 size_t max_packet_size;
95
pbos@webrtc.org9420a1f2014-03-13 12:52:27 +000096 // Padding will be used up to this bitrate regardless of the bitrate
97 // produced by the encoder. Padding above what's actually produced by the
98 // encoder helps maintaining a higher bitrate estimate.
pbos@webrtc.orgbef6e622014-03-19 10:59:52 +000099 int min_transmit_bitrate_bps;
pbos@webrtc.org9420a1f2014-03-13 12:52:27 +0000100
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000101 // RTP header extensions to use for this send stream.
102 std::vector<RtpExtension> extensions;
103
104 // See NackConfig for description.
105 NackConfig nack;
106
107 // See FecConfig for description.
108 FecConfig fec;
109
pbos@webrtc.orgc7667752014-01-24 09:30:53 +0000110 // Settings for RTP retransmission payload format, see RFC 4588 for
111 // details.
112 struct Rtx {
113 Rtx() : payload_type(0) {}
114 // SSRCs to use for the RTX streams.
115 std::vector<uint32_t> ssrcs;
116
117 // Payload type to use for the RTX stream.
118 int payload_type;
119 } rtx;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000120
121 // RTCP CNAME, see RFC 3550.
122 std::string c_name;
123 } rtp;
124
125 // Called for each I420 frame before encoding the frame. Can be used for
126 // effects, snapshots etc. 'NULL' disables the callback.
127 I420FrameCallback* pre_encode_callback;
128
129 // Called for each encoded frame, e.g. used for file storage. 'NULL'
130 // disables the callback.
sprang@webrtc.org4a9843f2013-11-26 11:41:59 +0000131 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000132
133 // Renderer for local preview. The local renderer will be called even if
134 // sending hasn't started. 'NULL' disables local rendering.
135 VideoRenderer* local_renderer;
136
137 // Expected delay needed by the renderer, i.e. the frame will be delivered
138 // this many milliseconds, if possible, earlier than expected render time.
139 // Only valid if |renderer| is set.
140 int render_delay_ms;
141
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000142 // Target delay in milliseconds. A positive value indicates this stream is
143 // used for streaming instead of a real-time call.
144 int target_delay_ms;
145
stefan@webrtc.orga0a91d82013-08-22 09:29:56 +0000146 // True if network a send-side packet buffer should be used to pace out
147 // packets onto the network.
148 bool pacing;
149
henrik.lundin@webrtc.org8fdf1912013-11-18 12:18:43 +0000150 // True if the stream should be suspended when the available bitrate fall
151 // below the minimum configured bitrate. If this variable is false, the
152 // stream may send at a rate higher than the estimated available bitrate.
henrik.lundin@webrtc.orgd7d60c82013-11-21 14:05:40 +0000153 // Enabling suspend_below_min_bitrate will also enable pacing and padding,
154 // otherwise, the video will be unable to recover from suspension.
henrik.lundin@webrtc.org8fdf1912013-11-18 12:18:43 +0000155 bool suspend_below_min_bitrate;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000156 };
157
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000158 // Gets interface used to insert captured frames. Valid as long as the
159 // VideoSendStream is valid.
160 virtual VideoSendStreamInput* Input() = 0;
161
pbos@webrtc.org9d0f79f2014-04-24 11:13:21 +0000162 virtual void Start() = 0;
163 virtual void Stop() = 0;
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000164
pbos@webrtc.orgf39df522014-03-19 08:43:57 +0000165 // Set which streams to send. Must have at least as many SSRCs as configured
166 // in the config. Encoder settings are passed on to the encoder instance along
167 // with the VideoStream settings.
168 virtual bool ReconfigureVideoEncoder(const std::vector<VideoStream>& streams,
169 void* encoder_settings) = 0;
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000170
sprang@webrtc.orgca723002014-01-07 09:54:34 +0000171 virtual Stats GetStats() const = 0;
172
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000173 protected:
174 virtual ~VideoSendStream() {}
175};
176
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000177} // namespace webrtc
178
mflodman@webrtc.org2a4595a2013-12-18 09:46:22 +0000179#endif // WEBRTC_VIDEO_SEND_STREAM_H_