Line data Source code
1 : /*
2 : * Copyright (c) 2012 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_RTP_STREAM_RECEIVER_H_
12 : #define WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_
13 :
14 : #include <list>
15 : #include <map>
16 : #include <memory>
17 : #include <string>
18 : #include <vector>
19 :
20 : #include "webrtc/base/constructormagic.h"
21 : #include "webrtc/base/criticalsection.h"
22 : #include "webrtc/modules/include/module_common_types.h"
23 : #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
24 : #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
25 : #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
26 : #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
27 : #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
28 : #include "webrtc/modules/video_coding/h264_sps_pps_tracker.h"
29 : #include "webrtc/modules/video_coding/include/video_coding_defines.h"
30 : #include "webrtc/modules/video_coding/packet_buffer.h"
31 : #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h"
32 : #include "webrtc/modules/video_coding/sequence_number_util.h"
33 : #include "webrtc/typedefs.h"
34 : #include "webrtc/video_receive_stream.h"
35 :
36 : namespace webrtc {
37 :
38 : class NackModule;
39 : class PacedSender;
40 : class PacketRouter;
41 : class ProcessThread;
42 : class ReceiveStatistics;
43 : class ReceiveStatisticsProxy;
44 : class RemoteBitrateEstimator;
45 : class RemoteNtpTimeEstimator;
46 : class RtcpRttStats;
47 : class RtpHeaderParser;
48 : class RTPPayloadRegistry;
49 : class RtpReceiver;
50 : class Transport;
51 : class UlpfecReceiver;
52 : class VCMTiming;
53 : class VieRemb;
54 :
55 : namespace vcm {
56 : class VideoReceiver;
57 : } // namespace vcm
58 :
59 : class RtpStreamReceiver : public RtpData,
60 : public RtpFeedback,
61 : public VCMFrameTypeCallback,
62 : public VCMPacketRequestCallback,
63 : public video_coding::OnReceivedFrameCallback,
64 : public video_coding::OnCompleteFrameCallback,
65 : public CallStatsObserver {
66 : public:
67 : RtpStreamReceiver(
68 : vcm::VideoReceiver* video_receiver,
69 : RemoteBitrateEstimator* remote_bitrate_estimator,
70 : Transport* transport,
71 : RtcpRttStats* rtt_stats,
72 : PacedSender* paced_sender,
73 : PacketRouter* packet_router,
74 : VieRemb* remb,
75 : const VideoReceiveStream::Config* config,
76 : ReceiveStatisticsProxy* receive_stats_proxy,
77 : ProcessThread* process_thread,
78 : RateLimiter* retransmission_rate_limiter,
79 : NackSender* nack_sender,
80 : KeyFrameRequestSender* keyframe_request_sender,
81 : video_coding::OnCompleteFrameCallback* complete_frame_callback,
82 : VCMTiming* timing);
83 : ~RtpStreamReceiver();
84 :
85 : bool AddReceiveCodec(const VideoCodec& video_codec,
86 : const std::map<std::string, std::string>& codec_params);
87 :
88 : bool AddReceiveCodec(const VideoCodec& video_codec);
89 :
90 : uint32_t GetRemoteSsrc() const;
91 : int GetCsrcs(uint32_t* csrcs) const;
92 : void GetRID(char rid[256]) const;
93 : bool SetReceiveRIDStatus(bool enable, int id);
94 :
95 : RtpReceiver* GetRtpReceiver() const;
96 0 : RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); }
97 :
98 : void StartReceive();
99 : void StopReceive();
100 :
101 : bool DeliverRtp(const uint8_t* rtp_packet,
102 : size_t rtp_packet_length,
103 : const PacketTime& packet_time);
104 : bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
105 :
106 : void FrameContinuous(uint16_t seq_num);
107 :
108 : void FrameDecoded(uint16_t seq_num);
109 :
110 : void SignalNetworkState(NetworkState state);
111 :
112 : // Implements RtpData.
113 : int32_t OnReceivedPayloadData(const uint8_t* payload_data,
114 : size_t payload_size,
115 : const WebRtcRTPHeader* rtp_header) override;
116 : bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
117 :
118 : // Implements RtpFeedback.
119 : int32_t OnInitializeDecoder(int8_t payload_type,
120 : const char payload_name[RTP_PAYLOAD_NAME_SIZE],
121 : int frequency,
122 : size_t channels,
123 : uint32_t rate) override;
124 : void OnIncomingSSRCChanged(uint32_t ssrc) override;
125 0 : void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override {}
126 :
127 : // Implements VCMFrameTypeCallback.
128 : int32_t RequestKeyFrame() override;
129 : int32_t SliceLossIndicationRequest(const uint64_t picture_id) override;
130 :
131 : bool IsUlpfecEnabled() const;
132 : bool IsRetransmissionsEnabled() const;
133 : // Don't use, still experimental.
134 : void RequestPacketRetransmit(const std::vector<uint16_t>& sequence_numbers);
135 :
136 : // Implements VCMPacketRequestCallback.
137 : int32_t ResendPackets(const uint16_t* sequenceNumbers,
138 : uint16_t length) override;
139 :
140 : // Implements OnReceivedFrameCallback.
141 : void OnReceivedFrame(
142 : std::unique_ptr<video_coding::RtpFrameObject> frame) override;
143 :
144 : // Implements OnCompleteFrameCallback.
145 : void OnCompleteFrame(
146 : std::unique_ptr<video_coding::FrameObject> frame) override;
147 :
148 : void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
149 :
150 : private:
151 : bool ReceivePacket(const uint8_t* packet,
152 : size_t packet_length,
153 : const RTPHeader& header,
154 : bool in_order);
155 : // Parses and handles for instance RTX and RED headers.
156 : // This function assumes that it's being called from only one thread.
157 : bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
158 : size_t packet_length,
159 : const RTPHeader& header);
160 : void NotifyReceiverOfFecPacket(const RTPHeader& header);
161 : bool IsPacketInOrder(const RTPHeader& header) const;
162 : bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
163 : void UpdateHistograms();
164 : void EnableReceiveRtpHeaderExtension(const std::string& extension, int id);
165 : bool IsRedEnabled() const;
166 : void InsertSpsPpsIntoTracker(uint8_t payload_type);
167 :
168 : Clock* const clock_;
169 : // Ownership of this object lies with VideoReceiveStream, which owns |this|.
170 : const VideoReceiveStream::Config& config_;
171 : vcm::VideoReceiver* const video_receiver_;
172 : RemoteBitrateEstimator* const remote_bitrate_estimator_;
173 : PacketRouter* const packet_router_;
174 : VieRemb* const remb_;
175 : ProcessThread* const process_thread_;
176 :
177 : RemoteNtpTimeEstimator ntp_estimator_;
178 : RTPPayloadRegistry rtp_payload_registry_;
179 :
180 : const std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
181 : const std::unique_ptr<RtpReceiver> rtp_receiver_;
182 : const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
183 : std::unique_ptr<UlpfecReceiver> ulpfec_receiver_;
184 :
185 : rtc::CriticalSection receive_cs_;
186 : bool receiving_ GUARDED_BY(receive_cs_);
187 : uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_);
188 : bool restored_packet_in_use_ GUARDED_BY(receive_cs_);
189 : bool receiving_rid_enabled_ GUARDED_BY(receive_cs_);
190 : int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_);
191 :
192 : const std::unique_ptr<RtpRtcp> rtp_rtcp_;
193 :
194 : // Members for the new jitter buffer experiment.
195 : bool jitter_buffer_experiment_;
196 : video_coding::OnCompleteFrameCallback* complete_frame_callback_;
197 : KeyFrameRequestSender* keyframe_request_sender_;
198 : VCMTiming* timing_;
199 : std::unique_ptr<NackModule> nack_module_;
200 : rtc::scoped_refptr<video_coding::PacketBuffer> packet_buffer_;
201 : std::unique_ptr<video_coding::RtpFrameReferenceFinder> reference_finder_;
202 : rtc::CriticalSection last_seq_num_cs_;
203 : std::map<uint16_t, uint16_t, DescendingSeqNumComp<uint16_t>>
204 : last_seq_num_for_pic_id_ GUARDED_BY(last_seq_num_cs_);
205 : video_coding::H264SpsPpsTracker tracker_;
206 : // TODO(johan): Remove pt_codec_params_ once
207 : // https://bugs.chromium.org/p/webrtc/issues/detail?id=6883 is resolved.
208 : // Maps a payload type to a map of out-of-band supplied codec parameters.
209 : std::map<uint8_t, std::map<std::string, std::string>> pt_codec_params_;
210 : int16_t last_payload_type_ = -1;
211 : };
212 :
213 : } // namespace webrtc
214 :
215 : #endif // WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_
|