| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace webrtc { | 27 namespace webrtc { |
| 28 | 28 |
| 29 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. | 29 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. |
| 30 static const size_t kMaxPaddingLength = 224; | 30 static const size_t kMaxPaddingLength = 224; |
| 31 static const int kSendSideDelayWindowMs = 1000; | 31 static const int kSendSideDelayWindowMs = 1000; |
| 32 static const uint32_t kAbsSendTimeFraction = 18; | 32 static const uint32_t kAbsSendTimeFraction = 18; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const size_t kRtpHeaderLength = 12; | 36 const size_t kRtpHeaderLength = 12; |
| 37 const uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1. |
| 37 | 38 |
| 38 const char* FrameTypeToString(FrameType frame_type) { | 39 const char* FrameTypeToString(FrameType frame_type) { |
| 39 switch (frame_type) { | 40 switch (frame_type) { |
| 40 case kEmptyFrame: | 41 case kEmptyFrame: |
| 41 return "empty"; | 42 return "empty"; |
| 42 case kAudioFrameSpeech: return "audio_speech"; | 43 case kAudioFrameSpeech: return "audio_speech"; |
| 43 case kAudioFrameCN: return "audio_cn"; | 44 case kAudioFrameCN: return "audio_cn"; |
| 44 case kVideoFrameKey: return "video_key"; | 45 case kVideoFrameKey: return "video_key"; |
| 45 case kVideoFrameDelta: return "video_delta"; | 46 case kVideoFrameDelta: return "video_delta"; |
| 46 } | 47 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 TransportSequenceNumberAllocator* sequence_number_allocator, | 120 TransportSequenceNumberAllocator* sequence_number_allocator, |
| 120 TransportFeedbackObserver* transport_feedback_observer, | 121 TransportFeedbackObserver* transport_feedback_observer, |
| 121 BitrateStatisticsObserver* bitrate_callback, | 122 BitrateStatisticsObserver* bitrate_callback, |
| 122 FrameCountObserver* frame_count_observer, | 123 FrameCountObserver* frame_count_observer, |
| 123 SendSideDelayObserver* send_side_delay_observer) | 124 SendSideDelayObserver* send_side_delay_observer) |
| 124 : clock_(clock), | 125 : clock_(clock), |
| 125 // TODO(holmer): Remove this conversion when we remove the use of | 126 // TODO(holmer): Remove this conversion when we remove the use of |
| 126 // TickTime. | 127 // TickTime. |
| 127 clock_delta_ms_(clock_->TimeInMilliseconds() - | 128 clock_delta_ms_(clock_->TimeInMilliseconds() - |
| 128 TickTime::MillisecondTimestamp()), | 129 TickTime::MillisecondTimestamp()), |
| 130 random_(clock_->TimeInMicroseconds()), |
| 129 bitrates_(new BitrateAggregator(bitrate_callback)), | 131 bitrates_(new BitrateAggregator(bitrate_callback)), |
| 130 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()), | 132 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()), |
| 131 audio_configured_(audio), | 133 audio_configured_(audio), |
| 132 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), | 134 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), |
| 133 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), | 135 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), |
| 134 paced_sender_(paced_sender), | 136 paced_sender_(paced_sender), |
| 135 transport_sequence_number_allocator_(sequence_number_allocator), | 137 transport_sequence_number_allocator_(sequence_number_allocator), |
| 136 transport_feedback_observer_(transport_feedback_observer), | 138 transport_feedback_observer_(transport_feedback_observer), |
| 137 last_capture_time_ms_sent_(0), | 139 last_capture_time_ms_sent_(0), |
| 138 send_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 140 send_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 178 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 177 target_bitrate_(0) { | 179 target_bitrate_(0) { |
| 178 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); | 180 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); |
| 179 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); | 181 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); |
| 180 // We need to seed the random generator. | 182 // We need to seed the random generator. |
| 181 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); | 183 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); |
| 182 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 184 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. |
| 183 ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 185 ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0. |
| 184 bitrates_->set_ssrc(ssrc_); | 186 bitrates_->set_ssrc(ssrc_); |
| 185 // Random start, 16 bits. Can't be 0. | 187 // Random start, 16 bits. Can't be 0. |
| 186 sequence_number_rtx_ = static_cast<uint16_t>(rand() + 1) & 0x7FFF; | 188 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 187 sequence_number_ = static_cast<uint16_t>(rand() + 1) & 0x7FFF; | 189 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 188 } | 190 } |
| 189 | 191 |
| 190 RTPSender::~RTPSender() { | 192 RTPSender::~RTPSender() { |
| 191 if (remote_ssrc_ != 0) { | 193 if (remote_ssrc_ != 0) { |
| 192 ssrc_db_.ReturnSSRC(remote_ssrc_); | 194 ssrc_db_.ReturnSSRC(remote_ssrc_); |
| 193 } | 195 } |
| 194 ssrc_db_.ReturnSSRC(ssrc_); | 196 ssrc_db_.ReturnSSRC(ssrc_); |
| 195 | 197 |
| 196 SSRCDatabase::ReturnSSRCDatabase(); | 198 SSRCDatabase::ReturnSSRCDatabase(); |
| 197 while (!payload_type_map_.empty()) { | 199 while (!payload_type_map_.empty()) { |
| (...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1649 CriticalSectionScoped lock(send_critsect_.get()); | 1651 CriticalSectionScoped lock(send_critsect_.get()); |
| 1650 if (!ssrc_forced_) { | 1652 if (!ssrc_forced_) { |
| 1651 // Generate a new SSRC. | 1653 // Generate a new SSRC. |
| 1652 ssrc_db_.ReturnSSRC(ssrc_); | 1654 ssrc_db_.ReturnSSRC(ssrc_); |
| 1653 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 1655 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. |
| 1654 bitrates_->set_ssrc(ssrc_); | 1656 bitrates_->set_ssrc(ssrc_); |
| 1655 } | 1657 } |
| 1656 // Don't initialize seq number if SSRC passed externally. | 1658 // Don't initialize seq number if SSRC passed externally. |
| 1657 if (!sequence_number_forced_ && !ssrc_forced_) { | 1659 if (!sequence_number_forced_ && !ssrc_forced_) { |
| 1658 // Generate a new sequence number. | 1660 // Generate a new sequence number. |
| 1659 sequence_number_ = | 1661 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 1660 rand() / (RAND_MAX / MAX_INIT_RTP_SEQ_NUMBER); // NOLINT | |
| 1661 } | 1662 } |
| 1662 } | 1663 } |
| 1663 } | 1664 } |
| 1664 | 1665 |
| 1665 void RTPSender::SetSendingMediaStatus(bool enabled) { | 1666 void RTPSender::SetSendingMediaStatus(bool enabled) { |
| 1666 CriticalSectionScoped cs(send_critsect_.get()); | 1667 CriticalSectionScoped cs(send_critsect_.get()); |
| 1667 sending_media_ = enabled; | 1668 sending_media_ = enabled; |
| 1668 } | 1669 } |
| 1669 | 1670 |
| 1670 bool RTPSender::SendingMedia() const { | 1671 bool RTPSender::SendingMedia() const { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 | 1713 |
| 1713 if (ssrc_ == ssrc && ssrc_forced_) { | 1714 if (ssrc_ == ssrc && ssrc_forced_) { |
| 1714 return; // Since it's same ssrc, don't reset anything. | 1715 return; // Since it's same ssrc, don't reset anything. |
| 1715 } | 1716 } |
| 1716 ssrc_forced_ = true; | 1717 ssrc_forced_ = true; |
| 1717 ssrc_db_.ReturnSSRC(ssrc_); | 1718 ssrc_db_.ReturnSSRC(ssrc_); |
| 1718 ssrc_db_.RegisterSSRC(ssrc); | 1719 ssrc_db_.RegisterSSRC(ssrc); |
| 1719 ssrc_ = ssrc; | 1720 ssrc_ = ssrc; |
| 1720 bitrates_->set_ssrc(ssrc_); | 1721 bitrates_->set_ssrc(ssrc_); |
| 1721 if (!sequence_number_forced_) { | 1722 if (!sequence_number_forced_) { |
| 1722 sequence_number_ = | 1723 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 1723 rand() / (RAND_MAX / MAX_INIT_RTP_SEQ_NUMBER); // NOLINT | |
| 1724 } | 1724 } |
| 1725 } | 1725 } |
| 1726 | 1726 |
| 1727 uint32_t RTPSender::SSRC() const { | 1727 uint32_t RTPSender::SSRC() const { |
| 1728 CriticalSectionScoped cs(send_critsect_.get()); | 1728 CriticalSectionScoped cs(send_critsect_.get()); |
| 1729 return ssrc_; | 1729 return ssrc_; |
| 1730 } | 1730 } |
| 1731 | 1731 |
| 1732 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 1732 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
| 1733 assert(csrcs.size() <= kRtpCsrcSize); | 1733 assert(csrcs.size() <= kRtpCsrcSize); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 CriticalSectionScoped lock(send_critsect_.get()); | 1906 CriticalSectionScoped lock(send_critsect_.get()); |
| 1907 | 1907 |
| 1908 RtpState state; | 1908 RtpState state; |
| 1909 state.sequence_number = sequence_number_rtx_; | 1909 state.sequence_number = sequence_number_rtx_; |
| 1910 state.start_timestamp = start_timestamp_; | 1910 state.start_timestamp = start_timestamp_; |
| 1911 | 1911 |
| 1912 return state; | 1912 return state; |
| 1913 } | 1913 } |
| 1914 | 1914 |
| 1915 } // namespace webrtc | 1915 } // namespace webrtc |
| OLD | NEW |