2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_VIDEO_SEND_STREAM_H_
12 #define WEBRTC_VIDEO_SEND_STREAM_H_
17 #include "webrtc/common_types.h"
18 #include "webrtc/config.h"
19 #include "webrtc/frame_callback.h"
20 #include "webrtc/video_renderer.h"
26 // Class to deliver captured frame to the video send stream.
27 class VideoSendStreamInput {
29 // 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 SwapFrame(I420VideoFrame* video_frame) = 0;
35 virtual ~VideoSendStreamInput() {}
38 class VideoSendStream {
42 : input_frame_rate(0),
46 int encode_frame_rate;
48 std::map<uint32_t, StreamStats> substreams;
53 : pre_encode_callback(NULL),
54 post_encode_callback(NULL),
58 suspend_below_min_bitrate(false) {}
59 std::string ToString() const;
61 struct EncoderSettings {
62 EncoderSettings() : payload_type(-1), encoder(NULL) {}
63 std::string ToString() const;
65 std::string payload_name;
68 // Uninitialized VideoEncoder instance to be used for encoding. Will be
69 // initialized from inside the VideoSendStream.
70 webrtc::VideoEncoder* encoder;
73 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
76 : max_packet_size(kDefaultMaxPacketSize),
77 min_transmit_bitrate_bps(0) {}
78 std::string ToString() const;
80 std::vector<uint32_t> ssrcs;
82 // Max RTP packet size delivered to send transport from VideoEngine.
83 size_t max_packet_size;
85 // Padding will be used up to this bitrate regardless of the bitrate
86 // produced by the encoder. Padding above what's actually produced by the
87 // encoder helps maintaining a higher bitrate estimate.
88 int min_transmit_bitrate_bps;
90 // RTP header extensions to use for this send stream.
91 std::vector<RtpExtension> extensions;
93 // See NackConfig for description.
96 // See FecConfig for description.
99 // Settings for RTP retransmission payload format, see RFC 4588 for
102 Rtx() : payload_type(-1), pad_with_redundant_payloads(false) {}
103 std::string ToString() const;
104 // SSRCs to use for the RTX streams.
105 std::vector<uint32_t> ssrcs;
107 // Payload type to use for the RTX stream.
109 // Use redundant payloads to pad the bitrate. Instead of padding with
110 // randomized packets, we will preemptively retransmit media packets on
112 bool pad_with_redundant_payloads;
115 // RTCP CNAME, see RFC 3550.
119 // Called for each I420 frame before encoding the frame. Can be used for
120 // effects, snapshots etc. 'NULL' disables the callback.
121 I420FrameCallback* pre_encode_callback;
123 // Called for each encoded frame, e.g. used for file storage. 'NULL'
124 // disables the callback.
125 EncodedFrameObserver* post_encode_callback;
127 // Renderer for local preview. The local renderer will be called even if
128 // sending hasn't started. 'NULL' disables local rendering.
129 VideoRenderer* local_renderer;
131 // Expected delay needed by the renderer, i.e. the frame will be delivered
132 // this many milliseconds, if possible, earlier than expected render time.
133 // Only valid if |local_renderer| is set.
136 // Target delay in milliseconds. A positive value indicates this stream is
137 // used for streaming instead of a real-time call.
140 // True if the stream should be suspended when the available bitrate fall
141 // below the minimum configured bitrate. If this variable is false, the
142 // stream may send at a rate higher than the estimated available bitrate.
143 bool suspend_below_min_bitrate;
146 // Gets interface used to insert captured frames. Valid as long as the
147 // VideoSendStream is valid.
148 virtual VideoSendStreamInput* Input() = 0;
150 virtual void Start() = 0;
151 virtual void Stop() = 0;
153 // Set which streams to send. Must have at least as many SSRCs as configured
154 // in the config. Encoder settings are passed on to the encoder instance along
155 // with the VideoStream settings.
156 virtual bool ReconfigureVideoEncoder(const VideoEncoderConfig& config) = 0;
158 virtual Stats GetStats() const = 0;
161 virtual ~VideoSendStream() {}
164 } // namespace webrtc
166 #endif // WEBRTC_VIDEO_SEND_STREAM_H_