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