blob: af33b7ca2f83afadac4b519f9a53eda217864eca [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 +000026struct SendStreamState;
27
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000028// Class to deliver captured frame to the video send stream.
29class VideoSendStreamInput {
30 public:
31 // TODO(mflodman) Replace time_since_capture_ms when I420VideoFrame uses NTP
32 // time.
33 virtual void PutFrame(const I420VideoFrame& video_frame,
pbos@webrtc.org9b303482013-05-23 12:37:11 +000034 uint32_t time_since_capture_ms) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000035
36 protected:
37 virtual ~VideoSendStreamInput() {}
38};
39
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000040class VideoSendStream {
41 public:
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000042 struct Stats {
43 Stats()
44 : input_frame_rate(0),
45 encode_frame(0),
46 key_frames(0),
47 delta_frames(0),
48 video_packets(0),
49 retransmitted_packets(0),
50 fec_packets(0),
51 padding_packets(0),
52 send_bitrate_bps(0),
53 delay_ms(0) {}
54 RtpStatistics rtp;
55 int input_frame_rate;
56 int encode_frame;
57 uint32_t key_frames;
58 uint32_t delta_frames;
59 uint32_t video_packets;
60 uint32_t retransmitted_packets;
61 uint32_t fec_packets;
62 uint32_t padding_packets;
63 int32_t send_bitrate_bps;
64 int delay_ms;
65 };
66
67 class StatsCallback {
68 public:
69 virtual ~StatsCallback() {}
70 virtual void ReceiveStats(const std::vector<Stats>& stats) = 0;
71 };
72
73 struct Config {
74 Config()
75 : pre_encode_callback(NULL),
76 encoded_callback(NULL),
77 local_renderer(NULL),
78 render_delay_ms(0),
79 encoder(NULL),
80 internal_source(false),
81 target_delay_ms(0),
stefan@webrtc.org360e3762013-08-22 09:29:56 +000082 pacing(false),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000083 stats_callback(NULL),
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +000084 start_state(NULL),
85 auto_mute(false) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000086 VideoCodec codec;
87
sprang@webrtc.org25fce9a2013-10-16 13:29:14 +000088 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000089 struct Rtp {
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000090 Rtp() : max_packet_size(kDefaultMaxPacketSize) {}
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000091
92 std::vector<uint32_t> ssrcs;
93
94 // Max RTP packet size delivered to send transport from VideoEngine.
95 size_t max_packet_size;
96
97 // RTP header extensions to use for this send stream.
98 std::vector<RtpExtension> extensions;
99
100 // See NackConfig for description.
101 NackConfig nack;
102
103 // See FecConfig for description.
104 FecConfig fec;
105
106 // See RtxConfig for description.
107 RtxConfig rtx;
108
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
114 // effects, snapshots etc. 'NULL' disables the callback.
115 I420FrameCallback* pre_encode_callback;
116
117 // Called for each encoded frame, e.g. used for file storage. 'NULL'
118 // disables the callback.
119 EncodedFrameObserver* encoded_callback;
120
121 // Renderer for local preview. The local renderer will be called even if
122 // sending hasn't started. 'NULL' disables local rendering.
123 VideoRenderer* local_renderer;
124
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.
127 // Only valid if |renderer| is set.
128 int render_delay_ms;
129
130 // TODO(mflodman) Move VideoEncoder to common_types.h and redefine.
131 // External encoding. 'encoder' is the external encoder instance and
132 // 'internal_source' is set to true if the encoder also captures the video
133 // frames.
134 VideoEncoder* encoder;
135 bool internal_source;
136
137 // Target delay in milliseconds. A positive value indicates this stream is
138 // used for streaming instead of a real-time call.
139 int target_delay_ms;
140
stefan@webrtc.org360e3762013-08-22 09:29:56 +0000141 // True if network a send-side packet buffer should be used to pace out
142 // packets onto the network.
143 bool pacing;
144
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000145 // Callback for periodically receiving send stats.
146 StatsCallback* stats_callback;
147
148 // Set to resume a previously destroyed send stream.
149 SendStreamState* start_state;
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +0000150
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +0000151 // True if video should be muted when video goes under the minimum video
152 // bitrate. Unless muted, video will be sent at a bitrate higher than
153 // estimated available.
154 bool auto_mute;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000155 };
156
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000157 // Gets interface used to insert captured frames. Valid as long as the
158 // VideoSendStream is valid.
159 virtual VideoSendStreamInput* Input() = 0;
160
161 virtual void StartSend() = 0;
162 virtual void StopSend() = 0;
163
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000164 // TODO(mflodman) Change VideoCodec struct and use here.
165 virtual bool SetTargetBitrate(
166 int min_bitrate, int max_bitrate,
167 const std::vector<SimulcastStream>& streams) = 0;
168
169 virtual void GetSendCodec(VideoCodec* send_codec) = 0;
170
171 protected:
172 virtual ~VideoSendStream() {}
173};
174
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000175} // namespace webrtc
176
177#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_