OLD | NEW |
| (Empty) |
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 RemoteNtpTimeEstimator; | |
45 class RtcpRttStats; | |
46 class RtpHeaderParser; | |
47 class RtpPacketReceived; | |
48 class RTPPayloadRegistry; | |
49 class RtpReceiver; | |
50 class Transport; | |
51 class UlpfecReceiver; | |
52 class VCMTiming; | |
53 | |
54 namespace vcm { | |
55 class VideoReceiver; | |
56 } // namespace vcm | |
57 | |
58 class RtpStreamReceiver : public RtpData, | |
59 public RecoveredPacketReceiver, | |
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 Transport* transport, | |
69 RtcpRttStats* rtt_stats, | |
70 PacketRouter* packet_router, | |
71 const VideoReceiveStream::Config* config, | |
72 ReceiveStatisticsProxy* receive_stats_proxy, | |
73 ProcessThread* process_thread, | |
74 NackSender* nack_sender, | |
75 KeyFrameRequestSender* keyframe_request_sender, | |
76 video_coding::OnCompleteFrameCallback* complete_frame_callback, | |
77 VCMTiming* timing); | |
78 ~RtpStreamReceiver(); | |
79 | |
80 bool AddReceiveCodec(const VideoCodec& video_codec, | |
81 const std::map<std::string, std::string>& codec_params); | |
82 uint32_t GetRemoteSsrc() const; | |
83 int GetCsrcs(uint32_t* csrcs) const; | |
84 | |
85 RtpReceiver* GetRtpReceiver() const; | |
86 RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); } | |
87 | |
88 void StartReceive(); | |
89 void StopReceive(); | |
90 | |
91 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); | |
92 | |
93 void FrameContinuous(uint16_t seq_num); | |
94 | |
95 void FrameDecoded(uint16_t seq_num); | |
96 | |
97 void SignalNetworkState(NetworkState state); | |
98 | |
99 // TODO(nisse): Intended to be part of an RtpPacketReceiver interface. | |
100 void OnRtpPacket(const RtpPacketReceived& packet); | |
101 | |
102 // Implements RtpData. | |
103 int32_t OnReceivedPayloadData(const uint8_t* payload_data, | |
104 size_t payload_size, | |
105 const WebRtcRTPHeader* rtp_header) override; | |
106 // Implements RecoveredPacketReceiver. | |
107 void OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; | |
108 | |
109 // Implements RtpFeedback. | |
110 int32_t OnInitializeDecoder(int8_t payload_type, | |
111 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | |
112 int frequency, | |
113 size_t channels, | |
114 uint32_t rate) override; | |
115 void OnIncomingSSRCChanged(uint32_t ssrc) override; | |
116 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override {} | |
117 | |
118 // Implements VCMFrameTypeCallback. | |
119 int32_t RequestKeyFrame() override; | |
120 | |
121 bool IsUlpfecEnabled() const; | |
122 bool IsRetransmissionsEnabled() const; | |
123 // Don't use, still experimental. | |
124 void RequestPacketRetransmit(const std::vector<uint16_t>& sequence_numbers); | |
125 | |
126 // Implements VCMPacketRequestCallback. | |
127 int32_t ResendPackets(const uint16_t* sequenceNumbers, | |
128 uint16_t length) override; | |
129 | |
130 // Implements OnReceivedFrameCallback. | |
131 void OnReceivedFrame( | |
132 std::unique_ptr<video_coding::RtpFrameObject> frame) override; | |
133 | |
134 // Implements OnCompleteFrameCallback. | |
135 void OnCompleteFrame( | |
136 std::unique_ptr<video_coding::FrameObject> frame) override; | |
137 | |
138 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; | |
139 | |
140 rtc::Optional<int64_t> LastReceivedPacketMs() const; | |
141 rtc::Optional<int64_t> LastReceivedKeyframePacketMs() const; | |
142 | |
143 private: | |
144 bool AddReceiveCodec(const VideoCodec& video_codec); | |
145 void ReceivePacket(const uint8_t* packet, | |
146 size_t packet_length, | |
147 const RTPHeader& header, | |
148 bool in_order); | |
149 // Parses and handles for instance RTX and RED headers. | |
150 // This function assumes that it's being called from only one thread. | |
151 void ParseAndHandleEncapsulatingHeader(const uint8_t* packet, | |
152 size_t packet_length, | |
153 const RTPHeader& header); | |
154 void NotifyReceiverOfFecPacket(const RTPHeader& header); | |
155 bool IsPacketInOrder(const RTPHeader& header) const; | |
156 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; | |
157 void UpdateHistograms(); | |
158 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); | |
159 bool IsRedEnabled() const; | |
160 void InsertSpsPpsIntoTracker(uint8_t payload_type); | |
161 | |
162 Clock* const clock_; | |
163 // Ownership of this object lies with VideoReceiveStream, which owns |this|. | |
164 const VideoReceiveStream::Config& config_; | |
165 PacketRouter* const packet_router_; | |
166 ProcessThread* const process_thread_; | |
167 | |
168 RemoteNtpTimeEstimator ntp_estimator_; | |
169 RTPPayloadRegistry rtp_payload_registry_; | |
170 | |
171 const std::unique_ptr<RtpHeaderParser> rtp_header_parser_; | |
172 const std::unique_ptr<RtpReceiver> rtp_receiver_; | |
173 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; | |
174 std::unique_ptr<UlpfecReceiver> ulpfec_receiver_; | |
175 | |
176 rtc::CriticalSection receive_cs_; | |
177 bool receiving_ GUARDED_BY(receive_cs_); | |
178 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); | |
179 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); | |
180 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); | |
181 | |
182 const std::unique_ptr<RtpRtcp> rtp_rtcp_; | |
183 | |
184 // Members for the new jitter buffer experiment. | |
185 video_coding::OnCompleteFrameCallback* complete_frame_callback_; | |
186 KeyFrameRequestSender* keyframe_request_sender_; | |
187 VCMTiming* timing_; | |
188 std::unique_ptr<NackModule> nack_module_; | |
189 rtc::scoped_refptr<video_coding::PacketBuffer> packet_buffer_; | |
190 std::unique_ptr<video_coding::RtpFrameReferenceFinder> reference_finder_; | |
191 rtc::CriticalSection last_seq_num_cs_; | |
192 std::map<uint16_t, uint16_t, DescendingSeqNumComp<uint16_t>> | |
193 last_seq_num_for_pic_id_ GUARDED_BY(last_seq_num_cs_); | |
194 video_coding::H264SpsPpsTracker tracker_; | |
195 // TODO(johan): Remove pt_codec_params_ once | |
196 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6883 is resolved. | |
197 // Maps a payload type to a map of out-of-band supplied codec parameters. | |
198 std::map<uint8_t, std::map<std::string, std::string>> pt_codec_params_; | |
199 int16_t last_payload_type_ = -1; | |
200 | |
201 bool has_received_frame_; | |
202 }; | |
203 | |
204 } // namespace webrtc | |
205 | |
206 #endif // WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_ | |
OLD | NEW |