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

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

Issue 1623543002: Refactor RtpSender and SSRCDatabase a bit. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add TODOs for Random() and delete dead code from Timing (move to separate cl?) Created 4 years, 11 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 <utility> 16 #include <utility>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/criticalsection.h"
19 #include "webrtc/base/random.h" 20 #include "webrtc/base/random.h"
20 #include "webrtc/base/thread_annotations.h" 21 #include "webrtc/base/thread_annotations.h"
22 #include "webrtc/base/thread_checker.h"
21 #include "webrtc/common_types.h" 23 #include "webrtc/common_types.h"
22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
23 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" 25 #include "webrtc/modules/rtp_rtcp/source/bitrate.h"
24 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" 26 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
25 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" 27 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h"
26 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" 28 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
27 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
28 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" 30 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
29 #include "webrtc/transport.h" 31 #include "webrtc/transport.h"
30 32
31 namespace webrtc { 33 namespace webrtc {
32 34
33 class BitrateAggregator;
34 class CriticalSectionWrapper;
35 class RTPSenderAudio; 35 class RTPSenderAudio;
36 class RTPSenderVideo; 36 class RTPSenderVideo;
37 class RtcEventLog; 37 class RtcEventLog;
38 38
39 class BitrateAggregator {
40 public:
41 explicit BitrateAggregator(BitrateStatisticsObserver* bitrate_callback);
42
43 void OnStatsUpdated() const;
44
45 Bitrate::Observer* total_bitrate_observer();
46 Bitrate::Observer* retransmit_bitrate_observer();
47 void set_ssrc(uint32_t ssrc);
48
49 private:
50 // We assume that these observers are called on the same thread, which is
51 // true for RtpSender as they are called on the Process thread.
52 class BitrateObserver : public Bitrate::Observer {
53 public:
54 explicit BitrateObserver(const BitrateAggregator& aggregator);
55
56 // Implements Bitrate::Observer.
57 void BitrateUpdated(const BitrateStatistics& stats) override;
58 BitrateStatistics statistics() const;
59
60 private:
61 BitrateStatistics statistics_;
62 const BitrateAggregator& aggregator_;
63 };
64
65 BitrateStatisticsObserver* const callback_;
66 BitrateObserver total_bitrate_observer_;
67 BitrateObserver retransmit_bitrate_observer_;
68 uint32_t ssrc_;
69 };
70
39 class RTPSenderInterface { 71 class RTPSenderInterface {
40 public: 72 public:
41 RTPSenderInterface() {} 73 RTPSenderInterface() {}
42 virtual ~RTPSenderInterface() {} 74 virtual ~RTPSenderInterface() {}
43 75
44 enum CVOMode { 76 enum CVOMode {
45 kCVONone, 77 kCVONone,
46 kCVOInactive, // CVO rtp header extension is registered but haven't 78 kCVOInactive, // CVO rtp header extension is registered but haven't
47 // received any frame with rotation pending. 79 // received any frame with rotation pending.
48 kCVOActivated, // CVO rtp header extension will be present in the rtp 80 kCVOActivated, // CVO rtp header extension will be present in the rtp
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 RTPSender(bool audio, 123 RTPSender(bool audio,
92 Clock* clock, 124 Clock* clock,
93 Transport* transport, 125 Transport* transport,
94 RtpAudioFeedback* audio_feedback, 126 RtpAudioFeedback* audio_feedback,
95 RtpPacketSender* paced_sender, 127 RtpPacketSender* paced_sender,
96 TransportSequenceNumberAllocator* sequence_number_allocator, 128 TransportSequenceNumberAllocator* sequence_number_allocator,
97 TransportFeedbackObserver* transport_feedback_callback, 129 TransportFeedbackObserver* transport_feedback_callback,
98 BitrateStatisticsObserver* bitrate_callback, 130 BitrateStatisticsObserver* bitrate_callback,
99 FrameCountObserver* frame_count_observer, 131 FrameCountObserver* frame_count_observer,
100 SendSideDelayObserver* send_side_delay_observer, 132 SendSideDelayObserver* send_side_delay_observer,
101 RtcEventLog* event_log); 133 RtcEventLog* event_log,
134 SSRCDatabase* ssrc_database);
102 virtual ~RTPSender(); 135 virtual ~RTPSender();
103 136
104 void ProcessBitrate(); 137 void ProcessBitrate();
105 138
106 uint16_t ActualSendBitrateKbit() const override; 139 uint16_t ActualSendBitrateKbit() const override;
107 140
108 uint32_t VideoBitrateSent() const; 141 uint32_t VideoBitrateSent() const;
109 uint32_t FecOverheadRate() const; 142 uint32_t FecOverheadRate() const;
110 uint32_t NackOverheadRate() const; 143 uint32_t NackOverheadRate() const;
111 144
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 kNotRegistered, 222 kNotRegistered,
190 kOk, 223 kOk,
191 kError, 224 kError,
192 }; 225 };
193 ExtensionStatus VerifyExtension(RTPExtensionType extension_type, 226 ExtensionStatus VerifyExtension(RTPExtensionType extension_type,
194 uint8_t* rtp_packet, 227 uint8_t* rtp_packet,
195 size_t rtp_packet_length, 228 size_t rtp_packet_length,
196 const RTPHeader& rtp_header, 229 const RTPHeader& rtp_header,
197 size_t extension_length_bytes, 230 size_t extension_length_bytes,
198 size_t* extension_offset) const 231 size_t* extension_offset) const
199 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_.get()); 232 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
200 233
201 bool UpdateAudioLevel(uint8_t* rtp_packet, 234 bool UpdateAudioLevel(uint8_t* rtp_packet,
202 size_t rtp_packet_length, 235 size_t rtp_packet_length,
203 const RTPHeader& rtp_header, 236 const RTPHeader& rtp_header,
204 bool is_voiced, 237 bool is_voiced,
205 uint8_t dBov) const; 238 uint8_t dBov) const;
206 239
207 bool UpdateVideoRotation(uint8_t* rtp_packet, 240 bool UpdateVideoRotation(uint8_t* rtp_packet,
208 size_t rtp_packet_length, 241 size_t rtp_packet_length,
209 const RTPHeader& rtp_header, 242 const RTPHeader& rtp_header,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 size_t rtp_packet_length, 412 size_t rtp_packet_length,
380 const RTPHeader& rtp_header) const; 413 const RTPHeader& rtp_header) const;
381 414
382 void UpdateRtpStats(const uint8_t* buffer, 415 void UpdateRtpStats(const uint8_t* buffer,
383 size_t packet_length, 416 size_t packet_length,
384 const RTPHeader& header, 417 const RTPHeader& header,
385 bool is_rtx, 418 bool is_rtx,
386 bool is_retransmit); 419 bool is_retransmit);
387 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; 420 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
388 421
389 Clock* clock_; 422 Clock* const clock_;
390 int64_t clock_delta_ms_; 423 const int64_t clock_delta_ms_;
391 Random random_ GUARDED_BY(send_critsect_); 424 Random random_ GUARDED_BY(send_critsect_);
392 425
393 rtc::scoped_ptr<BitrateAggregator> bitrates_; 426 BitrateAggregator bitrates_;
394 Bitrate total_bitrate_sent_; 427 Bitrate total_bitrate_sent_;
395 428
396 const bool audio_configured_; 429 const bool audio_configured_;
397 rtc::scoped_ptr<RTPSenderAudio> audio_; 430 const rtc::scoped_ptr<RTPSenderAudio> audio_;
398 rtc::scoped_ptr<RTPSenderVideo> video_; 431 const rtc::scoped_ptr<RTPSenderVideo> video_;
399 432
400 RtpPacketSender* const paced_sender_; 433 RtpPacketSender* const paced_sender_;
401 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; 434 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
402 TransportFeedbackObserver* const transport_feedback_observer_; 435 TransportFeedbackObserver* const transport_feedback_observer_;
403 int64_t last_capture_time_ms_sent_; 436 int64_t last_capture_time_ms_sent_;
404 rtc::scoped_ptr<CriticalSectionWrapper> send_critsect_; 437 rtc::CriticalSection send_critsect_;
405 438
406 Transport *transport_; 439 Transport *transport_;
407 bool sending_media_ GUARDED_BY(send_critsect_); 440 bool sending_media_ GUARDED_BY(send_critsect_);
408 441
409 size_t max_payload_length_; 442 size_t max_payload_length_;
410 uint16_t packet_over_head_; 443 uint16_t packet_over_head_;
411 444
412 int8_t payload_type_ GUARDED_BY(send_critsect_); 445 int8_t payload_type_ GUARDED_BY(send_critsect_);
413 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; 446 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
414 447
(...skipping 18 matching lines...) Expand all
433 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); 466 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
434 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); 467 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
435 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); 468 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
436 FrameCountObserver* const frame_count_observer_; 469 FrameCountObserver* const frame_count_observer_;
437 SendSideDelayObserver* const send_side_delay_observer_; 470 SendSideDelayObserver* const send_side_delay_observer_;
438 RtcEventLog* const event_log_; 471 RtcEventLog* const event_log_;
439 472
440 // RTP variables 473 // RTP variables
441 bool start_timestamp_forced_ GUARDED_BY(send_critsect_); 474 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
442 uint32_t start_timestamp_ GUARDED_BY(send_critsect_); 475 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
443 SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_); 476 SSRCDatabase* const ssrc_db_;
444 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_); 477 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
445 bool sequence_number_forced_ GUARDED_BY(send_critsect_); 478 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
446 uint16_t sequence_number_ GUARDED_BY(send_critsect_); 479 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
447 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_); 480 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
448 bool ssrc_forced_ GUARDED_BY(send_critsect_); 481 bool ssrc_forced_ GUARDED_BY(send_critsect_);
449 uint32_t ssrc_ GUARDED_BY(send_critsect_); 482 uint32_t ssrc_ GUARDED_BY(send_critsect_);
450 uint32_t timestamp_ GUARDED_BY(send_critsect_); 483 uint32_t timestamp_ GUARDED_BY(send_critsect_);
451 int64_t capture_time_ms_ GUARDED_BY(send_critsect_); 484 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
452 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_); 485 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
453 bool media_has_been_sent_ GUARDED_BY(send_critsect_); 486 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
454 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_); 487 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
455 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_); 488 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
456 int rtx_ GUARDED_BY(send_critsect_); 489 int rtx_ GUARDED_BY(send_critsect_);
457 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_); 490 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
458 // TODO(changbin): Remove rtx_payload_type_ once interop with old clients that 491 // TODO(changbin): Remove rtx_payload_type_ once interop with old clients that
459 // only understand one RTX PT is no longer needed. 492 // only understand one RTX PT is no longer needed.
460 int rtx_payload_type_ GUARDED_BY(send_critsect_); 493 int rtx_payload_type_ GUARDED_BY(send_critsect_);
461 // Mapping rtx_payload_type_map_[associated] = rtx. 494 // Mapping rtx_payload_type_map_[associated] = rtx.
462 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); 495 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_);
463 496
464 // Note: Don't access this variable directly, always go through 497 // Note: Don't access this variable directly, always go through
465 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember 498 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
466 // that by the time the function returns there is no guarantee 499 // that by the time the function returns there is no guarantee
467 // that the target bitrate is still valid. 500 // that the target bitrate is still valid.
468 rtc::scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_; 501 rtc::scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_;
469 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); 502 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_);
503 rtc::ThreadChecker thread_checker_;
470 504
471 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); 505 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
472 }; 506 };
473 507
474 } // namespace webrtc 508 } // namespace webrtc
475 509
476 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ 510 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698