Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender.h

Issue 2061423003: Refactor NACK bitrate allocation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Moved rate limiter and addressed comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 RTPSender(bool audio, 86 RTPSender(bool audio,
87 Clock* clock, 87 Clock* clock,
88 Transport* transport, 88 Transport* transport,
89 RtpPacketSender* paced_sender, 89 RtpPacketSender* paced_sender,
90 TransportSequenceNumberAllocator* sequence_number_allocator, 90 TransportSequenceNumberAllocator* sequence_number_allocator,
91 TransportFeedbackObserver* transport_feedback_callback, 91 TransportFeedbackObserver* transport_feedback_callback,
92 BitrateStatisticsObserver* bitrate_callback, 92 BitrateStatisticsObserver* bitrate_callback,
93 FrameCountObserver* frame_count_observer, 93 FrameCountObserver* frame_count_observer,
94 SendSideDelayObserver* send_side_delay_observer, 94 SendSideDelayObserver* send_side_delay_observer,
95 RtcEventLog* event_log, 95 RtcEventLog* event_log,
96 SendPacketObserver* send_packet_observer); 96 SendPacketObserver* send_packet_observer,
97 NackRateLimiter* nack_rate_limiter);
97 98
98 virtual ~RTPSender(); 99 virtual ~RTPSender();
99 100
100 void ProcessBitrate(); 101 void ProcessBitrate();
101 102
102 uint16_t ActualSendBitrateKbit() const override; 103 uint16_t ActualSendBitrateKbit() const override;
103 104
104 uint32_t VideoBitrateSent() const; 105 uint32_t VideoBitrateSent() const;
105 uint32_t FecOverheadRate() const; 106 uint32_t FecOverheadRate() const;
106 uint32_t NackOverheadRate() const; 107 uint32_t NackOverheadRate() const;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 int SetSelectiveRetransmissions(uint8_t settings); 221 int SetSelectiveRetransmissions(uint8_t settings);
221 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers, 222 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
222 int64_t avg_rtt); 223 int64_t avg_rtt);
223 224
224 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); 225 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
225 226
226 bool StorePackets() const; 227 bool StorePackets() const;
227 228
228 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); 229 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0);
229 230
230 bool ProcessNACKBitRate(uint32_t now);
231
232 // Feedback to decide when to stop sending playout delay. 231 // Feedback to decide when to stop sending playout delay.
233 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); 232 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks);
234 233
235 // RTX. 234 // RTX.
236 void SetRtxStatus(int mode); 235 void SetRtxStatus(int mode);
237 int RtxStatus() const; 236 int RtxStatus() const;
238 237
239 uint32_t RtxSsrc() const; 238 uint32_t RtxSsrc() const;
240 void SetRtxSsrc(uint32_t ssrc); 239 void SetRtxSsrc(uint32_t ssrc);
241 240
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 typedef std::map<int64_t, int> SendDelayMap; 332 typedef std::map<int64_t, int> SendDelayMap;
334 333
335 size_t CreateRtpHeader(uint8_t* header, 334 size_t CreateRtpHeader(uint8_t* header,
336 int8_t payload_type, 335 int8_t payload_type,
337 uint32_t ssrc, 336 uint32_t ssrc,
338 bool marker_bit, 337 bool marker_bit,
339 uint32_t timestamp, 338 uint32_t timestamp,
340 uint16_t sequence_number, 339 uint16_t sequence_number,
341 const std::vector<uint32_t>& csrcs) const; 340 const std::vector<uint32_t>& csrcs) const;
342 341
343 void UpdateNACKBitRate(uint32_t bytes, int64_t now);
344
345 bool PrepareAndSendPacket(uint8_t* buffer, 342 bool PrepareAndSendPacket(uint8_t* buffer,
346 size_t length, 343 size_t length,
347 int64_t capture_time_ms, 344 int64_t capture_time_ms,
348 bool send_over_rtx, 345 bool send_over_rtx,
349 bool is_retransmit, 346 bool is_retransmit,
350 int probe_cluster_id); 347 int probe_cluster_id);
351 348
352 // Return the number of bytes sent. Note that both of these functions may 349 // Return the number of bytes sent. Note that both of these functions may
353 // return a larger value that their argument. 350 // return a larger value that their argument.
354 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id); 351 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 396
400 bool AllocateTransportSequenceNumber(int* packet_id) const; 397 bool AllocateTransportSequenceNumber(int* packet_id) const;
401 398
402 void UpdateRtpStats(const uint8_t* buffer, 399 void UpdateRtpStats(const uint8_t* buffer,
403 size_t packet_length, 400 size_t packet_length,
404 const RTPHeader& header, 401 const RTPHeader& header,
405 bool is_rtx, 402 bool is_rtx,
406 bool is_retransmit); 403 bool is_retransmit);
407 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; 404 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
408 405
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_; 406 Clock* const clock_;
442 const int64_t clock_delta_ms_; 407 const int64_t clock_delta_ms_;
443 Random random_ GUARDED_BY(send_critsect_); 408 Random random_ GUARDED_BY(send_critsect_);
444 409
445 BitrateAggregator bitrates_;
446 Bitrate total_bitrate_sent_;
447
448 const bool audio_configured_; 410 const bool audio_configured_;
449 const std::unique_ptr<RTPSenderAudio> audio_; 411 const std::unique_ptr<RTPSenderAudio> audio_;
450 const std::unique_ptr<RTPSenderVideo> video_; 412 const std::unique_ptr<RTPSenderVideo> video_;
451 413
452 RtpPacketSender* const paced_sender_; 414 RtpPacketSender* const paced_sender_;
453 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; 415 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
454 TransportFeedbackObserver* const transport_feedback_observer_; 416 TransportFeedbackObserver* const transport_feedback_observer_;
455 int64_t last_capture_time_ms_sent_; 417 int64_t last_capture_time_ms_sent_;
456 rtc::CriticalSection send_critsect_; 418 rtc::CriticalSection send_critsect_;
457 419
458 Transport *transport_; 420 Transport *transport_;
459 bool sending_media_ GUARDED_BY(send_critsect_); 421 bool sending_media_ GUARDED_BY(send_critsect_);
460 422
461 size_t max_payload_length_; 423 size_t max_payload_length_;
462 424
463 int8_t payload_type_ GUARDED_BY(send_critsect_); 425 int8_t payload_type_ GUARDED_BY(send_critsect_);
464 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; 426 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
465 427
466 RtpHeaderExtensionMap rtp_header_extension_map_; 428 RtpHeaderExtensionMap rtp_header_extension_map_;
467 int32_t transmission_time_offset_; 429 int32_t transmission_time_offset_;
468 uint32_t absolute_send_time_; 430 uint32_t absolute_send_time_;
469 VideoRotation rotation_; 431 VideoRotation rotation_;
470 bool video_rotation_active_; 432 bool video_rotation_active_;
471 uint16_t transport_sequence_number_; 433 uint16_t transport_sequence_number_;
472 434
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 435 // Tracks the current request for playout delay limits from application
479 // and decides whether the current RTP frame should include the playout 436 // and decides whether the current RTP frame should include the playout
480 // delay extension on header. 437 // delay extension on header.
481 PlayoutDelayOracle playout_delay_oracle_; 438 PlayoutDelayOracle playout_delay_oracle_;
482 bool playout_delay_active_ GUARDED_BY(send_critsect_); 439 bool playout_delay_active_ GUARDED_BY(send_critsect_);
483 440
484 RTPPacketHistory packet_history_; 441 RTPPacketHistory packet_history_;
485 442
486 // Statistics 443 // Statistics
487 rtc::CriticalSection statistics_crit_; 444 rtc::CriticalSection statistics_crit_;
488 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); 445 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
489 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); 446 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
490 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); 447 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
491 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); 448 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
492 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); 449 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
450 RateStatistics total_bitrate_sent_ GUARDED_BY(statistics_crit_);
451 RateStatistics nack_bitrate_sent_ GUARDED_BY(statistics_crit_);
493 FrameCountObserver* const frame_count_observer_; 452 FrameCountObserver* const frame_count_observer_;
494 SendSideDelayObserver* const send_side_delay_observer_; 453 SendSideDelayObserver* const send_side_delay_observer_;
495 RtcEventLog* const event_log_; 454 RtcEventLog* const event_log_;
496 SendPacketObserver* const send_packet_observer_; 455 SendPacketObserver* const send_packet_observer_;
456 BitrateStatisticsObserver* const bitrate_callback_;
497 457
498 // RTP variables 458 // RTP variables
499 bool start_timestamp_forced_ GUARDED_BY(send_critsect_); 459 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
500 uint32_t start_timestamp_ GUARDED_BY(send_critsect_); 460 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
501 SSRCDatabase* const ssrc_db_; 461 SSRCDatabase* const ssrc_db_;
502 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_); 462 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
503 bool sequence_number_forced_ GUARDED_BY(send_critsect_); 463 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
504 uint16_t sequence_number_ GUARDED_BY(send_critsect_); 464 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
505 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_); 465 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
506 bool ssrc_forced_ GUARDED_BY(send_critsect_); 466 bool ssrc_forced_ GUARDED_BY(send_critsect_);
507 uint32_t ssrc_ GUARDED_BY(send_critsect_); 467 uint32_t ssrc_ GUARDED_BY(send_critsect_);
508 uint32_t timestamp_ GUARDED_BY(send_critsect_); 468 uint32_t timestamp_ GUARDED_BY(send_critsect_);
509 int64_t capture_time_ms_ GUARDED_BY(send_critsect_); 469 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
510 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_); 470 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
511 bool media_has_been_sent_ GUARDED_BY(send_critsect_); 471 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
512 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_); 472 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
513 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_); 473 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
514 int rtx_ GUARDED_BY(send_critsect_); 474 int rtx_ GUARDED_BY(send_critsect_);
515 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_); 475 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
516 // Mapping rtx_payload_type_map_[associated] = rtx. 476 // Mapping rtx_payload_type_map_[associated] = rtx.
517 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); 477 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_);
518 478
519 // Note: Don't access this variable directly, always go through 479 // Note: Don't access this variable directly, always go through
520 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember 480 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
521 // that by the time the function returns there is no guarantee 481 // that by the time the function returns there is no guarantee
522 // that the target bitrate is still valid. 482 // that the target bitrate is still valid.
523 rtc::CriticalSection target_bitrate_critsect_; 483 rtc::CriticalSection target_bitrate_critsect_;
524 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); 484 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_);
danilchap 2016/06/28 14:26:18 Is target_bitrate_ still in use?
sprang_webrtc 2016/07/04 09:33:04 Right, this was a big part of why I did this refac
525 485
486 NackRateLimiter* const nack_rate_limiter_;
487
526 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); 488 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
527 }; 489 };
528 490
529 } // namespace webrtc 491 } // namespace webrtc
530 492
531 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ 493 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698