blob: 11a37ae1af5e00920306d52af167c4c204053038 [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
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.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:
29 // TODO(mflodman) Replace time_since_capture_ms when I420VideoFrame uses NTP
30 // time.
31 virtual void PutFrame(const I420VideoFrame& video_frame,
pbos@webrtc.org08f3ca92013-05-23 12:37:11 +000032 uint32_t time_since_capture_ms) = 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),
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),
74 encoded_callback(NULL),
75 local_renderer(NULL),
76 render_delay_ms(0),
77 encoder(NULL),
78 internal_source(false),
79 target_delay_ms(0),
stefan@webrtc.org55afdbe2013-08-22 09:29:56 +000080 pacing(false),
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000081 stats_callback(NULL),
henrik.lundin@webrtc.org45901772013-11-18 12:18:43 +000082 suspend_below_min_bitrate(false) {}
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000083 VideoCodec codec;
84
sprang@webrtc.org44bb62a2013-10-16 13:29:14 +000085 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000086 struct Rtp {
pbos@webrtc.org51e01012013-10-17 14:14:42 +000087 Rtp() : max_packet_size(kDefaultMaxPacketSize) {}
pbos@webrtc.org6f1c3ef2013-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.
116 EncodedFrameObserver* encoded_callback;
117
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.org55afdbe2013-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.org6f1c3ef2013-06-05 11:33:21 +0000142 // Callback for periodically receiving send stats.
143 StatsCallback* stats_callback;
144
henrik.lundin@webrtc.org45901772013-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.
148 bool suspend_below_min_bitrate;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000149 };
150
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000151 // Gets interface used to insert captured frames. Valid as long as the
152 // VideoSendStream is valid.
153 virtual VideoSendStreamInput* Input() = 0;
154
pbos@webrtc.org7f9f8402013-11-20 11:36:47 +0000155 virtual void StartSending() = 0;
156 virtual void StopSending() = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000157
pbos@webrtc.org69040542013-11-14 08:58:14 +0000158 virtual bool SetCodec(const VideoCodec& codec) = 0;
159 virtual VideoCodec GetCodec() = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000160
161 protected:
162 virtual ~VideoSendStream() {}
163};
164
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000165} // namespace webrtc
166
167#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_