blob: 2358042e5a9084de5cc79a760bf9273fb46f433d [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
11#ifndef WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_
12#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_
13
14#include <string>
15#include <vector>
16
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:
29 // TODO(mflodman) Replace time_since_capture_ms when I420VideoFrame uses NTP
30 // time.
31 virtual void PutFrame(const I420VideoFrame& video_frame,
pbos@webrtc.org9b303482013-05-23 12:37:11 +000032 uint32_t time_since_capture_ms) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000033
34 protected:
35 virtual ~VideoSendStreamInput() {}
36};
37
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000038class VideoSendStream {
39 public:
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000040 struct Stats {
41 Stats()
42 : input_frame_rate(0),
43 encode_frame(0),
44 key_frames(0),
45 delta_frames(0),
46 video_packets(0),
47 retransmitted_packets(0),
48 fec_packets(0),
49 padding_packets(0),
50 send_bitrate_bps(0),
51 delay_ms(0) {}
52 RtpStatistics rtp;
53 int input_frame_rate;
54 int encode_frame;
55 uint32_t key_frames;
56 uint32_t delta_frames;
57 uint32_t video_packets;
58 uint32_t retransmitted_packets;
59 uint32_t fec_packets;
60 uint32_t padding_packets;
61 int32_t send_bitrate_bps;
62 int delay_ms;
63 };
64
65 class StatsCallback {
66 public:
67 virtual ~StatsCallback() {}
68 virtual void ReceiveStats(const std::vector<Stats>& stats) = 0;
69 };
70
71 struct Config {
72 Config()
73 : pre_encode_callback(NULL),
sprang@webrtc.org40709352013-11-26 11:41:59 +000074 post_encode_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000075 local_renderer(NULL),
76 render_delay_ms(0),
77 encoder(NULL),
78 internal_source(false),
79 target_delay_ms(0),
stefan@webrtc.org360e3762013-08-22 09:29:56 +000080 pacing(false),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000081 stats_callback(NULL),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +000082 suspend_below_min_bitrate(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000083 VideoCodec codec;
84
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000085 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000086 struct Rtp {
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000087 Rtp() : max_packet_size(kDefaultMaxPacketSize) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000088
89 std::vector<uint32_t> ssrcs;
90
91 // Max RTP packet size delivered to send transport from VideoEngine.
92 size_t max_packet_size;
93
94 // RTP header extensions to use for this send stream.
95 std::vector<RtpExtension> extensions;
96
97 // See NackConfig for description.
98 NackConfig nack;
99
100 // See FecConfig for description.
101 FecConfig fec;
102
103 // See RtxConfig for description.
104 RtxConfig rtx;
105
106 // RTCP CNAME, see RFC 3550.
107 std::string c_name;
108 } rtp;
109
110 // Called for each I420 frame before encoding the frame. Can be used for
111 // effects, snapshots etc. 'NULL' disables the callback.
112 I420FrameCallback* pre_encode_callback;
113
114 // Called for each encoded frame, e.g. used for file storage. 'NULL'
115 // disables the callback.
sprang@webrtc.org40709352013-11-26 11:41:59 +0000116 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000117
118 // Renderer for local preview. The local renderer will be called even if
119 // sending hasn't started. 'NULL' disables local rendering.
120 VideoRenderer* local_renderer;
121
122 // Expected delay needed by the renderer, i.e. the frame will be delivered
123 // this many milliseconds, if possible, earlier than expected render time.
124 // Only valid if |renderer| is set.
125 int render_delay_ms;
126
127 // TODO(mflodman) Move VideoEncoder to common_types.h and redefine.
128 // External encoding. 'encoder' is the external encoder instance and
129 // 'internal_source' is set to true if the encoder also captures the video
130 // frames.
131 VideoEncoder* encoder;
132 bool internal_source;
133
134 // Target delay in milliseconds. A positive value indicates this stream is
135 // used for streaming instead of a real-time call.
136 int target_delay_ms;
137
stefan@webrtc.org360e3762013-08-22 09:29:56 +0000138 // True if network a send-side packet buffer should be used to pace out
139 // packets onto the network.
140 bool pacing;
141
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000142 // Callback for periodically receiving send stats.
143 StatsCallback* stats_callback;
144
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000145 // True if the stream should be suspended when the available bitrate fall
146 // below the minimum configured bitrate. If this variable is false, the
147 // stream may send at a rate higher than the estimated available bitrate.
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +0000148 // Enabling suspend_below_min_bitrate will also enable pacing and padding,
149 // otherwise, the video will be unable to recover from suspension.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000150 bool suspend_below_min_bitrate;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000151 };
152
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000153 // Gets interface used to insert captured frames. Valid as long as the
154 // VideoSendStream is valid.
155 virtual VideoSendStreamInput* Input() = 0;
156
pbos@webrtc.org53c85732013-11-20 11:36:47 +0000157 virtual void StartSending() = 0;
158 virtual void StopSending() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000159
pbos@webrtc.org64887612013-11-14 08:58:14 +0000160 virtual bool SetCodec(const VideoCodec& codec) = 0;
161 virtual VideoCodec GetCodec() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000162
163 protected:
164 virtual ~VideoSendStream() {}
165};
166
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000167} // namespace webrtc
168
169#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_