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; |
(...skipping 17 matching lines...) Expand all Loading... |
54 virtual uint32_t Timestamp() const = 0; | 55 virtual uint32_t Timestamp() const = 0; |
55 | 56 |
56 virtual int32_t BuildRTPheader(uint8_t* data_buffer, | 57 virtual int32_t BuildRTPheader(uint8_t* data_buffer, |
57 int8_t payload_type, | 58 int8_t payload_type, |
58 bool marker_bit, | 59 bool marker_bit, |
59 uint32_t capture_timestamp, | 60 uint32_t capture_timestamp, |
60 int64_t capture_time_ms, | 61 int64_t capture_time_ms, |
61 bool timestamp_provided = true, | 62 bool timestamp_provided = true, |
62 bool inc_sequence_number = true) = 0; | 63 bool inc_sequence_number = true) = 0; |
63 | 64 |
64 virtual size_t RTPHeaderLength() const = 0; | 65 // This returns the expected header length taking into consideration |
| 66 // the optional RTP header extensions that may not be currently enabled. |
| 67 virtual size_t RtpHeaderCurrentLength() const = 0; |
| 68 // This returns the maximum RTP header length if all the header extensions |
| 69 // were on the packet. |
| 70 virtual size_t RtpHeaderMaxLength() const = 0; |
65 // Returns the next sequence number to use for a packet and allocates | 71 // 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 | 72 // 'packets_to_send' number of sequence numbers. It's important all allocated |
67 // sequence numbers are used in sequence to avoid perceived packet loss. | 73 // sequence numbers are used in sequence to avoid perceived packet loss. |
68 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; | 74 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; |
69 virtual uint16_t SequenceNumber() const = 0; | 75 virtual uint16_t SequenceNumber() const = 0; |
70 virtual size_t MaxPayloadLength() const = 0; | 76 virtual size_t MaxPayloadLength() const = 0; |
71 virtual size_t MaxDataPayloadLength() const = 0; | 77 virtual size_t MaxDataPayloadLength() const = 0; |
72 virtual uint16_t ActualSendBitrateKbit() const = 0; | 78 virtual uint16_t ActualSendBitrateKbit() const = 0; |
73 | 79 |
74 virtual int32_t SendToNetwork(uint8_t* data_buffer, | 80 virtual int32_t SendToNetwork(uint8_t* data_buffer, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // RTP header extension | 169 // RTP header extension |
164 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset); | 170 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset); |
165 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time); | 171 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time); |
166 void SetVideoRotation(VideoRotation rotation); | 172 void SetVideoRotation(VideoRotation rotation); |
167 int32_t SetTransportSequenceNumber(uint16_t sequence_number); | 173 int32_t SetTransportSequenceNumber(uint16_t sequence_number); |
168 | 174 |
169 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); | 175 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); |
170 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override; | 176 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override; |
171 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); | 177 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); |
172 | 178 |
173 size_t RtpHeaderExtensionTotalLength() const; | 179 size_t RtpHeaderExtensionCurrentLength() const; |
| 180 size_t RtpHeaderExtensionMaxLength() const; |
174 | 181 |
175 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer, bool marker_bit) const; | 182 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer, bool marker_bit) const; |
176 | 183 |
177 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const; | 184 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const; |
178 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const; | 185 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const; |
179 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const; | 186 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const; |
180 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const; | 187 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const; |
181 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer, | 188 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer, |
182 uint16_t sequence_number) const; | 189 uint16_t sequence_number) const; |
| 190 uint8_t BuildPlayoutDelayExtension(uint8_t* data_buffer, |
| 191 uint16_t min_playout_delay_ms, |
| 192 uint16_t max_playout_delay_ms) const; |
183 | 193 |
184 // Verifies that the specified extension is registered, and that it is | 194 // Verifies that the specified extension is registered, and that it is |
185 // present in rtp packet. If extension is not registered kNotRegistered is | 195 // 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 | 196 // 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 | 197 // 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 | 198 // offset of the extension from the beginning of the rtp packet and kOk is |
189 // returned. | 199 // returned. |
190 enum class ExtensionStatus { | 200 enum class ExtensionStatus { |
191 kNotRegistered, | 201 kNotRegistered, |
192 kOk, | 202 kOk, |
(...skipping 29 matching lines...) Expand all Loading... |
222 int64_t avg_rtt); | 232 int64_t avg_rtt); |
223 | 233 |
224 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); | 234 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); |
225 | 235 |
226 bool StorePackets() const; | 236 bool StorePackets() const; |
227 | 237 |
228 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); | 238 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); |
229 | 239 |
230 bool ProcessNACKBitRate(uint32_t now); | 240 bool ProcessNACKBitRate(uint32_t now); |
231 | 241 |
| 242 // Feedback to decide when to stop sending playout delay. |
| 243 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks); |
| 244 |
232 // RTX. | 245 // RTX. |
233 void SetRtxStatus(int mode); | 246 void SetRtxStatus(int mode); |
234 int RtxStatus() const; | 247 int RtxStatus() const; |
235 | 248 |
236 uint32_t RtxSsrc() const; | 249 uint32_t RtxSsrc() const; |
237 void SetRtxSsrc(uint32_t ssrc); | 250 void SetRtxSsrc(uint32_t ssrc); |
238 | 251 |
239 void SetRtxPayloadType(int payload_type, int associated_payload_type); | 252 void SetRtxPayloadType(int payload_type, int associated_payload_type); |
240 | 253 |
241 // Functions wrapping RTPSenderInterface. | 254 // Functions wrapping RTPSenderInterface. |
242 int32_t BuildRTPheader(uint8_t* data_buffer, | 255 int32_t BuildRTPheader(uint8_t* data_buffer, |
243 int8_t payload_type, | 256 int8_t payload_type, |
244 bool marker_bit, | 257 bool marker_bit, |
245 uint32_t capture_timestamp, | 258 uint32_t capture_timestamp, |
246 int64_t capture_time_ms, | 259 int64_t capture_time_ms, |
247 const bool timestamp_provided = true, | 260 const bool timestamp_provided = true, |
248 const bool inc_sequence_number = true) override; | 261 const bool inc_sequence_number = true) override; |
249 | 262 |
250 size_t RTPHeaderLength() const override; | 263 size_t RtpHeaderCurrentLength() const override; |
| 264 size_t RtpHeaderMaxLength() const override; |
251 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override; | 265 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override; |
252 size_t MaxPayloadLength() const override; | 266 size_t MaxPayloadLength() const override; |
253 | 267 |
254 // Current timestamp. | 268 // Current timestamp. |
255 uint32_t Timestamp() const override; | 269 uint32_t Timestamp() const override; |
256 uint32_t SSRC() const override; | 270 uint32_t SSRC() const override; |
257 | 271 |
258 int32_t SendToNetwork(uint8_t* data_buffer, | 272 int32_t SendToNetwork(uint8_t* data_buffer, |
259 size_t payload_length, | 273 size_t payload_length, |
260 size_t rtp_header_length, | 274 size_t rtp_header_length, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 void UpdateAbsoluteSendTime(uint8_t* rtp_packet, | 388 void UpdateAbsoluteSendTime(uint8_t* rtp_packet, |
375 size_t rtp_packet_length, | 389 size_t rtp_packet_length, |
376 const RTPHeader& rtp_header, | 390 const RTPHeader& rtp_header, |
377 int64_t now_ms) const; | 391 int64_t now_ms) const; |
378 | 392 |
379 bool UpdateTransportSequenceNumber(uint16_t sequence_number, | 393 bool UpdateTransportSequenceNumber(uint16_t sequence_number, |
380 uint8_t* rtp_packet, | 394 uint8_t* rtp_packet, |
381 size_t rtp_packet_length, | 395 size_t rtp_packet_length, |
382 const RTPHeader& rtp_header) const; | 396 const RTPHeader& rtp_header) const; |
383 | 397 |
| 398 void UpdatePlayoutDelayLimits(uint8_t* rtp_packet, |
| 399 size_t rtp_packet_length, |
| 400 const RTPHeader& rtp_header, |
| 401 uint16_t min_playout_delay, |
| 402 uint16_t max_playout_delay) const; |
| 403 |
384 bool AllocateTransportSequenceNumber(int* packet_id) const; | 404 bool AllocateTransportSequenceNumber(int* packet_id) const; |
385 | 405 |
386 void UpdateRtpStats(const uint8_t* buffer, | 406 void UpdateRtpStats(const uint8_t* buffer, |
387 size_t packet_length, | 407 size_t packet_length, |
388 const RTPHeader& header, | 408 const RTPHeader& header, |
389 bool is_rtx, | 409 bool is_rtx, |
390 bool is_retransmit); | 410 bool is_retransmit); |
391 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; | 411 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; |
392 | 412 |
393 class BitrateAggregator { | 413 class BitrateAggregator { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 uint32_t absolute_send_time_; | 472 uint32_t absolute_send_time_; |
453 VideoRotation rotation_; | 473 VideoRotation rotation_; |
454 CVOMode cvo_mode_; | 474 CVOMode cvo_mode_; |
455 uint16_t transport_sequence_number_; | 475 uint16_t transport_sequence_number_; |
456 | 476 |
457 // NACK | 477 // NACK |
458 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; | 478 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; |
459 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; | 479 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; |
460 Bitrate nack_bitrate_; | 480 Bitrate nack_bitrate_; |
461 | 481 |
| 482 // Tracks the current request for playout delay limits from application |
| 483 // and decides whether the current RTP frame should include the playout |
| 484 // delay extension on header. |
| 485 PlayoutDelayOracle playout_delay_oracle_; |
| 486 |
462 RTPPacketHistory packet_history_; | 487 RTPPacketHistory packet_history_; |
463 | 488 |
464 // Statistics | 489 // Statistics |
465 rtc::CriticalSection statistics_crit_; | 490 rtc::CriticalSection statistics_crit_; |
466 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); | 491 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); |
467 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); | 492 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); |
468 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); | 493 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); |
469 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); | 494 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); |
470 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); | 495 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); |
471 FrameCountObserver* const frame_count_observer_; | 496 FrameCountObserver* const frame_count_observer_; |
(...skipping 28 matching lines...) Expand all Loading... |
500 // that the target bitrate is still valid. | 525 // that the target bitrate is still valid. |
501 rtc::CriticalSection target_bitrate_critsect_; | 526 rtc::CriticalSection target_bitrate_critsect_; |
502 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); | 527 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); |
503 | 528 |
504 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); | 529 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); |
505 }; | 530 }; |
506 | 531 |
507 } // namespace webrtc | 532 } // namespace webrtc |
508 | 533 |
509 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 534 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
OLD | NEW |