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/rate_statistics.h" | |
24 #include "webrtc/base/thread_annotations.h" | 23 #include "webrtc/base/thread_annotations.h" |
25 #include "webrtc/common_types.h" | 24 #include "webrtc/common_types.h" |
26 #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" |
27 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" | 27 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
30 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
31 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 31 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
32 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" | 32 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" |
33 #include "webrtc/transport.h" | 33 #include "webrtc/transport.h" |
34 | 34 |
35 namespace webrtc { | 35 namespace webrtc { |
36 | 36 |
37 class RateLimiter; | |
38 class RTPSenderAudio; | 37 class RTPSenderAudio; |
39 class RTPSenderVideo; | 38 class RTPSenderVideo; |
40 class RtcEventLog; | 39 class RtcEventLog; |
41 | 40 |
42 class RTPSenderInterface { | 41 class RTPSenderInterface { |
43 public: | 42 public: |
44 RTPSenderInterface() {} | 43 RTPSenderInterface() {} |
45 virtual ~RTPSenderInterface() {} | 44 virtual ~RTPSenderInterface() {} |
46 | 45 |
47 virtual uint32_t SSRC() const = 0; | 46 virtual uint32_t SSRC() const = 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 RTPSender(bool audio, | 86 RTPSender(bool audio, |
88 Clock* clock, | 87 Clock* clock, |
89 Transport* transport, | 88 Transport* transport, |
90 RtpPacketSender* paced_sender, | 89 RtpPacketSender* paced_sender, |
91 TransportSequenceNumberAllocator* sequence_number_allocator, | 90 TransportSequenceNumberAllocator* sequence_number_allocator, |
92 TransportFeedbackObserver* transport_feedback_callback, | 91 TransportFeedbackObserver* transport_feedback_callback, |
93 BitrateStatisticsObserver* bitrate_callback, | 92 BitrateStatisticsObserver* bitrate_callback, |
94 FrameCountObserver* frame_count_observer, | 93 FrameCountObserver* frame_count_observer, |
95 SendSideDelayObserver* send_side_delay_observer, | 94 SendSideDelayObserver* send_side_delay_observer, |
96 RtcEventLog* event_log, | 95 RtcEventLog* event_log, |
97 SendPacketObserver* send_packet_observer, | 96 SendPacketObserver* send_packet_observer); |
98 RateLimiter* nack_rate_limiter); | |
99 | 97 |
100 virtual ~RTPSender(); | 98 virtual ~RTPSender(); |
101 | 99 |
102 void ProcessBitrate(); | 100 void ProcessBitrate(); |
103 | 101 |
104 uint16_t ActualSendBitrateKbit() const override; | 102 uint16_t ActualSendBitrateKbit() const override; |
105 | 103 |
106 uint32_t VideoBitrateSent() const; | 104 uint32_t VideoBitrateSent() const; |
107 uint32_t FecOverheadRate() const; | 105 uint32_t FecOverheadRate() const; |
108 uint32_t NackOverheadRate() const; | 106 uint32_t NackOverheadRate() const; |
109 | 107 |
| 108 void SetTargetBitrate(uint32_t bitrate); |
| 109 uint32_t GetTargetBitrate(); |
| 110 |
110 // Includes size of RTP and FEC headers. | 111 // Includes size of RTP and FEC headers. |
111 size_t MaxDataPayloadLength() const override; | 112 size_t MaxDataPayloadLength() const override; |
112 | 113 |
113 int32_t RegisterPayload(const char* payload_name, | 114 int32_t RegisterPayload(const char* payload_name, |
114 const int8_t payload_type, | 115 const int8_t payload_type, |
115 const uint32_t frequency, | 116 const uint32_t frequency, |
116 const size_t channels, | 117 const size_t channels, |
117 const uint32_t rate); | 118 const uint32_t rate); |
118 | 119 |
119 int32_t DeRegisterSendPayload(const int8_t payload_type); | 120 int32_t DeRegisterSendPayload(const int8_t payload_type); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 int SetSelectiveRetransmissions(uint8_t settings); | 220 int SetSelectiveRetransmissions(uint8_t settings); |
220 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers, | 221 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers, |
221 int64_t avg_rtt); | 222 int64_t avg_rtt); |
222 | 223 |
223 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); | 224 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); |
224 | 225 |
225 bool StorePackets() const; | 226 bool StorePackets() const; |
226 | 227 |
227 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); | 228 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); |
228 | 229 |
| 230 bool ProcessNACKBitRate(uint32_t now); |
| 231 |
229 // Feedback to decide when to stop sending playout delay. | 232 // Feedback to decide when to stop sending playout delay. |
230 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); | 233 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); |
231 | 234 |
232 // RTX. | 235 // RTX. |
233 void SetRtxStatus(int mode); | 236 void SetRtxStatus(int mode); |
234 int RtxStatus() const; | 237 int RtxStatus() const; |
235 | 238 |
236 uint32_t RtxSsrc() const; | 239 uint32_t RtxSsrc() const; |
237 void SetRtxSsrc(uint32_t ssrc); | 240 void SetRtxSsrc(uint32_t ssrc); |
238 | 241 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 typedef std::map<int64_t, int> SendDelayMap; | 333 typedef std::map<int64_t, int> SendDelayMap; |
331 | 334 |
332 size_t CreateRtpHeader(uint8_t* header, | 335 size_t CreateRtpHeader(uint8_t* header, |
333 int8_t payload_type, | 336 int8_t payload_type, |
334 uint32_t ssrc, | 337 uint32_t ssrc, |
335 bool marker_bit, | 338 bool marker_bit, |
336 uint32_t timestamp, | 339 uint32_t timestamp, |
337 uint16_t sequence_number, | 340 uint16_t sequence_number, |
338 const std::vector<uint32_t>& csrcs) const; | 341 const std::vector<uint32_t>& csrcs) const; |
339 | 342 |
| 343 void UpdateNACKBitRate(uint32_t bytes, int64_t now); |
| 344 |
340 bool PrepareAndSendPacket(uint8_t* buffer, | 345 bool PrepareAndSendPacket(uint8_t* buffer, |
341 size_t length, | 346 size_t length, |
342 int64_t capture_time_ms, | 347 int64_t capture_time_ms, |
343 bool send_over_rtx, | 348 bool send_over_rtx, |
344 bool is_retransmit, | 349 bool is_retransmit, |
345 int probe_cluster_id); | 350 int probe_cluster_id); |
346 | 351 |
347 // Return the number of bytes sent. Note that both of these functions may | 352 // Return the number of bytes sent. Note that both of these functions may |
348 // return a larger value that their argument. | 353 // return a larger value that their argument. |
349 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id); | 354 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 399 |
395 bool AllocateTransportSequenceNumber(int* packet_id) const; | 400 bool AllocateTransportSequenceNumber(int* packet_id) const; |
396 | 401 |
397 void UpdateRtpStats(const uint8_t* buffer, | 402 void UpdateRtpStats(const uint8_t* buffer, |
398 size_t packet_length, | 403 size_t packet_length, |
399 const RTPHeader& header, | 404 const RTPHeader& header, |
400 bool is_rtx, | 405 bool is_rtx, |
401 bool is_retransmit); | 406 bool is_retransmit); |
402 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; | 407 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; |
403 | 408 |
| 409 class BitrateAggregator { |
| 410 public: |
| 411 explicit BitrateAggregator(BitrateStatisticsObserver* bitrate_callback); |
| 412 |
| 413 void OnStatsUpdated() const; |
| 414 |
| 415 Bitrate::Observer* total_bitrate_observer(); |
| 416 Bitrate::Observer* retransmit_bitrate_observer(); |
| 417 void set_ssrc(uint32_t ssrc); |
| 418 |
| 419 private: |
| 420 // We assume that these observers are called on the same thread, which is |
| 421 // true for RtpSender as they are called on the Process thread. |
| 422 class BitrateObserver : public Bitrate::Observer { |
| 423 public: |
| 424 explicit BitrateObserver(const BitrateAggregator& aggregator); |
| 425 |
| 426 // Implements Bitrate::Observer. |
| 427 void BitrateUpdated(const BitrateStatistics& stats) override; |
| 428 const BitrateStatistics& statistics() const; |
| 429 |
| 430 private: |
| 431 BitrateStatistics statistics_; |
| 432 const BitrateAggregator& aggregator_; |
| 433 }; |
| 434 |
| 435 BitrateStatisticsObserver* const callback_; |
| 436 BitrateObserver total_bitrate_observer_; |
| 437 BitrateObserver retransmit_bitrate_observer_; |
| 438 uint32_t ssrc_; |
| 439 }; |
| 440 |
404 Clock* const clock_; | 441 Clock* const clock_; |
405 const int64_t clock_delta_ms_; | 442 const int64_t clock_delta_ms_; |
406 Random random_ GUARDED_BY(send_critsect_); | 443 Random random_ GUARDED_BY(send_critsect_); |
407 | 444 |
| 445 BitrateAggregator bitrates_; |
| 446 Bitrate total_bitrate_sent_; |
| 447 |
408 const bool audio_configured_; | 448 const bool audio_configured_; |
409 const std::unique_ptr<RTPSenderAudio> audio_; | 449 const std::unique_ptr<RTPSenderAudio> audio_; |
410 const std::unique_ptr<RTPSenderVideo> video_; | 450 const std::unique_ptr<RTPSenderVideo> video_; |
411 | 451 |
412 RtpPacketSender* const paced_sender_; | 452 RtpPacketSender* const paced_sender_; |
413 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; | 453 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; |
414 TransportFeedbackObserver* const transport_feedback_observer_; | 454 TransportFeedbackObserver* const transport_feedback_observer_; |
415 int64_t last_capture_time_ms_sent_; | 455 int64_t last_capture_time_ms_sent_; |
416 rtc::CriticalSection send_critsect_; | 456 rtc::CriticalSection send_critsect_; |
417 | 457 |
418 Transport *transport_; | 458 Transport *transport_; |
419 bool sending_media_ GUARDED_BY(send_critsect_); | 459 bool sending_media_ GUARDED_BY(send_critsect_); |
420 | 460 |
421 size_t max_payload_length_; | 461 size_t max_payload_length_; |
422 | 462 |
423 int8_t payload_type_ GUARDED_BY(send_critsect_); | 463 int8_t payload_type_ GUARDED_BY(send_critsect_); |
424 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; | 464 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; |
425 | 465 |
426 RtpHeaderExtensionMap rtp_header_extension_map_; | 466 RtpHeaderExtensionMap rtp_header_extension_map_; |
427 int32_t transmission_time_offset_; | 467 int32_t transmission_time_offset_; |
428 uint32_t absolute_send_time_; | 468 uint32_t absolute_send_time_; |
429 VideoRotation rotation_; | 469 VideoRotation rotation_; |
430 bool video_rotation_active_; | 470 bool video_rotation_active_; |
431 uint16_t transport_sequence_number_; | 471 uint16_t transport_sequence_number_; |
432 | 472 |
| 473 // NACK |
| 474 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; |
| 475 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; |
| 476 Bitrate nack_bitrate_; |
| 477 |
433 // Tracks the current request for playout delay limits from application | 478 // Tracks the current request for playout delay limits from application |
434 // and decides whether the current RTP frame should include the playout | 479 // and decides whether the current RTP frame should include the playout |
435 // delay extension on header. | 480 // delay extension on header. |
436 PlayoutDelayOracle playout_delay_oracle_; | 481 PlayoutDelayOracle playout_delay_oracle_; |
437 bool playout_delay_active_ GUARDED_BY(send_critsect_); | 482 bool playout_delay_active_ GUARDED_BY(send_critsect_); |
438 | 483 |
439 RTPPacketHistory packet_history_; | 484 RTPPacketHistory packet_history_; |
440 | 485 |
441 // Statistics | 486 // Statistics |
442 rtc::CriticalSection statistics_crit_; | 487 rtc::CriticalSection statistics_crit_; |
443 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); | 488 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); |
444 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); | 489 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); |
445 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); | 490 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); |
446 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); | 491 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); |
447 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); | 492 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); |
448 RateStatistics total_bitrate_sent_ GUARDED_BY(statistics_crit_); | |
449 RateStatistics nack_bitrate_sent_ GUARDED_BY(statistics_crit_); | |
450 FrameCountObserver* const frame_count_observer_; | 493 FrameCountObserver* const frame_count_observer_; |
451 SendSideDelayObserver* const send_side_delay_observer_; | 494 SendSideDelayObserver* const send_side_delay_observer_; |
452 RtcEventLog* const event_log_; | 495 RtcEventLog* const event_log_; |
453 SendPacketObserver* const send_packet_observer_; | 496 SendPacketObserver* const send_packet_observer_; |
454 BitrateStatisticsObserver* const bitrate_callback_; | |
455 | 497 |
456 // RTP variables | 498 // RTP variables |
457 bool start_timestamp_forced_ GUARDED_BY(send_critsect_); | 499 bool start_timestamp_forced_ GUARDED_BY(send_critsect_); |
458 uint32_t start_timestamp_ GUARDED_BY(send_critsect_); | 500 uint32_t start_timestamp_ GUARDED_BY(send_critsect_); |
459 SSRCDatabase* const ssrc_db_; | 501 SSRCDatabase* const ssrc_db_; |
460 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_); | 502 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_); |
461 bool sequence_number_forced_ GUARDED_BY(send_critsect_); | 503 bool sequence_number_forced_ GUARDED_BY(send_critsect_); |
462 uint16_t sequence_number_ GUARDED_BY(send_critsect_); | 504 uint16_t sequence_number_ GUARDED_BY(send_critsect_); |
463 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_); | 505 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_); |
464 bool ssrc_forced_ GUARDED_BY(send_critsect_); | 506 bool ssrc_forced_ GUARDED_BY(send_critsect_); |
465 uint32_t ssrc_ GUARDED_BY(send_critsect_); | 507 uint32_t ssrc_ GUARDED_BY(send_critsect_); |
466 uint32_t timestamp_ GUARDED_BY(send_critsect_); | 508 uint32_t timestamp_ GUARDED_BY(send_critsect_); |
467 int64_t capture_time_ms_ GUARDED_BY(send_critsect_); | 509 int64_t capture_time_ms_ GUARDED_BY(send_critsect_); |
468 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_); | 510 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_); |
469 bool media_has_been_sent_ GUARDED_BY(send_critsect_); | 511 bool media_has_been_sent_ GUARDED_BY(send_critsect_); |
470 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_); | 512 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_); |
471 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_); | 513 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_); |
472 int rtx_ GUARDED_BY(send_critsect_); | 514 int rtx_ GUARDED_BY(send_critsect_); |
473 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_); | 515 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_); |
474 // Mapping rtx_payload_type_map_[associated] = rtx. | 516 // Mapping rtx_payload_type_map_[associated] = rtx. |
475 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); | 517 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); |
476 | 518 |
477 RateLimiter* const retransmission_rate_limiter_; | 519 // Note: Don't access this variable directly, always go through |
| 520 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember |
| 521 // that by the time the function returns there is no guarantee |
| 522 // that the target bitrate is still valid. |
| 523 rtc::CriticalSection target_bitrate_critsect_; |
| 524 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); |
478 | 525 |
479 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); | 526 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); |
480 }; | 527 }; |
481 | 528 |
482 } // namespace webrtc | 529 } // namespace webrtc |
483 | 530 |
484 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 531 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
OLD | NEW |