diff options
author | pkasting@chromium.org <pkasting@chromium.org> | 2015-02-23 21:28:22 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org> | 2015-02-23 21:29:45 +0000 |
commit | d324546ced76d4e792338af4f7d02a5cd8819f92 (patch) | |
tree | c3e213b516950981ec2bb45658319649826ccad9 | |
parent | 722739108a9a1b30cbcb8285ce0b76762b356fb3 (diff) | |
download | webrtc-d324546ced76d4e792338af4f7d02a5cd8819f92.tar.gz |
Misc. cleanup split out of https://webrtc-codereview.appspot.com/37699004/ :
* Move constants into the files/functions that use them
* Declare variables in the narrowest scope possible
* Use correct (expected, actual) order for gtest macros
* Remove unused functions
* Untabify
* 80-column limit
* Avoid C-style casts
* Prefer true typed constants to "enum hack" constants
* Print size_t using the right format macro
* Shorten and simplify code
* Other random cleanup bits and style fixes
BUG=none
TEST=none
R=henrik.lundin@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36179004
Cr-Commit-Position: refs/heads/master@{#8467}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8467 4adac7df-926f-26a2-2b94-8c16560cd09d
43 files changed, 394 insertions, 542 deletions
diff --git a/talk/app/webrtc/webrtcsdp.cc b/talk/app/webrtc/webrtcsdp.cc index d34ce3e654..b2b33fa27d 100644 --- a/talk/app/webrtc/webrtcsdp.cc +++ b/talk/app/webrtc/webrtcsdp.cc @@ -74,7 +74,6 @@ using cricket::kCodecParamSctpStreams; using cricket::kCodecParamMaxAverageBitrate; using cricket::kCodecParamMaxPlaybackRate; using cricket::kCodecParamAssociatedPayloadType; -using cricket::kWildcardPayloadType; using cricket::MediaContentDescription; using cricket::MediaType; using cricket::NS_JINGLE_ICE_UDP; @@ -223,6 +222,10 @@ static const int kIsacSwbDefaultRate = 56000; // From acm_common_defs.h static const char kDefaultSctpmapProtocol[] = "webrtc-datachannel"; +// RTP payload type is in the 0-127 range. Use -1 to indicate "all" payload +// types. +const int kWildcardPayloadType = -1; + struct SsrcInfo { SsrcInfo() : msid_identifier(kDefaultMsid), @@ -3049,8 +3052,8 @@ bool ParseFmtpAttributes(const std::string& line, const MediaType media_type, return false; } - std::string payload_type; - if (!GetValue(fields[0], kAttributeFmtp, &payload_type, error)) { + std::string payload_type_str; + if (!GetValue(fields[0], kAttributeFmtp, &payload_type_str, error)) { return false; } @@ -3070,16 +3073,16 @@ bool ParseFmtpAttributes(const std::string& line, const MediaType media_type, codec_params[name] = value; } - int int_payload_type = 0; - if (!GetPayloadTypeFromString(line, payload_type, &int_payload_type, error)) { + int payload_type = 0; + if (!GetPayloadTypeFromString(line, payload_type_str, &payload_type, error)) { return false; } if (media_type == cricket::MEDIA_TYPE_AUDIO) { UpdateCodec<AudioContentDescription, cricket::AudioCodec>( - media_desc, int_payload_type, codec_params); + media_desc, payload_type, codec_params); } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { UpdateCodec<VideoContentDescription, cricket::VideoCodec>( - media_desc, int_payload_type, codec_params); + media_desc, payload_type, codec_params); } return true; } @@ -3117,13 +3120,11 @@ bool ParseRtcpFbAttribute(const std::string& line, const MediaType media_type, const cricket::FeedbackParam feedback_param(id, param); if (media_type == cricket::MEDIA_TYPE_AUDIO) { - UpdateCodec<AudioContentDescription, cricket::AudioCodec>(media_desc, - payload_type, - feedback_param); + UpdateCodec<AudioContentDescription, cricket::AudioCodec>( + media_desc, payload_type, feedback_param); } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { - UpdateCodec<VideoContentDescription, cricket::VideoCodec>(media_desc, - payload_type, - feedback_param); + UpdateCodec<VideoContentDescription, cricket::VideoCodec>( + media_desc, payload_type, feedback_param); } return true; } diff --git a/talk/app/webrtc/webrtcsdp_unittest.cc b/talk/app/webrtc/webrtcsdp_unittest.cc index a80f4012b5..d9b2672f5d 100644 --- a/talk/app/webrtc/webrtcsdp_unittest.cc +++ b/talk/app/webrtc/webrtcsdp_unittest.cc @@ -2182,8 +2182,8 @@ TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { DataContentDescription* dcdesc = static_cast<DataContentDescription*>( mutant->GetContentDescriptionByName(kDataContentName)); std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); - EXPECT_EQ(codecs.size(), 1UL); - EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId); + EXPECT_EQ(1U, codecs.size()); + EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id); codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); dcdesc->set_codecs(codecs); diff --git a/talk/media/base/codec.cc b/talk/media/base/codec.cc index 166b34c5cb..e22dce2455 100644 --- a/talk/media/base/codec.cc +++ b/talk/media/base/codec.cc @@ -37,7 +37,6 @@ namespace cricket { -static const int kMaxStaticPayloadId = 95; const int kMaxPayloadId = 127; bool FeedbackParam::operator==(const FeedbackParam& other) const { @@ -120,6 +119,7 @@ bool Codec::operator==(const Codec& c) const { bool Codec::Matches(const Codec& codec) const { // Match the codec id/name based on the typical static/dynamic name rules. // Matching is case-insensitive. + const int kMaxStaticPayloadId = 95; return (codec.id <= kMaxStaticPayloadId) ? (id == codec.id) : (_stricmp(name.c_str(), codec.name.c_str()) == 0); } diff --git a/talk/media/base/constants.cc b/talk/media/base/constants.cc index 19a960f35a..46f29bff28 100644 --- a/talk/media/base/constants.cc +++ b/talk/media/base/constants.cc @@ -43,10 +43,6 @@ const char kRtxCodecName[] = "rtx"; const char kRedCodecName[] = "red"; const char kUlpfecCodecName[] = "ulpfec"; -// RTP payload type is in the 0-127 range. Use 128 to indicate "all" payload -// types. -const int kWildcardPayloadType = -1; - const char kCodecParamAssociatedPayloadType[] = "apt"; const char kOpusCodecName[] = "opus"; diff --git a/talk/media/base/constants.h b/talk/media/base/constants.h index 5168acb897..ce2748c25b 100644 --- a/talk/media/base/constants.h +++ b/talk/media/base/constants.h @@ -48,7 +48,6 @@ extern const char kRedCodecName[]; extern const char kUlpfecCodecName[]; // Codec parameters -extern const int kWildcardPayloadType; extern const char kCodecParamAssociatedPayloadType[]; extern const char kOpusCodecName[]; diff --git a/talk/media/base/rtpdump_unittest.cc b/talk/media/base/rtpdump_unittest.cc index acf60b919d..04caf0c0e0 100644 --- a/talk/media/base/rtpdump_unittest.cc +++ b/talk/media/base/rtpdump_unittest.cc @@ -44,22 +44,23 @@ TEST(RtpDumpTest, ReadRtpDumpPacket) { RtpTestUtility::kTestRawRtpPackets[0].WriteToByteBuffer(kTestSsrc, &rtp_buf); RtpDumpPacket rtp_packet(rtp_buf.Data(), rtp_buf.Length(), 0, false); - int type; + int payload_type; int seq_num; uint32 ts; uint32 ssrc; + int rtcp_type; EXPECT_FALSE(rtp_packet.is_rtcp()); EXPECT_TRUE(rtp_packet.IsValidRtpPacket()); EXPECT_FALSE(rtp_packet.IsValidRtcpPacket()); - EXPECT_TRUE(rtp_packet.GetRtpPayloadType(&type)); - EXPECT_EQ(0, type); + EXPECT_TRUE(rtp_packet.GetRtpPayloadType(&payload_type)); + EXPECT_EQ(0, payload_type); EXPECT_TRUE(rtp_packet.GetRtpSeqNum(&seq_num)); EXPECT_EQ(0, seq_num); EXPECT_TRUE(rtp_packet.GetRtpTimestamp(&ts)); EXPECT_EQ(0U, ts); EXPECT_TRUE(rtp_packet.GetRtpSsrc(&ssrc)); EXPECT_EQ(kTestSsrc, ssrc); - EXPECT_FALSE(rtp_packet.GetRtcpType(&type)); + EXPECT_FALSE(rtp_packet.GetRtcpType(&rtcp_type)); rtc::ByteBuffer rtcp_buf; RtpTestUtility::kTestRawRtcpPackets[0].WriteToByteBuffer(&rtcp_buf); @@ -68,8 +69,8 @@ TEST(RtpDumpTest, ReadRtpDumpPacket) { EXPECT_TRUE(rtcp_packet.is_rtcp()); EXPECT_FALSE(rtcp_packet.IsValidRtpPacket()); EXPECT_TRUE(rtcp_packet.IsValidRtcpPacket()); - EXPECT_TRUE(rtcp_packet.GetRtcpType(&type)); - EXPECT_EQ(0, type); + EXPECT_TRUE(rtcp_packet.GetRtcpType(&rtcp_type)); + EXPECT_EQ(0, rtcp_type); } // Test that we read only the RTP dump file. diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc index d4db7b7e27..428676f9b6 100644 --- a/talk/media/webrtc/webrtcvideoengine.cc +++ b/talk/media/webrtc/webrtcvideoengine.cc @@ -169,8 +169,6 @@ static const int kDefaultLogSeverity = rtc::LS_WARNING; static const int kDefaultNumberOfTemporalLayers = 1; // 1:1 -static const int kExternalVideoPayloadTypeBase = 120; - static const int kChannelIdUnset = -1; static const uint32 kDefaultChannelSsrcKey = 0; static const uint32 kSsrcUnset = 0; @@ -184,12 +182,11 @@ static int GetBitrate(int value, int deflt) { } // Static allocation of payload type values for external video codec. -static int GetExternalVideoPayloadType(int index) { -#if ENABLE_DEBUG - static const int kMaxExternalVideoCodecs = 8; - ASSERT(index >= 0 && index < kMaxExternalVideoCodecs); -#endif - return kExternalVideoPayloadTypeBase + index; +static int GetExternalVideoPayloadType(size_t index) { + static const int kExternalVideoPayloadTypeBase = 120; + index += kExternalVideoPayloadTypeBase; + ASSERT(index < 128); + return static_cast<int>(index); } static void LogMultiline(rtc::LoggingSeverity sev, char* text) { @@ -633,7 +630,7 @@ class WebRtcLocalStreamInfo { // from the worker thread. class WebRtcVideoChannelRecvInfo { public: - typedef std::map<int, webrtc::VideoDecoder*> DecoderMap; // key: payload type + typedef std::map<int, webrtc::VideoDecoder*> DecoderMap; // Key: payload type explicit WebRtcVideoChannelRecvInfo(int channel_id) : channel_id_(channel_id), render_adapter_(NULL, channel_id), @@ -712,7 +709,7 @@ class WebRtcOveruseObserver : public webrtc::CpuOveruseObserver { class WebRtcVideoChannelSendInfo : public sigslot::has_slots<> { public: - typedef std::map<int, webrtc::VideoEncoder*> EncoderMap; // key: payload type + typedef std::map<int, webrtc::VideoEncoder*> EncoderMap; // Key: payload type enum AdaptFormatType { // This is how we make SetSendStreamFormat take precedence over @@ -1298,8 +1295,8 @@ bool WebRtcVideoEngine::FindCodec(const VideoCodec& in) { const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs = encoder_factory_->codecs(); for (size_t j = 0; j < codecs.size(); ++j) { - VideoCodec codec(GetExternalVideoPayloadType(static_cast<int>(j)), - codecs[j].name, 0, 0, 0, 0); + VideoCodec codec(GetExternalVideoPayloadType(j), codecs[j].name, 0, 0, 0, + 0); if (codec.Matches(in)) return true; } @@ -1406,9 +1403,9 @@ bool WebRtcVideoEngine::ConvertFromCricketVideoCodec( for (size_t i = 0; i < codecs.size(); ++i) { if (_stricmp(in_codec.name.c_str(), codecs[i].name.c_str()) == 0) { out_codec->codecType = codecs[i].type; - out_codec->plType = GetExternalVideoPayloadType(static_cast<int>(i)); + out_codec->plType = GetExternalVideoPayloadType(i); rtc::strcpyn(out_codec->plName, sizeof(out_codec->plName), - codecs[i].name.c_str(), codecs[i].name.length()); + codecs[i].name.c_str(), codecs[i].name.length()); found = true; break; } @@ -1545,7 +1542,7 @@ bool WebRtcVideoEngine::RebuildCodecList(const VideoCodec& in_codec) { internal_codec_names.end(); if (!is_internal_codec) { VideoCodec codec( - GetExternalVideoPayloadType(static_cast<int>(i)), + GetExternalVideoPayloadType(i), codecs[i].name, codecs[i].max_width, codecs[i].max_height, @@ -1872,10 +1869,10 @@ bool WebRtcVideoMediaChannel::SetSendCodecs( // Select the first matched codec. webrtc::VideoCodec& codec(send_codecs[0]); - // Set RTX payload type if primary now active. This value will be used in + // Set RTX payload type if primary now active. This value will be used in // SetSendCodec. std::map<int, int>::const_iterator rtx_it = - primary_rtx_pt_mapping.find(static_cast<int>(codec.plType)); + primary_rtx_pt_mapping.find(codec.plType); if (rtx_it != primary_rtx_pt_mapping.end()) { send_rtx_type_ = rtx_it->second; } @@ -3673,8 +3670,8 @@ bool WebRtcVideoMediaChannel::SetNackFec(int channel_id, if (enable) { if (engine_->vie()->rtp()->SetHybridNACKFECStatus( channel_id, nack_enabled, red_payload_type, fec_payload_type) != 0) { - LOG_RTCERR4(SetHybridNACKFECStatus, - channel_id, nack_enabled, red_payload_type, fec_payload_type); + LOG_RTCERR4(SetHybridNACKFECStatus, channel_id, nack_enabled, + red_payload_type, fec_payload_type); return false; } LOG(LS_INFO) << "Hybrid NACK/FEC enabled for channel " << channel_id; @@ -3832,8 +3829,8 @@ bool WebRtcVideoMediaChannel::SetReceiveCodecs( LOG(LS_ERROR) << "Only one RTX codec at a time is supported."; return false; } - std::map<int, int>::iterator apt_it = associated_payload_types_.find( - it->plType); + std::map<int, int>::iterator apt_it = + associated_payload_types_.find(it->plType); bool valid_apt = false; if (apt_it != associated_payload_types_.end()) { std::map<int, webrtc::VideoCodec*>::iterator codec_it = diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc index 781acf6dbc..cbd6eea923 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -133,13 +133,6 @@ static const int kDefaultQpMax = 56; static const int kDefaultRtcpReceiverReportSsrc = 1; -// External video encoders are given payloads 120-127. This also means that we -// only support up to 8 external payload types. -static const int kExternalVideoPayloadTypeBase = 120; -#ifndef NDEBUG -static const size_t kMaxExternalVideoCodecs = 8; -#endif - const char kH264CodecName[] = "H264"; static bool FindFirstMatchingCodec(const std::vector<VideoCodec>& codecs, @@ -557,7 +550,6 @@ std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const { return supported_codecs; } - assert(external_encoder_factory_->codecs().size() <= kMaxExternalVideoCodecs); const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs = external_encoder_factory_->codecs(); for (size_t i = 0; i < codecs.size(); ++i) { @@ -566,7 +558,12 @@ std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const { continue; } - VideoCodec codec(kExternalVideoPayloadTypeBase + static_cast<int>(i), + // External video encoders are given payloads 120-127. This also means that + // we only support up to 8 external payload types. + const int kExternalVideoPayloadTypeBase = 120; + size_t payload_type = kExternalVideoPayloadTypeBase + i; + assert(payload_type < 128); + VideoCodec codec(static_cast<int>(payload_type), codecs[i].name, codecs[i].max_width, codecs[i].max_height, @@ -2071,7 +2068,8 @@ WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) { std::vector<VideoCodecSettings> video_codecs; std::map<int, bool> payload_used; std::map<int, VideoCodec::CodecType> payload_codec_type; - std::map<int, int> rtx_mapping; // video payload type -> rtx payload type. + // |rtx_mapping| maps video payload type to rtx payload type. + std::map<int, int> rtx_mapping; webrtc::FecConfig fec_settings; diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc index be19833965..deb0e298ac 100644 --- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc @@ -1679,8 +1679,7 @@ TEST_F(WebRtcVideoChannel2Test, SetDefaultSendCodecs) { EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); - EXPECT_EQ(static_cast<int>(default_rtx_codec_.id), - config.rtp.rtx.payload_type); + EXPECT_EQ(default_rtx_codec_.id, config.rtp.rtx.payload_type); // TODO(juberti): Check RTCP, PLI, TMMBR. } @@ -1846,10 +1845,9 @@ TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectBadPayloadTypes) { std::vector<cricket::VideoCodec> codecs; codecs.push_back(kVp8Codec); for (size_t i = 0; i < arraysize(kIncorrectPayloads); ++i) { - int payload_type = kIncorrectPayloads[i]; - codecs[0].id = payload_type; + codecs[0].id = kIncorrectPayloads[i]; EXPECT_FALSE(channel_->SetSendCodecs(codecs)) - << "Bad payload type '" << payload_type << "' accepted."; + << "Bad payload type '" << kIncorrectPayloads[i] << "' accepted."; } } diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc index a6fc3073ae..80b3be980f 100644 --- a/talk/media/webrtc/webrtcvoiceengine.cc +++ b/talk/media/webrtc/webrtcvoiceengine.cc @@ -539,7 +539,7 @@ void WebRtcVoiceEngine::ConstructCodecs() { codec.params[kCodecParamMaxPTime] = rtc::ToString(kPreferredMaxPTime); } - codec.SetParam(kCodecParamUseInbandFec, "1"); + codec.SetParam(kCodecParamUseInbandFec, 1); // TODO(hellner): Add ptime, sprop-stereo, and stereo // when they can be set to values other than the default. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc index 6e003615df..7710046d24 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc @@ -448,20 +448,12 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst, // Checks if the bitrate is valid for the codec. bool ACMCodecDB::IsRateValid(int codec_id, int rate) { - if (database_[codec_id].rate == rate) { - return true; - } else { - return false; - } + return database_[codec_id].rate == rate; } // Checks if the bitrate is valid for iSAC. bool ACMCodecDB::IsISACRateValid(int rate) { - if ((rate == -1) || ((rate <= 56000) && (rate >= 10000))) { - return true; - } else { - return false; - } + return (rate == -1) || ((rate <= 56000) && (rate >= 10000)); } // Checks if the bitrate is valid for iLBC. @@ -541,27 +533,17 @@ bool ACMCodecDB::IsG7291RateValid(int rate) { // Checks if the bitrate is valid for Speex. bool ACMCodecDB::IsSpeexRateValid(int rate) { - if (rate > 2000) { - return true; - } else { - return false; - } + return rate > 2000; } // Checks if the bitrate is valid for Opus. bool ACMCodecDB::IsOpusRateValid(int rate) { - if ((rate < 6000) || (rate > 510000)) { - return false; - } - return true; + return (rate >= 6000) && (rate <= 510000); } // Checks if the payload type is in the valid range. bool ACMCodecDB::ValidPayloadType(int payload_type) { - if ((payload_type < 0) || (payload_type > 127)) { - return false; - } - return true; + return (payload_type >= 0) && (payload_type <= 127); } bool ACMCodecDB::OwnsDecoder(int codec_id) { diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc index 5d78625deb..7acb45ac64 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc @@ -507,8 +507,8 @@ int32_t AcmReceiver::AddCodec(int acm_codec_id, // First unregister. Then register with new payload-type/channels. if (neteq_->RemovePayloadType(decoders_[acm_codec_id].payload_type) != NetEq::kOK) { - LOG_F(LS_ERROR) << "Cannot remover payload " - << static_cast<int>(decoders_[acm_codec_id].payload_type); + LOG_F(LS_ERROR) << "Cannot remove payload " + << static_cast<int>(decoders_[acm_codec_id].payload_type); return -1; } } @@ -562,7 +562,7 @@ int AcmReceiver::RemoveAllCodecs() { decoders_[n].registered = false; } else { LOG_F(LS_ERROR) << "Cannot remove payload " - << static_cast<int>(decoders_[n].payload_type); + << static_cast<int>(decoders_[n].payload_type); ret_val = -1; } } diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h index 72e1e75ede..07daf5899a 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h @@ -240,8 +240,6 @@ class AudioCodingModuleImpl : public AudioCodingModule { AudioDecodingCallStats* stats) const OVERRIDE; private: - int UnregisterReceiveCodecSafe(int payload_type); - ACMGenericCodec* CreateCodec(const CodecInst& codec); int InitializeReceiverSafe() EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); diff --git a/webrtc/modules/audio_coding/main/acm2/initial_delay_manager_unittest.cc b/webrtc/modules/audio_coding/main/acm2/initial_delay_manager_unittest.cc index 4bf9437dee..6585946a69 100644 --- a/webrtc/modules/audio_coding/main/acm2/initial_delay_manager_unittest.cc +++ b/webrtc/modules/audio_coding/main/acm2/initial_delay_manager_unittest.cc @@ -332,7 +332,6 @@ TEST_F(InitialDelayManagerTest, NoLatePacketAfterCng) { // Second packet as CNG. NextRtpHeader(&rtp_info_, &rtp_receive_timestamp_); - const uint8_t kCngPayloadType = 1; // Arbitrary. rtp_info_.header.payloadType = kCngPayloadType; manager_->UpdateLastReceivedPacket(rtp_info_, rtp_receive_timestamp_, InitialDelayManager::kCngPacket, false, diff --git a/webrtc/modules/audio_coding/main/test/Channel.h b/webrtc/modules/audio_coding/main/test/Channel.h index 4ab32b9d32..5ec78b2c73 100644 --- a/webrtc/modules/audio_coding/main/test/Channel.h +++ b/webrtc/modules/audio_coding/main/test/Channel.h @@ -66,7 +66,7 @@ class Channel : public AudioPacketizationCallback { void Stats(uint32_t* numPackets); - void Stats(uint8_t* payloadLenByte, uint32_t* payloadType); + void Stats(uint8_t* payloadType, uint32_t* payloadLenByte); void PrintStats(CodecInst& codecInst); diff --git a/webrtc/modules/audio_coding/main/test/RTPFile.cc b/webrtc/modules/audio_coding/main/test/RTPFile.cc index e403020194..4e81943de4 100644 --- a/webrtc/modules/audio_coding/main/test/RTPFile.cc +++ b/webrtc/modules/audio_coding/main/test/RTPFile.cc @@ -43,21 +43,18 @@ void RTPStream::ParseRTPHeader(WebRtcRTPHeader* rtpInfo, void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, int16_t seqNo, uint32_t timeStamp, uint32_t ssrc) { - rtpHeader[0] = (unsigned char) 0x80; - rtpHeader[1] = (unsigned char) (payloadType & 0xFF); - rtpHeader[2] = (unsigned char) ((seqNo >> 8) & 0xFF); - rtpHeader[3] = (unsigned char) ((seqNo) & 0xFF); - rtpHeader[4] = (unsigned char) ((timeStamp >> 24) & 0xFF); - rtpHeader[5] = (unsigned char) ((timeStamp >> 16) & 0xFF); - - rtpHeader[6] = (unsigned char) ((timeStamp >> 8) & 0xFF); - rtpHeader[7] = (unsigned char) (timeStamp & 0xFF); - - rtpHeader[8] = (unsigned char) ((ssrc >> 24) & 0xFF); - rtpHeader[9] = (unsigned char) ((ssrc >> 16) & 0xFF); - - rtpHeader[10] = (unsigned char) ((ssrc >> 8) & 0xFF); - rtpHeader[11] = (unsigned char) (ssrc & 0xFF); + rtpHeader[0] = 0x80; + rtpHeader[1] = payloadType; + rtpHeader[2] = (seqNo >> 8) & 0xFF; + rtpHeader[3] = seqNo & 0xFF; + rtpHeader[4] = timeStamp >> 24; + rtpHeader[5] = (timeStamp >> 16) & 0xFF; + rtpHeader[6] = (timeStamp >> 8) & 0xFF; + rtpHeader[7] = timeStamp & 0xFF; + rtpHeader[8] = ssrc >> 24; + rtpHeader[9] = (ssrc >> 16) & 0xFF; + rtpHeader[10] = (ssrc >> 8) & 0xFF; + rtpHeader[11] = ssrc & 0xFF; } RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo, diff --git a/webrtc/modules/audio_coding/neteq/decoder_database.cc b/webrtc/modules/audio_coding/neteq/decoder_database.cc index 69c7b7bf1d..b9097b0873 100644 --- a/webrtc/modules/audio_coding/neteq/decoder_database.cc +++ b/webrtc/modules/audio_coding/neteq/decoder_database.cc @@ -38,7 +38,7 @@ void DecoderDatabase::Reset() { int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type, NetEqDecoder codec_type) { - if (rtp_payload_type > kMaxRtpPayloadType) { + if (rtp_payload_type > 0x7F) { return kInvalidRtpPayloadType; } if (!CodecSupported(codec_type)) { @@ -74,8 +74,7 @@ int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type, decoder->Init(); std::pair<DecoderMap::iterator, bool> ret; DecoderInfo info(codec_type, fs_hz, decoder, true); - ret = decoders_.insert( - std::pair<uint8_t, DecoderInfo>(rtp_payload_type, info)); + ret = decoders_.insert(std::make_pair(rtp_payload_type, info)); if (ret.second == false) { // Database already contains a decoder with type |rtp_payload_type|. return kDecoderExists; diff --git a/webrtc/modules/audio_coding/neteq/decoder_database.h b/webrtc/modules/audio_coding/neteq/decoder_database.h index cae1021993..1dbc685c37 100644 --- a/webrtc/modules/audio_coding/neteq/decoder_database.h +++ b/webrtc/modules/audio_coding/neteq/decoder_database.h @@ -57,7 +57,6 @@ class DecoderDatabase { bool external; }; - static const uint8_t kMaxRtpPayloadType = 0x7F; // Max for a 7-bit number. // Maximum value for 8 bits, and an invalid RTP payload type (since it is // only 7 bits). static const uint8_t kRtpPayloadTypeError = 0xFF; diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc index bfbf4b3cd1..f1a3a90d77 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -414,7 +414,7 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, decoder_database_->IsRed(rtp_header.header.payloadType) || decoder_database_->IsComfortNoise(rtp_header.header.payloadType)) { LOG_F(LS_ERROR) << "Sync-packet with an unacceptable payload type " - << static_cast<int>(rtp_header.header.payloadType); + << static_cast<int>(rtp_header.header.payloadType); return kSyncPacketNotAccepted; } if (first_packet_ || @@ -422,8 +422,8 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, rtp_header.header.ssrc != ssrc_) { // Even if |current_rtp_payload_type_| is 0xFF, sync-packet isn't // accepted. - LOG_F(LS_ERROR) << "Changing codec, SSRC or first packet " - "with sync-packet."; + LOG_F(LS_ERROR) + << "Changing codec, SSRC or first packet with sync-packet."; return kSyncPacketNotAccepted; } } diff --git a/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.cc b/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.cc index d4c2191a56..3d44fbcb25 100644 --- a/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.cc +++ b/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.cc @@ -352,82 +352,72 @@ bool NETEQTEST_RTPpacket::isLost() const uint8_t NETEQTEST_RTPpacket::payloadType() const { - webrtc::WebRtcRTPHeader tempRTPinfo; - if(_datagram && _datagramLen >= _kBasicHeaderLen) { + webrtc::WebRtcRTPHeader tempRTPinfo; parseRTPheader(&tempRTPinfo); + return tempRTPinfo.header.payloadType; } else { return 0; } - - return tempRTPinfo.header.payloadType; } uint16_t NETEQTEST_RTPpacket::sequenceNumber() const { - webrtc::WebRtcRTPHeader tempRTPinfo; - if(_datagram && _datagramLen >= _kBasicHeaderLen) { + webrtc::WebRtcRTPHeader tempRTPinfo; parseRTPheader(&tempRTPinfo); + return tempRTPinfo.header.sequenceNumber; } else { return 0; } - - return tempRTPinfo.header.sequenceNumber; } uint32_t NETEQTEST_RTPpacket::timeStamp() const { - webrtc::WebRtcRTPHeader tempRTPinfo; - if(_datagram && _datagramLen >= _kBasicHeaderLen) { + webrtc::WebRtcRTPHeader tempRTPinfo; parseRTPheader(&tempRTPinfo); + return tempRTPinfo.header.timestamp; } else { return 0; } - - return tempRTPinfo.header.timestamp; } uint32_t NETEQTEST_RTPpacket::SSRC() const { - webrtc::WebRtcRTPHeader tempRTPinfo; - if(_datagram && _datagramLen >= _kBasicHeaderLen) { + webrtc::WebRtcRTPHeader tempRTPinfo; parseRTPheader(&tempRTPinfo); + return tempRTPinfo.header.ssrc; } else { return 0; } - - return tempRTPinfo.header.ssrc; } uint8_t NETEQTEST_RTPpacket::markerBit() const { - webrtc::WebRtcRTPHeader tempRTPinfo; - if(_datagram && _datagramLen >= _kBasicHeaderLen) { + webrtc::WebRtcRTPHeader tempRTPinfo; parseRTPheader(&tempRTPinfo); + return tempRTPinfo.header.markerBit; } else { return 0; } - - return tempRTPinfo.header.markerBit; } @@ -445,7 +435,7 @@ int NETEQTEST_RTPpacket::setPayloadType(uint8_t pt) _rtpInfo.header.payloadType = pt; } - _datagram[1]=(unsigned char)(pt & 0xFF); + _datagram[1] = pt; return 0; @@ -624,38 +614,31 @@ int NETEQTEST_RTPpacket::splitStereo(NETEQTEST_RTPpacket* slaveRtp, } -void NETEQTEST_RTPpacket::makeRTPheader(unsigned char* rtp_data, uint8_t payloadType, uint16_t seqNo, uint32_t timestamp, uint32_t ssrc, uint8_t markerBit) const +void NETEQTEST_RTPpacket::makeRTPheader(unsigned char* rtp_data, + uint8_t payloadType, + uint16_t seqNo, + uint32_t timestamp, + uint32_t ssrc, + uint8_t markerBit) const { - rtp_data[0]=(unsigned char)0x80; - if (markerBit) - { - rtp_data[0] |= 0x01; - } - else - { - rtp_data[0] &= 0xFE; - } - rtp_data[1]=(unsigned char)(payloadType & 0xFF); - rtp_data[2]=(unsigned char)((seqNo>>8)&0xFF); - rtp_data[3]=(unsigned char)((seqNo)&0xFF); - rtp_data[4]=(unsigned char)((timestamp>>24)&0xFF); - rtp_data[5]=(unsigned char)((timestamp>>16)&0xFF); - - rtp_data[6]=(unsigned char)((timestamp>>8)&0xFF); - rtp_data[7]=(unsigned char)(timestamp & 0xFF); - - rtp_data[8]=(unsigned char)((ssrc>>24)&0xFF); - rtp_data[9]=(unsigned char)((ssrc>>16)&0xFF); - - rtp_data[10]=(unsigned char)((ssrc>>8)&0xFF); - rtp_data[11]=(unsigned char)(ssrc & 0xFF); + rtp_data[0] = markerBit ? 0x81 : 0x80; + rtp_data[1] = payloadType; + rtp_data[2] = seqNo >> 8; + rtp_data[3] = seqNo & 0xFF; + rtp_data[4] = timestamp >> 24; + rtp_data[5] = (timestamp >> 16) & 0xFF; + rtp_data[6] = (timestamp >> 8) & 0xFF; + rtp_data[7] = timestamp & 0xFF; + rtp_data[8] = ssrc >> 24; + rtp_data[9] = (ssrc >> 16) & 0xFF; + rtp_data[10] = (ssrc >> 8) & 0xFF; + rtp_data[11] = ssrc & 0xFF; } -uint16_t - NETEQTEST_RTPpacket::parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo, - uint8_t **payloadPtr) const +uint16_t NETEQTEST_RTPpacket::parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo, + uint8_t **payloadPtr) const { - int16_t *rtp_data = (int16_t *) _datagram; + uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram); int i_P, i_X, i_CC; assert(_datagramLen >= 12); @@ -667,61 +650,54 @@ uint16_t if (payloadPtr) { - *payloadPtr = (uint8_t*) &rtp_data[i_startPosition >> 1]; + *payloadPtr = + reinterpret_cast<uint8_t*>(&rtp_data[i_startPosition >> 1]); } - return (uint16_t) (_datagramLen - i_startPosition - i_padlength); + return static_cast<uint16_t>(_datagramLen - i_startPosition - i_padlength); } void NETEQTEST_RTPpacket::parseBasicHeader(webrtc::WebRtcRTPHeader* RTPinfo, int *i_P, int *i_X, int *i_CC) const { - int16_t *rtp_data = (int16_t *) _datagram; + uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram); if (_datagramLen < 12) { assert(false); return; } - *i_P=(((uint16_t)(rtp_data[0] & 0x20))>>5); /* Extract the P bit */ - *i_X=(((uint16_t)(rtp_data[0] & 0x10))>>4); /* Extract the X bit */ - *i_CC=(uint16_t)(rtp_data[0] & 0xF); /* Get the CC number */ - /* Get the marker bit */ - RTPinfo->header.markerBit = (uint8_t) ((rtp_data[0] >> 15) & 0x01); - /* Get the coder type */ - RTPinfo->header.payloadType = (uint8_t) ((rtp_data[0] >> 8) & 0x7F); - /* Get the packet number */ + *i_P = (rtp_data[0] >> 5) & 0x01; + *i_X = (rtp_data[0] >> 4) & 0x01; + *i_CC = rtp_data[0] & 0xF; + RTPinfo->header.markerBit = (rtp_data[0] >> 15) & 0x01; + RTPinfo->header.payloadType = (rtp_data[0] >> 8) & 0x7F; RTPinfo->header.sequenceNumber = - ((( ((uint16_t)rtp_data[1]) >> 8) & 0xFF) | - ( ((uint16_t)(rtp_data[1] & 0xFF)) << 8)); - /* Get timestamp */ - RTPinfo->header.timestamp = ((((uint16_t)rtp_data[2]) & 0xFF) << 24) | - ((((uint16_t)rtp_data[2]) & 0xFF00) << 8) | - ((((uint16_t)rtp_data[3]) >> 8) & 0xFF) | - ((((uint16_t)rtp_data[3]) & 0xFF) << 8); - /* Get the SSRC */ - RTPinfo->header.ssrc = ((((uint16_t)rtp_data[4]) & 0xFF) << 24) | - ((((uint16_t)rtp_data[4]) & 0xFF00) << 8) | - ((((uint16_t)rtp_data[5]) >> 8) & 0xFF) | - ((((uint16_t)rtp_data[5]) & 0xFF) << 8); + (rtp_data[1] >> 8) | ((rtp_data[1] & 0xFF) << 8); + RTPinfo->header.timestamp = + ((rtp_data[2] & 0xFF) << 24) | ((rtp_data[2] & 0xFF00) << 8) | + (rtp_data[3] >> 8) | ((rtp_data[3] & 0xFF) << 8); + RTPinfo->header.ssrc = + ((rtp_data[4] & 0xFF) << 24) | ((rtp_data[4] & 0xFF00) << 8) | + (rtp_data[5] >> 8) | ((rtp_data[5] & 0xFF) << 8); } int NETEQTEST_RTPpacket::calcHeaderLength(int i_X, int i_CC) const { int i_extlength = 0; - int16_t *rtp_data = (int16_t *) _datagram; + uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram); if (i_X == 1) { // Extension header exists. // Find out how many int32_t it consists of. - assert(_datagramLen > 2 * (7 + 2 * i_CC)); - if (_datagramLen > 2 * (7 + 2 * i_CC)) + int offset = 7 + 2 * i_CC; + assert(_datagramLen > 2 * offset); + if (_datagramLen > 2 * offset) { - i_extlength = (((((uint16_t) rtp_data[7 + 2 * i_CC]) >> 8) - & 0xFF) | (((uint16_t) (rtp_data[7 + 2 * i_CC] & 0xFF)) - << 8)) + 1; + i_extlength = 1 + + (((rtp_data[offset]) >> 8) | ((rtp_data[offset] & 0xFF) << 8)); } } @@ -730,7 +706,7 @@ int NETEQTEST_RTPpacket::calcHeaderLength(int i_X, int i_CC) const int NETEQTEST_RTPpacket::calcPadLength(int i_P) const { - int16_t *rtp_data = (int16_t *) _datagram; + uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram); if (i_P == 1) { /* Padding exists. Find out how many bytes the padding consists of. */ @@ -742,7 +718,7 @@ int NETEQTEST_RTPpacket::calcPadLength(int i_P) const else { /* even number of bytes => last byte in lower byte */ - return ((uint16_t) rtp_data[(_datagramLen >> 1) - 1]) >> 8; + return rtp_data[(_datagramLen >> 1) - 1] >> 8; } } return 0; @@ -838,7 +814,7 @@ int NETEQTEST_RTPpacket::extractRED(int index, webrtc::WebRtcRTPHeader& red) { // Header found. red.header.payloadType = ptr[0] & 0x7F; - uint32_t offset = (ptr[1] << 6) + ((ptr[2] & 0xFC) >> 2); + uint32_t offset = (ptr[1] << 6) + (ptr[2] >> 2); red.header.sequenceNumber = sequenceNumber(); red.header.timestamp = timeStamp() - offset; red.header.markerBit = markerBit(); diff --git a/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h b/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h index 86bf3b0182..3fbce8be5c 100644 --- a/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h +++ b/webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h @@ -36,7 +36,6 @@ public: int readFixedFromFile(FILE *fp, size_t len); virtual int writeToFile(FILE *fp); void blockPT(uint8_t pt); - //int16_t payloadType(); virtual void parseHeader(); void parseHeader(webrtc::WebRtcRTPHeader* rtp_header); const webrtc::WebRtcRTPHeader* RTPinfo() const; diff --git a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc index e6d8f2e21b..4e779b49b0 100644 --- a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc +++ b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc @@ -71,15 +71,47 @@ /* Function declarations */ /*************************/ -void NetEQTest_GetCodec_and_PT(char * name, webrtc::NetEqDecoder *codec, int *PT, int frameLen, int *fs, int *bitrate, int *useRed); -int NetEQTest_init_coders(webrtc::NetEqDecoder coder, int enc_frameSize, int bitrate, int sampfreq , int vad, int numChannels); -void defineCodecs(webrtc::NetEqDecoder *usedCodec, int *noOfCodecs ); +void NetEQTest_GetCodec_and_PT(char* name, + webrtc::NetEqDecoder* codec, + int* PT, + int frameLen, + int* fs, + int* bitrate, + int* useRed); +int NetEQTest_init_coders(webrtc::NetEqDecoder coder, + int enc_frameSize, + int bitrate, + int sampfreq, + int vad, + int numChannels); +void defineCodecs(webrtc::NetEqDecoder* usedCodec, int* noOfCodecs); int NetEQTest_free_coders(webrtc::NetEqDecoder coder, int numChannels); -int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * encoded,int sampleRate , int * vad, int useVAD, int bitrate, int numChannels); -void makeRTPheader(unsigned char* rtp_data, int payloadType, int seqNo, uint32_t timestamp, uint32_t ssrc); -int makeRedundantHeader(unsigned char* rtp_data, int *payloadType, int numPayloads, uint32_t *timestamp, uint16_t *blockLen, - int seqNo, uint32_t ssrc); -int makeDTMFpayload(unsigned char* payload_data, int Event, int End, int Volume, int Duration); +int NetEQTest_encode(int coder, + int16_t* indata, + int frameLen, + unsigned char* encoded, + int sampleRate, + int* vad, + int useVAD, + int bitrate, + int numChannels); +void makeRTPheader(unsigned char* rtp_data, + int payloadType, + int seqNo, + uint32_t timestamp, + uint32_t ssrc); +int makeRedundantHeader(unsigned char* rtp_data, + int* payloadType, + int numPayloads, + uint32_t* timestamp, + uint16_t* blockLen, + int seqNo, + uint32_t ssrc); +int makeDTMFpayload(unsigned char* payload_data, + int Event, + int End, + int Volume, + int Duration); void stereoDeInterleave(int16_t* audioSamples, int numSamples); void stereoInterleave(unsigned char* data, int dataLen, int stride); @@ -231,37 +263,37 @@ WebRtcVadInst *VAD_inst[2]; int main(int argc, char* argv[]) { - int packet_size, fs; - webrtc::NetEqDecoder usedCodec; - int payloadType; - int bitrate = 0; - int useVAD, vad; + int packet_size, fs; + webrtc::NetEqDecoder usedCodec; + int payloadType; + int bitrate = 0; + int useVAD, vad; int useRed=0; - int len, enc_len; - int16_t org_data[4000]; - unsigned char rtp_data[8000]; - int16_t seqNo=0xFFF; - uint32_t ssrc=1235412312; - uint32_t timestamp=0xAC1245; - uint16_t length, plen; - uint32_t offset; - double sendtime = 0; + int len, enc_len; + int16_t org_data[4000]; + unsigned char rtp_data[8000]; + int16_t seqNo=0xFFF; + uint32_t ssrc=1235412312; + uint32_t timestamp=0xAC1245; + uint16_t length, plen; + uint32_t offset; + double sendtime = 0; int red_PT[2] = {0}; uint32_t red_TS[2] = {0}; uint16_t red_len[2] = {0}; int RTPheaderLen=12; uint8_t red_data[8000]; #ifdef INSERT_OLD_PACKETS - uint16_t old_length, old_plen; - int old_enc_len; - int first_old_packet=1; - unsigned char old_rtp_data[8000]; - int packet_age=0; + uint16_t old_length, old_plen; + int old_enc_len; + int first_old_packet=1; + unsigned char old_rtp_data[8000]; + int packet_age=0; #endif #ifdef INSERT_DTMF_PACKETS - int NTone = 1; - int DTMFfirst = 1; - uint32_t DTMFtimestamp; + int NTone = 1; + int DTMFfirst = 1; + uint32_t DTMFtimestamp; bool dtmfSent = false; #endif bool usingStereo = false; @@ -789,7 +821,13 @@ int main(int argc, char* argv[]) /* Subfunctions */ /****************/ -void NetEQTest_GetCodec_and_PT(char * name, webrtc::NetEqDecoder *codec, int *PT, int frameLen, int *fs, int *bitrate, int *useRed) { +void NetEQTest_GetCodec_and_PT(char* name, + webrtc::NetEqDecoder* codec, + int* PT, + int frameLen, + int* fs, + int* bitrate, + int* useRed) { *bitrate = 0; /* Default bitrate setting */ *useRed = 0; /* Default no redundancy */ @@ -1626,59 +1664,71 @@ int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * e -void makeRTPheader(unsigned char* rtp_data, int payloadType, int seqNo, uint32_t timestamp, uint32_t ssrc){ - - rtp_data[0]=(unsigned char)0x80; - rtp_data[1]=(unsigned char)(payloadType & 0xFF); - rtp_data[2]=(unsigned char)((seqNo>>8)&0xFF); - rtp_data[3]=(unsigned char)((seqNo)&0xFF); - rtp_data[4]=(unsigned char)((timestamp>>24)&0xFF); - rtp_data[5]=(unsigned char)((timestamp>>16)&0xFF); - - rtp_data[6]=(unsigned char)((timestamp>>8)&0xFF); - rtp_data[7]=(unsigned char)(timestamp & 0xFF); - - rtp_data[8]=(unsigned char)((ssrc>>24)&0xFF); - rtp_data[9]=(unsigned char)((ssrc>>16)&0xFF); - - rtp_data[10]=(unsigned char)((ssrc>>8)&0xFF); - rtp_data[11]=(unsigned char)(ssrc & 0xFF); +void makeRTPheader(unsigned char* rtp_data, + int payloadType, + int seqNo, + uint32_t timestamp, + uint32_t ssrc) { + rtp_data[0] = 0x80; + rtp_data[1] = payloadType & 0xFF; + rtp_data[2] = (seqNo >> 8) & 0xFF; + rtp_data[3] = seqNo & 0xFF; + rtp_data[4] = timestamp >> 24; + rtp_data[5] = (timestamp >> 16) & 0xFF; + rtp_data[6] = (timestamp >> 8) & 0xFF; + rtp_data[7] = timestamp & 0xFF; + rtp_data[8] = ssrc >> 24; + rtp_data[9] = (ssrc >> 16) & 0xFF; + rtp_data[10] = (ssrc >> 8) & 0xFF; + rtp_data[11] = ssrc & 0xFF; } -int makeRedundantHeader(unsigned char* rtp_data, int *payloadType, int numPayloads, uint32_t *timestamp, uint16_t *blockLen, - int seqNo, uint32_t ssrc) +int makeRedundantHeader(unsigned char* rtp_data, + int* payloadType, + int numPayloads, + uint32_t* timestamp, + uint16_t* blockLen, + int seqNo, + uint32_t ssrc) { - int i; - unsigned char *rtpPointer; + unsigned char* rtpPointer; uint16_t offset; /* first create "standard" RTP header */ - makeRTPheader(rtp_data, NETEQ_CODEC_RED_PT, seqNo, timestamp[numPayloads-1], ssrc); + makeRTPheader(rtp_data, NETEQ_CODEC_RED_PT, seqNo, timestamp[numPayloads-1], + ssrc); rtpPointer = &rtp_data[12]; /* add one sub-header for each redundant payload (not the primary) */ - for(i=0; i<numPayloads-1; i++) { /* |0 1 2 3 4 5 6 7| */ - if(blockLen[i] > 0) { - offset = (uint16_t) (timestamp[numPayloads-1] - timestamp[i]); - - rtpPointer[0] = (unsigned char) ( 0x80 | (0x7F & payloadType[i]) ); /* |F| block PT | */ - rtpPointer[1] = (unsigned char) ((offset >> 6) & 0xFF); /* | timestamp- | */ - rtpPointer[2] = (unsigned char) ( ((offset & 0x3F)<<2) | - ( (blockLen[i]>>8) & 0x03 ) ); /* | -offset |bl-| */ - rtpPointer[3] = (unsigned char) ( blockLen[i] & 0xFF ); /* | -ock length | */ + for (i = 0; i < numPayloads - 1; i++) { + if (blockLen[i] > 0) { + offset = static_cast<uint16_t>( + timestamp[numPayloads - 1] - timestamp[i]); + + // Byte |0| |1 2 | 3 | + // Bit |0|1234567|01234567012345|6701234567| + // |F|payload| timestamp | block | + // | | type | offset | length | + rtpPointer[0] = (payloadType[i] & 0x7F) | 0x80; + rtpPointer[1] = (offset >> 6) & 0xFF; + rtpPointer[2] = + ((offset & 0x3F) << 2) | ((blockLen[i] >> 8) & 0x03); + rtpPointer[3] = blockLen[i] & 0xFF; rtpPointer += 4; } } - /* last sub-header */ - rtpPointer[0]= (unsigned char) (0x00 | (0x7F&payloadType[numPayloads-1]));/* |F| block PT | */ - rtpPointer += 1; + // Bit |0|1234567| + // |0|payload| + // | | type | + rtpPointer[0] = payloadType[numPayloads - 1] & 0x7F; + ++rtpPointer; - return(rtpPointer - rtp_data); /* length of header in bytes */ + return rtpPointer - rtp_data; // length of header in bytes } diff --git a/webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.cc b/webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.cc index 3942c13bb8..65c4e9dc82 100644 --- a/webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.cc +++ b/webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.cc @@ -51,14 +51,14 @@ Packet* ConstantPcmPacketSource::NextPacket() { void ConstantPcmPacketSource::WriteHeader(uint8_t* packet_memory) { packet_memory[0] = 0x80; - packet_memory[1] = payload_type_ & 0xFF; - packet_memory[2] = (seq_number_ >> 8) & 0xFF; + packet_memory[1] = static_cast<uint8_t>(payload_type_); + packet_memory[2] = seq_number_ >> 8; packet_memory[3] = seq_number_ & 0xFF; - packet_memory[4] = (timestamp_ >> 24) & 0xFF; + packet_memory[4] = timestamp_ >> 24; packet_memory[5] = (timestamp_ >> 16) & 0xFF; packet_memory[6] = (timestamp_ >> 8) & 0xFF; packet_memory[7] = timestamp_ & 0xFF; - packet_memory[8] = (payload_ssrc_ >> 24) & 0xFF; + packet_memory[8] = payload_ssrc_ >> 24; packet_memory[9] = (payload_ssrc_ >> 16) & 0xFF; packet_memory[10] = (payload_ssrc_ >> 8) & 0xFF; packet_memory[11] = payload_ssrc_ & 0xFF; diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc index bc0706398d..efa86d8d8d 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc @@ -183,214 +183,90 @@ std::string CodecName(webrtc::NetEqDecoder codec) { } } +void RegisterPayloadType(NetEq* neteq, + webrtc::NetEqDecoder codec, + google::int32 flag) { + if (neteq->RegisterPayloadType(codec, static_cast<uint8_t>(flag))) { + std::cerr << "Cannot register payload type " << flag << " as " + << CodecName(codec) << std::endl; + exit(1); + } +} + // Registers all decoders in |neteq|. void RegisterPayloadTypes(NetEq* neteq) { assert(neteq); - int error; - error = neteq->RegisterPayloadType(webrtc::kDecoderPCMu, - static_cast<uint8_t>(FLAGS_pcmu)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_pcmu << - " as " << CodecName(webrtc::kDecoderPCMu).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderPCMa, - static_cast<uint8_t>(FLAGS_pcma)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_pcma << - " as " << CodecName(webrtc::kDecoderPCMa).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderILBC, - static_cast<uint8_t>(FLAGS_ilbc)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_ilbc << - " as " << CodecName(webrtc::kDecoderILBC).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderISAC, - static_cast<uint8_t>(FLAGS_isac)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_isac << - " as " << CodecName(webrtc::kDecoderISAC).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderISACswb, - static_cast<uint8_t>(FLAGS_isac_swb)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_isac_swb << - " as " << CodecName(webrtc::kDecoderISACswb).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderOpus, - static_cast<uint8_t>(FLAGS_opus)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_opus << " as " - << CodecName(webrtc::kDecoderOpus).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderPCM16B, - static_cast<uint8_t>(FLAGS_pcm16b)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_pcm16b << - " as " << CodecName(webrtc::kDecoderPCM16B).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderPCM16Bwb, - static_cast<uint8_t>(FLAGS_pcm16b_wb)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_pcm16b_wb << - " as " << CodecName(webrtc::kDecoderPCM16Bwb).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderPCM16Bswb32kHz, - static_cast<uint8_t>(FLAGS_pcm16b_swb32)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_pcm16b_swb32 << - " as " << CodecName(webrtc::kDecoderPCM16Bswb32kHz).c_str() << - std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderPCM16Bswb48kHz, - static_cast<uint8_t>(FLAGS_pcm16b_swb48)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_pcm16b_swb48 << - " as " << CodecName(webrtc::kDecoderPCM16Bswb48kHz).c_str() << - std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderG722, - static_cast<uint8_t>(FLAGS_g722)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_g722 << - " as " << CodecName(webrtc::kDecoderG722).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderAVT, - static_cast<uint8_t>(FLAGS_avt)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_avt << - " as " << CodecName(webrtc::kDecoderAVT).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderRED, - static_cast<uint8_t>(FLAGS_red)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_red << - " as " << CodecName(webrtc::kDecoderRED).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderCNGnb, - static_cast<uint8_t>(FLAGS_cn_nb)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_cn_nb << - " as " << CodecName(webrtc::kDecoderCNGnb).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderCNGwb, - static_cast<uint8_t>(FLAGS_cn_wb)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_cn_wb << - " as " << CodecName(webrtc::kDecoderCNGwb).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderCNGswb32kHz, - static_cast<uint8_t>(FLAGS_cn_swb32)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_cn_swb32 << - " as " << CodecName(webrtc::kDecoderCNGswb32kHz).c_str() << std::endl; - exit(1); - } - error = neteq->RegisterPayloadType(webrtc::kDecoderCNGswb48kHz, - static_cast<uint8_t>(FLAGS_cn_swb48)); - if (error) { - std::cerr << "Cannot register payload type " << FLAGS_cn_swb48 << - " as " << CodecName(webrtc::kDecoderCNGswb48kHz).c_str() << std::endl; - exit(1); - } + RegisterPayloadType(neteq, webrtc::kDecoderPCMu, FLAGS_pcmu); + RegisterPayloadType(neteq, webrtc::kDecoderPCMa, FLAGS_pcma); + RegisterPayloadType(neteq, webrtc::kDecoderILBC, FLAGS_ilbc); + RegisterPayloadType(neteq, webrtc::kDecoderISAC, FLAGS_isac); + RegisterPayloadType(neteq, webrtc::kDecoderISACswb, FLAGS_isac_swb); + RegisterPayloadType(neteq, webrtc::kDecoderOpus, FLAGS_opus); + RegisterPayloadType(neteq, webrtc::kDecoderPCM16B, FLAGS_pcm16b); + RegisterPayloadType(neteq, webrtc::kDecoderPCM16Bwb, FLAGS_pcm16b_wb); + RegisterPayloadType(neteq, webrtc::kDecoderPCM16Bswb32kHz, + FLAGS_pcm16b_swb32); + RegisterPayloadType(neteq, webrtc::kDecoderPCM16Bswb48kHz, + FLAGS_pcm16b_swb48); + RegisterPayloadType(neteq, webrtc::kDecoderG722, FLAGS_g722); + RegisterPayloadType(neteq, webrtc::kDecoderAVT, FLAGS_avt); + RegisterPayloadType(neteq, webrtc::kDecoderRED, FLAGS_red); + RegisterPayloadType(neteq, webrtc::kDecoderCNGnb, FLAGS_cn_nb); + RegisterPayloadType(neteq, webrtc::kDecoderCNGwb, FLAGS_cn_wb); + RegisterPayloadType(neteq, webrtc::kDecoderCNGswb32kHz, FLAGS_cn_swb32); + RegisterPayloadType(neteq, webrtc::kDecoderCNGswb48kHz, FLAGS_cn_swb48); +} + +void PrintCodecMappingEntry(webrtc::NetEqDecoder codec, google::int32 flag) { + std::cout << CodecName(codec) << ": " << flag << std::endl; } void PrintCodecMapping() { - std::cout << CodecName(webrtc::kDecoderPCMu).c_str() << ": " << FLAGS_pcmu << - std::endl; - std::cout << CodecName(webrtc::kDecoderPCMa).c_str() << ": " << FLAGS_pcma << - std::endl; - std::cout << CodecName(webrtc::kDecoderILBC).c_str() << ": " << FLAGS_ilbc << - std::endl; - std::cout << CodecName(webrtc::kDecoderISAC).c_str() << ": " << FLAGS_isac << - std::endl; - std::cout << CodecName(webrtc::kDecoderISACswb).c_str() << ": " << - FLAGS_isac_swb << std::endl; - std::cout << CodecName(webrtc::kDecoderOpus).c_str() << ": " << FLAGS_opus - << std::endl; - std::cout << CodecName(webrtc::kDecoderPCM16B).c_str() << ": " << - FLAGS_pcm16b << std::endl; - std::cout << CodecName(webrtc::kDecoderPCM16Bwb).c_str() << ": " << - FLAGS_pcm16b_wb << std::endl; - std::cout << CodecName(webrtc::kDecoderPCM16Bswb32kHz).c_str() << ": " << - FLAGS_pcm16b_swb32 << std::endl; - std::cout << CodecName(webrtc::kDecoderPCM16Bswb48kHz).c_str() << ": " << - FLAGS_pcm16b_swb48 << std::endl; - std::cout << CodecName(webrtc::kDecoderG722).c_str() << ": " << FLAGS_g722 << - std::endl; - std::cout << CodecName(webrtc::kDecoderAVT).c_str() << ": " << FLAGS_avt << - std::endl; - std::cout << CodecName(webrtc::kDecoderRED).c_str() << ": " << FLAGS_red << - std::endl; - std::cout << CodecName(webrtc::kDecoderCNGnb).c_str() << ": " << - FLAGS_cn_nb << std::endl; - std::cout << CodecName(webrtc::kDecoderCNGwb).c_str() << ": " << - FLAGS_cn_wb << std::endl; - std::cout << CodecName(webrtc::kDecoderCNGswb32kHz).c_str() << ": " << - FLAGS_cn_swb32 << std::endl; - std::cout << CodecName(webrtc::kDecoderCNGswb48kHz).c_str() << ": " << - FLAGS_cn_swb48 << std::endl; + PrintCodecMappingEntry(webrtc::kDecoderPCMu, FLAGS_pcmu); + PrintCodecMappingEntry(webrtc::kDecoderPCMa, FLAGS_pcma); + PrintCodecMappingEntry(webrtc::kDecoderILBC, FLAGS_ilbc); + PrintCodecMappingEntry(webrtc::kDecoderISAC, FLAGS_isac); + PrintCodecMappingEntry(webrtc::kDecoderISACswb, FLAGS_isac_swb); + PrintCodecMappingEntry(webrtc::kDecoderOpus, FLAGS_opus); + PrintCodecMappingEntry(webrtc::kDecoderPCM16B, FLAGS_pcm16b); + PrintCodecMappingEntry(webrtc::kDecoderPCM16Bwb, FLAGS_pcm16b_wb); + PrintCodecMappingEntry(webrtc::kDecoderPCM16Bswb32kHz, FLAGS_pcm16b_swb32); + PrintCodecMappingEntry(webrtc::kDecoderPCM16Bswb48kHz, FLAGS_pcm16b_swb48); + PrintCodecMappingEntry(webrtc::kDecoderG722, FLAGS_g722); + PrintCodecMappingEntry(webrtc::kDecoderAVT, FLAGS_avt); + PrintCodecMappingEntry(webrtc::kDecoderRED, FLAGS_red); + PrintCodecMappingEntry(webrtc::kDecoderCNGnb, FLAGS_cn_nb); + PrintCodecMappingEntry(webrtc::kDecoderCNGwb, FLAGS_cn_wb); + PrintCodecMappingEntry(webrtc::kDecoderCNGswb32kHz, FLAGS_cn_swb32); + PrintCodecMappingEntry(webrtc::kDecoderCNGswb48kHz, FLAGS_cn_swb48); } -bool IsComfortNosie(uint8_t payload_type) { - if (payload_type == FLAGS_cn_nb || - payload_type == FLAGS_cn_wb || - payload_type == FLAGS_cn_swb32 || - payload_type == FLAGS_cn_swb48) { - return true; - } else { - return false; - } +bool IsComfortNoise(uint8_t payload_type) { + return payload_type == FLAGS_cn_nb || payload_type == FLAGS_cn_wb || + payload_type == FLAGS_cn_swb32 || payload_type == FLAGS_cn_swb48; } int CodecSampleRate(uint8_t payload_type) { - if (payload_type == FLAGS_pcmu || - payload_type == FLAGS_pcma || - payload_type == FLAGS_ilbc || - payload_type == FLAGS_pcm16b || - payload_type == FLAGS_cn_nb) { + if (payload_type == FLAGS_pcmu || payload_type == FLAGS_pcma || + payload_type == FLAGS_ilbc || payload_type == FLAGS_pcm16b || + payload_type == FLAGS_cn_nb) return 8000; - } else if (payload_type == FLAGS_isac || - payload_type == FLAGS_pcm16b_wb || - payload_type == FLAGS_g722 || - payload_type == FLAGS_cn_wb) { + if (payload_type == FLAGS_isac || payload_type == FLAGS_pcm16b_wb || + payload_type == FLAGS_g722 || payload_type == FLAGS_cn_wb) return 16000; - } else if (payload_type == FLAGS_isac_swb || - payload_type == FLAGS_pcm16b_swb32 || - payload_type == FLAGS_cn_swb32) { + if (payload_type == FLAGS_isac_swb || payload_type == FLAGS_pcm16b_swb32 || + payload_type == FLAGS_cn_swb32) return 32000; - } else if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 || - payload_type == FLAGS_cn_swb48) { + if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 || + payload_type == FLAGS_cn_swb48) return 48000; - } else if (payload_type == FLAGS_avt || - payload_type == FLAGS_red) { - return 0; - } else { - return -1; - } + if (payload_type == FLAGS_avt || payload_type == FLAGS_red) + return 0; + return -1; } int CodecTimestampRate(uint8_t payload_type) { - if (payload_type == FLAGS_g722) { - return 8000; - } else { - return CodecSampleRate(payload_type); - } + return (payload_type == FLAGS_g722) ? 8000 : CodecSampleRate(payload_type); } size_t ReplacePayload(webrtc::test::InputAudioFile* replacement_audio_file, @@ -402,7 +278,7 @@ size_t ReplacePayload(webrtc::test::InputAudioFile* replacement_audio_file, const webrtc::test::Packet* next_packet) { size_t payload_len = 0; // Check for CNG. - if (IsComfortNosie(rtp_header->header.payloadType)) { + if (IsComfortNoise(rtp_header->header.payloadType)) { // If CNG, simply insert a zero-energy one-byte payload. if (*payload_mem_size_bytes < 1) { (*payload).reset(new uint8_t[1]); diff --git a/webrtc/modules/audio_coding/neteq/tools/packet_unittest.cc b/webrtc/modules/audio_coding/neteq/tools/packet_unittest.cc index 10bcc5cf7f..b32f54e03c 100644 --- a/webrtc/modules/audio_coding/neteq/tools/packet_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/tools/packet_unittest.cc @@ -26,14 +26,14 @@ void MakeRtpHeader(int payload_type, uint32_t ssrc, uint8_t* rtp_data) { rtp_data[0] = 0x80; - rtp_data[1] = payload_type & 0xFF; + rtp_data[1] = static_cast<uint8_t>(payload_type); rtp_data[2] = (seq_number >> 8) & 0xFF; rtp_data[3] = (seq_number) & 0xFF; - rtp_data[4] = (timestamp >> 24) & 0xFF; + rtp_data[4] = timestamp >> 24; rtp_data[5] = (timestamp >> 16) & 0xFF; rtp_data[6] = (timestamp >> 8) & 0xFF; rtp_data[7] = timestamp & 0xFF; - rtp_data[8] = (ssrc >> 24) & 0xFF; + rtp_data[8] = ssrc >> 24; rtp_data[9] = (ssrc >> 16) & 0xFF; rtp_data[10] = (ssrc >> 8) & 0xFF; rtp_data[11] = ssrc & 0xFF; diff --git a/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h index aaf84259dd..873ac31515 100644 --- a/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h +++ b/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h @@ -234,7 +234,9 @@ class MockRtpRtcp : public RtpRtcp { MOCK_METHOD1(SetTargetSendBitrate, void(uint32_t bitrate_bps)); MOCK_METHOD3(SetGenericFECStatus, - int32_t(const bool enable, const uint8_t payloadTypeRED, const uint8_t payloadTypeFEC)); + int32_t(const bool enable, + const uint8_t payloadTypeRED, + const uint8_t payloadTypeFEC)); MOCK_METHOD3(GenericFECStatus, int32_t(bool& enable, uint8_t& payloadTypeRED, uint8_t& payloadTypeFEC)); MOCK_METHOD2(SetFecParameters, diff --git a/webrtc/modules/rtp_rtcp/source/fec_test_helper.h b/webrtc/modules/rtp_rtcp/source/fec_test_helper.h index 825396122a..e1791adba3 100644 --- a/webrtc/modules/rtp_rtcp/source/fec_test_helper.h +++ b/webrtc/modules/rtp_rtcp/source/fec_test_helper.h @@ -16,15 +16,9 @@ namespace webrtc { -enum { - kFecPayloadType = 96 -}; -enum { - kRedPayloadType = 97 -}; -enum { - kVp8PayloadType = 120 -}; +const uint8_t kFecPayloadType = 96; +const uint8_t kRedPayloadType = 97; +const uint8_t kVp8PayloadType = 120; typedef ForwardErrorCorrection::Packet Packet; diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc index 0a0ee8915b..4e532e6d05 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc @@ -185,23 +185,23 @@ TEST(NACKStringBuilderTest, TestCase13) { EXPECT_EQ(std::string("5-6,9"), builder.GetResult()); } -void CreateRtpPacket(const bool marker_bit, const uint8_t payload, +void CreateRtpPacket(const bool marker_bit, const uint8_t payload_type, const uint16_t seq_num, const uint32_t timestamp, const uint32_t ssrc, uint8_t* array, size_t* cur_pos) { - ASSERT_TRUE(payload <= 127); + ASSERT_LE(payload_type, 127); array[(*cur_pos)++] = 0x80; - array[(*cur_pos)++] = payload | (marker_bit ? 0x80 : 0); + array[(*cur_pos)++] = payload_type | (marker_bit ? 0x80 : 0); array[(*cur_pos)++] = seq_num >> 8; - array[(*cur_pos)++] = seq_num; + array[(*cur_pos)++] = seq_num & 0xFF; array[(*cur_pos)++] = timestamp >> 24; - array[(*cur_pos)++] = timestamp >> 16; - array[(*cur_pos)++] = timestamp >> 8; - array[(*cur_pos)++] = timestamp; + array[(*cur_pos)++] = (timestamp >> 16) & 0xFF; + array[(*cur_pos)++] = (timestamp >> 8) & 0xFF; + array[(*cur_pos)++] = timestamp & 0xFF; array[(*cur_pos)++] = ssrc >> 24; - array[(*cur_pos)++] = ssrc >> 16; - array[(*cur_pos)++] = ssrc >> 8; - array[(*cur_pos)++] = ssrc; + array[(*cur_pos)++] = (ssrc >> 16) & 0xFF; + array[(*cur_pos)++] = (ssrc >> 8) & 0xFF; + array[(*cur_pos)++] = ssrc & 0xFF; // VP8 payload header array[(*cur_pos)++] = 0x90; // X bit = 1 array[(*cur_pos)++] = 0x20; // T bit = 1 @@ -353,19 +353,19 @@ TEST_F(RtcpSenderTest, IJStatus) { TEST_F(RtcpSenderTest, TestCompound) { const bool marker_bit = false; - const uint8_t payload = 100; + const uint8_t payload_type = 100; const uint16_t seq_num = 11111; const uint32_t timestamp = 1234567; const uint32_t ssrc = 0x11111111; size_t packet_length = 0; - CreateRtpPacket(marker_bit, payload, seq_num, timestamp, ssrc, packet_, + CreateRtpPacket(marker_bit, payload_type, seq_num, timestamp, ssrc, packet_, &packet_length); EXPECT_EQ(25u, packet_length); VideoCodec codec_inst; strncpy(codec_inst.plName, "VP8", webrtc::kPayloadNameSize - 1); codec_inst.codecType = webrtc::kVideoCodecVP8; - codec_inst.plType = payload; + codec_inst.plType = payload_type; EXPECT_EQ(0, rtp_receiver_->RegisterReceivePayload(codec_inst.plName, codec_inst.plType, 90000, diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc index 2dacbdd142..b2c846c3c3 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc @@ -225,8 +225,7 @@ TEST_P(ParameterizedRtpPayloadRegistryTest, bool ignored; EXPECT_EQ(-1, rtp_payload_registry_->RegisterReceivePayload( - "whatever", static_cast<uint8_t>(payload_type), 19, 1, 17, - &ignored)); + "whatever", static_cast<uint8_t>(payload_type), 19, 1, 17, &ignored)); } INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes, diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc index dc5241a793..e19378aa2e 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc @@ -64,7 +64,7 @@ bool RTPReceiverAudio::TelephoneEventForwardToDecoder() const { bool RTPReceiverAudio::TelephoneEventPayloadType( int8_t payload_type) const { CriticalSectionScoped lock(crit_sect_.get()); - return (telephone_event_payload_type_ == payload_type) ? true : false; + return telephone_event_payload_type_ == payload_type; } bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type, diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index fe1af00a3d..0991cc40f4 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -1614,9 +1614,9 @@ int32_t RTPSender::SetGenericFECStatus(bool enable, payload_type_fec); } -int32_t RTPSender::GenericFECStatus( - bool *enable, uint8_t *payload_type_red, - uint8_t *payload_type_fec) const { +int32_t RTPSender::GenericFECStatus(bool* enable, + uint8_t* payload_type_red, + uint8_t* payload_type_fec) const { if (audio_configured_) { return -1; } diff --git a/webrtc/modules/rtp_rtcp/source/rtp_utility.cc b/webrtc/modules/rtp_rtcp/source/rtp_utility.cc index 2897fac636..b12839e16e 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_utility.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_utility.cc @@ -242,21 +242,19 @@ bool RtpHeaderParser::RTCP() const { return false; } - const uint8_t V = _ptrRTPDataBegin[0] >> 6; + const uint8_t V = _ptrRTPDataBegin[0] >> 6; if (V != kRtcpExpectedVersion) { return false; } - const uint8_t payloadType = _ptrRTPDataBegin[1]; - bool RTCP = false; + const uint8_t payloadType = _ptrRTPDataBegin[1]; switch (payloadType) { case 192: - RTCP = true; - break; + return true; case 193: // not supported // pass through and check for a potential RTP packet - break; + return false; case 195: case 200: case 201: @@ -266,10 +264,10 @@ bool RtpHeaderParser::RTCP() const { case 205: case 206: case 207: - RTCP = true; - break; + return true; + default: + return false; } - return RTCP; } bool RtpHeaderParser::ParseRtcp(RTPHeader* header) const { diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc index 59c36d33ff..c60ed8f0be 100644 --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc @@ -22,6 +22,12 @@ #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" +namespace { + +const unsigned char kPayloadType = 100; + +}; + namespace webrtc { class RtpRtcpVideoTest : public ::testing::Test { @@ -136,7 +142,6 @@ class RtpRtcpVideoTest : public ::testing::Test { uint8_t video_frame_[65000]; size_t payload_data_length_; SimulatedClock fake_clock; - enum { kPayloadType = 100 }; }; TEST_F(RtpRtcpVideoTest, BasicVideo) { @@ -172,7 +177,7 @@ TEST_F(RtpRtcpVideoTest, PaddingOnlyFrames) { EXPECT_TRUE(parser->Parse(padding_packet, packet_size, &header)); PayloadUnion payload_specific; EXPECT_TRUE(rtp_payload_registry_.GetPayloadSpecifics(header.payloadType, - &payload_specific)); + &payload_specific)); const uint8_t* payload = padding_packet + header.headerLength; const size_t payload_length = packet_size - header.headerLength; EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, payload, diff --git a/webrtc/modules/utility/source/rtp_dump_impl.cc b/webrtc/modules/utility/source/rtp_dump_impl.cc index c9cb2eead3..495a1e4060 100644 --- a/webrtc/modules/utility/source/rtp_dump_impl.cc +++ b/webrtc/modules/utility/source/rtp_dump_impl.cc @@ -207,22 +207,9 @@ int32_t RtpDumpImpl::DumpPacket(const uint8_t* packet, size_t packetLength) bool RtpDumpImpl::RTCP(const uint8_t* packet) const { - const uint8_t payloadType = packet[1]; - bool is_rtcp = false; - - switch(payloadType) - { - case 192: - is_rtcp = true; - break; - case 193: case 195: - break; - case 200: case 201: case 202: case 203: - case 204: case 205: case 206: case 207: - is_rtcp = true; - break; - } - return is_rtcp; + return packet[1] == 192 || packet[1] == 200 || packet[1] == 201 || + packet[1] == 202 || packet[1] == 203 || packet[1] == 204 || + packet[1] == 205 || packet[1] == 206 || packet[1] == 207; } // TODO (hellner): why is TickUtil not used here? diff --git a/webrtc/modules/video_coding/main/interface/video_coding.h b/webrtc/modules/video_coding/main/interface/video_coding.h index bba68c56f0..2371685625 100644 --- a/webrtc/modules/video_coding/main/interface/video_coding.h +++ b/webrtc/modules/video_coding/main/interface/video_coding.h @@ -191,8 +191,8 @@ public: // Return value : VCM_OK, on success. // < 0, on error. virtual int32_t RegisterExternalEncoder(VideoEncoder* externalEncoder, - uint8_t payloadType, - bool internalSource = false) = 0; + uint8_t payloadType, + bool internalSource = false) = 0; // API to get codec config parameters to be sent out-of-band to a receiver. // @@ -380,8 +380,8 @@ public: // Return value : VCM_OK, on success. // < 0, on error. virtual int32_t RegisterExternalDecoder(VideoDecoder* externalDecoder, - uint8_t payloadType, - bool internalRenderTiming) = 0; + uint8_t payloadType, + bool internalRenderTiming) = 0; // Register a receive callback. Will be called whenever there is a new frame ready // for rendering. diff --git a/webrtc/modules/video_coding/main/source/codec_database.cc b/webrtc/modules/video_coding/main/source/codec_database.cc index 5ae09d9799..e498054aca 100644 --- a/webrtc/modules/video_coding/main/source/codec_database.cc +++ b/webrtc/modules/video_coding/main/source/codec_database.cc @@ -649,8 +649,8 @@ VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder( return NULL; } VCMGenericDecoder* ptr_decoder = NULL; - const VCMExtDecoderMapItem* external_dec_item = FindExternalDecoderItem( - payload_type); + const VCMExtDecoderMapItem* external_dec_item = + FindExternalDecoderItem(payload_type); if (external_dec_item) { // External codec. ptr_decoder = new VCMGenericDecoder( diff --git a/webrtc/modules/video_coding/main/test/normal_test.h b/webrtc/modules/video_coding/main/test/normal_test.h index 91862c95e1..b2fb38747b 100644 --- a/webrtc/modules/video_coding/main/test/normal_test.h +++ b/webrtc/modules/video_coding/main/test/normal_test.h @@ -38,15 +38,13 @@ class VCMNTEncodeCompleteCallback : public webrtc::VCMPacketizationCallback const webrtc::RTPFragmentationHeader& fragmentationHeader, const webrtc::RTPVideoHeader* videoHdr) OVERRIDE; - // Register exisitng VCM. + // Register existing VCM. // Currently - encode and decode with the same vcm module. void RegisterReceiverVCM(webrtc::VideoCodingModule *vcm); // Return sum of encoded data (all frames in the sequence) size_t EncodedBytes(); // return number of encoder-skipped frames uint32_t SkipCnt(); - // conversion function for payload type (needed for the callback function) -// RTPVideoVideoCodecTypes ConvertPayloadType(uint8_t payloadType); private: FILE* _encodedFile; diff --git a/webrtc/test/rtp_file_reader.cc b/webrtc/test/rtp_file_reader.cc index dcb5f0fedd..2006bc13ab 100644 --- a/webrtc/test/rtp_file_reader.cc +++ b/webrtc/test/rtp_file_reader.cc @@ -17,6 +17,7 @@ #include <vector> #include "webrtc/base/checks.h" +#include "webrtc/base/format_macros.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" @@ -259,15 +260,15 @@ class PcapReader : public RtpFileReaderImpl { } printf("Total packets in file: %d\n", total_packet_count); - printf("Total RTP/RTCP packets: %d\n", static_cast<int>(packets_.size())); + printf("Total RTP/RTCP packets: %" PRIuS "\n", packets_.size()); for (SsrcMapIterator mit = packets_by_ssrc_.begin(); mit != packets_by_ssrc_.end(); ++mit) { uint32_t ssrc = mit->first; const std::vector<uint32_t>& packet_numbers = mit->second; uint8_t pt = packets_[packet_numbers[0]].rtp_header.payloadType; - printf("SSRC: %08x, %d packets, pt=%d\n", ssrc, - static_cast<int>(packet_numbers.size()), pt); + printf("SSRC: %08x, %" PRIuS " packets, pt=%d\n", ssrc, + packet_numbers.size(), pt); } // TODO(solenberg): Better validation of identified SSRC streams. diff --git a/webrtc/video_engine/test/auto_test/source/vie_autotest.cc b/webrtc/video_engine/test/auto_test/source/vie_autotest.cc index aa9dbd54ce..2240509647 100644 --- a/webrtc/video_engine/test/auto_test/source/vie_autotest.cc +++ b/webrtc/video_engine/test/auto_test/source/vie_autotest.cc @@ -138,7 +138,7 @@ void ViEAutoTest::PrintAudioCodec(const webrtc::CodecInst audioCodec) ViETest::Log("\t: %u", audioCodec.pacsize); ViETest::Log("\t: %u", audioCodec.plfreq); ViETest::Log("\t: %s", audioCodec.plname); - ViETest::Log("\t: %u", audioCodec.pltype); + ViETest::Log("\t: %d", audioCodec.pltype); ViETest::Log("\t: %u", audioCodec.rate); ViETest::Log(""); } diff --git a/webrtc/video_engine/test/libvietest/testbed/tb_external_transport.cc b/webrtc/video_engine/test/libvietest/testbed/tb_external_transport.cc index e7018b954a..822a4e5ddc 100644 --- a/webrtc/video_engine/test/libvietest/testbed/tb_external_transport.cc +++ b/webrtc/video_engine/test/libvietest/testbed/tb_external_transport.cc @@ -33,9 +33,6 @@ #pragma warning(disable: 4355) // 'this' : used in base member initializer list #endif -const uint8_t kSenderReportPayloadType = 200; -const uint8_t kReceiverReportPayloadType = 201; - TbExternalTransport::TbExternalTransport( webrtc::ViENetwork& vieNetwork, int sender_channel, @@ -496,8 +493,10 @@ bool TbExternalTransport::ViEExternalTransportProcess() // Send to ViE if (packet) { - uint8_t pltype = static_cast<uint8_t>(packet->packetBuffer[1]); - if (pltype == kSenderReportPayloadType) { + uint8_t packet_type = static_cast<uint8_t>(packet->packetBuffer[1]); + const uint8_t kSenderReportPacketType = 200; + const uint8_t kReceiverReportPacketType = 201; + if (packet_type == kSenderReportPacketType) { // Sender report. if (receive_channels_) { for (SsrcChannelMap::iterator it = receive_channels_->begin(); @@ -511,7 +510,7 @@ bool TbExternalTransport::ViEExternalTransportProcess() packet->packetBuffer, packet->length); } - } else if (pltype == kReceiverReportPayloadType) { + } else if (packet_type == kReceiverReportPacketType) { // Receiver report. _vieNetwork.ReceivedRTCPPacket(sender_channel_, packet->packetBuffer, diff --git a/webrtc/video_engine/vie_codec_impl.cc b/webrtc/video_engine/vie_codec_impl.cc index aa0a21ac6c..c64a738867 100644 --- a/webrtc/video_engine/vie_codec_impl.cc +++ b/webrtc/video_engine/vie_codec_impl.cc @@ -650,7 +650,7 @@ bool ViECodecImpl::CodecValid(const VideoCodec& video_codec) { } if (video_codec.plType == 0 || video_codec.plType > 127) { - LOG(LS_ERROR) << "Invalif payload type: " + LOG(LS_ERROR) << "Invalid payload type: " << static_cast<int>(video_codec.plType); return false; } diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index cc3bb1b01c..a9af60584f 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -1513,7 +1513,7 @@ Channel::GetRecPayloadType(CodecInst& codec) } codec.pltype = payloadType; WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,_channelId), - "Channel::GetRecPayloadType() => pltype=%u", codec.pltype); + "Channel::GetRecPayloadType() => pltype=%d", codec.pltype); return 0; } diff --git a/webrtc/voice_engine/test/win_test/WinTestDlg.cc b/webrtc/voice_engine/test/win_test/WinTestDlg.cc index ea87a0d404..03011b64f0 100644 --- a/webrtc/voice_engine/test/win_test/WinTestDlg.cc +++ b/webrtc/voice_engine/test/win_test/WinTestDlg.cc @@ -931,9 +931,12 @@ void CTelephonyEvent::OnBnClickedButtonSetRxTelephonePt() return; CodecInst codec; strcpy_s(codec.plname, 32, "telephone-event"); - codec.pltype = pt; codec.channels = 1; codec.plfreq = 8000; + codec.pltype = pt; + codec.channels = 1; + codec.plfreq = 8000; TEST2(_veCodecPtr->SetRecPayloadType(_channel, codec) == 0, - _T("SetSendTelephoneEventPayloadType(channel=%d, codec.pltype=%u)"), _channel, codec.pltype); + _T("SetRecPayloadType(channel=%d, codec.pltype=%d)"), _channel, + codec.pltype); } void CTelephonyEvent::OnBnClickedButtonSetTxTelephonePt() @@ -943,7 +946,8 @@ void CTelephonyEvent::OnBnClickedButtonSetTxTelephonePt() if (ret == FALSE || pt < 0 || pt > 127) return; TEST2(_veDTMFPtr->SetSendTelephoneEventPayloadType(_channel, pt) == 0, - _T("SetSendTelephoneEventPayloadType(channel=%d, type=%u)"), _channel, pt); + _T("SetSendTelephoneEventPayloadType(channel=%d, type=%d)"), _channel, + pt); } void CTelephonyEvent::OnBnClickedCheckDetectInband() |