blob: 540f5be46232b82537ea6ed857f27c286dccf084 [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"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000021#include "webrtc/video_renderer.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000022
23namespace webrtc {
24
25class VideoEncoder;
26
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027// Class to deliver captured frame to the video send stream.
Peter Boström4b91bd02015-06-26 06:58:16 +020028class VideoCaptureInput {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000029 public:
pbos@webrtc.org724947b2013-12-11 16:26:16 +000030 // These methods do not lock internally and must be called sequentially.
31 // If your application switches input sources synchronization must be done
32 // externally to make sure that any old frames are not delivered concurrently.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070033 virtual void IncomingCapturedFrame(const VideoFrame& video_frame) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000034
35 protected:
Peter Boström4b91bd02015-06-26 06:58:16 +020036 virtual ~VideoCaptureInput() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000037};
38
Jelena Marusiccd670222015-07-16 09:30:09 +020039class VideoSendStream : public SendStream {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000040 public:
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000041 struct StreamStats {
42 FrameCounts frame_counts;
43 int width = 0;
44 int height = 0;
45 // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
46 int total_bitrate_bps = 0;
47 int retransmit_bitrate_bps = 0;
48 int avg_delay_ms = 0;
49 int max_delay_ms = 0;
50 StreamDataCounters rtp_stats;
51 RtcpPacketTypeCounter rtcp_packet_type_counts;
52 RtcpStatistics rtcp_stats;
53 };
54
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000055 struct Stats {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020056 int input_frame_rate = 0;
57 int encode_frame_rate = 0;
58 int avg_encode_time_ms = 0;
59 int encode_usage_percent = 0;
60 int target_media_bitrate_bps = 0;
61 int media_bitrate_bps = 0;
62 bool suspended = false;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000063 std::map<uint32_t, StreamStats> substreams;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000064 };
65
66 struct Config {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000067 std::string ToString() const;
68
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000069 struct EncoderSettings {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000070 std::string ToString() const;
71
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000072 std::string payload_name;
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020073 int payload_type = -1;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000074
75 // Uninitialized VideoEncoder instance to be used for encoding. Will be
76 // initialized from inside the VideoSendStream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020077 VideoEncoder* encoder = nullptr;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000078 } encoder_settings;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000079
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000080 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000081 struct Rtp {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000082 std::string ToString() const;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000083
84 std::vector<uint32_t> ssrcs;
85
86 // Max RTP packet size delivered to send transport from VideoEngine.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020087 size_t max_packet_size = kDefaultMaxPacketSize;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000088
89 // RTP header extensions to use for this send stream.
90 std::vector<RtpExtension> extensions;
91
92 // See NackConfig for description.
93 NackConfig nack;
94
95 // See FecConfig for description.
96 FecConfig fec;
97
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +000098 // Settings for RTP retransmission payload format, see RFC 4588 for
99 // details.
100 struct Rtx {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000101 std::string ToString() const;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000102 // SSRCs to use for the RTX streams.
103 std::vector<uint32_t> ssrcs;
104
105 // Payload type to use for the RTX stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200106 int payload_type = -1;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000107 } rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000108
109 // RTCP CNAME, see RFC 3550.
110 std::string c_name;
111 } rtp;
112
113 // Called for each I420 frame before encoding the frame. Can be used for
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200114 // effects, snapshots etc. 'nullptr' disables the callback.
115 I420FrameCallback* pre_encode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000116
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200117 // Called for each encoded frame, e.g. used for file storage. 'nullptr'
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000118 // disables the callback.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200119 EncodedFrameObserver* post_encode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000120
121 // Renderer for local preview. The local renderer will be called even if
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200122 // sending hasn't started. 'nullptr' disables local rendering.
123 VideoRenderer* local_renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000124
125 // Expected delay needed by the renderer, i.e. the frame will be delivered
126 // this many milliseconds, if possible, earlier than expected render time.
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000127 // Only valid if |local_renderer| is set.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200128 int render_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000129
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000130 // Target delay in milliseconds. A positive value indicates this stream is
131 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200132 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000133
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000134 // True if the stream should be suspended when the available bitrate fall
135 // below the minimum configured bitrate. If this variable is false, the
136 // stream may send at a rate higher than the estimated available bitrate.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200137 bool suspend_below_min_bitrate = false;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000138 };
139
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000140 // Gets interface used to insert captured frames. Valid as long as the
141 // VideoSendStream is valid.
Peter Boström4b91bd02015-06-26 06:58:16 +0200142 virtual VideoCaptureInput* Input() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000143
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000144 // Set which streams to send. Must have at least as many SSRCs as configured
145 // in the config. Encoder settings are passed on to the encoder instance along
146 // with the VideoStream settings.
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000147 virtual bool ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000148
pbos@webrtc.org273a4142014-12-01 15:23:21 +0000149 virtual Stats GetStats() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000150};
151
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000152} // namespace webrtc
153
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000154#endif // WEBRTC_VIDEO_SEND_STREAM_H_