blob: 7c1a6fd0297e64b0f34579d588f1ad87bf6e0c51 [file] [log] [blame]
mflodman@webrtc.org69b0d2c2013-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.org2a4595a2013-12-18 09:46:22 +000011#ifndef WEBRTC_VIDEO_SEND_STREAM_H_
12#define WEBRTC_VIDEO_SEND_STREAM_H_
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000013
14#include <string>
15#include <vector>
16
17#include "webrtc/common_types.h"
pbos@webrtc.orgb581c902013-10-28 16:32:01 +000018#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/video_renderer.h"
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000021
22namespace webrtc {
23
24class VideoEncoder;
25
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000026// Class to deliver captured frame to the video send stream.
27class VideoSendStreamInput {
28 public:
pbos@webrtc.org7123a802013-12-11 16:26:16 +000029 // These methods do not lock internally and must be called sequentially.
30 // If your application switches input sources synchronization must be done
31 // externally to make sure that any old frames are not delivered concurrently.
32 virtual void PutFrame(const I420VideoFrame& video_frame) = 0;
33 virtual void SwapFrame(I420VideoFrame* video_frame) = 0;
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000034
35 protected:
36 virtual ~VideoSendStreamInput() {}
37};
38
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +000039class VideoSendStream {
40 public:
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000041 struct Stats {
42 Stats()
43 : input_frame_rate(0),
44 encode_frame(0),
45 key_frames(0),
46 delta_frames(0),
47 video_packets(0),
48 retransmitted_packets(0),
49 fec_packets(0),
50 padding_packets(0),
51 send_bitrate_bps(0),
52 delay_ms(0) {}
53 RtpStatistics rtp;
54 int input_frame_rate;
55 int encode_frame;
56 uint32_t key_frames;
57 uint32_t delta_frames;
58 uint32_t video_packets;
59 uint32_t retransmitted_packets;
60 uint32_t fec_packets;
61 uint32_t padding_packets;
62 int32_t send_bitrate_bps;
63 int delay_ms;
64 };
65
66 class StatsCallback {
67 public:
68 virtual ~StatsCallback() {}
69 virtual void ReceiveStats(const std::vector<Stats>& stats) = 0;
70 };
71
72 struct Config {
73 Config()
74 : pre_encode_callback(NULL),
sprang@webrtc.org4a9843f2013-11-26 11:41:59 +000075 post_encode_callback(NULL),
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000076 local_renderer(NULL),
77 render_delay_ms(0),
78 encoder(NULL),
79 internal_source(false),
80 target_delay_ms(0),
stefan@webrtc.orga0a91d82013-08-22 09:29:56 +000081 pacing(false),
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000082 stats_callback(NULL),
henrik.lundin@webrtc.org8fdf1912013-11-18 12:18:43 +000083 suspend_below_min_bitrate(false) {}
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000084 VideoCodec codec;
85
sprang@webrtc.org6133dd52013-10-16 13:29:14 +000086 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000087 struct Rtp {
pbos@webrtc.orgb1ef0d72013-10-17 14:14:42 +000088 Rtp() : max_packet_size(kDefaultMaxPacketSize) {}
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +000089
90 std::vector<uint32_t> ssrcs;
91
92 // Max RTP packet size delivered to send transport from VideoEngine.
93 size_t max_packet_size;
94
95 // RTP header extensions to use for this send stream.
96 std::vector<RtpExtension> extensions;
97
98 // See NackConfig for description.
99 NackConfig nack;
100
101 // See FecConfig for description.
102 FecConfig fec;
103
104 // See RtxConfig for description.
105 RtxConfig rtx;
106
107 // RTCP CNAME, see RFC 3550.
108 std::string c_name;
109 } rtp;
110
111 // Called for each I420 frame before encoding the frame. Can be used for
112 // effects, snapshots etc. 'NULL' disables the callback.
113 I420FrameCallback* pre_encode_callback;
114
115 // Called for each encoded frame, e.g. used for file storage. 'NULL'
116 // disables the callback.
sprang@webrtc.org4a9843f2013-11-26 11:41:59 +0000117 EncodedFrameObserver* post_encode_callback;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000118
119 // Renderer for local preview. The local renderer will be called even if
120 // sending hasn't started. 'NULL' disables local rendering.
121 VideoRenderer* local_renderer;
122
123 // Expected delay needed by the renderer, i.e. the frame will be delivered
124 // this many milliseconds, if possible, earlier than expected render time.
125 // Only valid if |renderer| is set.
126 int render_delay_ms;
127
128 // TODO(mflodman) Move VideoEncoder to common_types.h and redefine.
129 // External encoding. 'encoder' is the external encoder instance and
130 // 'internal_source' is set to true if the encoder also captures the video
131 // frames.
132 VideoEncoder* encoder;
133 bool internal_source;
134
135 // Target delay in milliseconds. A positive value indicates this stream is
136 // used for streaming instead of a real-time call.
137 int target_delay_ms;
138
stefan@webrtc.orga0a91d82013-08-22 09:29:56 +0000139 // True if network a send-side packet buffer should be used to pace out
140 // packets onto the network.
141 bool pacing;
142
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000143 // Callback for periodically receiving send stats.
144 StatsCallback* stats_callback;
145
henrik.lundin@webrtc.org8fdf1912013-11-18 12:18:43 +0000146 // True if the stream should be suspended when the available bitrate fall
147 // below the minimum configured bitrate. If this variable is false, the
148 // stream may send at a rate higher than the estimated available bitrate.
henrik.lundin@webrtc.orgd7d60c82013-11-21 14:05:40 +0000149 // Enabling suspend_below_min_bitrate will also enable pacing and padding,
150 // otherwise, the video will be unable to recover from suspension.
henrik.lundin@webrtc.org8fdf1912013-11-18 12:18:43 +0000151 bool suspend_below_min_bitrate;
pbos@webrtc.org2c343fc2013-06-05 11:33:21 +0000152 };
153
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000154 // Gets interface used to insert captured frames. Valid as long as the
155 // VideoSendStream is valid.
156 virtual VideoSendStreamInput* Input() = 0;
157
pbos@webrtc.org48cc9dc2013-11-20 11:36:47 +0000158 virtual void StartSending() = 0;
159 virtual void StopSending() = 0;
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000160
pbos@webrtc.org8f2997c2013-11-14 08:58:14 +0000161 virtual bool SetCodec(const VideoCodec& codec) = 0;
162 virtual VideoCodec GetCodec() = 0;
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000163
164 protected:
165 virtual ~VideoSendStream() {}
166};
167
mflodman@webrtc.org69b0d2c2013-04-18 12:02:52 +0000168} // namespace webrtc
169
mflodman@webrtc.org2a4595a2013-12-18 09:46:22 +0000170#endif // WEBRTC_VIDEO_SEND_STREAM_H_