1 /* 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_SEND_STREAM_H_ 12 #define WEBRTC_VIDEO_SEND_STREAM_H_ 13 14 #include <map> 15 #include <string> 16 17 #include "webrtc/common_types.h" 18 #include "webrtc/config.h" 19 #include "webrtc/frame_callback.h" 20 #include "webrtc/video_renderer.h" 21 22 namespace webrtc { 23 24 class VideoEncoder; 25 26 // Class to deliver captured frame to the video send stream. 27 class VideoSendStreamInput { 28 public: 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; 33 34 protected: 35 virtual ~VideoSendStreamInput() {} 36 }; 37 38 class VideoSendStream { 39 public: 40 struct Stats { 41 Stats() 42 : input_frame_rate(0), 43 encode_frame_rate(0), 44 suspended(false) {} 45 int input_frame_rate; 46 int encode_frame_rate; 47 bool suspended; 48 std::map<uint32_t, StreamStats> substreams; 49 }; 50 51 struct Config { 52 Config() 53 : pre_encode_callback(NULL), 54 post_encode_callback(NULL), 55 local_renderer(NULL), 56 render_delay_ms(0), 57 target_delay_ms(0), 58 suspend_below_min_bitrate(false) {} 59 std::string ToString() const; 60 61 struct EncoderSettings { 62 EncoderSettings() : payload_type(-1), encoder(NULL) {} 63 std::string ToString() const; 64 65 std::string payload_name; 66 int payload_type; 67 68 // Uninitialized VideoEncoder instance to be used for encoding. Will be 69 // initialized from inside the VideoSendStream. 70 webrtc::VideoEncoder* encoder; 71 } encoder_settings; 72 73 static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4. 74 struct Rtp { 75 Rtp() 76 : max_packet_size(kDefaultMaxPacketSize), 77 min_transmit_bitrate_bps(0) {} 78 std::string ToString() const; 79 80 std::vector<uint32_t> ssrcs; 81 82 // Max RTP packet size delivered to send transport from VideoEngine. 83 size_t max_packet_size; 84 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; 89 90 // RTP header extensions to use for this send stream. 91 std::vector<RtpExtension> extensions; 92 93 // See NackConfig for description. 94 NackConfig nack; 95 96 // See FecConfig for description. 97 FecConfig fec; 98 99 // Settings for RTP retransmission payload format, see RFC 4588 for 100 // details. 101 struct Rtx { 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; 106 107 // Payload type to use for the RTX stream. 108 int payload_type; 109 // Use redundant payloads to pad the bitrate. Instead of padding with 110 // randomized packets, we will preemptively retransmit media packets on 111 // the RTX stream. 112 bool pad_with_redundant_payloads; 113 } rtx; 114 115 // RTCP CNAME, see RFC 3550. 116 std::string c_name; 117 } rtp; 118 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; 122 123 // Called for each encoded frame, e.g. used for file storage. 'NULL' 124 // disables the callback. 125 EncodedFrameObserver* post_encode_callback; 126 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; 130 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. 134 int render_delay_ms; 135 136 // Target delay in milliseconds. A positive value indicates this stream is 137 // used for streaming instead of a real-time call. 138 int target_delay_ms; 139 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; 144 }; 145 146 // Gets interface used to insert captured frames. Valid as long as the 147 // VideoSendStream is valid. 148 virtual VideoSendStreamInput* Input() = 0; 149 150 virtual void Start() = 0; 151 virtual void Stop() = 0; 152 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; 157 158 virtual Stats GetStats() const = 0; 159 160 protected: 161 virtual ~VideoSendStream() {} 162 }; 163 164 } // namespace webrtc 165 166 #endif // WEBRTC_VIDEO_SEND_STREAM_H_ 167