diff --git a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h index 8363d82f6a..02a62556e6 100644 --- a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h +++ b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h @@ -25,6 +25,8 @@ namespace webrtc{ +const WebRtc_Word32 kDefaultVideoFrequency = 90000; + enum RTCPMethod { kRtcpOff = 0, diff --git a/webrtc/modules/rtp_rtcp/source/Bitrate.h b/webrtc/modules/rtp_rtcp/source/Bitrate.h deleted file mode 100644 index be45343ec4..0000000000 --- a/webrtc/modules/rtp_rtcp/source/Bitrate.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ -#define WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ - -#include "typedefs.h" -#include "rtp_rtcp_config.h" // misc. defines (e.g. MAX_PACKET_LENGTH) -#include "common_types.h" // Transport -#include -#include - -namespace webrtc { -class RtpRtcpClock; - -class Bitrate -{ -public: - Bitrate(RtpRtcpClock* clock); - - // calculate rates - void Process(); - - // update with a packet - void Update(const WebRtc_Word32 bytes); - - // packet rate last second, updated roughly every 100 ms - WebRtc_UWord32 PacketRate() const; - - // bitrate last second, updated roughly every 100 ms - WebRtc_UWord32 BitrateLast() const; - - // bitrate last second, updated now - WebRtc_UWord32 BitrateNow() const; - -protected: - RtpRtcpClock& _clock; - -private: - WebRtc_UWord32 _packetRate; - WebRtc_UWord32 _bitrate; - WebRtc_UWord8 _bitrateNextIdx; - WebRtc_Word64 _packetRateArray[10]; - WebRtc_Word64 _bitrateArray[10]; - WebRtc_Word64 _bitrateDiffMS[10]; - WebRtc_Word64 _timeLastRateUpdate; - WebRtc_UWord32 _bytesCount; - WebRtc_UWord32 _packetCount; -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ diff --git a/webrtc/modules/rtp_rtcp/source/bitrate.cc b/webrtc/modules/rtp_rtcp/source/bitrate.cc index 38cf537974..ea37e86bec 100644 --- a/webrtc/modules/rtp_rtcp/source/bitrate.cc +++ b/webrtc/modules/rtp_rtcp/source/bitrate.cc @@ -8,94 +8,91 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "Bitrate.h" -#include "rtp_utility.h" +#include "webrtc/modules/rtp_rtcp/source/bitrate.h" + +#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" namespace webrtc { -Bitrate::Bitrate(RtpRtcpClock* clock) : - _clock(*clock), - _packetRate(0), - _bitrate(0), - _bitrateNextIdx(0), - _timeLastRateUpdate(0), - _bytesCount(0), - _packetCount(0) -{ - memset(_packetRateArray, 0, sizeof(_packetRateArray)); - memset(_bitrateDiffMS, 0, sizeof(_bitrateDiffMS)); - memset(_bitrateArray, 0, sizeof(_bitrateArray)); + +Bitrate::Bitrate(RtpRtcpClock* clock) + : clock_(*clock), + packet_rate_(0), + bitrate_(0), + bitrate_next_idx_(0), + time_last_rate_update_(0), + bytes_count_(0), + packet_count_(0) { + memset(packet_rate_array_, 0, sizeof(packet_rate_array_)); + memset(bitrate_diff_ms_, 0, sizeof(bitrate_diff_ms_)); + memset(bitrate_array_, 0, sizeof(bitrate_array_)); } -void -Bitrate::Update(const WebRtc_Word32 bytes) -{ - _bytesCount += bytes; - _packetCount++; +void Bitrate::Update(const WebRtc_Word32 bytes) { + bytes_count_ += bytes; + packet_count_++; } -WebRtc_UWord32 -Bitrate::PacketRate() const -{ - return _packetRate; +WebRtc_UWord32 Bitrate::PacketRate() const { + return packet_rate_; } WebRtc_UWord32 Bitrate::BitrateLast() const { - return _bitrate; + return bitrate_; } WebRtc_UWord32 Bitrate::BitrateNow() const { - WebRtc_Word64 now = _clock.GetTimeInMS(); - WebRtc_Word64 diffMS = now -_timeLastRateUpdate; + WebRtc_Word64 now = clock_.GetTimeInMS(); + WebRtc_Word64 diff_ms = now - time_last_rate_update_; - if(diffMS > 10000) { // 10 sec - // too high diff ignore - return _bitrate; // bits/s + if (diff_ms > 10000) { // 10 seconds. + // Too high difference, ignore. + return bitrate_; } - WebRtc_Word64 bitsSinceLastRateUpdate = 8 * _bytesCount * 1000; + WebRtc_Word64 bits_since_last_rate_update = 8 * bytes_count_ * 1000; - // have to consider the time when the measurement was done - // ((bits/sec * sec) + (bits)) / sec - WebRtc_Word64 bitrate = (static_cast(_bitrate) * 1000 + - bitsSinceLastRateUpdate) / (1000 + diffMS); + // We have to consider the time when the measurement was done: + // ((bits/sec * sec) + (bits)) / sec. + WebRtc_Word64 bitrate = (static_cast(bitrate_) * 1000 + + bits_since_last_rate_update) / (1000 + diff_ms); return static_cast(bitrate); } void Bitrate::Process() { // Triggered by timer. - WebRtc_Word64 now = _clock.GetTimeInMS(); - WebRtc_Word64 diffMS = now -_timeLastRateUpdate; + WebRtc_Word64 now = clock_.GetTimeInMS(); + WebRtc_Word64 diff_ms = now - time_last_rate_update_; - if (diffMS < 100) { + if (diff_ms < 100) { // Not enough data, wait... return; } - if (diffMS > 10000) { // 10 sec - // too high diff ignore - _timeLastRateUpdate = now; - _bytesCount = 0; - _packetCount = 0; + if (diff_ms > 10000) { // 10 seconds. + // Too high difference, ignore. + time_last_rate_update_ = now; + bytes_count_ = 0; + packet_count_ = 0; return; } - _packetRateArray[_bitrateNextIdx] = (_packetCount * 1000) / diffMS; - _bitrateArray[_bitrateNextIdx] = 8 * ((_bytesCount * 1000) / diffMS); - _bitrateDiffMS[_bitrateNextIdx] = diffMS; - _bitrateNextIdx++; - if (_bitrateNextIdx >= 10) { - _bitrateNextIdx = 0; + packet_rate_array_[bitrate_next_idx_] = (packet_count_ * 1000) / diff_ms; + bitrate_array_[bitrate_next_idx_] = 8 * ((bytes_count_ * 1000) / diff_ms); + bitrate_diff_ms_[bitrate_next_idx_] = diff_ms; + bitrate_next_idx_++; + if (bitrate_next_idx_ >= 10) { + bitrate_next_idx_ = 0; } - WebRtc_Word64 sumDiffMS = 0; - WebRtc_Word64 sumBitrateMS = 0; - WebRtc_Word64 sumPacketrateMS = 0; + WebRtc_Word64 sum_diffMS = 0; + WebRtc_Word64 sum_bitrateMS = 0; + WebRtc_Word64 sum_packetrateMS = 0; for (int i = 0; i < 10; i++) { - sumDiffMS += _bitrateDiffMS[i]; - sumBitrateMS += _bitrateArray[i] * _bitrateDiffMS[i]; - sumPacketrateMS += _packetRateArray[i] * _bitrateDiffMS[i]; + sum_diffMS += bitrate_diff_ms_[i]; + sum_bitrateMS += bitrate_array_[i] * bitrate_diff_ms_[i]; + sum_packetrateMS += packet_rate_array_[i] * bitrate_diff_ms_[i]; } - _timeLastRateUpdate = now; - _bytesCount = 0; - _packetCount = 0; - _packetRate = static_cast(sumPacketrateMS / sumDiffMS); - _bitrate = static_cast(sumBitrateMS / sumDiffMS); + time_last_rate_update_ = now; + bytes_count_ = 0; + packet_count_ = 0; + packet_rate_ = static_cast(sum_packetrateMS / sum_diffMS); + bitrate_ = static_cast(sum_bitrateMS / sum_diffMS); } -} // namespace webrtc +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/source/bitrate.h b/webrtc/modules/rtp_rtcp/source/bitrate.h new file mode 100644 index 0000000000..8a2d94f326 --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/bitrate.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ +#define WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ + +#include +#include + +#include "webrtc/common_types.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" +#include "webrtc/typedefs.h" + +namespace webrtc { + +class RtpRtcpClock; + +class Bitrate { + public: + explicit Bitrate(RtpRtcpClock* clock); + + // Calculates rates. + void Process(); + + // Update with a packet. + void Update(const WebRtc_Word32 bytes); + + // Packet rate last second, updated roughly every 100 ms. + WebRtc_UWord32 PacketRate() const; + + // Bitrate last second, updated roughly every 100 ms. + WebRtc_UWord32 BitrateLast() const; + + // Bitrate last second, updated now. + WebRtc_UWord32 BitrateNow() const; + + protected: + RtpRtcpClock& clock_; + + private: + WebRtc_UWord32 packet_rate_; + WebRtc_UWord32 bitrate_; + WebRtc_UWord8 bitrate_next_idx_; + WebRtc_Word64 packet_rate_array_[10]; + WebRtc_Word64 bitrate_array_[10]; + WebRtc_Word64 bitrate_diff_ms_[10]; + WebRtc_Word64 time_last_rate_update_; + WebRtc_UWord32 bytes_count_; + WebRtc_UWord32 packet_count_; +}; + +} // namespace webrtc + +#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BITRATE_H_ diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver.cc index 00b2ed1a0b..6fd8f77651 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_receiver.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver.cc @@ -8,20 +8,19 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "rtp_receiver.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_receiver.h" #include -#include // floor -#include // abs -#include //memcpy +#include +#include +#include -#include "critical_section_wrapper.h" -#include "rtp_receiver_audio.h" -#include "rtp_receiver_strategy.h" -#include "rtp_receiver_video.h" -#include "rtp_rtcp_defines.h" -#include "rtp_rtcp_impl.h" -#include "trace.h" +#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" +#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" +#include "webrtc/system_wrappers/interface/trace.h" namespace webrtc { @@ -36,405 +35,373 @@ RTPReceiver::RTPReceiver(const WebRtc_Word32 id, const bool audio, RtpRtcpClock* clock, ModuleRtpRtcpImpl* owner, - RtpAudioFeedback* incomingMessagesCallback) : - Bitrate(clock), - _id(id), - _rtpRtcp(*owner), - _criticalSectionCbs(CriticalSectionWrapper::CreateCriticalSection()), - _cbRtpFeedback(NULL), - _cbRtpData(NULL), + RtpAudioFeedback* incoming_messages_callback) + : Bitrate(clock), + id_(id), + rtp_rtcp_(*owner), + critical_section_cbs_(CriticalSectionWrapper::CreateCriticalSection()), + cb_rtp_feedback_(NULL), + cb_rtp_data_(NULL), - _criticalSectionRTPReceiver( + critical_section_rtp_receiver_( CriticalSectionWrapper::CreateCriticalSection()), - _lastReceiveTime(0), - _lastReceivedPayloadLength(0), - _lastReceivedPayloadType(-1), - _lastReceivedMediaPayloadType(-1), + last_receive_time_(0), + last_received_payload_length_(0), + last_received_payload_type_(-1), + last_received_media_payload_type_(-1), - _packetTimeOutMS(0), + packet_timeout_ms_(0), - _redPayloadType(-1), - _payloadTypeMap(), - _rtpHeaderExtensionMap(), - _SSRC(0), - _numCSRCs(0), - _currentRemoteCSRC(), - _numEnergy(0), - _currentRemoteEnergy(), - _useSSRCFilter(false), - _SSRCFilter(0), + red_payload_type_(-1), + payload_type_map_(), + rtp_header_extension_map_(), + ssrc_(0), + num_csrcs_(0), + current_remote_csrc_(), + num_energy_(0), + current_remote_energy_(), + use_ssrc_filter_(false), + ssrc_filter_(0), - _jitterQ4(0), - _jitterMaxQ4(0), - _cumulativeLoss(0), - _jitterQ4TransmissionTimeOffset(0), - _localTimeLastReceivedTimestamp(0), - _lastReceivedFrameTimeMs(0), - _lastReceivedTimestamp(0), - _lastReceivedSequenceNumber(0), - _lastReceivedTransmissionTimeOffset(0), + jitter_q4_(0), + jitter_max_q4_(0), + cumulative_loss_(0), + jitter_q4_transmission_time_offset_(0), + local_time_last_received_timestamp_(0), + last_received_frame_time_ms_(0), + last_received_timestamp_(0), + last_received_sequence_number_(0), + last_received_transmission_time_offset_(0), - _receivedSeqFirst(0), - _receivedSeqMax(0), - _receivedSeqWraps(0), + received_seq_first_(0), + received_seq_max_(0), + received_seq_wraps_(0), - _receivedPacketOH(12), // RTP header - _receivedByteCount(0), - _receivedOldPacketCount(0), - _receivedInorderPacketCount(0), + received_packet_oh_(12), // RTP header. + received_byte_count_(0), + received_old_packet_count_(0), + received_inorder_packet_count_(0), - _lastReportInorderPackets(0), - _lastReportOldPackets(0), - _lastReportSeqMax(0), - _lastReportFractionLost(0), - _lastReportCumulativeLost(0), - _lastReportExtendedHighSeqNum(0), - _lastReportJitter(0), - _lastReportJitterTransmissionTimeOffset(0), + last_report_inorder_packets_(0), + last_report_old_packets_(0), + last_report_seq_max_(0), + last_report_fraction_lost_(0), + last_report_cumulative_lost_(0), + last_report_extended_high_seq_num_(0), + last_report_jitter_(0), + last_report_jitter_transmission_time_offset_(0), - _nackMethod(kNackOff), - _RTX(false), - _ssrcRTX(0) { + nack_method_(kNackOff), + rtx_(false), + ssrc_rtx_(0) { // TODO(phoglund): Remove hacks requiring direct access to the audio receiver - // and only instantiate one of these directly into the _rtpMediaReceiver + // and only instantiate one of these directly into the rtp_media_receiver_ // field. Right now an audio receiver carries around a video handler and // vice versa, which doesn't make sense. - _rtpReceiverAudio = new RTPReceiverAudio(id, this, incomingMessagesCallback); - _rtpReceiverVideo = new RTPReceiverVideo(id, this, owner); + rtp_receiver_audio_ = new RTPReceiverAudio(id, this, + incoming_messages_callback); + rtp_receiver_video_ = new RTPReceiverVideo(id, this, owner); if (audio) { - _rtpMediaReceiver = _rtpReceiverAudio; + rtp_media_receiver_ = rtp_receiver_audio_; } else { - _rtpMediaReceiver = _rtpReceiverVideo; + rtp_media_receiver_ = rtp_receiver_video_; } - memset(_currentRemoteCSRC, 0, sizeof(_currentRemoteCSRC)); - memset(_currentRemoteEnergy, 0, sizeof(_currentRemoteEnergy)); + memset(current_remote_csrc_, 0, sizeof(current_remote_csrc_)); + memset(current_remote_energy_, 0, sizeof(current_remote_energy_)); WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id, "%s created", __FUNCTION__); } RTPReceiver::~RTPReceiver() { - if (_cbRtpFeedback) { - for (int i = 0; i < _numCSRCs; i++) { - _cbRtpFeedback->OnIncomingCSRCChanged(_id,_currentRemoteCSRC[i], false); + if (cb_rtp_feedback_) { + for (int i = 0; i < num_csrcs_; ++i) { + cb_rtp_feedback_->OnIncomingCSRCChanged(id_, current_remote_csrc_[i], + false); } } - delete _criticalSectionCbs; - delete _criticalSectionRTPReceiver; + delete critical_section_cbs_; + delete critical_section_rtp_receiver_; - while (!_payloadTypeMap.empty()) { - std::map::iterator it = _payloadTypeMap.begin(); + while (!payload_type_map_.empty()) { + std::map::iterator it = payload_type_map_.begin(); delete it->second; - _payloadTypeMap.erase(it); + payload_type_map_.erase(it); } - delete _rtpReceiverVideo; - delete _rtpReceiverAudio; - WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, _id, "%s deleted", __FUNCTION__); + delete rtp_receiver_video_; + delete rtp_receiver_audio_; + WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id_, "%s deleted", __FUNCTION__); } -RtpVideoCodecTypes -RTPReceiver::VideoCodecType() const -{ - ModuleRTPUtility::PayloadUnion mediaSpecific; - _rtpMediaReceiver->GetLastMediaSpecificPayload(&mediaSpecific); - return mediaSpecific.Video.videoCodecType; +RtpVideoCodecTypes RTPReceiver::VideoCodecType() const { + ModuleRTPUtility::PayloadUnion media_specific; + rtp_media_receiver_->GetLastMediaSpecificPayload(&media_specific); + return media_specific.Video.videoCodecType; } -WebRtc_UWord32 -RTPReceiver::MaxConfiguredBitrate() const -{ - ModuleRTPUtility::PayloadUnion mediaSpecific; - _rtpMediaReceiver->GetLastMediaSpecificPayload(&mediaSpecific); - return mediaSpecific.Video.maxRate; +WebRtc_UWord32 RTPReceiver::MaxConfiguredBitrate() const { + ModuleRTPUtility::PayloadUnion media_specific; + rtp_media_receiver_->GetLastMediaSpecificPayload(&media_specific); + return media_specific.Video.maxRate; } -bool -RTPReceiver::REDPayloadType(const WebRtc_Word8 payloadType) const -{ - return (_redPayloadType == payloadType)?true:false; +bool RTPReceiver::REDPayloadType(const WebRtc_Word8 payload_type) const { + return (red_payload_type_ == payload_type) ? true : false; } -WebRtc_Word8 -RTPReceiver::REDPayloadType() const -{ - return _redPayloadType; +WebRtc_Word8 RTPReceiver::REDPayloadType() const { + return red_payload_type_; } - // configure a timeout value -WebRtc_Word32 -RTPReceiver::SetPacketTimeout(const WebRtc_UWord32 timeoutMS) -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - _packetTimeOutMS = timeoutMS; - return 0; +WebRtc_Word32 RTPReceiver::SetPacketTimeout(const WebRtc_UWord32 timeout_ms) { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + packet_timeout_ms_ = timeout_ms; + return 0; } -bool RTPReceiver::HaveNotReceivedPackets() const -{ - return _lastReceiveTime == 0; +bool RTPReceiver::HaveNotReceivedPackets() const { + return last_receive_time_ == 0; } -void RTPReceiver::PacketTimeout() -{ - bool packetTimeOut = false; - { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - if(_packetTimeOutMS == 0) - { - // not configured - return; - } - - if (HaveNotReceivedPackets()) - { - // not active - return; - } - - WebRtc_Word64 now = _clock.GetTimeInMS(); - - if(now - _lastReceiveTime > _packetTimeOutMS) - { - packetTimeOut = true; - _lastReceiveTime = 0; // only one callback - _lastReceivedPayloadType = -1; // makes RemotePayload return -1, which we want - _lastReceivedMediaPayloadType = -1; - } - } - CriticalSectionScoped lock(_criticalSectionCbs); - if(packetTimeOut && _cbRtpFeedback) - { - _cbRtpFeedback->OnPacketTimeout(_id); - } -} - -void -RTPReceiver::ProcessDeadOrAlive(const bool rtcpAlive, const WebRtc_Word64 now) -{ - if(_cbRtpFeedback == NULL) - { - // no callback - return; - } - RTPAliveType alive = kRtpDead; - - if(_lastReceiveTime + 1000 > now) - { - // always alive if we have received a RTP packet the last sec - alive = kRtpAlive; - - } else - { - if(rtcpAlive) - { - alive = _rtpMediaReceiver->ProcessDeadOrAlive( - _lastReceivedPayloadLength); - }else - { - // no RTP packet for 1 sec and no RTCP - // dead - } +void RTPReceiver::PacketTimeout() { + bool packet_time_out = false; + { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + if (packet_timeout_ms_ == 0) { + // Not configured. + return; } - - CriticalSectionScoped lock(_criticalSectionCbs); - if(_cbRtpFeedback) - { - _cbRtpFeedback->OnPeriodicDeadOrAlive(_id, alive); + if (HaveNotReceivedPackets()) { + // Not active. + return; } + + WebRtc_Word64 now = clock_.GetTimeInMS(); + + if (now - last_receive_time_ > packet_timeout_ms_) { + packet_time_out = true; + last_receive_time_ = 0; // Only one callback. + last_received_payload_type_ = -1; // Makes RemotePayload return -1. + last_received_media_payload_type_ = -1; + } + } + CriticalSectionScoped lock(critical_section_cbs_); + if (packet_time_out && cb_rtp_feedback_) { + cb_rtp_feedback_->OnPacketTimeout(id_); + } } -WebRtc_UWord16 -RTPReceiver::PacketOHReceived() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _receivedPacketOH; +void RTPReceiver::ProcessDeadOrAlive(const bool rtcp_alive, + const WebRtc_Word64 now) { + if (cb_rtp_feedback_ == NULL) { + // No callback. + return; + } + RTPAliveType alive = kRtpDead; + + if (last_receive_time_ + 1000 > now) { + // Always alive if we have received a RTP packet the last second. + alive = kRtpAlive; + + } else { + if (rtcp_alive) { + alive = rtp_media_receiver_->ProcessDeadOrAlive( + last_received_payload_length_); + } else { + // No RTP packet for 1 sec and no RTCP: dead. + } + } + + CriticalSectionScoped lock(critical_section_cbs_); + if (cb_rtp_feedback_) { + cb_rtp_feedback_->OnPeriodicDeadOrAlive(id_, alive); + } } -WebRtc_UWord32 -RTPReceiver::PacketCountReceived() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _receivedInorderPacketCount; +WebRtc_UWord16 RTPReceiver::PacketOHReceived() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return received_packet_oh_; } -WebRtc_UWord32 -RTPReceiver::ByteCountReceived() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _receivedByteCount; +WebRtc_UWord32 RTPReceiver::PacketCountReceived() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return received_inorder_packet_count_; } -WebRtc_Word32 -RTPReceiver::RegisterIncomingRTPCallback(RtpFeedback* incomingMessagesCallback) -{ - CriticalSectionScoped lock(_criticalSectionCbs); - _cbRtpFeedback = incomingMessagesCallback; - return 0; +WebRtc_UWord32 RTPReceiver::ByteCountReceived() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return received_byte_count_; } -WebRtc_Word32 -RTPReceiver::RegisterIncomingDataCallback(RtpData* incomingDataCallback) -{ - CriticalSectionScoped lock(_criticalSectionCbs); - _cbRtpData = incomingDataCallback; - return 0; +WebRtc_Word32 RTPReceiver::RegisterIncomingRTPCallback( + RtpFeedback* incoming_messages_callback) { + CriticalSectionScoped lock(critical_section_cbs_); + cb_rtp_feedback_ = incoming_messages_callback; + return 0; +} + +WebRtc_Word32 RTPReceiver::RegisterIncomingDataCallback( + RtpData* incoming_data_callback) { + CriticalSectionScoped lock(critical_section_cbs_); + cb_rtp_data_ = incoming_data_callback; + return 0; } WebRtc_Word32 RTPReceiver::RegisterReceivePayload( - const char payloadName[RTP_PAYLOAD_NAME_SIZE], - const WebRtc_Word8 payloadType, + const char payload_name[RTP_PAYLOAD_NAME_SIZE], + const WebRtc_Word8 payload_type, const WebRtc_UWord32 frequency, const WebRtc_UWord8 channels, const WebRtc_UWord32 rate) { - assert(payloadName); - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + assert(payload_name); + CriticalSectionScoped lock(critical_section_rtp_receiver_); - // sanity - switch (payloadType) { - // reserved payload types to avoid RTCP conflicts when marker bit is set - case 64: // 192 Full INTRA-frame request - case 72: // 200 Sender report - case 73: // 201 Receiver report - case 74: // 202 Source description - case 75: // 203 Goodbye - case 76: // 204 Application-defined - case 77: // 205 Transport layer FB message - case 78: // 206 Payload-specific FB message - case 79: // 207 Extended report - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, + // Sanity check. + switch (payload_type) { + // Reserved payload types to avoid RTCP conflicts when marker bit is set. + case 64: // 192 Full INTRA-frame request. + case 72: // 200 Sender report. + case 73: // 201 Receiver report. + case 74: // 202 Source description. + case 75: // 203 Goodbye. + case 76: // 204 Application-defined. + case 77: // 205 Transport layer FB message. + case 78: // 206 Payload-specific FB message. + case 79: // 207 Extended report. + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, "%s invalid payloadtype:%d", - __FUNCTION__, payloadType); + __FUNCTION__, payload_type); return -1; default: break; } - size_t payloadNameLength = strlen(payloadName); + size_t payload_name_length = strlen(payload_name); std::map::iterator it = - _payloadTypeMap.find(payloadType); - if (it != _payloadTypeMap.end()) { - // we already use this payload type + payload_type_map_.find(payload_type); + + if (it != payload_type_map_.end()) { + // We already use this payload type. Payload* payload = it->second; assert(payload); - size_t nameLength = strlen(payload->name); + size_t name_length = strlen(payload->name); - // check if it's the same as we already have - // if same ignore sending an error - if (payloadNameLength == nameLength && - StringCompare(payload->name, payloadName, payloadNameLength)) { - if (_rtpMediaReceiver->PayloadIsCompatible(*payload, frequency, - channels, rate)) { - _rtpMediaReceiver->UpdatePayloadRate(payload, rate); + // Check if it's the same as we already have. + // If same, ignore sending an error. + if (payload_name_length == name_length && + StringCompare(payload->name, payload_name, payload_name_length)) { + if (rtp_media_receiver_->PayloadIsCompatible(*payload, frequency, + channels, rate)) { + rtp_media_receiver_->UpdatePayloadRate(payload, rate); return 0; } } - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, - "%s invalid argument payloadType:%d already registered", - __FUNCTION__, payloadType); + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, + "%s invalid argument payload_type:%d already registered", + __FUNCTION__, payload_type); return -1; } - _rtpMediaReceiver->PossiblyRemoveExistingPayloadType( - &_payloadTypeMap, payloadName, payloadNameLength, frequency, channels, - rate); + rtp_media_receiver_->PossiblyRemoveExistingPayloadType( + &payload_type_map_, payload_name, payload_name_length, frequency, channels, + rate); Payload* payload = NULL; - // save the RED payload type - // used in both audio and video - if (StringCompare(payloadName,"red",3)) { - _redPayloadType = payloadType; + // Save the RED payload type. Used in both audio and video. + if (StringCompare(payload_name, "red", 3)) { + red_payload_type_ = payload_type; payload = new Payload; payload->audio = false; payload->name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; - strncpy(payload->name, payloadName, RTP_PAYLOAD_NAME_SIZE - 1); + strncpy(payload->name, payload_name, RTP_PAYLOAD_NAME_SIZE - 1); } else { - payload = _rtpMediaReceiver->CreatePayloadType( - payloadName, payloadType, frequency, channels, rate); + payload = rtp_media_receiver_->CreatePayloadType( + payload_name, payload_type, frequency, channels, rate); } if (payload == NULL) { - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, - "%s filed to register payload", + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, + "%s failed to register payload", __FUNCTION__); return -1; } - _payloadTypeMap[payloadType] = payload; + payload_type_map_[payload_type] = payload; - // Successful set of payload type, clear the value of last receivedPT, - // since it might mean something else - _lastReceivedPayloadType = -1; - _lastReceivedMediaPayloadType = -1; + // Successful set of payload type, clear the value of last received payload + // type since it might mean something else. + last_received_payload_type_ = -1; + last_received_media_payload_type_ = -1; return 0; } WebRtc_Word32 RTPReceiver::DeRegisterReceivePayload( - const WebRtc_Word8 payloadType) { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + const WebRtc_Word8 payload_type) { + CriticalSectionScoped lock(critical_section_rtp_receiver_); std::map::iterator it = - _payloadTypeMap.find(payloadType); + payload_type_map_.find(payload_type); - if (it == _payloadTypeMap.end()) { - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, - "%s failed to find payloadType:%d", - __FUNCTION__, payloadType); + if (it == payload_type_map_.end()) { + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, + "%s failed to find payload_type:%d", + __FUNCTION__, payload_type); return -1; } delete it->second; - _payloadTypeMap.erase(it); + payload_type_map_.erase(it); return 0; } WebRtc_Word32 RTPReceiver::ReceivePayloadType( - const char payloadName[RTP_PAYLOAD_NAME_SIZE], + const char payload_name[RTP_PAYLOAD_NAME_SIZE], const WebRtc_UWord32 frequency, const WebRtc_UWord8 channels, const WebRtc_UWord32 rate, - WebRtc_Word8* payloadType) const { - if (payloadType == NULL) { - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, + WebRtc_Word8* payload_type) const { + if (payload_type == NULL) { + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, "%s invalid argument", __FUNCTION__); return -1; } - size_t payloadNameLength = strlen(payloadName); + size_t payload_name_length = strlen(payload_name); - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + CriticalSectionScoped lock(critical_section_rtp_receiver_); std::map::const_iterator it = - _payloadTypeMap.begin(); + payload_type_map_.begin(); - while (it != _payloadTypeMap.end()) { + while (it != payload_type_map_.end()) { Payload* payload = it->second; assert(payload); - size_t nameLength = strlen(payload->name); - if (payloadNameLength == nameLength && - StringCompare(payload->name, payloadName, payloadNameLength)) { - // name match - if( payload->audio) { + size_t name_length = strlen(payload->name); + if (payload_name_length == name_length && + StringCompare(payload->name, payload_name, payload_name_length)) { + // Name matches. + if (payload->audio) { if (rate == 0) { - // [default] audio, check freq and channels + // [default] audio, check freq and channels. if (payload->typeSpecific.Audio.frequency == frequency && payload->typeSpecific.Audio.channels == channels) { - *payloadType = it->first; + *payload_type = it->first; return 0; } } else { - // audio, check freq, channels and rate - if( payload->typeSpecific.Audio.frequency == frequency && + // Non-default audio, check freq, channels and rate. + if (payload->typeSpecific.Audio.frequency == frequency && payload->typeSpecific.Audio.channels == channels && payload->typeSpecific.Audio.rate == rate) { // extra rate condition added - *payloadType = it->first; + *payload_type = it->first; return 0; } } } else { - // video - *payloadType = it->first; + // Video. + *payload_type = it->first; return 0; } } @@ -444,74 +411,74 @@ WebRtc_Word32 RTPReceiver::ReceivePayloadType( } WebRtc_Word32 RTPReceiver::ReceivePayload( - const WebRtc_Word8 payloadType, - char payloadName[RTP_PAYLOAD_NAME_SIZE], + const WebRtc_Word8 payload_type, + char payload_name[RTP_PAYLOAD_NAME_SIZE], WebRtc_UWord32* frequency, WebRtc_UWord8* channels, WebRtc_UWord32* rate) const { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + CriticalSectionScoped lock(critical_section_rtp_receiver_); std::map::const_iterator it = - _payloadTypeMap.find(payloadType); + payload_type_map_.find(payload_type); - if (it == _payloadTypeMap.end()) { + if (it == payload_type_map_.end()) { return -1; } Payload* payload = it->second; assert(payload); - if(frequency) { - if(payload->audio) { + if (frequency) { + if (payload->audio) { *frequency = payload->typeSpecific.Audio.frequency; } else { *frequency = kDefaultVideoFrequency; } } if (channels) { - if(payload->audio) { + if (payload->audio) { *channels = payload->typeSpecific.Audio.channels; } else { *channels = 1; } } if (rate) { - if(payload->audio) { + if (payload->audio) { *rate = payload->typeSpecific.Audio.rate; } else { assert(false); *rate = 0; } } - if (payloadName) { - payloadName[RTP_PAYLOAD_NAME_SIZE - 1] = 0; - strncpy(payloadName, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); + if (payload_name) { + payload_name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; + strncpy(payload_name, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); } return 0; } WebRtc_Word32 RTPReceiver::RemotePayload( - char payloadName[RTP_PAYLOAD_NAME_SIZE], - WebRtc_Word8* payloadType, - WebRtc_UWord32* frequency, - WebRtc_UWord8* channels) const { - if(_lastReceivedPayloadType == -1) { - WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, + char payload_name[RTP_PAYLOAD_NAME_SIZE], + WebRtc_Word8* payload_type, + WebRtc_UWord32* frequency, + WebRtc_UWord8* channels) const { + if (last_received_payload_type_ == -1) { + WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, "%s invalid state", __FUNCTION__); return -1; } std::map::const_iterator it = - _payloadTypeMap.find(_lastReceivedPayloadType); + payload_type_map_.find(last_received_payload_type_); - if (it == _payloadTypeMap.end()) { + if (it == payload_type_map_.end()) { return -1; } Payload* payload = it->second; assert(payload); - payloadName[RTP_PAYLOAD_NAME_SIZE - 1] = 0; - strncpy(payloadName, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); + payload_name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; + strncpy(payload_name, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); - if (payloadType) { - *payloadType = _lastReceivedPayloadType; + if (payload_type) { + *payload_type = last_received_payload_type_; } if (frequency) { if (payload->audio) { @@ -530,138 +497,126 @@ WebRtc_Word32 RTPReceiver::RemotePayload( return 0; } -WebRtc_Word32 -RTPReceiver::RegisterRtpHeaderExtension(const RTPExtensionType type, - const WebRtc_UWord8 id) -{ - CriticalSectionScoped cs(_criticalSectionRTPReceiver); - return _rtpHeaderExtensionMap.Register(type, id); +WebRtc_Word32 RTPReceiver::RegisterRtpHeaderExtension( + const RTPExtensionType type, + const WebRtc_UWord8 id) { + CriticalSectionScoped cs(critical_section_rtp_receiver_); + return rtp_header_extension_map_.Register(type, id); } -WebRtc_Word32 -RTPReceiver::DeregisterRtpHeaderExtension(const RTPExtensionType type) -{ - CriticalSectionScoped cs(_criticalSectionRTPReceiver); - return _rtpHeaderExtensionMap.Deregister(type); +WebRtc_Word32 RTPReceiver::DeregisterRtpHeaderExtension( + const RTPExtensionType type) { + CriticalSectionScoped cs(critical_section_rtp_receiver_); + return rtp_header_extension_map_.Deregister(type); } -void RTPReceiver::GetHeaderExtensionMapCopy(RtpHeaderExtensionMap* map) const -{ - CriticalSectionScoped cs(_criticalSectionRTPReceiver); - _rtpHeaderExtensionMap.GetCopy(map); +void RTPReceiver::GetHeaderExtensionMapCopy(RtpHeaderExtensionMap* map) const { + CriticalSectionScoped cs(critical_section_rtp_receiver_); + rtp_header_extension_map_.GetCopy(map); } -NACKMethod -RTPReceiver::NACK() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _nackMethod; +NACKMethod RTPReceiver::NACK() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return nack_method_; } - // Turn negative acknowledgement requests on/off -WebRtc_Word32 -RTPReceiver::SetNACKStatus(const NACKMethod method) -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - _nackMethod = method; - return 0; +// Turn negative acknowledgment requests on/off. +WebRtc_Word32 RTPReceiver::SetNACKStatus(const NACKMethod method) { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + nack_method_ = method; + return 0; } void RTPReceiver::SetRTXStatus(const bool enable, - const WebRtc_UWord32 SSRC) { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - _RTX = enable; - _ssrcRTX = SSRC; + const WebRtc_UWord32 ssrc) { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + rtx_ = enable; + ssrc_rtx_ = ssrc; } -void RTPReceiver::RTXStatus(bool* enable, WebRtc_UWord32* SSRC) const { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - *enable = _RTX; - *SSRC = _ssrcRTX; +void RTPReceiver::RTXStatus(bool* enable, WebRtc_UWord32* ssrc) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + *enable = rtx_; + *ssrc = ssrc_rtx_; } -WebRtc_UWord32 -RTPReceiver::SSRC() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _SSRC; +WebRtc_UWord32 RTPReceiver::SSRC() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return ssrc_; } - // Get remote CSRC -WebRtc_Word32 -RTPReceiver::CSRCs( WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize]) const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); +// Get remote CSRC. +WebRtc_Word32 RTPReceiver::CSRCs( + WebRtc_UWord32 array_of_csrcs[kRtpCsrcSize]) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); - assert(_numCSRCs <= kRtpCsrcSize); + assert(num_csrcs_ <= kRtpCsrcSize); - if(_numCSRCs >0) - { - memcpy(arrOfCSRC, _currentRemoteCSRC, sizeof(WebRtc_UWord32)*_numCSRCs); - } - return _numCSRCs; + if (num_csrcs_ > 0) { + memcpy(array_of_csrcs, current_remote_csrc_, + sizeof(WebRtc_UWord32)*num_csrcs_); + } + return num_csrcs_; } -WebRtc_Word32 -RTPReceiver::Energy( WebRtc_UWord8 arrOfEnergy[kRtpCsrcSize]) const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); +WebRtc_Word32 RTPReceiver::Energy( + WebRtc_UWord8 array_of_energy[kRtpCsrcSize]) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); - assert(_numEnergy <= kRtpCsrcSize); + assert(num_energy_ <= kRtpCsrcSize); - if(_numEnergy >0) - { - memcpy(arrOfEnergy, _currentRemoteEnergy, sizeof(WebRtc_UWord8)*_numCSRCs); - } - return _numEnergy; + if (num_energy_ > 0) { + memcpy(array_of_energy, current_remote_energy_, + sizeof(WebRtc_UWord8)*num_csrcs_); + } + return num_energy_; } WebRtc_Word32 RTPReceiver::IncomingRTPPacket( - WebRtcRTPHeader* rtp_header, - const WebRtc_UWord8* packet, - const WebRtc_UWord16 packet_length) { - // rtp_header contains the parsed RTP header. - // Adjust packet length w r t RTP padding. + WebRtcRTPHeader* rtp_header, + const WebRtc_UWord8* packet, + const WebRtc_UWord16 packet_length) { + // The rtp_header argument contains the parsed RTP header. int length = packet_length - rtp_header->header.paddingLength; - // length sanity + // Sanity check. if ((length - rtp_header->header.headerLength) < 0) { - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, - "%s invalid argument", - __FUNCTION__); - return -1; + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, + "%s invalid argument", + __FUNCTION__); + return -1; } - if (_RTX) { - if (_ssrcRTX == rtp_header->header.ssrc) { + if (rtx_) { + if (ssrc_rtx_ == rtp_header->header.ssrc) { // Sanity check. if (rtp_header->header.headerLength + 2 > packet_length) { return -1; } - rtp_header->header.ssrc = _SSRC; + rtp_header->header.ssrc = ssrc_; rtp_header->header.sequenceNumber = - (packet[rtp_header->header.headerLength] << 8) + - packet[1 + rtp_header->header.headerLength]; + (packet[rtp_header->header.headerLength] << 8) + + packet[1 + rtp_header->header.headerLength]; // Count the RTX header as part of the RTP header. rtp_header->header.headerLength += 2; } } - if (_useSSRCFilter) { - if (rtp_header->header.ssrc != _SSRCFilter) { - WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, + if (use_ssrc_filter_) { + if (rtp_header->header.ssrc != ssrc_filter_) { + WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, "%s drop packet due to SSRC filter", __FUNCTION__); return -1; } } - if (_lastReceiveTime == 0) { - // trigger only once - CriticalSectionScoped lock(_criticalSectionCbs); - if (_cbRtpFeedback) { + if (last_receive_time_ == 0) { + // Trigger only once. + CriticalSectionScoped lock(critical_section_cbs_); + if (cb_rtp_feedback_) { if (length - rtp_header->header.headerLength == 0) { - // keepalive packet - _cbRtpFeedback->OnReceivedPacket(_id, kPacketKeepAlive); + // Keep-alive packet. + cb_rtp_feedback_->OnReceivedPacket(id_, kPacketKeepAlive); } else { - _cbRtpFeedback->OnReceivedPacket(_id, kPacketRtp); + cb_rtp_feedback_->OnReceivedPacket(id_, kPacketRtp); } } } @@ -669,25 +624,24 @@ WebRtc_Word32 RTPReceiver::IncomingRTPPacket( if (length > 0) { first_payload_byte = packet[rtp_header->header.headerLength]; } - // trigger our callbacks + // Trigger our callbacks. CheckSSRCChanged(rtp_header); bool is_red = false; - ModuleRTPUtility::PayloadUnion specificPayload = {}; + ModuleRTPUtility::PayloadUnion specific_payload = {}; if (CheckPayloadChanged(rtp_header, first_payload_byte, is_red, - &specificPayload) == -1) { - if (length - rtp_header->header.headerLength == 0) - { - // ok keepalive packet - WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, + &specific_payload) == -1) { + if (length - rtp_header->header.headerLength == 0) { + // OK, keep-alive packet. + WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, id_, "%s received keepalive", __FUNCTION__); return 0; } - WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, + WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, "%s received invalid payloadtype", __FUNCTION__); return -1; @@ -695,387 +649,366 @@ WebRtc_Word32 RTPReceiver::IncomingRTPPacket( CheckCSRC(rtp_header); WebRtc_UWord16 payload_data_length = - ModuleRTPUtility::GetPayloadDataLength(rtp_header, packet_length); + ModuleRTPUtility::GetPayloadDataLength(rtp_header, packet_length); - WebRtc_Word32 retVal = _rtpMediaReceiver->ParseRtpPacket( - rtp_header, specificPayload, is_red, packet, - packet_length, _clock.GetTimeInMS()); + WebRtc_Word32 ret_val = rtp_media_receiver_->ParseRtpPacket( + rtp_header, specific_payload, is_red, packet, + packet_length, clock_.GetTimeInMS()); - if(retVal < 0) { - return retVal; + if (ret_val < 0) { + return ret_val; } - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + CriticalSectionScoped lock(critical_section_rtp_receiver_); - // this compare to _receivedSeqMax - // we store the last received after we have done the callback + // This compares to received_seq_max_. We store the last received after we + // have done the callback. bool old_packet = RetransmitOfOldPacket(rtp_header->header.sequenceNumber, rtp_header->header.timestamp); - // this updates _receivedSeqMax and other members + // This updates received_seq_max_ and other members. UpdateStatistics(rtp_header, payload_data_length, old_packet); - // Need to be updated after RetransmitOfOldPacket & - // RetransmitOfOldPacketUpdateStatistics - _lastReceiveTime = _clock.GetTimeInMS(); - _lastReceivedPayloadLength = payload_data_length; + // Need to be updated after RetransmitOfOldPacket and + // RetransmitOfOldPacketUpdateStatistics. + last_receive_time_ = clock_.GetTimeInMS(); + last_received_payload_length_ = payload_data_length; if (!old_packet) { - if (_lastReceivedTimestamp != rtp_header->header.timestamp) { - _lastReceivedTimestamp = rtp_header->header.timestamp; - _lastReceivedFrameTimeMs = _clock.GetTimeInMS(); + if (last_received_timestamp_ != rtp_header->header.timestamp) { + last_received_timestamp_ = rtp_header->header.timestamp; + last_received_frame_time_ms_ = clock_.GetTimeInMS(); } - _lastReceivedSequenceNumber = rtp_header->header.sequenceNumber; - _lastReceivedTransmissionTimeOffset = - rtp_header->extension.transmissionTimeOffset; + last_received_sequence_number_ = rtp_header->header.sequenceNumber; + last_received_transmission_time_offset_ = + rtp_header->extension.transmissionTimeOffset; } - return retVal; + return ret_val; } -// must not have critsect when called -WebRtc_Word32 -RTPReceiver::CallbackOfReceivedPayloadData(const WebRtc_UWord8* payloadData, - const WebRtc_UWord16 payloadSize, - const WebRtcRTPHeader* rtpHeader) -{ - CriticalSectionScoped lock(_criticalSectionCbs); - if(_cbRtpData) - { - return _cbRtpData->OnReceivedPayloadData(payloadData, payloadSize, rtpHeader); - } - return -1; +// Implementation note: must not hold critsect when called! +WebRtc_Word32 RTPReceiver::CallbackOfReceivedPayloadData( + const WebRtc_UWord8* payload_data, + const WebRtc_UWord16 payload_size, + const WebRtcRTPHeader* rtp_header) { + CriticalSectionScoped lock(critical_section_cbs_); + if (cb_rtp_data_) { + return cb_rtp_data_->OnReceivedPayloadData(payload_data, payload_size, + rtp_header); + } + return -1; } -// we already have the _criticalSectionRTPReceiver critsect when we call this -void -RTPReceiver::UpdateStatistics(const WebRtcRTPHeader* rtpHeader, - const WebRtc_UWord16 bytes, - const bool oldPacket) -{ - WebRtc_UWord32 freq = _rtpMediaReceiver->GetFrequencyHz(); +// Implementation note: we expect to have the critical_section_rtp_receiver_ +// critsect when we call this. +void RTPReceiver::UpdateStatistics(const WebRtcRTPHeader* rtp_header, + const WebRtc_UWord16 bytes, + const bool old_packet) { + WebRtc_UWord32 frequency_hz = rtp_media_receiver_->GetFrequencyHz(); - Bitrate::Update(bytes); + Bitrate::Update(bytes); - _receivedByteCount += bytes; + received_byte_count_ += bytes; - if (_receivedSeqMax == 0 && _receivedSeqWraps == 0) - { - // First received report - _receivedSeqFirst = rtpHeader->header.sequenceNumber; - _receivedSeqMax = rtpHeader->header.sequenceNumber; - _receivedInorderPacketCount = 1; - _localTimeLastReceivedTimestamp = - GetCurrentRTP(&_clock, freq); //time in samples - return; + if (received_seq_max_ == 0 && received_seq_wraps_ == 0) { + // This is the first received report. + received_seq_first_ = rtp_header->header.sequenceNumber; + received_seq_max_ = rtp_header->header.sequenceNumber; + received_inorder_packet_count_ = 1; + local_time_last_received_timestamp_ = + GetCurrentRTP(&clock_, frequency_hz); // Time in samples. + return; + } + + // Count only the new packets received. + if (InOrderPacket(rtp_header->header.sequenceNumber)) { + const WebRtc_UWord32 RTPtime = + GetCurrentRTP(&clock_, frequency_hz); // Time in samples. + received_inorder_packet_count_++; + + // Wrong if we use RetransmitOfOldPacket. + WebRtc_Word32 seq_diff = + rtp_header->header.sequenceNumber - received_seq_max_; + if (seq_diff < 0) { + // Wrap around detected. + received_seq_wraps_++; } + // new max + received_seq_max_ = rtp_header->header.sequenceNumber; - // count only the new packets received - if(InOrderPacket(rtpHeader->header.sequenceNumber)) - { - const WebRtc_UWord32 RTPtime = - GetCurrentRTP(&_clock, freq); //time in samples - _receivedInorderPacketCount++; + if (rtp_header->header.timestamp != last_received_timestamp_ && + received_inorder_packet_count_ > 1) { + WebRtc_Word32 time_diff_samples = + (RTPtime - local_time_last_received_timestamp_) - + (rtp_header->header.timestamp - last_received_timestamp_); - // wrong if we use RetransmitOfOldPacket - WebRtc_Word32 seqDiff = rtpHeader->header.sequenceNumber - _receivedSeqMax; - if (seqDiff < 0) - { - // Wrap around detected - _receivedSeqWraps++; - } - // new max - _receivedSeqMax = rtpHeader->header.sequenceNumber; + time_diff_samples = abs(time_diff_samples); - if (rtpHeader->header.timestamp != _lastReceivedTimestamp && - _receivedInorderPacketCount > 1) - { - WebRtc_Word32 timeDiffSamples = (RTPtime - _localTimeLastReceivedTimestamp) - - (rtpHeader->header.timestamp - _lastReceivedTimestamp); + // lib_jingle sometimes deliver crazy jumps in TS for the same stream. + // If this happens, don't update jitter value. Use 5 secs video frequency + // as the treshold. + if (time_diff_samples < 450000) { + // Note we calculate in Q4 to avoid using float. + WebRtc_Word32 jitter_diff_q4 = (time_diff_samples << 4) - jitter_q4_; + jitter_q4_ += ((jitter_diff_q4 + 8) >> 4); + } - timeDiffSamples = abs(timeDiffSamples); + // Extended jitter report, RFC 5450. + // Actual network jitter, excluding the source-introduced jitter. + WebRtc_Word32 time_diff_samples_ext = + (RTPtime - local_time_last_received_timestamp_) - + ((rtp_header->header.timestamp + + rtp_header->extension.transmissionTimeOffset) - + (last_received_timestamp_ + + last_received_transmission_time_offset_)); - // libJingle sometimes deliver crazy jumps in TS for the same stream - // If this happen don't update jitter value - if(timeDiffSamples < 450000) // Use 5 secs video frequency as border - { - // note we calculate in Q4 to avoid using float - WebRtc_Word32 jitterDiffQ4 = (timeDiffSamples << 4) - _jitterQ4; - _jitterQ4 += ((jitterDiffQ4 + 8) >> 4); - } + time_diff_samples_ext = abs(time_diff_samples_ext); - // Extended jitter report, RFC 5450. - // Actual network jitter, excluding the source-introduced jitter. - WebRtc_Word32 timeDiffSamplesExt = - (RTPtime - _localTimeLastReceivedTimestamp) - - ((rtpHeader->header.timestamp + - rtpHeader->extension.transmissionTimeOffset) - - (_lastReceivedTimestamp + - _lastReceivedTransmissionTimeOffset)); - - timeDiffSamplesExt = abs(timeDiffSamplesExt); - - if(timeDiffSamplesExt < 450000) // Use 5 secs video freq as border - { - // note we calculate in Q4 to avoid using float - WebRtc_Word32 jitterDiffQ4TransmissionTimeOffset = - (timeDiffSamplesExt << 4) - _jitterQ4TransmissionTimeOffset; - _jitterQ4TransmissionTimeOffset += - ((jitterDiffQ4TransmissionTimeOffset + 8) >> 4); - } - } - _localTimeLastReceivedTimestamp = RTPtime; - } else - { - if(oldPacket) - { - _receivedOldPacketCount++; - }else - { - _receivedInorderPacketCount++; - } + if (time_diff_samples_ext < 450000) { + WebRtc_Word32 jitter_diffQ4TransmissionTimeOffset = + (time_diff_samples_ext << 4) - jitter_q4_transmission_time_offset_; + jitter_q4_transmission_time_offset_ += + ((jitter_diffQ4TransmissionTimeOffset + 8) >> 4); + } } + local_time_last_received_timestamp_ = RTPtime; + } else { + if (old_packet) { + received_old_packet_count_++; + } else { + received_inorder_packet_count_++; + } + } - WebRtc_UWord16 packetOH = rtpHeader->header.headerLength + rtpHeader->header.paddingLength; + WebRtc_UWord16 packet_oh = + rtp_header->header.headerLength + rtp_header->header.paddingLength; - // our measured overhead - // filter from RFC 5104 4.2.1.2 - // avg_OH (new) = 15/16*avg_OH (old) + 1/16*pckt_OH, - _receivedPacketOH = (15*_receivedPacketOH + packetOH) >> 4; + // Our measured overhead. Filter from RFC 5104 4.2.1.2: + // avg_OH (new) = 15/16*avg_OH (old) + 1/16*pckt_OH, + received_packet_oh_ = (15 * received_packet_oh_ + packet_oh) >> 4; } -// we already have the _criticalSectionRTPReceiver critsect when we call this +// Implementation note: we expect to have the critical_section_rtp_receiver_ +// critsect when we call this. bool RTPReceiver::RetransmitOfOldPacket( - const WebRtc_UWord16 sequenceNumber, - const WebRtc_UWord32 rtpTimeStamp) const { - if (InOrderPacket(sequenceNumber)) { + const WebRtc_UWord16 sequence_number, + const WebRtc_UWord32 rtp_time_stamp) const { + if (InOrderPacket(sequence_number)) { return false; } - WebRtc_UWord32 frequencyKHz = _rtpMediaReceiver->GetFrequencyHz() / 1000; - WebRtc_Word64 timeDiffMS = _clock.GetTimeInMS() - _lastReceiveTime; + WebRtc_UWord32 frequency_khz = rtp_media_receiver_->GetFrequencyHz() / 1000; + WebRtc_Word64 time_diff_ms = clock_.GetTimeInMS() - last_receive_time_; + // Diff in time stamp since last received in order. - WebRtc_Word32 rtpTimeStampDiffMS = static_cast( - rtpTimeStamp - _lastReceivedTimestamp) / frequencyKHz; + WebRtc_Word32 rtp_time_stamp_diff_ms = + static_cast(rtp_time_stamp - last_received_timestamp_) / + frequency_khz; + + WebRtc_UWord16 min_rtt = 0; + WebRtc_Word32 max_delay_ms = 0; + rtp_rtcp_.RTT(ssrc_, NULL, NULL, &min_rtt, NULL); + if (min_rtt == 0) { + // Jitter variance in samples. + float jitter = jitter_q4_ >> 4; - WebRtc_UWord16 minRTT = 0; - WebRtc_Word32 maxDelayMs = 0; - _rtpRtcp.RTT(_SSRC, NULL, NULL, &minRTT, NULL); - if (minRTT == 0) { - float jitter = _jitterQ4 >> 4; // Jitter variance in samples. // Jitter standard deviation in samples. - float jitterStd = sqrt(jitter); - // 2 times the std deviation => 95% confidence. - // And transform to ms by dividing by the frequency in kHz. - maxDelayMs = static_cast((2 * jitterStd) / frequencyKHz); + float jitter_std = sqrt(jitter); - // Min maxDelayMs is 1. - if (maxDelayMs == 0) { - maxDelayMs = 1; + // 2 times the standard deviation => 95% confidence. + // And transform to milliseconds by dividing by the frequency in kHz. + max_delay_ms = static_cast((2 * jitter_std) / frequency_khz); + + // Min max_delay_ms is 1. + if (max_delay_ms == 0) { + max_delay_ms = 1; } } else { - maxDelayMs = (minRTT / 3) + 1; + max_delay_ms = (min_rtt / 3) + 1; } - if (timeDiffMS > rtpTimeStampDiffMS + maxDelayMs) { + if (time_diff_ms > rtp_time_stamp_diff_ms + max_delay_ms) { return true; } return false; } -bool -RTPReceiver::InOrderPacket(const WebRtc_UWord16 sequenceNumber) const -{ - if(_receivedSeqMax >= sequenceNumber) - { - if(!(_receivedSeqMax > 0xff00 && sequenceNumber < 0x0ff ))//detect wrap around - { - if(_receivedSeqMax - NACK_PACKETS_MAX_SIZE > sequenceNumber) - { - // we have a restart of the remote side - }else - { - // we received a retransmit of a packet we already have - return false; - } - } - }else - { - // check for a wrap - if(sequenceNumber > 0xff00 && _receivedSeqMax < 0x0ff )//detect wrap around - { - if(_receivedSeqMax - NACK_PACKETS_MAX_SIZE > sequenceNumber) - { - // we have a restart of the remote side - }else - { - // we received a retransmit of a packet we already have - return false; - } - } +bool RTPReceiver::InOrderPacket(const WebRtc_UWord16 sequence_number) const { + if (received_seq_max_ >= sequence_number) { + // Detect wrap-around. + if (!(received_seq_max_ > 0xff00 && sequence_number < 0x0ff)) { + if (received_seq_max_ - NACK_PACKETS_MAX_SIZE > sequence_number) { + // We have a restart of the remote side. + } else { + // we received a retransmit of a packet we already have. + return false; + } } - return true; + } else { + // Detect wrap-around. + if (sequence_number > 0xff00 && received_seq_max_ < 0x0ff) { + if (received_seq_max_ - NACK_PACKETS_MAX_SIZE > sequence_number) { + // We have a restart of the remote side + } else { + // We received a retransmit of a packet we already have + return false; + } + } + } + return true; } -WebRtc_UWord16 -RTPReceiver::SequenceNumber() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _lastReceivedSequenceNumber; +WebRtc_UWord16 RTPReceiver::SequenceNumber() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return last_received_sequence_number_; } -WebRtc_UWord32 -RTPReceiver::TimeStamp() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _lastReceivedTimestamp; +WebRtc_UWord32 RTPReceiver::TimeStamp() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return last_received_timestamp_; } -int32_t RTPReceiver::LastReceivedTimeMs() const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - return _lastReceivedFrameTimeMs; +int32_t RTPReceiver::LastReceivedTimeMs() const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + return last_received_frame_time_ms_; } WebRtc_UWord32 RTPReceiver::PayloadTypeToPayload( - const WebRtc_UWord8 payloadType, - Payload*& payload) const { + const WebRtc_UWord8 payload_type, + Payload*& payload) const { std::map::const_iterator it = - _payloadTypeMap.find(payloadType); + payload_type_map_.find(payload_type); - // check that this is a registered payload type - if (it == _payloadTypeMap.end()) { + // Check that this is a registered payload type. + if (it == payload_type_map_.end()) { return -1; } payload = it->second; return 0; } -// timeStamp of the last incoming packet that is the first packet of its frame -WebRtc_Word32 -RTPReceiver::EstimatedRemoteTimeStamp(WebRtc_UWord32& timestamp) const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - WebRtc_UWord32 freq = _rtpMediaReceiver->GetFrequencyHz(); +// Compute time stamp of the last incoming packet that is the first packet of +// its frame. +WebRtc_Word32 RTPReceiver::EstimatedRemoteTimeStamp( + WebRtc_UWord32& timestamp) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + WebRtc_UWord32 frequency_hz = rtp_media_receiver_->GetFrequencyHz(); - if(_localTimeLastReceivedTimestamp == 0) - { - WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, "%s invalid state", __FUNCTION__); - return -1; - } - //time in samples - WebRtc_UWord32 diff = GetCurrentRTP(&_clock, freq) - - _localTimeLastReceivedTimestamp; - - timestamp = _lastReceivedTimestamp + diff; - return 0; -} - - // get the currently configured SSRC filter -WebRtc_Word32 -RTPReceiver::SSRCFilter(WebRtc_UWord32& allowedSSRC) const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - if(_useSSRCFilter) - { - allowedSSRC = _SSRCFilter; - return 0; - } - WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, "%s invalid state", __FUNCTION__); + if (local_time_last_received_timestamp_ == 0) { + WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, + "%s invalid state", __FUNCTION__); return -1; + } + // Time in samples. + WebRtc_UWord32 diff = GetCurrentRTP(&clock_, frequency_hz) - + local_time_last_received_timestamp_; + + timestamp = last_received_timestamp_ + diff; + return 0; } - // set a SSRC to be used as a filter for incoming RTP streams -WebRtc_Word32 -RTPReceiver::SetSSRCFilter(const bool enable, const WebRtc_UWord32 allowedSSRC) -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); - - _useSSRCFilter = enable; - if(enable) - { - _SSRCFilter = allowedSSRC; - } else - { - _SSRCFilter = 0; - } +// Get the currently configured SSRC filter. +WebRtc_Word32 RTPReceiver::SSRCFilter(WebRtc_UWord32& allowed_ssrc) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + if (use_ssrc_filter_) { + allowed_ssrc = ssrc_filter_; return 0; + } + WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, + "%s invalid state", __FUNCTION__); + return -1; } -// no criticalsection when called -void RTPReceiver::CheckSSRCChanged(const WebRtcRTPHeader* rtpHeader) { - bool newSSRC = false; - bool reInitializeDecoder = false; - char payloadName[RTP_PAYLOAD_NAME_SIZE]; - WebRtc_UWord32 frequency = kDefaultVideoFrequency; // default video freq +// Set a SSRC to be used as a filter for incoming RTP streams. +WebRtc_Word32 RTPReceiver::SetSSRCFilter( + const bool enable, const WebRtc_UWord32 allowed_ssrc) { + CriticalSectionScoped lock(critical_section_rtp_receiver_); + + use_ssrc_filter_ = enable; + if (enable) { + ssrc_filter_ = allowed_ssrc; + } else { + ssrc_filter_ = 0; + } + return 0; +} + +// Implementation note: must not hold critsect when called. +void RTPReceiver::CheckSSRCChanged(const WebRtcRTPHeader* rtp_header) { + bool new_ssrc = false; + bool re_initialize_decoder = false; + char payload_name[RTP_PAYLOAD_NAME_SIZE]; + WebRtc_UWord32 frequency = kDefaultVideoFrequency; WebRtc_UWord8 channels = 1; WebRtc_UWord32 rate = 0; { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + CriticalSectionScoped lock(critical_section_rtp_receiver_); - if (_SSRC != rtpHeader->header.ssrc || - (_lastReceivedPayloadType == -1 && _SSRC == 0)) { - // we need the _payloadType to make the call if the remote SSRC is 0 - newSSRC = true; + if (ssrc_ != rtp_header->header.ssrc || + (last_received_payload_type_ == -1 && ssrc_ == 0)) { + // We need the payload_type_ to make the call if the remote SSRC is 0. + new_ssrc = true; - // reset last report ResetStatistics(); - _lastReceivedTimestamp = 0; - _lastReceivedSequenceNumber = 0; - _lastReceivedTransmissionTimeOffset = 0; - _lastReceivedFrameTimeMs = 0; + last_received_timestamp_ = 0; + last_received_sequence_number_ = 0; + last_received_transmission_time_offset_ = 0; + last_received_frame_time_ms_ = 0; - if (_SSRC) { // do we have a SSRC? then the stream is restarted - // if we have the same codec? reinit decoder - if (rtpHeader->header.payloadType == _lastReceivedPayloadType) { - reInitializeDecoder = true; + // Do we have a SSRC? Then the stream is restarted. + if (ssrc_) { + // Do we have the same codec? Then re-initialize coder. + if (rtp_header->header.payloadType == last_received_payload_type_) { + re_initialize_decoder = true; std::map::iterator it = - _payloadTypeMap.find(rtpHeader->header.payloadType); + payload_type_map_.find(rtp_header->header.payloadType); - if (it == _payloadTypeMap.end()) { + if (it == payload_type_map_.end()) { return; } Payload* payload = it->second; assert(payload); - payloadName[RTP_PAYLOAD_NAME_SIZE - 1] = 0; - strncpy(payloadName, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); - if(payload->audio) { + payload_name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; + strncpy(payload_name, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); + if (payload->audio) { frequency = payload->typeSpecific.Audio.frequency; - channels = payload->typeSpecific.Audio.channels; + channels = payload->typeSpecific.Audio.channels; rate = payload->typeSpecific.Audio.rate; } else { frequency = kDefaultVideoFrequency; } } } - _SSRC = rtpHeader->header.ssrc; + ssrc_ = rtp_header->header.ssrc; } } - if(newSSRC) { - // we need to get this to our RTCP sender and receiver - // need to do this outside critical section - _rtpRtcp.SetRemoteSSRC(rtpHeader->header.ssrc); + if (new_ssrc) { + // We need to get this to our RTCP sender and receiver. + // We need to do this outside critical section. + rtp_rtcp_.SetRemoteSSRC(rtp_header->header.ssrc); } - CriticalSectionScoped lock(_criticalSectionCbs); - if(_cbRtpFeedback) { - if(newSSRC) { - _cbRtpFeedback->OnIncomingSSRCChanged(_id, rtpHeader->header.ssrc); + CriticalSectionScoped lock(critical_section_cbs_); + if (cb_rtp_feedback_) { + if (new_ssrc) { + cb_rtp_feedback_->OnIncomingSSRCChanged(id_, rtp_header->header.ssrc); } - if(reInitializeDecoder) { - if (-1 == _cbRtpFeedback->OnInitializeDecoder(_id, - rtpHeader->header.payloadType, payloadName, frequency, channels, - rate)) { // new stream same codec - WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, + if (re_initialize_decoder) { + if (-1 == cb_rtp_feedback_->OnInitializeDecoder( + id_, rtp_header->header.payloadType, payload_name, frequency, + channels, rate)) { + // New stream, same codec. + WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, "Failed to create decoder for payload type:%d", - rtpHeader->header.payloadType); + rtp_header->header.payloadType); } } } } -// no criticalsection when called +// Implementation note: must not hold critsect when called. // TODO(phoglund): Move as much as possible of this code path into the media // specific receivers. Basically this method goes through a lot of trouble to // compute something which is only used by the media specific parts later. If @@ -1083,98 +1016,99 @@ void RTPReceiver::CheckSSRCChanged(const WebRtcRTPHeader* rtpHeader) { // media_specific interface (such as CheckPayloadChange, possibly get/set // last known payload). WebRtc_Word32 RTPReceiver::CheckPayloadChanged( - const WebRtcRTPHeader* rtpHeader, - const WebRtc_Word8 firstPayloadByte, - bool& isRED, - ModuleRTPUtility::PayloadUnion* specificPayload) { - bool reInitializeDecoder = false; + const WebRtcRTPHeader* rtp_header, + const WebRtc_Word8 first_payload_byte, + bool& is_red, + ModuleRTPUtility::PayloadUnion* specific_payload) { + bool re_initialize_decoder = false; - char payloadName[RTP_PAYLOAD_NAME_SIZE]; - WebRtc_Word8 payloadType = rtpHeader->header.payloadType; + char payload_name[RTP_PAYLOAD_NAME_SIZE]; + WebRtc_Word8 payload_type = rtp_header->header.payloadType; { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + CriticalSectionScoped lock(critical_section_rtp_receiver_); - if (payloadType != _lastReceivedPayloadType) { - if (REDPayloadType(payloadType)) { - // get the real codec payload type - payloadType = firstPayloadByte & 0x7f; - isRED = true; + if (payload_type != last_received_payload_type_) { + if (REDPayloadType(payload_type)) { + // Get the real codec payload type. + payload_type = first_payload_byte & 0x7f; + is_red = true; - if (REDPayloadType(payloadType)) { - // Invalid payload type, traced by caller. If we proceeded here, - // this would be set as |_lastReceivedPayloadType|, and we would no - // longer catch corrupt packets at this level. - return -1; + if (REDPayloadType(payload_type)) { + // Invalid payload type, traced by caller. If we proceeded here, + // this would be set as |_last_received_payload_type|, and we would no + // longer catch corrupt packets at this level. + return -1; } - //when we receive RED we need to check the real payload type - if (payloadType == _lastReceivedPayloadType) { - _rtpMediaReceiver->GetLastMediaSpecificPayload(specificPayload); + // When we receive RED we need to check the real payload type. + if (payload_type == last_received_payload_type_) { + rtp_media_receiver_->GetLastMediaSpecificPayload(specific_payload); return 0; } } - bool shouldResetStatistics = false; - bool shouldDiscardChanges = false; + bool should_reset_statistics = false; + bool should_discard_changes = false; - _rtpMediaReceiver->CheckPayloadChanged( - payloadType, specificPayload, &shouldResetStatistics, - &shouldDiscardChanges); + rtp_media_receiver_->CheckPayloadChanged( + payload_type, specific_payload, &should_reset_statistics, + &should_discard_changes); - if (shouldResetStatistics) { + if (should_reset_statistics) { ResetStatistics(); } - if (shouldDiscardChanges) { - isRED = false; + if (should_discard_changes) { + is_red = false; return 0; } std::map::iterator it = - _payloadTypeMap.find(payloadType); + payload_type_map_.find(payload_type); - // check that this is a registered payload type - if (it == _payloadTypeMap.end()) { + // Check that this is a registered payload type. + if (it == payload_type_map_.end()) { return -1; } Payload* payload = it->second; assert(payload); - payloadName[RTP_PAYLOAD_NAME_SIZE - 1] = 0; - strncpy(payloadName, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); + payload_name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; + strncpy(payload_name, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); - _lastReceivedPayloadType = payloadType; + last_received_payload_type_ = payload_type; - reInitializeDecoder = true; + re_initialize_decoder = true; - _rtpMediaReceiver->SetLastMediaSpecificPayload(payload->typeSpecific); - _rtpMediaReceiver->GetLastMediaSpecificPayload(specificPayload); + rtp_media_receiver_->SetLastMediaSpecificPayload(payload->typeSpecific); + rtp_media_receiver_->GetLastMediaSpecificPayload(specific_payload); - if(!payload->audio) { - if (VideoCodecType() == kRtpFecVideo) - { + if (!payload->audio) { + if (VideoCodecType() == kRtpFecVideo) { // Only reset the decoder on media packets. - reInitializeDecoder = false; + re_initialize_decoder = false; } else { - if (_lastReceivedMediaPayloadType == _lastReceivedPayloadType) { + if (last_received_media_payload_type_ == + last_received_payload_type_) { // Only reset the decoder if the media codec type has changed. - reInitializeDecoder = false; + re_initialize_decoder = false; } - _lastReceivedMediaPayloadType = _lastReceivedPayloadType; + last_received_media_payload_type_ = last_received_payload_type_; } } - if (reInitializeDecoder) { - // reset statistics + if (re_initialize_decoder) { ResetStatistics(); } } else { - _rtpMediaReceiver->GetLastMediaSpecificPayload(specificPayload); - isRED = false; + rtp_media_receiver_->GetLastMediaSpecificPayload(specific_payload); + is_red = false; } - } // end critsect - if (reInitializeDecoder) { - CriticalSectionScoped lock(_criticalSectionCbs); - if (_cbRtpFeedback) { - if (-1 == _rtpMediaReceiver->InvokeOnInitializeDecoder( - _cbRtpFeedback, _id, payloadType, payloadName, *specificPayload)) { + } // End critsect. + + if (re_initialize_decoder) { + CriticalSectionScoped lock(critical_section_cbs_); + if (cb_rtp_feedback_) { + if (-1 == rtp_media_receiver_->InvokeOnInitializeDecoder( + cb_rtp_feedback_, id_, payload_type, payload_name, + *specific_payload)) { return -1; // Wrong payload type. } } @@ -1182,345 +1116,308 @@ WebRtc_Word32 RTPReceiver::CheckPayloadChanged( return 0; } -// no criticalsection when called -void RTPReceiver::CheckCSRC(const WebRtcRTPHeader* rtpHeader) { - WebRtc_Word32 numCSRCsDiff = 0; - WebRtc_UWord32 oldRemoteCSRC[kRtpCsrcSize]; - WebRtc_UWord8 oldNumCSRCs = 0; +// Implementation note: must not hold critsect when called. +void RTPReceiver::CheckCSRC(const WebRtcRTPHeader* rtp_header) { + WebRtc_Word32 num_csrcs_diff = 0; + WebRtc_UWord32 old_remote_csrc[kRtpCsrcSize]; + WebRtc_UWord8 old_num_csrcs = 0; { - CriticalSectionScoped lock(_criticalSectionRTPReceiver); + CriticalSectionScoped lock(critical_section_rtp_receiver_); - if (_rtpReceiverAudio->TelephoneEventPayloadType( - rtpHeader->header.payloadType)) { - // Don't do this for DTMF packets + if (rtp_receiver_audio_->TelephoneEventPayloadType( + rtp_header->header.payloadType)) { + // Don't do this for DTMF packets. return; } - _numEnergy = rtpHeader->type.Audio.numEnergy; - if (rtpHeader->type.Audio.numEnergy > 0 && - rtpHeader->type.Audio.numEnergy <= kRtpCsrcSize) { - memcpy(_currentRemoteEnergy, - rtpHeader->type.Audio.arrOfEnergy, - rtpHeader->type.Audio.numEnergy); + num_energy_ = rtp_header->type.Audio.numEnergy; + if (rtp_header->type.Audio.numEnergy > 0 && + rtp_header->type.Audio.numEnergy <= kRtpCsrcSize) { + memcpy(current_remote_energy_, + rtp_header->type.Audio.arrOfEnergy, + rtp_header->type.Audio.numEnergy); } - oldNumCSRCs = _numCSRCs; - if (oldNumCSRCs > 0) { + old_num_csrcs = num_csrcs_; + if (old_num_csrcs > 0) { // Make a copy of old. - memcpy(oldRemoteCSRC, _currentRemoteCSRC, - _numCSRCs * sizeof(WebRtc_UWord32)); + memcpy(old_remote_csrc, current_remote_csrc_, + num_csrcs_ * sizeof(WebRtc_UWord32)); } - const WebRtc_UWord8 numCSRCs = rtpHeader->header.numCSRCs; - if ((numCSRCs > 0) && (numCSRCs <= kRtpCsrcSize)) { - // Copy new - memcpy(_currentRemoteCSRC, - rtpHeader->header.arrOfCSRCs, - numCSRCs * sizeof(WebRtc_UWord32)); + const WebRtc_UWord8 num_csrcs = rtp_header->header.numCSRCs; + if ((num_csrcs > 0) && (num_csrcs <= kRtpCsrcSize)) { + // Copy new. + memcpy(current_remote_csrc_, + rtp_header->header.arrOfCSRCs, + num_csrcs * sizeof(WebRtc_UWord32)); } - if (numCSRCs > 0 || oldNumCSRCs > 0) { - numCSRCsDiff = numCSRCs - oldNumCSRCs; - _numCSRCs = numCSRCs; // Update stored CSRCs. + if (num_csrcs > 0 || old_num_csrcs > 0) { + num_csrcs_diff = num_csrcs - old_num_csrcs; + num_csrcs_ = num_csrcs; // Update stored CSRCs. } else { // No change. return; } - } // End scoped CriticalSection. + } // End critsect. - CriticalSectionScoped lock(_criticalSectionCbs); - if (_cbRtpFeedback == NULL) { + CriticalSectionScoped lock(critical_section_cbs_); + if (cb_rtp_feedback_ == NULL) { return; } - bool haveCalledCallback = false; + bool have_called_callback = false; // Search for new CSRC in old array. - for (WebRtc_UWord8 i = 0; i < rtpHeader->header.numCSRCs; ++i) { - const WebRtc_UWord32 csrc = rtpHeader->header.arrOfCSRCs[i]; + for (WebRtc_UWord8 i = 0; i < rtp_header->header.numCSRCs; ++i) { + const WebRtc_UWord32 csrc = rtp_header->header.arrOfCSRCs[i]; - bool foundMatch = false; - for (WebRtc_UWord8 j = 0; j < oldNumCSRCs; ++j) { - if (csrc == oldRemoteCSRC[j]) { // old list - foundMatch = true; + bool found_match = false; + for (WebRtc_UWord8 j = 0; j < old_num_csrcs; ++j) { + if (csrc == old_remote_csrc[j]) { // old list + found_match = true; break; } } - if (!foundMatch && csrc) { + if (!found_match && csrc) { // Didn't find it, report it as new. - haveCalledCallback = true; - _cbRtpFeedback->OnIncomingCSRCChanged(_id, csrc, true); + have_called_callback = true; + cb_rtp_feedback_->OnIncomingCSRCChanged(id_, csrc, true); } } // Search for old CSRC in new array. - for (WebRtc_UWord8 i = 0; i < oldNumCSRCs; ++i) { - const WebRtc_UWord32 csrc = oldRemoteCSRC[i]; + for (WebRtc_UWord8 i = 0; i < old_num_csrcs; ++i) { + const WebRtc_UWord32 csrc = old_remote_csrc[i]; - bool foundMatch = false; - for (WebRtc_UWord8 j = 0; j < rtpHeader->header.numCSRCs; ++j) { - if (csrc == rtpHeader->header.arrOfCSRCs[j]) { - foundMatch = true; + bool found_match = false; + for (WebRtc_UWord8 j = 0; j < rtp_header->header.numCSRCs; ++j) { + if (csrc == rtp_header->header.arrOfCSRCs[j]) { + found_match = true; break; } } - if (!foundMatch && csrc) { + if (!found_match && csrc) { // Did not find it, report as removed. - haveCalledCallback = true; - _cbRtpFeedback->OnIncomingCSRCChanged(_id, csrc, false); + have_called_callback = true; + cb_rtp_feedback_->OnIncomingCSRCChanged(id_, csrc, false); } } - if (!haveCalledCallback) { - // If the CSRC list contain non-unique entries we will endup here. + if (!have_called_callback) { + // If the CSRC list contain non-unique entries we will end up here. // Using CSRC 0 to signal this event, not interop safe, other - // implementations might have CSRC 0 as avalid value. - if (numCSRCsDiff > 0) { - _cbRtpFeedback->OnIncomingCSRCChanged(_id, 0, true); - } else if (numCSRCsDiff < 0) { - _cbRtpFeedback->OnIncomingCSRCChanged(_id, 0, false); + // implementations might have CSRC 0 as a valid value. + if (num_csrcs_diff > 0) { + cb_rtp_feedback_->OnIncomingCSRCChanged(id_, 0, true); + } else if (num_csrcs_diff < 0) { + cb_rtp_feedback_->OnIncomingCSRCChanged(id_, 0, false); } } } -WebRtc_Word32 -RTPReceiver::ResetStatistics() -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); +WebRtc_Word32 RTPReceiver::ResetStatistics() { + CriticalSectionScoped lock(critical_section_rtp_receiver_); - _lastReportInorderPackets = 0; - _lastReportOldPackets = 0; - _lastReportSeqMax = 0; - _lastReportFractionLost = 0; - _lastReportCumulativeLost = 0; - _lastReportExtendedHighSeqNum = 0; - _lastReportJitter = 0; - _lastReportJitterTransmissionTimeOffset = 0; - _jitterQ4 = 0; - _jitterMaxQ4 = 0; - _cumulativeLoss = 0; - _jitterQ4TransmissionTimeOffset = 0; - _receivedSeqWraps = 0; - _receivedSeqMax = 0; - _receivedSeqFirst = 0; - _receivedByteCount = 0; - _receivedOldPacketCount = 0; - _receivedInorderPacketCount = 0; - return 0; + last_report_inorder_packets_ = 0; + last_report_old_packets_ = 0; + last_report_seq_max_ = 0; + last_report_fraction_lost_ = 0; + last_report_cumulative_lost_ = 0; + last_report_extended_high_seq_num_ = 0; + last_report_jitter_ = 0; + last_report_jitter_transmission_time_offset_ = 0; + jitter_q4_ = 0; + jitter_max_q4_ = 0; + cumulative_loss_ = 0; + jitter_q4_transmission_time_offset_ = 0; + received_seq_wraps_ = 0; + received_seq_max_ = 0; + received_seq_first_ = 0; + received_byte_count_ = 0; + received_old_packet_count_ = 0; + received_inorder_packet_count_ = 0; + return 0; } -WebRtc_Word32 -RTPReceiver::ResetDataCounters() -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); +WebRtc_Word32 RTPReceiver::ResetDataCounters() { + CriticalSectionScoped lock(critical_section_rtp_receiver_); - _receivedByteCount = 0; - _receivedOldPacketCount = 0; - _receivedInorderPacketCount = 0; - _lastReportInorderPackets = 0; + received_byte_count_ = 0; + received_old_packet_count_ = 0; + received_inorder_packet_count_ = 0; + last_report_inorder_packets_ = 0; - return 0; + return 0; } -WebRtc_Word32 -RTPReceiver::Statistics(WebRtc_UWord8 *fraction_lost, - WebRtc_UWord32 *cum_lost, - WebRtc_UWord32 *ext_max, - WebRtc_UWord32 *jitter, - WebRtc_UWord32 *max_jitter, - WebRtc_UWord32 *jitter_transmission_time_offset, - bool reset) const -{ - WebRtc_Word32 missing; - return Statistics(fraction_lost, - cum_lost, - ext_max, - jitter, - max_jitter, - jitter_transmission_time_offset, - &missing, - reset); +WebRtc_Word32 RTPReceiver::Statistics( + WebRtc_UWord8* fraction_lost, + WebRtc_UWord32* cum_lost, + WebRtc_UWord32* ext_max, + WebRtc_UWord32* jitter, + WebRtc_UWord32* max_jitter, + WebRtc_UWord32* jitter_transmission_time_offset, + bool reset) const { + WebRtc_Word32 missing; + return Statistics(fraction_lost, + cum_lost, + ext_max, + jitter, + max_jitter, + jitter_transmission_time_offset, + &missing, + reset); } -WebRtc_Word32 -RTPReceiver::Statistics(WebRtc_UWord8 *fraction_lost, - WebRtc_UWord32 *cum_lost, - WebRtc_UWord32 *ext_max, - WebRtc_UWord32 *jitter, - WebRtc_UWord32 *max_jitter, - WebRtc_UWord32 *jitter_transmission_time_offset, - WebRtc_Word32 *missing, - bool reset) const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); +WebRtc_Word32 RTPReceiver::Statistics( + WebRtc_UWord8* fraction_lost, + WebRtc_UWord32* cum_lost, + WebRtc_UWord32* ext_max, + WebRtc_UWord32* jitter, + WebRtc_UWord32* max_jitter, + WebRtc_UWord32* jitter_transmission_time_offset, + WebRtc_Word32* missing, + bool reset) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); - if (missing == NULL) - { - return -1; + if (missing == NULL) { + return -1; + } + if (received_seq_first_ == 0 && received_byte_count_ == 0) { + // We have not received anything. -1 required by RTCP sender. + return -1; + } + if (!reset) { + if (last_report_inorder_packets_ == 0) { + // No report. + return -1; } - if(_receivedSeqFirst == 0 && _receivedByteCount == 0) - { - // we have not received anything - // -1 required by RTCP sender - return -1; + // Just get last report. + if (fraction_lost) { + *fraction_lost = last_report_fraction_lost_; } - if(!reset) - { - if(_lastReportInorderPackets == 0) - { - // no report - return -1; - } - // just get last report - if(fraction_lost) - { - *fraction_lost = _lastReportFractionLost; - } - if(cum_lost) - { - *cum_lost = _lastReportCumulativeLost; // 24 bits valid - } - if(ext_max) - { - *ext_max = _lastReportExtendedHighSeqNum; - } - if(jitter) - { - *jitter =_lastReportJitter; - } - if(max_jitter) - { - // note that the internal jitter value is in Q4 - // and needs to be scaled by 1/16 - *max_jitter = (_jitterMaxQ4 >> 4); - } - if(jitter_transmission_time_offset) - { - *jitter_transmission_time_offset = - _lastReportJitterTransmissionTimeOffset; - } - return 0; + if (cum_lost) { + *cum_lost = last_report_cumulative_lost_; // 24 bits valid. } - - if (_lastReportInorderPackets == 0) - { - // First time we send a report - _lastReportSeqMax = _receivedSeqFirst-1; + if (ext_max) { + *ext_max = last_report_extended_high_seq_num_; } - /* - * calc fraction lost - */ - WebRtc_UWord16 expSinceLast = (_receivedSeqMax - _lastReportSeqMax); - - if(_lastReportSeqMax > _receivedSeqMax) - { - // can we assume that the seqNum can't go decrease over a full RTCP period ? - expSinceLast = 0; + if (jitter) { + *jitter = last_report_jitter_; } - - // number of received RTP packets since last report, counts all packets but not re-transmissions - WebRtc_UWord32 recSinceLast = _receivedInorderPacketCount - _lastReportInorderPackets; - - if(_nackMethod == kNackOff) - { - // this is needed for re-ordered packets - WebRtc_UWord32 oldPackets = _receivedOldPacketCount - _lastReportOldPackets; - recSinceLast += oldPackets; - }else - { - // with NACK we don't know the expected retransmitions during the last second - // we know how many "old" packets we have received we just count the numer of - // old received to estimate the loss but it still does not guarantee an exact number - // since we run this based on time triggered by sending of a RTP packet this - // should have a minimum effect - - // with NACK we don't count old packets as received since they are re-transmitted - // we use RTT to decide if a packet is re-ordered or re-transmitted + if (max_jitter) { + // Note: internal jitter value is in Q4 and needs to be scaled by 1/16. + *max_jitter = (jitter_max_q4_ >> 4); } - - *missing = 0; - if(expSinceLast > recSinceLast) - { - *missing = (expSinceLast - recSinceLast); - } - WebRtc_UWord8 fractionLost = 0; - if(expSinceLast) - { - // scale 0 to 255, where 255 is 100% loss - fractionLost = (WebRtc_UWord8) ((255 * (*missing)) / expSinceLast); - } - if(fraction_lost) - { - *fraction_lost = fractionLost; - } - // we need a counter for cumulative loss too - _cumulativeLoss += *missing; - - if(_jitterQ4 > _jitterMaxQ4) - { - _jitterMaxQ4 = _jitterQ4; - } - if(cum_lost) - { - *cum_lost = _cumulativeLoss; - } - if(ext_max) - { - *ext_max = (_receivedSeqWraps<<16) + _receivedSeqMax; - } - if(jitter) - { - // note that the internal jitter value is in Q4 - // and needs to be scaled by 1/16 - *jitter = (_jitterQ4 >> 4); - } - if(max_jitter) - { - // note that the internal jitter value is in Q4 - // and needs to be scaled by 1/16 - *max_jitter = (_jitterMaxQ4 >> 4); - } - if(jitter_transmission_time_offset) - { - // note that the internal jitter value is in Q4 - // and needs to be scaled by 1/16 - *jitter_transmission_time_offset = - (_jitterQ4TransmissionTimeOffset >> 4); - } - if(reset) - { - // store this report - _lastReportFractionLost = fractionLost; - _lastReportCumulativeLost = _cumulativeLoss; // 24 bits valid - _lastReportExtendedHighSeqNum = (_receivedSeqWraps<<16) + _receivedSeqMax; - _lastReportJitter = (_jitterQ4 >> 4); - _lastReportJitterTransmissionTimeOffset = - (_jitterQ4TransmissionTimeOffset >> 4); - - // only for report blocks in RTCP SR and RR - _lastReportInorderPackets = _receivedInorderPacketCount; - _lastReportOldPackets = _receivedOldPacketCount; - _lastReportSeqMax = _receivedSeqMax; + if (jitter_transmission_time_offset) { + *jitter_transmission_time_offset = + last_report_jitter_transmission_time_offset_; } return 0; + } + + if (last_report_inorder_packets_ == 0) { + // First time we send a report. + last_report_seq_max_ = received_seq_first_ - 1; + } + // Calculate fraction lost. + WebRtc_UWord16 exp_since_last = (received_seq_max_ - last_report_seq_max_); + + if (last_report_seq_max_ > received_seq_max_) { + // Can we assume that the seq_num can't go decrease over a full RTCP period? + exp_since_last = 0; + } + + // Number of received RTP packets since last report, counts all packets but + // not re-transmissions. + WebRtc_UWord32 rec_since_last = + received_inorder_packet_count_ - last_report_inorder_packets_; + + if (nack_method_ == kNackOff) { + // This is needed for re-ordered packets. + WebRtc_UWord32 old_packets = + received_old_packet_count_ - last_report_old_packets_; + rec_since_last += old_packets; + } else { + // With NACK we don't know the expected retransmitions during the last + // second. We know how many "old" packets we have received. We just count + // the number of old received to estimate the loss, but it still does not + // guarantee an exact number since we run this based on time triggered by + // sending of a RTP packet. This should have a minimum effect. + + // With NACK we don't count old packets as received since they are + // re-transmitted. We use RTT to decide if a packet is re-ordered or + // re-transmitted. + } + + *missing = 0; + if (exp_since_last > rec_since_last) { + *missing = (exp_since_last - rec_since_last); + } + WebRtc_UWord8 local_fraction_lost = 0; + if (exp_since_last) { + // Scale 0 to 255, where 255 is 100% loss. + local_fraction_lost = (WebRtc_UWord8)((255 * (*missing)) / exp_since_last); + } + if (fraction_lost) { + *fraction_lost = local_fraction_lost; + } + + // We need a counter for cumulative loss too. + cumulative_loss_ += *missing; + + if (jitter_q4_ > jitter_max_q4_) { + jitter_max_q4_ = jitter_q4_; + } + if (cum_lost) { + *cum_lost = cumulative_loss_; + } + if (ext_max) { + *ext_max = (received_seq_wraps_ << 16) + received_seq_max_; + } + // Note: internal jitter value is in Q4 and needs to be scaled by 1/16. + if (jitter) { + *jitter = (jitter_q4_ >> 4); + } + if (max_jitter) { + *max_jitter = (jitter_max_q4_ >> 4); + } + if (jitter_transmission_time_offset) { + *jitter_transmission_time_offset = + (jitter_q4_transmission_time_offset_ >> 4); + } + if (reset) { + // Store this report. + last_report_fraction_lost_ = local_fraction_lost; + last_report_cumulative_lost_ = cumulative_loss_; // 24 bits valid. + last_report_extended_high_seq_num_ = + (received_seq_wraps_ << 16) + received_seq_max_; + last_report_jitter_ = (jitter_q4_ >> 4); + last_report_jitter_transmission_time_offset_ = + (jitter_q4_transmission_time_offset_ >> 4); + + // Only for report blocks in RTCP SR and RR. + last_report_inorder_packets_ = received_inorder_packet_count_; + last_report_old_packets_ = received_old_packet_count_; + last_report_seq_max_ = received_seq_max_; + } + return 0; } -WebRtc_Word32 -RTPReceiver::DataCounters(WebRtc_UWord32 *bytesReceived, - WebRtc_UWord32 *packetsReceived) const -{ - CriticalSectionScoped lock(_criticalSectionRTPReceiver); +WebRtc_Word32 RTPReceiver::DataCounters( + WebRtc_UWord32* bytes_received, + WebRtc_UWord32* packets_received) const { + CriticalSectionScoped lock(critical_section_rtp_receiver_); - if(bytesReceived) - { - *bytesReceived = _receivedByteCount; - } - if(packetsReceived) - { - *packetsReceived = _receivedOldPacketCount + _receivedInorderPacketCount; - } - return 0; + if (bytes_received) { + *bytes_received = received_byte_count_; + } + if (packets_received) { + *packets_received = + received_old_packet_count_ + received_inorder_packet_count_; + } + return 0; } -void -RTPReceiver::ProcessBitrate() -{ - CriticalSectionScoped cs(_criticalSectionRTPReceiver); +void RTPReceiver::ProcessBitrate() { + CriticalSectionScoped cs(critical_section_rtp_receiver_); - Bitrate::Process(); + Bitrate::Process(); } } // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver.h index 0787f54f0e..824b8390c2 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_receiver.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver.h @@ -13,16 +13,16 @@ #include -#include "typedefs.h" -#include "rtp_utility.h" - -#include "rtp_header_extension.h" -#include "rtp_rtcp.h" -#include "rtp_rtcp_defines.h" -#include "rtcp_receiver_help.h" -#include "Bitrate.h" +#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" +#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/source/bitrate.h" +#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" +#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" +#include "webrtc/typedefs.h" namespace webrtc { + class RtpRtcpFeedback; class ModuleRtpRtcpImpl; class Trace; @@ -30,241 +30,241 @@ class RTPReceiverAudio; class RTPReceiverVideo; class RTPReceiverStrategy; -const WebRtc_Word32 kDefaultVideoFrequency = 90000; +class RTPReceiver : public Bitrate { + public: + RTPReceiver(const WebRtc_Word32 id, + const bool audio, + RtpRtcpClock* clock, + ModuleRtpRtcpImpl* owner, + RtpAudioFeedback* incoming_messages_callback); -class RTPReceiver : public Bitrate -{ -public: - RTPReceiver(const WebRtc_Word32 id, - const bool audio, - RtpRtcpClock* clock, - ModuleRtpRtcpImpl* owner, - RtpAudioFeedback* incomingMessagesCallback); + virtual ~RTPReceiver(); - virtual ~RTPReceiver(); + RtpVideoCodecTypes VideoCodecType() const; + WebRtc_UWord32 MaxConfiguredBitrate() const; - RtpVideoCodecTypes VideoCodecType() const; - WebRtc_UWord32 MaxConfiguredBitrate() const; + WebRtc_Word32 SetPacketTimeout(const WebRtc_UWord32 timeout_ms); + void PacketTimeout(); - WebRtc_Word32 SetPacketTimeout(const WebRtc_UWord32 timeoutMS); - void PacketTimeout(); + void ProcessDeadOrAlive(const bool RTCPalive, const WebRtc_Word64 now); - void ProcessDeadOrAlive(const bool RTCPalive, const WebRtc_Word64 now); + void ProcessBitrate(); - void ProcessBitrate(); + WebRtc_Word32 RegisterIncomingDataCallback(RtpData* incoming_data_callback); + WebRtc_Word32 RegisterIncomingRTPCallback( + RtpFeedback* incoming_messages_callback); - WebRtc_Word32 RegisterIncomingDataCallback(RtpData* incomingDataCallback); - WebRtc_Word32 RegisterIncomingRTPCallback(RtpFeedback* incomingMessagesCallback); + WebRtc_Word32 RegisterReceivePayload( + const char payload_name[RTP_PAYLOAD_NAME_SIZE], + const WebRtc_Word8 payload_type, + const WebRtc_UWord32 frequency, + const WebRtc_UWord8 channels, + const WebRtc_UWord32 rate); - WebRtc_Word32 RegisterReceivePayload( - const char payloadName[RTP_PAYLOAD_NAME_SIZE], - const WebRtc_Word8 payloadType, - const WebRtc_UWord32 frequency, - const WebRtc_UWord8 channels, - const WebRtc_UWord32 rate); + WebRtc_Word32 DeRegisterReceivePayload(const WebRtc_Word8 payload_type); - WebRtc_Word32 DeRegisterReceivePayload(const WebRtc_Word8 payloadType); + WebRtc_Word32 ReceivePayloadType( + const char payload_name[RTP_PAYLOAD_NAME_SIZE], + const WebRtc_UWord32 frequency, + const WebRtc_UWord8 channels, + const WebRtc_UWord32 rate, + WebRtc_Word8* payload_type) const; - WebRtc_Word32 ReceivePayloadType( - const char payloadName[RTP_PAYLOAD_NAME_SIZE], - const WebRtc_UWord32 frequency, - const WebRtc_UWord8 channels, - const WebRtc_UWord32 rate, - WebRtc_Word8* payloadType) const; + WebRtc_Word32 ReceivePayload(const WebRtc_Word8 payload_type, + char payload_name[RTP_PAYLOAD_NAME_SIZE], + WebRtc_UWord32* frequency, + WebRtc_UWord8* channels, + WebRtc_UWord32* rate) const; - WebRtc_Word32 ReceivePayload(const WebRtc_Word8 payloadType, - char payloadName[RTP_PAYLOAD_NAME_SIZE], - WebRtc_UWord32* frequency, - WebRtc_UWord8* channels, - WebRtc_UWord32* rate) const; + WebRtc_Word32 RemotePayload(char payload_name[RTP_PAYLOAD_NAME_SIZE], + WebRtc_Word8* payload_type, + WebRtc_UWord32* frequency, + WebRtc_UWord8* channels) const; - WebRtc_Word32 RemotePayload(char payloadName[RTP_PAYLOAD_NAME_SIZE], - WebRtc_Word8* payloadType, - WebRtc_UWord32* frequency, - WebRtc_UWord8* channels) const; + WebRtc_Word32 IncomingRTPPacket( + WebRtcRTPHeader* rtpheader, + const WebRtc_UWord8* incoming_rtp_packet, + const WebRtc_UWord16 incoming_rtp_packet_length); - WebRtc_Word32 IncomingRTPPacket(WebRtcRTPHeader* rtpheader, - const WebRtc_UWord8* incomingRtpPacket, - const WebRtc_UWord16 incomingRtpPacketLengt); + NACKMethod NACK() const ; - NACKMethod NACK() const ; + // Turn negative acknowledgement requests on/off. + WebRtc_Word32 SetNACKStatus(const NACKMethod method); - // Turn negative acknowledgement requests on/off - WebRtc_Word32 SetNACKStatus(const NACKMethod method); + // Returns the last received timestamp. + virtual WebRtc_UWord32 TimeStamp() const; + int32_t LastReceivedTimeMs() const; + virtual WebRtc_UWord16 SequenceNumber() const; + WebRtc_Word32 EstimatedRemoteTimeStamp(WebRtc_UWord32& timestamp) const; - // last received - virtual WebRtc_UWord32 TimeStamp() const; - int32_t LastReceivedTimeMs() const; - virtual WebRtc_UWord16 SequenceNumber() const; + WebRtc_UWord32 SSRC() const; - WebRtc_Word32 EstimatedRemoteTimeStamp(WebRtc_UWord32& timestamp) const; + WebRtc_Word32 CSRCs(WebRtc_UWord32 array_of_csrc[kRtpCsrcSize]) const; - WebRtc_UWord32 SSRC() const; + WebRtc_Word32 Energy(WebRtc_UWord8 array_of_energy[kRtpCsrcSize]) const; - WebRtc_Word32 CSRCs( WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize]) const; + // Get the currently configured SSRC filter. + WebRtc_Word32 SSRCFilter(WebRtc_UWord32& allowed_ssrc) const; - WebRtc_Word32 Energy( WebRtc_UWord8 arrOfEnergy[kRtpCsrcSize]) const; + // Set a SSRC to be used as a filter for incoming RTP streams. + WebRtc_Word32 SetSSRCFilter(const bool enable, + const WebRtc_UWord32 allowed_ssrc); - // get the currently configured SSRC filter - WebRtc_Word32 SSRCFilter(WebRtc_UWord32& allowedSSRC) const; + WebRtc_Word32 Statistics(WebRtc_UWord8* fraction_lost, + WebRtc_UWord32* cum_lost, + WebRtc_UWord32* ext_max, + WebRtc_UWord32* jitter, // Will be moved from JB. + WebRtc_UWord32* max_jitter, + WebRtc_UWord32* jitter_transmission_time_offset, + bool reset) const; - // set a SSRC to be used as a filter for incoming RTP streams - WebRtc_Word32 SetSSRCFilter(const bool enable, const WebRtc_UWord32 allowedSSRC); + WebRtc_Word32 Statistics(WebRtc_UWord8* fraction_lost, + WebRtc_UWord32* cum_lost, + WebRtc_UWord32* ext_max, + WebRtc_UWord32* jitter, // Will be moved from JB. + WebRtc_UWord32* max_jitter, + WebRtc_UWord32* jitter_transmission_time_offset, + WebRtc_Word32* missing, + bool reset) const; - WebRtc_Word32 Statistics(WebRtc_UWord8 *fraction_lost, - WebRtc_UWord32 *cum_lost, - WebRtc_UWord32 *ext_max, - WebRtc_UWord32 *jitter, // will be moved from JB - WebRtc_UWord32 *max_jitter, - WebRtc_UWord32 *jitter_transmission_time_offset, - bool reset) const; + WebRtc_Word32 DataCounters(WebRtc_UWord32* bytes_received, + WebRtc_UWord32* packets_received) const; - WebRtc_Word32 Statistics(WebRtc_UWord8 *fraction_lost, - WebRtc_UWord32 *cum_lost, - WebRtc_UWord32 *ext_max, - WebRtc_UWord32 *jitter, // will be moved from JB - WebRtc_UWord32 *max_jitter, - WebRtc_UWord32 *jitter_transmission_time_offset, - WebRtc_Word32 *missing, - bool reset) const; + WebRtc_Word32 ResetStatistics(); - WebRtc_Word32 DataCounters(WebRtc_UWord32 *bytesReceived, - WebRtc_UWord32 *packetsReceived) const; + WebRtc_Word32 ResetDataCounters(); - WebRtc_Word32 ResetStatistics(); + WebRtc_UWord16 PacketOHReceived() const; - WebRtc_Word32 ResetDataCounters(); + WebRtc_UWord32 PacketCountReceived() const; - WebRtc_UWord16 PacketOHReceived() const; + WebRtc_UWord32 ByteCountReceived() const; - WebRtc_UWord32 PacketCountReceived() const; + WebRtc_Word32 RegisterRtpHeaderExtension(const RTPExtensionType type, + const WebRtc_UWord8 id); - WebRtc_UWord32 ByteCountReceived() const; + WebRtc_Word32 DeregisterRtpHeaderExtension(const RTPExtensionType type); - WebRtc_Word32 RegisterRtpHeaderExtension(const RTPExtensionType type, - const WebRtc_UWord8 id); + void GetHeaderExtensionMapCopy(RtpHeaderExtensionMap* map) const; - WebRtc_Word32 DeregisterRtpHeaderExtension(const RTPExtensionType type); + virtual WebRtc_UWord32 PayloadTypeToPayload( + const WebRtc_UWord8 payload_type, + ModuleRTPUtility::Payload*& payload) const; - void GetHeaderExtensionMapCopy(RtpHeaderExtensionMap* map) const; + // RTX. + void SetRTXStatus(const bool enable, const WebRtc_UWord32 ssrc); - virtual WebRtc_UWord32 PayloadTypeToPayload(const WebRtc_UWord8 payloadType, - ModuleRTPUtility::Payload*& payload) const; - /* - * RTX - */ - void SetRTXStatus(const bool enable, const WebRtc_UWord32 SSRC); + void RTXStatus(bool* enable, WebRtc_UWord32* ssrc) const; - void RTXStatus(bool* enable, WebRtc_UWord32* SSRC) const; + RTPReceiverAudio* GetAudioReceiver() const { + return rtp_receiver_audio_; + } - RTPReceiverAudio* GetAudioReceiver() const { return _rtpReceiverAudio; } + virtual WebRtc_Word32 CallbackOfReceivedPayloadData( + const WebRtc_UWord8* payload_data, + const WebRtc_UWord16 payload_size, + const WebRtcRTPHeader* rtp_header); - virtual WebRtc_Word32 CallbackOfReceivedPayloadData( - const WebRtc_UWord8* payloadData, - const WebRtc_UWord16 payloadSize, - const WebRtcRTPHeader* rtpHeader); + virtual WebRtc_Word8 REDPayloadType() const; - virtual WebRtc_Word8 REDPayloadType() const; + bool HaveNotReceivedPackets() const; + protected: - bool HaveNotReceivedPackets() const; -protected: + virtual bool RetransmitOfOldPacket(const WebRtc_UWord16 sequence_number, + const WebRtc_UWord32 rtp_time_stamp) const; - virtual bool RetransmitOfOldPacket(const WebRtc_UWord16 sequenceNumber, - const WebRtc_UWord32 rtpTimeStamp) const; + void UpdateStatistics(const WebRtcRTPHeader* rtp_header, + const WebRtc_UWord16 bytes, + const bool old_packet); + private: + // Returns whether RED is configured with payload_type. + bool REDPayloadType(const WebRtc_Word8 payload_type) const; - void UpdateStatistics(const WebRtcRTPHeader* rtpHeader, - const WebRtc_UWord16 bytes, - const bool oldPacket); + bool InOrderPacket(const WebRtc_UWord16 sequence_number) const; -private: - // Is RED configured with payload type payloadType - bool REDPayloadType(const WebRtc_Word8 payloadType) const; + void CheckSSRCChanged(const WebRtcRTPHeader* rtp_header); + void CheckCSRC(const WebRtcRTPHeader* rtp_header); + WebRtc_Word32 CheckPayloadChanged(const WebRtcRTPHeader* rtp_header, + const WebRtc_Word8 first_payload_byte, + bool& isRED, + ModuleRTPUtility::PayloadUnion* payload); - bool InOrderPacket(const WebRtc_UWord16 sequenceNumber) const; + void UpdateNACKBitRate(WebRtc_Word32 bytes, WebRtc_UWord32 now); + bool ProcessNACKBitRate(WebRtc_UWord32 now); - void CheckSSRCChanged(const WebRtcRTPHeader* rtpHeader); - void CheckCSRC(const WebRtcRTPHeader* rtpHeader); - WebRtc_Word32 CheckPayloadChanged(const WebRtcRTPHeader* rtpHeader, - const WebRtc_Word8 firstPayloadByte, - bool& isRED, - ModuleRTPUtility::PayloadUnion* payload); + private: + RTPReceiverAudio* rtp_receiver_audio_; + RTPReceiverVideo* rtp_receiver_video_; + RTPReceiverStrategy* rtp_media_receiver_; - void UpdateNACKBitRate(WebRtc_Word32 bytes, WebRtc_UWord32 now); - bool ProcessNACKBitRate(WebRtc_UWord32 now); + WebRtc_Word32 id_; + ModuleRtpRtcpImpl& rtp_rtcp_; -private: - RTPReceiverAudio* _rtpReceiverAudio; - RTPReceiverVideo* _rtpReceiverVideo; - RTPReceiverStrategy* _rtpMediaReceiver; + CriticalSectionWrapper* critical_section_cbs_; + RtpFeedback* cb_rtp_feedback_; + RtpData* cb_rtp_data_; - WebRtc_Word32 _id; - ModuleRtpRtcpImpl& _rtpRtcp; + CriticalSectionWrapper* critical_section_rtp_receiver_; + mutable WebRtc_Word64 last_receive_time_; + WebRtc_UWord16 last_received_payload_length_; + WebRtc_Word8 last_received_payload_type_; + WebRtc_Word8 last_received_media_payload_type_; - CriticalSectionWrapper* _criticalSectionCbs; - RtpFeedback* _cbRtpFeedback; - RtpData* _cbRtpData; + WebRtc_UWord32 packet_timeout_ms_; + WebRtc_Word8 red_payload_type_; - CriticalSectionWrapper* _criticalSectionRTPReceiver; - mutable WebRtc_Word64 _lastReceiveTime; - WebRtc_UWord16 _lastReceivedPayloadLength; - WebRtc_Word8 _lastReceivedPayloadType; - WebRtc_Word8 _lastReceivedMediaPayloadType; + ModuleRTPUtility::PayloadTypeMap payload_type_map_; + RtpHeaderExtensionMap rtp_header_extension_map_; - WebRtc_UWord32 _packetTimeOutMS; - WebRtc_Word8 _redPayloadType; + // SSRCs. + WebRtc_UWord32 ssrc_; + WebRtc_UWord8 num_csrcs_; + WebRtc_UWord32 current_remote_csrc_[kRtpCsrcSize]; + WebRtc_UWord8 num_energy_; + WebRtc_UWord8 current_remote_energy_[kRtpCsrcSize]; - ModuleRTPUtility::PayloadTypeMap _payloadTypeMap; - RtpHeaderExtensionMap _rtpHeaderExtensionMap; + bool use_ssrc_filter_; + WebRtc_UWord32 ssrc_filter_; - // SSRCs - WebRtc_UWord32 _SSRC; - WebRtc_UWord8 _numCSRCs; - WebRtc_UWord32 _currentRemoteCSRC[kRtpCsrcSize]; - WebRtc_UWord8 _numEnergy; - WebRtc_UWord8 _currentRemoteEnergy[kRtpCsrcSize]; + // Stats on received RTP packets. + WebRtc_UWord32 jitter_q4_; + mutable WebRtc_UWord32 jitter_max_q4_; + mutable WebRtc_UWord32 cumulative_loss_; + WebRtc_UWord32 jitter_q4_transmission_time_offset_; - bool _useSSRCFilter; - WebRtc_UWord32 _SSRCFilter; + WebRtc_UWord32 local_time_last_received_timestamp_; + int64_t last_received_frame_time_ms_; + WebRtc_UWord32 last_received_timestamp_; + WebRtc_UWord16 last_received_sequence_number_; + WebRtc_Word32 last_received_transmission_time_offset_; + WebRtc_UWord16 received_seq_first_; + WebRtc_UWord16 received_seq_max_; + WebRtc_UWord16 received_seq_wraps_; - // stats on received RTP packets - WebRtc_UWord32 _jitterQ4; - mutable WebRtc_UWord32 _jitterMaxQ4; - mutable WebRtc_UWord32 _cumulativeLoss; - WebRtc_UWord32 _jitterQ4TransmissionTimeOffset; + // Current counter values. + WebRtc_UWord16 received_packet_oh_; + WebRtc_UWord32 received_byte_count_; + WebRtc_UWord32 received_old_packet_count_; + WebRtc_UWord32 received_inorder_packet_count_; - WebRtc_UWord32 _localTimeLastReceivedTimestamp; - int64_t _lastReceivedFrameTimeMs; - WebRtc_UWord32 _lastReceivedTimestamp; - WebRtc_UWord16 _lastReceivedSequenceNumber; - WebRtc_Word32 _lastReceivedTransmissionTimeOffset; - WebRtc_UWord16 _receivedSeqFirst; - WebRtc_UWord16 _receivedSeqMax; - WebRtc_UWord16 _receivedSeqWraps; + // Counter values when we sent the last report. + mutable WebRtc_UWord32 last_report_inorder_packets_; + mutable WebRtc_UWord32 last_report_old_packets_; + mutable WebRtc_UWord16 last_report_seq_max_; + mutable WebRtc_UWord8 last_report_fraction_lost_; + mutable WebRtc_UWord32 last_report_cumulative_lost_; // 24 bits valid. + mutable WebRtc_UWord32 last_report_extended_high_seq_num_; + mutable WebRtc_UWord32 last_report_jitter_; + mutable WebRtc_UWord32 last_report_jitter_transmission_time_offset_; - // current counter values - WebRtc_UWord16 _receivedPacketOH; - WebRtc_UWord32 _receivedByteCount; - WebRtc_UWord32 _receivedOldPacketCount; - WebRtc_UWord32 _receivedInorderPacketCount; + NACKMethod nack_method_; - // counter values when we sent the last report - mutable WebRtc_UWord32 _lastReportInorderPackets; - mutable WebRtc_UWord32 _lastReportOldPackets; - mutable WebRtc_UWord16 _lastReportSeqMax; - mutable WebRtc_UWord8 _lastReportFractionLost; - mutable WebRtc_UWord32 _lastReportCumulativeLost; // 24 bits valid - mutable WebRtc_UWord32 _lastReportExtendedHighSeqNum; - mutable WebRtc_UWord32 _lastReportJitter; - mutable WebRtc_UWord32 _lastReportJitterTransmissionTimeOffset; - - NACKMethod _nackMethod; - - bool _RTX; - WebRtc_UWord32 _ssrcRTX; + bool rtx_; + WebRtc_UWord32 ssrc_rtx_; }; } // namespace webrtc -#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_H_ +#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_H_ diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h index 0dc59ded82..248cb90665 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_VIDEO_H_ #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_VIDEO_H_ -#include "Bitrate.h" +#include "bitrate.h" #include "rtp_receiver.h" #include "rtp_receiver_strategy.h" #include "rtp_rtcp_defines.h" diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp.gypi b/webrtc/modules/rtp_rtcp/source/rtp_rtcp.gypi index f5816ff94e..fe75625e87 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp.gypi +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp.gypi @@ -31,7 +31,7 @@ '../interface/rtp_rtcp.h', '../interface/rtp_rtcp_defines.h', 'bitrate.cc', - 'Bitrate.h', + 'bitrate.h', 'rtp_rtcp_config.h', 'rtp_rtcp_impl.cc', 'rtp_rtcp_impl.h', diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index abbe395cbd..6cfa44fe0b 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -75,14 +75,14 @@ RTPSender::RTPSender(const WebRtc_Word32 id, memset(_nackByteCount, 0, sizeof(_nackByteCount)); memset(_CSRC, 0, sizeof(_CSRC)); // We need to seed the random generator. - srand( (WebRtc_UWord32)_clock.GetTimeInMS() ); + srand( (WebRtc_UWord32)clock_.GetTimeInMS() ); _ssrc = _ssrcDB.CreateSSRC(); // Can't be 0. if (audio) { - _audio = new RTPSenderAudio(id, &_clock, this); + _audio = new RTPSenderAudio(id, &clock_, this); _audio->RegisterAudioCallback(audio_feedback); } else { - _video = new RTPSenderVideo(id, &_clock, this); + _video = new RTPSenderVideo(id, &clock_, this); } WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id, "%s created", __FUNCTION__); } @@ -576,7 +576,7 @@ int RTPSender::SetSelectiveRetransmissions(uint8_t settings) { void RTPSender::OnReceivedNACK(const WebRtc_UWord16 nackSequenceNumbersLength, const WebRtc_UWord16* nackSequenceNumbers, const WebRtc_UWord16 avgRTT) { - const WebRtc_Word64 now = _clock.GetTimeInMS(); + const WebRtc_Word64 now = clock_.GetTimeInMS(); WebRtc_UWord32 bytesReSent = 0; // Enough bandwidth to send NACK? @@ -700,7 +700,7 @@ void RTPSender::TimeToSendPacket(uint16_t sequence_number, WebRtcRTPHeader rtp_header; rtpParser.Parse(rtp_header); - int64_t diff_ms = _clock.GetTimeInMS() - capture_time_ms; + int64_t diff_ms = clock_.GetTimeInMS() - capture_time_ms; if (UpdateTransmissionTimeOffset(data_buffer, length, rtp_header, diff_ms)) { // Update stored packet in case of receiving a re-transmission request. _packetHistory->ReplaceRTPHeader(data_buffer, @@ -738,7 +738,7 @@ WebRtc_Word32 RTPSender::SendToNetwork(uint8_t* buffer, // TODO(holmer): This should be changed all over Video Engine so that negative // time is consider invalid, while 0 is considered a valid time. if (capture_time_ms > 0) { - int64_t time_now = _clock.GetTimeInMS(); + int64_t time_now = clock_.GetTimeInMS(); UpdateTransmissionTimeOffset(buffer, payload_length + rtp_header_length, rtp_header, time_now - capture_time_ms); } @@ -1007,7 +1007,7 @@ bool RTPSender::UpdateTransmissionTimeOffset( void RTPSender::SetSendingStatus(const bool enabled) { if (enabled) { - WebRtc_UWord32 freq; + WebRtc_UWord32 frequency_hz; if (_audioConfigured) { WebRtc_UWord32 frequency = _audio->AudioFrequency(); @@ -1023,11 +1023,12 @@ void RTPSender::SetSendingStatus(const bool enabled) { assert(false); return; } - freq = frequency; + frequency_hz = frequency; } else { - freq = 90000; // 90 KHz for all video + frequency_hz = kDefaultVideoFrequency; } - WebRtc_UWord32 RTPtime = ModuleRTPUtility::GetCurrentRTP(&_clock, freq); + WebRtc_UWord32 RTPtime = ModuleRTPUtility::GetCurrentRTP(&clock_, + frequency_hz); // will be ignored if it's already configured via API SetStartTimestamp(RTPtime, false); diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.h b/webrtc/modules/rtp_rtcp/source/rtp_sender.h index a85b2c709a..58bfca5084 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.h @@ -17,7 +17,7 @@ #include "webrtc/common_types.h" #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" -#include "webrtc/modules/rtp_rtcp/source/Bitrate.h" +#include "webrtc/modules/rtp_rtcp/source/bitrate.h" #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h index 64ac058d69..33e6b26263 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h @@ -22,7 +22,7 @@ #include "video_codec_information.h" #include "forward_error_correction.h" -#include "Bitrate.h" +#include "bitrate.h" #include "rtp_sender.h" #include "producer_fec.h"