OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
21 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/base/random.h" | 22 #include "webrtc/base/random.h" |
23 #include "webrtc/base/thread_annotations.h" | 23 #include "webrtc/base/thread_annotations.h" |
24 #include "webrtc/common_types.h" | 24 #include "webrtc/common_types.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
26 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" | 26 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" |
| 27 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
29 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
30 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 31 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
31 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" | 32 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" |
32 #include "webrtc/transport.h" | 33 #include "webrtc/transport.h" |
33 | 34 |
34 namespace webrtc { | 35 namespace webrtc { |
35 | 36 |
36 class RTPSenderAudio; | 37 class RTPSenderAudio; |
37 class RTPSenderVideo; | 38 class RTPSenderVideo; |
38 class RtcEventLog; | 39 class RtcEventLog; |
39 | 40 |
40 class RTPSenderInterface { | 41 class RTPSenderInterface { |
41 public: | 42 public: |
42 RTPSenderInterface() {} | 43 RTPSenderInterface() {} |
43 virtual ~RTPSenderInterface() {} | 44 virtual ~RTPSenderInterface() {} |
44 | 45 |
45 enum CVOMode { | |
46 kCVONone, | |
47 kCVOInactive, // CVO rtp header extension is registered but haven't | |
48 // received any frame with rotation pending. | |
49 kCVOActivated, // CVO rtp header extension will be present in the rtp | |
50 // packets. | |
51 }; | |
52 | |
53 virtual uint32_t SSRC() const = 0; | 46 virtual uint32_t SSRC() const = 0; |
54 virtual uint32_t Timestamp() const = 0; | 47 virtual uint32_t Timestamp() const = 0; |
55 | 48 |
56 virtual int32_t BuildRTPheader(uint8_t* data_buffer, | 49 virtual int32_t BuildRTPheader(uint8_t* data_buffer, |
57 int8_t payload_type, | 50 int8_t payload_type, |
58 bool marker_bit, | 51 bool marker_bit, |
59 uint32_t capture_timestamp, | 52 uint32_t capture_timestamp, |
60 int64_t capture_time_ms, | 53 int64_t capture_time_ms, |
61 bool timestamp_provided = true, | 54 bool timestamp_provided = true, |
62 bool inc_sequence_number = true) = 0; | 55 bool inc_sequence_number = true) = 0; |
63 | 56 |
64 virtual size_t RTPHeaderLength() const = 0; | 57 // This returns the expected header length taking into consideration |
| 58 // the optional RTP header extensions that may not be currently active. |
| 59 virtual size_t RtpHeaderLength() const = 0; |
65 // Returns the next sequence number to use for a packet and allocates | 60 // Returns the next sequence number to use for a packet and allocates |
66 // 'packets_to_send' number of sequence numbers. It's important all allocated | 61 // 'packets_to_send' number of sequence numbers. It's important all allocated |
67 // sequence numbers are used in sequence to avoid perceived packet loss. | 62 // sequence numbers are used in sequence to avoid perceived packet loss. |
68 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; | 63 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; |
69 virtual uint16_t SequenceNumber() const = 0; | 64 virtual uint16_t SequenceNumber() const = 0; |
70 virtual size_t MaxPayloadLength() const = 0; | 65 virtual size_t MaxPayloadLength() const = 0; |
71 virtual size_t MaxDataPayloadLength() const = 0; | 66 virtual size_t MaxDataPayloadLength() const = 0; |
72 virtual uint16_t ActualSendBitrateKbit() const = 0; | 67 virtual uint16_t ActualSendBitrateKbit() const = 0; |
73 | 68 |
74 virtual int32_t SendToNetwork(uint8_t* data_buffer, | 69 virtual int32_t SendToNetwork(uint8_t* data_buffer, |
75 size_t payload_length, | 70 size_t payload_length, |
76 size_t rtp_header_length, | 71 size_t rtp_header_length, |
77 int64_t capture_time_ms, | 72 int64_t capture_time_ms, |
78 StorageType storage, | 73 StorageType storage, |
79 RtpPacketSender::Priority priority) = 0; | 74 RtpPacketSender::Priority priority) = 0; |
80 | 75 |
81 virtual bool UpdateVideoRotation(uint8_t* rtp_packet, | 76 virtual bool UpdateVideoRotation(uint8_t* rtp_packet, |
82 size_t rtp_packet_length, | 77 size_t rtp_packet_length, |
83 const RTPHeader& rtp_header, | 78 const RTPHeader& rtp_header, |
84 VideoRotation rotation) const = 0; | 79 VideoRotation rotation) const = 0; |
85 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0; | 80 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0; |
86 virtual CVOMode ActivateCVORtpHeaderExtension() = 0; | 81 virtual bool ActivateCVORtpHeaderExtension() = 0; |
87 }; | 82 }; |
88 | 83 |
89 class RTPSender : public RTPSenderInterface { | 84 class RTPSender : public RTPSenderInterface { |
90 public: | 85 public: |
91 RTPSender(bool audio, | 86 RTPSender(bool audio, |
92 Clock* clock, | 87 Clock* clock, |
93 Transport* transport, | 88 Transport* transport, |
94 RtpPacketSender* paced_sender, | 89 RtpPacketSender* paced_sender, |
95 TransportSequenceNumberAllocator* sequence_number_allocator, | 90 TransportSequenceNumberAllocator* sequence_number_allocator, |
96 TransportFeedbackObserver* transport_feedback_callback, | 91 TransportFeedbackObserver* transport_feedback_callback, |
(...skipping 66 matching lines...) Loading... |
163 // RTP header extension | 158 // RTP header extension |
164 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset); | 159 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset); |
165 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time); | 160 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time); |
166 void SetVideoRotation(VideoRotation rotation); | 161 void SetVideoRotation(VideoRotation rotation); |
167 int32_t SetTransportSequenceNumber(uint16_t sequence_number); | 162 int32_t SetTransportSequenceNumber(uint16_t sequence_number); |
168 | 163 |
169 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); | 164 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); |
170 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override; | 165 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override; |
171 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); | 166 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); |
172 | 167 |
173 size_t RtpHeaderExtensionTotalLength() const; | 168 size_t RtpHeaderExtensionLength() const; |
174 | 169 |
175 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer, bool marker_bit) const; | 170 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer, bool marker_bit) const; |
176 | 171 |
177 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const; | 172 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const; |
178 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const; | 173 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const; |
179 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const; | 174 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const; |
180 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const; | 175 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const; |
181 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer, | 176 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer, |
182 uint16_t sequence_number) const; | 177 uint16_t sequence_number) const; |
| 178 uint8_t BuildPlayoutDelayExtension(uint8_t* data_buffer, |
| 179 uint16_t min_playout_delay_ms, |
| 180 uint16_t max_playout_delay_ms) const; |
183 | 181 |
184 // Verifies that the specified extension is registered, and that it is | 182 // Verifies that the specified extension is registered, and that it is |
185 // present in rtp packet. If extension is not registered kNotRegistered is | 183 // present in rtp packet. If extension is not registered kNotRegistered is |
186 // returned. If extension cannot be found in the rtp header, or if it is | 184 // returned. If extension cannot be found in the rtp header, or if it is |
187 // malformed, kError is returned. Otherwise *extension_offset is set to the | 185 // malformed, kError is returned. Otherwise *extension_offset is set to the |
188 // offset of the extension from the beginning of the rtp packet and kOk is | 186 // offset of the extension from the beginning of the rtp packet and kOk is |
189 // returned. | 187 // returned. |
190 enum class ExtensionStatus { | 188 enum class ExtensionStatus { |
191 kNotRegistered, | 189 kNotRegistered, |
192 kOk, | 190 kOk, |
(...skipping 29 matching lines...) Loading... |
222 int64_t avg_rtt); | 220 int64_t avg_rtt); |
223 | 221 |
224 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); | 222 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); |
225 | 223 |
226 bool StorePackets() const; | 224 bool StorePackets() const; |
227 | 225 |
228 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); | 226 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); |
229 | 227 |
230 bool ProcessNACKBitRate(uint32_t now); | 228 bool ProcessNACKBitRate(uint32_t now); |
231 | 229 |
| 230 // Feedback to decide when to stop sending playout delay. |
| 231 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks); |
| 232 |
232 // RTX. | 233 // RTX. |
233 void SetRtxStatus(int mode); | 234 void SetRtxStatus(int mode); |
234 int RtxStatus() const; | 235 int RtxStatus() const; |
235 | 236 |
236 uint32_t RtxSsrc() const; | 237 uint32_t RtxSsrc() const; |
237 void SetRtxSsrc(uint32_t ssrc); | 238 void SetRtxSsrc(uint32_t ssrc); |
238 | 239 |
239 void SetRtxPayloadType(int payload_type, int associated_payload_type); | 240 void SetRtxPayloadType(int payload_type, int associated_payload_type); |
240 | 241 |
241 // Functions wrapping RTPSenderInterface. | 242 // Functions wrapping RTPSenderInterface. |
242 int32_t BuildRTPheader(uint8_t* data_buffer, | 243 int32_t BuildRTPheader(uint8_t* data_buffer, |
243 int8_t payload_type, | 244 int8_t payload_type, |
244 bool marker_bit, | 245 bool marker_bit, |
245 uint32_t capture_timestamp, | 246 uint32_t capture_timestamp, |
246 int64_t capture_time_ms, | 247 int64_t capture_time_ms, |
247 const bool timestamp_provided = true, | 248 const bool timestamp_provided = true, |
248 const bool inc_sequence_number = true) override; | 249 const bool inc_sequence_number = true) override; |
249 | 250 |
250 size_t RTPHeaderLength() const override; | 251 size_t RtpHeaderLength() const override; |
251 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override; | 252 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override; |
252 size_t MaxPayloadLength() const override; | 253 size_t MaxPayloadLength() const override; |
253 | 254 |
254 // Current timestamp. | 255 // Current timestamp. |
255 uint32_t Timestamp() const override; | 256 uint32_t Timestamp() const override; |
256 uint32_t SSRC() const override; | 257 uint32_t SSRC() const override; |
257 | 258 |
258 int32_t SendToNetwork(uint8_t* data_buffer, | 259 int32_t SendToNetwork(uint8_t* data_buffer, |
259 size_t payload_length, | 260 size_t payload_length, |
260 size_t rtp_header_length, | 261 size_t rtp_header_length, |
(...skipping 44 matching lines...) Loading... |
305 // Called on update of RTP statistics. | 306 // Called on update of RTP statistics. |
306 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); | 307 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); |
307 StreamDataCountersCallback* GetRtpStatisticsCallback() const; | 308 StreamDataCountersCallback* GetRtpStatisticsCallback() const; |
308 | 309 |
309 uint32_t BitrateSent() const; | 310 uint32_t BitrateSent() const; |
310 | 311 |
311 void SetRtpState(const RtpState& rtp_state); | 312 void SetRtpState(const RtpState& rtp_state); |
312 RtpState GetRtpState() const; | 313 RtpState GetRtpState() const; |
313 void SetRtxRtpState(const RtpState& rtp_state); | 314 void SetRtxRtpState(const RtpState& rtp_state); |
314 RtpState GetRtxRtpState() const; | 315 RtpState GetRtxRtpState() const; |
315 CVOMode ActivateCVORtpHeaderExtension() override; | 316 bool ActivateCVORtpHeaderExtension() override; |
316 | 317 |
317 protected: | 318 protected: |
318 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); | 319 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); |
319 | 320 |
320 private: | 321 private: |
321 // Maps capture time in milliseconds to send-side delay in milliseconds. | 322 // Maps capture time in milliseconds to send-side delay in milliseconds. |
322 // Send-side delay is the difference between transmission time and capture | 323 // Send-side delay is the difference between transmission time and capture |
323 // time. | 324 // time. |
324 typedef std::map<int64_t, int> SendDelayMap; | 325 typedef std::map<int64_t, int> SendDelayMap; |
325 | 326 |
(...skipping 48 matching lines...) Loading... |
374 void UpdateAbsoluteSendTime(uint8_t* rtp_packet, | 375 void UpdateAbsoluteSendTime(uint8_t* rtp_packet, |
375 size_t rtp_packet_length, | 376 size_t rtp_packet_length, |
376 const RTPHeader& rtp_header, | 377 const RTPHeader& rtp_header, |
377 int64_t now_ms) const; | 378 int64_t now_ms) const; |
378 | 379 |
379 bool UpdateTransportSequenceNumber(uint16_t sequence_number, | 380 bool UpdateTransportSequenceNumber(uint16_t sequence_number, |
380 uint8_t* rtp_packet, | 381 uint8_t* rtp_packet, |
381 size_t rtp_packet_length, | 382 size_t rtp_packet_length, |
382 const RTPHeader& rtp_header) const; | 383 const RTPHeader& rtp_header) const; |
383 | 384 |
| 385 void UpdatePlayoutDelayLimits(uint8_t* rtp_packet, |
| 386 size_t rtp_packet_length, |
| 387 const RTPHeader& rtp_header, |
| 388 uint16_t min_playout_delay, |
| 389 uint16_t max_playout_delay) const; |
| 390 |
384 bool AllocateTransportSequenceNumber(int* packet_id) const; | 391 bool AllocateTransportSequenceNumber(int* packet_id) const; |
385 | 392 |
386 void UpdateRtpStats(const uint8_t* buffer, | 393 void UpdateRtpStats(const uint8_t* buffer, |
387 size_t packet_length, | 394 size_t packet_length, |
388 const RTPHeader& header, | 395 const RTPHeader& header, |
389 bool is_rtx, | 396 bool is_rtx, |
390 bool is_retransmit); | 397 bool is_retransmit); |
391 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; | 398 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; |
392 | 399 |
393 class BitrateAggregator { | 400 class BitrateAggregator { |
(...skipping 50 matching lines...) Loading... |
444 | 451 |
445 size_t max_payload_length_; | 452 size_t max_payload_length_; |
446 | 453 |
447 int8_t payload_type_ GUARDED_BY(send_critsect_); | 454 int8_t payload_type_ GUARDED_BY(send_critsect_); |
448 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; | 455 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; |
449 | 456 |
450 RtpHeaderExtensionMap rtp_header_extension_map_; | 457 RtpHeaderExtensionMap rtp_header_extension_map_; |
451 int32_t transmission_time_offset_; | 458 int32_t transmission_time_offset_; |
452 uint32_t absolute_send_time_; | 459 uint32_t absolute_send_time_; |
453 VideoRotation rotation_; | 460 VideoRotation rotation_; |
454 CVOMode cvo_mode_; | 461 bool video_rotation_active_; |
455 uint16_t transport_sequence_number_; | 462 uint16_t transport_sequence_number_; |
456 | 463 |
457 // NACK | 464 // NACK |
458 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; | 465 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; |
459 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; | 466 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; |
460 Bitrate nack_bitrate_; | 467 Bitrate nack_bitrate_; |
461 | 468 |
| 469 // Tracks the current request for playout delay limits from application |
| 470 // and decides whether the current RTP frame should include the playout |
| 471 // delay extension on header. |
| 472 PlayoutDelayOracle playout_delay_oracle_; |
| 473 bool playout_delay_active_ GUARDED_BY(send_critsect_); |
| 474 |
462 RTPPacketHistory packet_history_; | 475 RTPPacketHistory packet_history_; |
463 | 476 |
464 // Statistics | 477 // Statistics |
465 rtc::CriticalSection statistics_crit_; | 478 rtc::CriticalSection statistics_crit_; |
466 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); | 479 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); |
467 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); | 480 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); |
468 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); | 481 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); |
469 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); | 482 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); |
470 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); | 483 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); |
471 FrameCountObserver* const frame_count_observer_; | 484 FrameCountObserver* const frame_count_observer_; |
(...skipping 28 matching lines...) Loading... |
500 // that the target bitrate is still valid. | 513 // that the target bitrate is still valid. |
501 rtc::CriticalSection target_bitrate_critsect_; | 514 rtc::CriticalSection target_bitrate_critsect_; |
502 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); | 515 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); |
503 | 516 |
504 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); | 517 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); |
505 }; | 518 }; |
506 | 519 |
507 } // namespace webrtc | 520 } // namespace webrtc |
508 | 521 |
509 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 522 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
OLD | NEW |