Line data Source code
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_RECEIVE_STREAM_H_
12 : #define WEBRTC_VIDEO_RECEIVE_STREAM_H_
13 :
14 : #include <limits>
15 : #include <map>
16 : #include <string>
17 : #include <vector>
18 :
19 : #include "webrtc/api/call/transport.h"
20 : #include "webrtc/base/platform_file.h"
21 : #include "webrtc/common_types.h"
22 : #include "webrtc/common_video/include/frame_callback.h"
23 : #include "webrtc/config.h"
24 : #include "webrtc/media/base/videosinkinterface.h"
25 : #include "webrtc/voice_engine/include/voe_base.h"
26 : #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
27 :
28 : namespace webrtc {
29 :
30 : class VideoDecoder;
31 :
32 0 : class VideoReceiveStream {
33 : public:
34 : // TODO(mflodman) Move all these settings to VideoDecoder and move the
35 : // declaration to common_types.h.
36 0 : struct Decoder {
37 : std::string ToString() const;
38 :
39 : // The actual decoder instance.
40 : VideoDecoder* decoder = nullptr;
41 :
42 : // Received RTP packets with this payload type will be sent to this decoder
43 : // instance.
44 : int payload_type = 0;
45 :
46 : // Name of the decoded payload (such as VP8). Maps back to the depacketizer
47 : // used to unpack incoming packets.
48 : std::string payload_name;
49 :
50 : // This map contains the codec specific parameters from SDP, i.e. the "fmtp"
51 : // parameters. It is the same as cricket::CodecParameterMap used in
52 : // cricket::VideoCodec.
53 : std::map<std::string, std::string> codec_params;
54 : };
55 :
56 0 : struct Stats {
57 : std::string ToString(int64_t time_ms) const;
58 :
59 : int network_frame_rate = 0;
60 : int decode_frame_rate = 0;
61 : int render_frame_rate = 0;
62 :
63 : // Decoder stats.
64 : std::string decoder_implementation_name = "unknown";
65 : FrameCounts frame_counts;
66 : int decode_ms = 0;
67 : int max_decode_ms = 0;
68 : int current_delay_ms = 0;
69 : int target_delay_ms = 0;
70 : int jitter_buffer_ms = 0;
71 : int min_playout_delay_ms = 0;
72 : int render_delay_ms = 10;
73 : uint32_t frames_decoded = 0;
74 :
75 : int current_payload_type = -1;
76 :
77 : int total_bitrate_bps = 0;
78 : int discarded_packets = 0;
79 :
80 : int width = 0;
81 : int height = 0;
82 :
83 0 : int sync_offset_ms = std::numeric_limits<int>::max();
84 :
85 : uint32_t ssrc = 0;
86 : std::string c_name;
87 : StreamDataCounters rtp_stats;
88 : RtcpPacketTypeCounter rtcp_packet_type_counts;
89 : RtcpStatistics rtcp_stats;
90 : };
91 :
92 0 : struct Config {
93 : private:
94 : // Access to the copy constructor is private to force use of the Copy()
95 : // method for those exceptional cases where we do use it.
96 0 : Config(const Config&) = default;
97 :
98 : public:
99 : Config() = delete;
100 0 : Config(Config&&) = default;
101 0 : explicit Config(Transport* rtcp_send_transport)
102 0 : : rtcp_send_transport(rtcp_send_transport) {}
103 :
104 : Config& operator=(Config&&) = default;
105 : Config& operator=(const Config&) = delete;
106 :
107 : // Mostly used by tests. Avoid creating copies if you can.
108 0 : Config Copy() const { return Config(*this); }
109 :
110 : std::string ToString() const;
111 :
112 : // Decoders for every payload that we can receive.
113 : std::vector<Decoder> decoders;
114 :
115 : // Receive-stream specific RTP settings.
116 0 : struct Rtp {
117 : std::string ToString() const;
118 :
119 : // Synchronization source (stream identifier) to be received.
120 : uint32_t remote_ssrc = 0;
121 : // Sender SSRC used for sending RTCP (such as receiver reports).
122 : uint32_t local_ssrc = 0;
123 :
124 : // See RtcpMode for description.
125 : RtcpMode rtcp_mode = RtcpMode::kCompound;
126 :
127 : // Extended RTCP settings.
128 0 : struct RtcpXr {
129 : // True if RTCP Receiver Reference Time Report Block extension
130 : // (RFC 3611) should be enabled.
131 : bool receiver_reference_time_report = false;
132 : } rtcp_xr;
133 :
134 : // See draft-alvestrand-rmcat-remb for information.
135 : bool remb = false;
136 :
137 : bool tmmbr = false;
138 :
139 : // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
140 : bool transport_cc = false;
141 :
142 : // TODO(jesup) - there should be a kKeyFrameReqNone
143 : KeyFrameRequestMethod keyframe_method = kKeyFrameReqPliRtcp;
144 :
145 : // See NackConfig for description.
146 : NackConfig nack;
147 :
148 : // See UlpfecConfig for description.
149 : UlpfecConfig ulpfec;
150 :
151 : // RTX settings for incoming video payloads that may be received. RTX is
152 : // disabled if there's no config present.
153 : struct Rtx {
154 : // SSRCs to use for the RTX streams.
155 : uint32_t ssrc = 0;
156 :
157 : // Payload type to use for the RTX stream.
158 : int payload_type = 0;
159 : };
160 :
161 : // Map from video RTP payload type -> RTX config.
162 : typedef std::map<int, Rtx> RtxMap;
163 : RtxMap rtx;
164 :
165 : // RTP header extensions used for the received stream.
166 : std::vector<RtpExtension> extensions;
167 : } rtp;
168 :
169 : // Transport for outgoing packets (RTCP).
170 : Transport* rtcp_send_transport = nullptr;
171 :
172 : // Must not be 'nullptr' when the stream is started.
173 : rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr;
174 :
175 : // Expected delay needed by the renderer, i.e. the frame will be delivered
176 : // this many milliseconds, if possible, earlier than the ideal render time.
177 : // Only valid if 'renderer' is set.
178 : int render_delay_ms = 10;
179 :
180 : // If set, pass frames on to the renderer as soon as they are
181 : // available.
182 : bool disable_prerenderer_smoothing = false;
183 :
184 : // Identifier for an A/V synchronization group. Empty string to disable.
185 : // TODO(pbos): Synchronize streams in a sync group, not just video streams
186 : // to one of the audio streams.
187 : std::string sync_group;
188 :
189 : // Called for each incoming video frame, i.e. in encoded state. E.g. used
190 : // when
191 : // saving the stream to a file. 'nullptr' disables the callback.
192 : EncodedFrameObserver* pre_decode_callback = nullptr;
193 :
194 : // Called for each decoded frame. E.g. used when adding effects to the
195 : // decoded
196 : // stream. 'nullptr' disables the callback.
197 : // TODO(tommi): This seems to be only used by a test or two. Consider
198 : // removing it (and use an appropriate alternative in the tests) as well
199 : // as the associated code in VideoStreamDecoder.
200 : I420FrameCallback* pre_render_callback = nullptr;
201 :
202 : // Target delay in milliseconds. A positive value indicates this stream is
203 : // used for streaming instead of a real-time call.
204 : int target_delay_ms = 0;
205 : };
206 :
207 : // Starts stream activity.
208 : // When a stream is active, it can receive, process and deliver packets.
209 : virtual void Start() = 0;
210 : // Stops stream activity.
211 : // When a stream is stopped, it can't receive, process or deliver packets.
212 : virtual void Stop() = 0;
213 :
214 : // TODO(pbos): Add info on currently-received codec to Stats.
215 : virtual Stats GetStats() const = 0;
216 :
217 : virtual bool
218 : GetRemoteRTCPSenderInfo(RTCPSenderInfo* sender_info) const = 0;
219 :
220 : virtual void SetSyncChannel(VoiceEngine* voice_engine, int audio_channel_id) = 0;
221 :
222 : // Takes ownership of the file, is responsible for closing it later.
223 : // Calling this method will close and finalize any current log.
224 : // Giving rtc::kInvalidPlatformFileValue disables logging.
225 : // If a frame to be written would make the log too large the write fails and
226 : // the log is closed and finalized. A |byte_limit| of 0 means no limit.
227 : virtual void EnableEncodedFrameRecording(rtc::PlatformFile file,
228 : size_t byte_limit) = 0;
229 : inline void DisableEncodedFrameRecording() {
230 : EnableEncodedFrameRecording(rtc::kInvalidPlatformFileValue, 0);
231 : }
232 :
233 : protected:
234 0 : virtual ~VideoReceiveStream() {}
235 : };
236 :
237 : } // namespace webrtc
238 :
239 : #endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_
|