blob: dd2bec127d24179ad57939b5e7537ce094737d98 [file] [log] [blame]
mflodman@webrtc.org06e80262013-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.org5e0cbcf2013-12-18 09:46:22 +000011#ifndef WEBRTC_VIDEO_SEND_STREAM_H_
12#define WEBRTC_VIDEO_SEND_STREAM_H_
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000013
sprang@webrtc.org49812e62014-01-07 09:54:34 +000014#include <map>
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000015#include <string>
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000016
17#include "webrtc/common_types.h"
pbos@webrtc.org24e20892013-10-28 16:32:01 +000018#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/video_renderer.h"
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000021
22namespace webrtc {
23
24class VideoEncoder;
25
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000026// Class to deliver captured frame to the video send stream.
27class VideoSendStreamInput {
28 public:
pbos@webrtc.orgc33d37c2013-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.orgc33d37c2013-12-11 16:26:16 +000032 virtual void SwapFrame(I420VideoFrame* video_frame) = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000033
34 protected:
35 virtual ~VideoSendStreamInput() {}
36};
37
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000038class VideoSendStream {
39 public:
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000040 struct Stats {
41 Stats()
42 : input_frame_rate(0),
sprang@webrtc.org49812e62014-01-07 09:54:34 +000043 encode_frame_rate(0),
henrik.lundin@webrtc.org9376c692014-03-13 13:31:21 +000044 suspended(false) {}
sprang@webrtc.org49812e62014-01-07 09:54:34 +000045 int input_frame_rate;
46 int encode_frame_rate;
henrik.lundin@webrtc.org9376c692014-03-13 13:31:21 +000047 bool suspended;
sprang@webrtc.org49812e62014-01-07 09:54:34 +000048 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000049 };
50
51 struct Config {
52 Config()
53 : pre_encode_callback(NULL),
sprang@webrtc.org2e98d452013-11-26 11:41:59 +000054 post_encode_callback(NULL),
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000055 local_renderer(NULL),
56 render_delay_ms(0),
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000057 target_delay_ms(0),
henrik.lundin@webrtc.org45901772013-11-18 12:18:43 +000058 suspend_below_min_bitrate(false) {}
pbos@webrtc.org7e686932014-05-15 09:35:06 +000059 std::string ToString() const;
60
pbos@webrtc.orge2a7a772014-03-19 08:43:57 +000061 struct EncoderSettings {
pbos@webrtc.orgbdfcddf2014-06-06 10:49:19 +000062 EncoderSettings() : payload_type(-1), encoder(NULL) {}
pbos@webrtc.org7e686932014-05-15 09:35:06 +000063 std::string ToString() const;
64
pbos@webrtc.orge2a7a772014-03-19 08:43:57 +000065 std::string payload_name;
66 int payload_type;
67
68 // Uninitialized VideoEncoder instance to be used for encoding. Will be
69 // initialized from inside the VideoSendStream.
70 webrtc::VideoEncoder* encoder;
pbos@webrtc.orge2a7a772014-03-19 08:43:57 +000071 } encoder_settings;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000072
sprang@webrtc.org44bb62a2013-10-16 13:29:14 +000073 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000074 struct Rtp {
pbos@webrtc.org3f83f9c2014-03-13 12:52:27 +000075 Rtp()
76 : max_packet_size(kDefaultMaxPacketSize),
pbos@webrtc.org1d61e3a2014-03-19 10:59:52 +000077 min_transmit_bitrate_bps(0) {}
pbos@webrtc.org7e686932014-05-15 09:35:06 +000078 std::string ToString() const;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000079
80 std::vector<uint32_t> ssrcs;
81
82 // Max RTP packet size delivered to send transport from VideoEngine.
83 size_t max_packet_size;
84
pbos@webrtc.org3f83f9c2014-03-13 12:52:27 +000085 // Padding will be used up to this bitrate regardless of the bitrate
86 // produced by the encoder. Padding above what's actually produced by the
87 // encoder helps maintaining a higher bitrate estimate.
pbos@webrtc.org1d61e3a2014-03-19 10:59:52 +000088 int min_transmit_bitrate_bps;
pbos@webrtc.org3f83f9c2014-03-13 12:52:27 +000089
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000090 // 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.orgc71929d2014-01-24 09:30:53 +000099 // Settings for RTP retransmission payload format, see RFC 4588 for
100 // details.
101 struct Rtx {
stefan@webrtc.org6845de72014-06-11 13:41:36 +0000102 Rtx() : payload_type(-1), pad_with_redundant_payloads(false) {}
pbos@webrtc.org7e686932014-05-15 09:35:06 +0000103 std::string ToString() const;
pbos@webrtc.orgc71929d2014-01-24 09:30:53 +0000104 // SSRCs to use for the RTX streams.
105 std::vector<uint32_t> ssrcs;
106
107 // Payload type to use for the RTX stream.
108 int payload_type;
stefan@webrtc.org6845de72014-06-11 13:41:36 +0000109 // Use redundant payloads to pad the bitrate. Instead of padding with
110 // randomized packets, we will preemptively retransmit media packets on
111 // the RTX stream.
112 bool pad_with_redundant_payloads;
pbos@webrtc.orgc71929d2014-01-24 09:30:53 +0000113 } rtx;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000114
115 // RTCP CNAME, see RFC 3550.
116 std::string c_name;
117 } rtp;
118
119 // Called for each I420 frame before encoding the frame. Can be used for
120 // effects, snapshots etc. 'NULL' disables the callback.
121 I420FrameCallback* pre_encode_callback;
122
123 // Called for each encoded frame, e.g. used for file storage. 'NULL'
124 // disables the callback.
sprang@webrtc.org2e98d452013-11-26 11:41:59 +0000125 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000126
127 // Renderer for local preview. The local renderer will be called even if
128 // sending hasn't started. 'NULL' disables local rendering.
129 VideoRenderer* local_renderer;
130
131 // Expected delay needed by the renderer, i.e. the frame will be delivered
132 // this many milliseconds, if possible, earlier than expected render time.
pbos@webrtc.org7e686932014-05-15 09:35:06 +0000133 // Only valid if |local_renderer| is set.
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000134 int render_delay_ms;
135
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000136 // Target delay in milliseconds. A positive value indicates this stream is
137 // used for streaming instead of a real-time call.
138 int target_delay_ms;
139
henrik.lundin@webrtc.org45901772013-11-18 12:18:43 +0000140 // True if the stream should be suspended when the available bitrate fall
141 // below the minimum configured bitrate. If this variable is false, the
142 // stream may send at a rate higher than the estimated available bitrate.
143 bool suspend_below_min_bitrate;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000144 };
145
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000146 // Gets interface used to insert captured frames. Valid as long as the
147 // VideoSendStream is valid.
148 virtual VideoSendStreamInput* Input() = 0;
149
pbos@webrtc.org16a058a2014-04-24 11:13:21 +0000150 virtual void Start() = 0;
151 virtual void Stop() = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000152
pbos@webrtc.orge2a7a772014-03-19 08:43:57 +0000153 // Set which streams to send. Must have at least as many SSRCs as configured
154 // in the config. Encoder settings are passed on to the encoder instance along
155 // with the VideoStream settings.
pbos@webrtc.org58b51402014-09-19 12:30:25 +0000156 virtual bool ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000157
sprang@webrtc.org49812e62014-01-07 09:54:34 +0000158 virtual Stats GetStats() const = 0;
159
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000160 protected:
161 virtual ~VideoSendStream() {}
162};
163
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000164} // namespace webrtc
165
mflodman@webrtc.org5e0cbcf2013-12-18 09:46:22 +0000166#endif // WEBRTC_VIDEO_SEND_STREAM_H_