blob: b5f8c9ad1cf086e4e0809c5829cded602007d056 [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"
Jelena Marusiccd670222015-07-16 09:30:09 +020020#include "webrtc/stream.h"
solenberg4fbae2b2015-08-28 04:07:10 -070021#include "webrtc/transport.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000022#include "webrtc/video_renderer.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000023
24namespace webrtc {
25
solenberge5269742015-09-08 05:13:22 -070026class LoadObserver;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027class VideoEncoder;
28
ivica8d15bd62015-10-07 02:43:12 -070029class EncodingTimeObserver {
30 public:
31 virtual ~EncodingTimeObserver() {}
32
33 virtual void OnReportEncodedTime(int64_t ntp_time_ms, int encode_time_ms) = 0;
34};
35
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000036// Class to deliver captured frame to the video send stream.
Peter Boström4b91bd02015-06-26 06:58:16 +020037class VideoCaptureInput {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000038 public:
pbos@webrtc.org724947b2013-12-11 16:26:16 +000039 // These methods do not lock internally and must be called sequentially.
40 // If your application switches input sources synchronization must be done
41 // externally to make sure that any old frames are not delivered concurrently.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070042 virtual void IncomingCapturedFrame(const VideoFrame& video_frame) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000043
44 protected:
Peter Boström4b91bd02015-06-26 06:58:16 +020045 virtual ~VideoCaptureInput() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000046};
47
Jelena Marusiccd670222015-07-16 09:30:09 +020048class VideoSendStream : public SendStream {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000049 public:
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000050 struct StreamStats {
51 FrameCounts frame_counts;
52 int width = 0;
53 int height = 0;
54 // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
55 int total_bitrate_bps = 0;
56 int retransmit_bitrate_bps = 0;
57 int avg_delay_ms = 0;
58 int max_delay_ms = 0;
59 StreamDataCounters rtp_stats;
60 RtcpPacketTypeCounter rtcp_packet_type_counts;
61 RtcpStatistics rtcp_stats;
62 };
63
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000064 struct Stats {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020065 int input_frame_rate = 0;
66 int encode_frame_rate = 0;
67 int avg_encode_time_ms = 0;
68 int encode_usage_percent = 0;
69 int target_media_bitrate_bps = 0;
70 int media_bitrate_bps = 0;
71 bool suspended = false;
asapersson17821db2015-12-14 02:08:12 -080072 bool bw_limited_resolution = false;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000073 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000074 };
75
76 struct Config {
solenberg4fbae2b2015-08-28 04:07:10 -070077 Config() = delete;
pbos2d566682015-09-28 09:59:31 -070078 explicit Config(Transport* send_transport)
solenberg4fbae2b2015-08-28 04:07:10 -070079 : send_transport(send_transport) {}
80
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000081 std::string ToString() const;
82
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000083 struct EncoderSettings {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000084 std::string ToString() const;
85
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000086 std::string payload_name;
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020087 int payload_type = -1;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000088
sophiechang47d78cc2015-09-03 18:24:44 -070089 // TODO(sophiechang): Delete this field when no one is using internal
90 // sources anymore.
91 bool internal_source = false;
92
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000093 // Uninitialized VideoEncoder instance to be used for encoding. Will be
94 // initialized from inside the VideoSendStream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020095 VideoEncoder* encoder = nullptr;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000096 } encoder_settings;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000097
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000098 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000099 struct Rtp {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000100 std::string ToString() const;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000101
102 std::vector<uint32_t> ssrcs;
103
deadbeef13871492015-12-09 12:37:51 -0800104 // See RtcpMode for description.
105 RtcpMode rtcp_mode = RtcpMode::kCompound;
106
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000107 // Max RTP packet size delivered to send transport from VideoEngine.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200108 size_t max_packet_size = kDefaultMaxPacketSize;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000109
110 // RTP header extensions to use for this send stream.
111 std::vector<RtpExtension> extensions;
112
113 // See NackConfig for description.
114 NackConfig nack;
115
116 // See FecConfig for description.
117 FecConfig fec;
118
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000119 // Settings for RTP retransmission payload format, see RFC 4588 for
120 // details.
121 struct Rtx {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000122 std::string ToString() const;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000123 // SSRCs to use for the RTX streams.
124 std::vector<uint32_t> ssrcs;
125
126 // Payload type to use for the RTX stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200127 int payload_type = -1;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000128 } rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000129
130 // RTCP CNAME, see RFC 3550.
131 std::string c_name;
132 } rtp;
133
solenberg4fbae2b2015-08-28 04:07:10 -0700134 // Transport for outgoing packets.
pbos2d566682015-09-28 09:59:31 -0700135 Transport* send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -0700136
solenberge5269742015-09-08 05:13:22 -0700137 // Callback for overuse and normal usage based on the jitter of incoming
138 // captured frames. 'nullptr' disables the callback.
139 LoadObserver* overuse_callback = nullptr;
140
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000141 // Called for each I420 frame before encoding the frame. Can be used for
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200142 // effects, snapshots etc. 'nullptr' disables the callback.
143 I420FrameCallback* pre_encode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000144
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200145 // Called for each encoded frame, e.g. used for file storage. 'nullptr'
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000146 // disables the callback.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200147 EncodedFrameObserver* post_encode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000148
149 // Renderer for local preview. The local renderer will be called even if
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200150 // sending hasn't started. 'nullptr' disables local rendering.
151 VideoRenderer* local_renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000152
153 // Expected delay needed by the renderer, i.e. the frame will be delivered
154 // this many milliseconds, if possible, earlier than expected render time.
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000155 // Only valid if |local_renderer| is set.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200156 int render_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000157
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000158 // Target delay in milliseconds. A positive value indicates this stream is
159 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200160 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000161
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000162 // True if the stream should be suspended when the available bitrate fall
163 // below the minimum configured bitrate. If this variable is false, the
164 // stream may send at a rate higher than the estimated available bitrate.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200165 bool suspend_below_min_bitrate = false;
ivica8d15bd62015-10-07 02:43:12 -0700166
167 // Called for each encoded frame. Passes the total time spent on encoding.
168 // TODO(ivica): Consolidate with post_encode_callback:
169 // https://code.google.com/p/webrtc/issues/detail?id=5042
170 EncodingTimeObserver* encoding_time_observer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000171 };
172
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000173 // Gets interface used to insert captured frames. Valid as long as the
174 // VideoSendStream is valid.
Peter Boström4b91bd02015-06-26 06:58:16 +0200175 virtual VideoCaptureInput* Input() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000176
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000177 // Set which streams to send. Must have at least as many SSRCs as configured
178 // in the config. Encoder settings are passed on to the encoder instance along
179 // with the VideoStream settings.
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000180 virtual bool ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000181
pbos@webrtc.org273a4142014-12-01 15:23:21 +0000182 virtual Stats GetStats() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000183};
184
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000185} // namespace webrtc
186
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000187#endif // WEBRTC_VIDEO_SEND_STREAM_H_