* 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
This commit is contained in:
pkasting@chromium.org
2015-02-23 21:28:22 +00:00
parent 722739108a
commit d324546ced
43 changed files with 393 additions and 541 deletions

View File

@@ -74,7 +74,6 @@ using cricket::kCodecParamSctpStreams;
using cricket::kCodecParamMaxAverageBitrate; using cricket::kCodecParamMaxAverageBitrate;
using cricket::kCodecParamMaxPlaybackRate; using cricket::kCodecParamMaxPlaybackRate;
using cricket::kCodecParamAssociatedPayloadType; using cricket::kCodecParamAssociatedPayloadType;
using cricket::kWildcardPayloadType;
using cricket::MediaContentDescription; using cricket::MediaContentDescription;
using cricket::MediaType; using cricket::MediaType;
using cricket::NS_JINGLE_ICE_UDP; 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"; 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 { struct SsrcInfo {
SsrcInfo() SsrcInfo()
: msid_identifier(kDefaultMsid), : msid_identifier(kDefaultMsid),
@@ -3049,8 +3052,8 @@ bool ParseFmtpAttributes(const std::string& line, const MediaType media_type,
return false; return false;
} }
std::string payload_type; std::string payload_type_str;
if (!GetValue(fields[0], kAttributeFmtp, &payload_type, error)) { if (!GetValue(fields[0], kAttributeFmtp, &payload_type_str, error)) {
return false; return false;
} }
@@ -3070,16 +3073,16 @@ bool ParseFmtpAttributes(const std::string& line, const MediaType media_type,
codec_params[name] = value; codec_params[name] = value;
} }
int int_payload_type = 0; int payload_type = 0;
if (!GetPayloadTypeFromString(line, payload_type, &int_payload_type, error)) { if (!GetPayloadTypeFromString(line, payload_type_str, &payload_type, error)) {
return false; return false;
} }
if (media_type == cricket::MEDIA_TYPE_AUDIO) { if (media_type == cricket::MEDIA_TYPE_AUDIO) {
UpdateCodec<AudioContentDescription, cricket::AudioCodec>( 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) { } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
UpdateCodec<VideoContentDescription, cricket::VideoCodec>( UpdateCodec<VideoContentDescription, cricket::VideoCodec>(
media_desc, int_payload_type, codec_params); media_desc, payload_type, codec_params);
} }
return true; return true;
} }
@@ -3117,13 +3120,11 @@ bool ParseRtcpFbAttribute(const std::string& line, const MediaType media_type,
const cricket::FeedbackParam feedback_param(id, param); const cricket::FeedbackParam feedback_param(id, param);
if (media_type == cricket::MEDIA_TYPE_AUDIO) { if (media_type == cricket::MEDIA_TYPE_AUDIO) {
UpdateCodec<AudioContentDescription, cricket::AudioCodec>(media_desc, UpdateCodec<AudioContentDescription, cricket::AudioCodec>(
payload_type, media_desc, payload_type, feedback_param);
feedback_param);
} else if (media_type == cricket::MEDIA_TYPE_VIDEO) { } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
UpdateCodec<VideoContentDescription, cricket::VideoCodec>(media_desc, UpdateCodec<VideoContentDescription, cricket::VideoCodec>(
payload_type, media_desc, payload_type, feedback_param);
feedback_param);
} }
return true; return true;
} }

View File

@@ -2182,8 +2182,8 @@ TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
DataContentDescription* dcdesc = static_cast<DataContentDescription*>( DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
mutant->GetContentDescriptionByName(kDataContentName)); mutant->GetContentDescriptionByName(kDataContentName));
std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
EXPECT_EQ(codecs.size(), 1UL); EXPECT_EQ(1U, codecs.size());
EXPECT_EQ(codecs[0].id, cricket::kGoogleSctpDataCodecId); EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
dcdesc->set_codecs(codecs); dcdesc->set_codecs(codecs);

View File

@@ -37,7 +37,6 @@
namespace cricket { namespace cricket {
static const int kMaxStaticPayloadId = 95;
const int kMaxPayloadId = 127; const int kMaxPayloadId = 127;
bool FeedbackParam::operator==(const FeedbackParam& other) const { 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 { bool Codec::Matches(const Codec& codec) const {
// Match the codec id/name based on the typical static/dynamic name rules. // Match the codec id/name based on the typical static/dynamic name rules.
// Matching is case-insensitive. // Matching is case-insensitive.
const int kMaxStaticPayloadId = 95;
return (codec.id <= kMaxStaticPayloadId) ? return (codec.id <= kMaxStaticPayloadId) ?
(id == codec.id) : (_stricmp(name.c_str(), codec.name.c_str()) == 0); (id == codec.id) : (_stricmp(name.c_str(), codec.name.c_str()) == 0);
} }

View File

@@ -43,10 +43,6 @@ const char kRtxCodecName[] = "rtx";
const char kRedCodecName[] = "red"; const char kRedCodecName[] = "red";
const char kUlpfecCodecName[] = "ulpfec"; 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 kCodecParamAssociatedPayloadType[] = "apt";
const char kOpusCodecName[] = "opus"; const char kOpusCodecName[] = "opus";

View File

@@ -48,7 +48,6 @@ extern const char kRedCodecName[];
extern const char kUlpfecCodecName[]; extern const char kUlpfecCodecName[];
// Codec parameters // Codec parameters
extern const int kWildcardPayloadType;
extern const char kCodecParamAssociatedPayloadType[]; extern const char kCodecParamAssociatedPayloadType[];
extern const char kOpusCodecName[]; extern const char kOpusCodecName[];

View File

@@ -44,22 +44,23 @@ TEST(RtpDumpTest, ReadRtpDumpPacket) {
RtpTestUtility::kTestRawRtpPackets[0].WriteToByteBuffer(kTestSsrc, &rtp_buf); RtpTestUtility::kTestRawRtpPackets[0].WriteToByteBuffer(kTestSsrc, &rtp_buf);
RtpDumpPacket rtp_packet(rtp_buf.Data(), rtp_buf.Length(), 0, false); RtpDumpPacket rtp_packet(rtp_buf.Data(), rtp_buf.Length(), 0, false);
int type; int payload_type;
int seq_num; int seq_num;
uint32 ts; uint32 ts;
uint32 ssrc; uint32 ssrc;
int rtcp_type;
EXPECT_FALSE(rtp_packet.is_rtcp()); EXPECT_FALSE(rtp_packet.is_rtcp());
EXPECT_TRUE(rtp_packet.IsValidRtpPacket()); EXPECT_TRUE(rtp_packet.IsValidRtpPacket());
EXPECT_FALSE(rtp_packet.IsValidRtcpPacket()); EXPECT_FALSE(rtp_packet.IsValidRtcpPacket());
EXPECT_TRUE(rtp_packet.GetRtpPayloadType(&type)); EXPECT_TRUE(rtp_packet.GetRtpPayloadType(&payload_type));
EXPECT_EQ(0, type); EXPECT_EQ(0, payload_type);
EXPECT_TRUE(rtp_packet.GetRtpSeqNum(&seq_num)); EXPECT_TRUE(rtp_packet.GetRtpSeqNum(&seq_num));
EXPECT_EQ(0, seq_num); EXPECT_EQ(0, seq_num);
EXPECT_TRUE(rtp_packet.GetRtpTimestamp(&ts)); EXPECT_TRUE(rtp_packet.GetRtpTimestamp(&ts));
EXPECT_EQ(0U, ts); EXPECT_EQ(0U, ts);
EXPECT_TRUE(rtp_packet.GetRtpSsrc(&ssrc)); EXPECT_TRUE(rtp_packet.GetRtpSsrc(&ssrc));
EXPECT_EQ(kTestSsrc, ssrc); EXPECT_EQ(kTestSsrc, ssrc);
EXPECT_FALSE(rtp_packet.GetRtcpType(&type)); EXPECT_FALSE(rtp_packet.GetRtcpType(&rtcp_type));
rtc::ByteBuffer rtcp_buf; rtc::ByteBuffer rtcp_buf;
RtpTestUtility::kTestRawRtcpPackets[0].WriteToByteBuffer(&rtcp_buf); RtpTestUtility::kTestRawRtcpPackets[0].WriteToByteBuffer(&rtcp_buf);
@@ -68,8 +69,8 @@ TEST(RtpDumpTest, ReadRtpDumpPacket) {
EXPECT_TRUE(rtcp_packet.is_rtcp()); EXPECT_TRUE(rtcp_packet.is_rtcp());
EXPECT_FALSE(rtcp_packet.IsValidRtpPacket()); EXPECT_FALSE(rtcp_packet.IsValidRtpPacket());
EXPECT_TRUE(rtcp_packet.IsValidRtcpPacket()); EXPECT_TRUE(rtcp_packet.IsValidRtcpPacket());
EXPECT_TRUE(rtcp_packet.GetRtcpType(&type)); EXPECT_TRUE(rtcp_packet.GetRtcpType(&rtcp_type));
EXPECT_EQ(0, type); EXPECT_EQ(0, rtcp_type);
} }
// Test that we read only the RTP dump file. // Test that we read only the RTP dump file.

View File

@@ -169,8 +169,6 @@ static const int kDefaultLogSeverity = rtc::LS_WARNING;
static const int kDefaultNumberOfTemporalLayers = 1; // 1:1 static const int kDefaultNumberOfTemporalLayers = 1; // 1:1
static const int kExternalVideoPayloadTypeBase = 120;
static const int kChannelIdUnset = -1; static const int kChannelIdUnset = -1;
static const uint32 kDefaultChannelSsrcKey = 0; static const uint32 kDefaultChannelSsrcKey = 0;
static const uint32 kSsrcUnset = 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 allocation of payload type values for external video codec.
static int GetExternalVideoPayloadType(int index) { static int GetExternalVideoPayloadType(size_t index) {
#if ENABLE_DEBUG static const int kExternalVideoPayloadTypeBase = 120;
static const int kMaxExternalVideoCodecs = 8; index += kExternalVideoPayloadTypeBase;
ASSERT(index >= 0 && index < kMaxExternalVideoCodecs); ASSERT(index < 128);
#endif return static_cast<int>(index);
return kExternalVideoPayloadTypeBase + index;
} }
static void LogMultiline(rtc::LoggingSeverity sev, char* text) { static void LogMultiline(rtc::LoggingSeverity sev, char* text) {
@@ -633,7 +630,7 @@ class WebRtcLocalStreamInfo {
// from the worker thread. // from the worker thread.
class WebRtcVideoChannelRecvInfo { class WebRtcVideoChannelRecvInfo {
public: 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) explicit WebRtcVideoChannelRecvInfo(int channel_id)
: channel_id_(channel_id), : channel_id_(channel_id),
render_adapter_(NULL, channel_id), render_adapter_(NULL, channel_id),
@@ -712,7 +709,7 @@ class WebRtcOveruseObserver : public webrtc::CpuOveruseObserver {
class WebRtcVideoChannelSendInfo : public sigslot::has_slots<> { class WebRtcVideoChannelSendInfo : public sigslot::has_slots<> {
public: public:
typedef std::map<int, webrtc::VideoEncoder*> EncoderMap; // key: payload type typedef std::map<int, webrtc::VideoEncoder*> EncoderMap; // Key: payload type
enum AdaptFormatType { enum AdaptFormatType {
// This is how we make SetSendStreamFormat take precedence over // 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 = const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs =
encoder_factory_->codecs(); encoder_factory_->codecs();
for (size_t j = 0; j < codecs.size(); ++j) { for (size_t j = 0; j < codecs.size(); ++j) {
VideoCodec codec(GetExternalVideoPayloadType(static_cast<int>(j)), VideoCodec codec(GetExternalVideoPayloadType(j), codecs[j].name, 0, 0, 0,
codecs[j].name, 0, 0, 0, 0); 0);
if (codec.Matches(in)) if (codec.Matches(in))
return true; return true;
} }
@@ -1406,7 +1403,7 @@ bool WebRtcVideoEngine::ConvertFromCricketVideoCodec(
for (size_t i = 0; i < codecs.size(); ++i) { for (size_t i = 0; i < codecs.size(); ++i) {
if (_stricmp(in_codec.name.c_str(), codecs[i].name.c_str()) == 0) { if (_stricmp(in_codec.name.c_str(), codecs[i].name.c_str()) == 0) {
out_codec->codecType = codecs[i].type; 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), 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; found = true;
@@ -1545,7 +1542,7 @@ bool WebRtcVideoEngine::RebuildCodecList(const VideoCodec& in_codec) {
internal_codec_names.end(); internal_codec_names.end();
if (!is_internal_codec) { if (!is_internal_codec) {
VideoCodec codec( VideoCodec codec(
GetExternalVideoPayloadType(static_cast<int>(i)), GetExternalVideoPayloadType(i),
codecs[i].name, codecs[i].name,
codecs[i].max_width, codecs[i].max_width,
codecs[i].max_height, codecs[i].max_height,
@@ -1875,7 +1872,7 @@ bool WebRtcVideoMediaChannel::SetSendCodecs(
// 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. // SetSendCodec.
std::map<int, int>::const_iterator rtx_it = 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()) { if (rtx_it != primary_rtx_pt_mapping.end()) {
send_rtx_type_ = rtx_it->second; send_rtx_type_ = rtx_it->second;
} }
@@ -3673,8 +3670,8 @@ bool WebRtcVideoMediaChannel::SetNackFec(int channel_id,
if (enable) { if (enable) {
if (engine_->vie()->rtp()->SetHybridNACKFECStatus( if (engine_->vie()->rtp()->SetHybridNACKFECStatus(
channel_id, nack_enabled, red_payload_type, fec_payload_type) != 0) { channel_id, nack_enabled, red_payload_type, fec_payload_type) != 0) {
LOG_RTCERR4(SetHybridNACKFECStatus, LOG_RTCERR4(SetHybridNACKFECStatus, channel_id, nack_enabled,
channel_id, nack_enabled, red_payload_type, fec_payload_type); red_payload_type, fec_payload_type);
return false; return false;
} }
LOG(LS_INFO) << "Hybrid NACK/FEC enabled for channel " << channel_id; 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."; LOG(LS_ERROR) << "Only one RTX codec at a time is supported.";
return false; return false;
} }
std::map<int, int>::iterator apt_it = associated_payload_types_.find( std::map<int, int>::iterator apt_it =
it->plType); associated_payload_types_.find(it->plType);
bool valid_apt = false; bool valid_apt = false;
if (apt_it != associated_payload_types_.end()) { if (apt_it != associated_payload_types_.end()) {
std::map<int, webrtc::VideoCodec*>::iterator codec_it = std::map<int, webrtc::VideoCodec*>::iterator codec_it =

View File

@@ -133,13 +133,6 @@ static const int kDefaultQpMax = 56;
static const int kDefaultRtcpReceiverReportSsrc = 1; 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"; const char kH264CodecName[] = "H264";
static bool FindFirstMatchingCodec(const std::vector<VideoCodec>& codecs, static bool FindFirstMatchingCodec(const std::vector<VideoCodec>& codecs,
@@ -557,7 +550,6 @@ std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const {
return supported_codecs; return supported_codecs;
} }
assert(external_encoder_factory_->codecs().size() <= kMaxExternalVideoCodecs);
const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs = const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs =
external_encoder_factory_->codecs(); external_encoder_factory_->codecs();
for (size_t i = 0; i < codecs.size(); ++i) { for (size_t i = 0; i < codecs.size(); ++i) {
@@ -566,7 +558,12 @@ std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const {
continue; 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].name,
codecs[i].max_width, codecs[i].max_width,
codecs[i].max_height, codecs[i].max_height,
@@ -2071,7 +2068,8 @@ WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) {
std::vector<VideoCodecSettings> video_codecs; std::vector<VideoCodecSettings> video_codecs;
std::map<int, bool> payload_used; std::map<int, bool> payload_used;
std::map<int, VideoCodec::CodecType> payload_codec_type; 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; webrtc::FecConfig fec_settings;

View File

@@ -1679,8 +1679,7 @@ TEST_F(WebRtcVideoChannel2Test, SetDefaultSendCodecs) {
EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size());
EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]);
EXPECT_EQ(static_cast<int>(default_rtx_codec_.id), EXPECT_EQ(default_rtx_codec_.id, config.rtp.rtx.payload_type);
config.rtp.rtx.payload_type);
// TODO(juberti): Check RTCP, PLI, TMMBR. // TODO(juberti): Check RTCP, PLI, TMMBR.
} }
@@ -1846,10 +1845,9 @@ TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectBadPayloadTypes) {
std::vector<cricket::VideoCodec> codecs; std::vector<cricket::VideoCodec> codecs;
codecs.push_back(kVp8Codec); codecs.push_back(kVp8Codec);
for (size_t i = 0; i < arraysize(kIncorrectPayloads); ++i) { for (size_t i = 0; i < arraysize(kIncorrectPayloads); ++i) {
int payload_type = kIncorrectPayloads[i]; codecs[0].id = kIncorrectPayloads[i];
codecs[0].id = payload_type;
EXPECT_FALSE(channel_->SetSendCodecs(codecs)) EXPECT_FALSE(channel_->SetSendCodecs(codecs))
<< "Bad payload type '" << payload_type << "' accepted."; << "Bad payload type '" << kIncorrectPayloads[i] << "' accepted.";
} }
} }

View File

@@ -539,7 +539,7 @@ void WebRtcVoiceEngine::ConstructCodecs() {
codec.params[kCodecParamMaxPTime] = codec.params[kCodecParamMaxPTime] =
rtc::ToString(kPreferredMaxPTime); rtc::ToString(kPreferredMaxPTime);
} }
codec.SetParam(kCodecParamUseInbandFec, "1"); codec.SetParam(kCodecParamUseInbandFec, 1);
// TODO(hellner): Add ptime, sprop-stereo, and stereo // TODO(hellner): Add ptime, sprop-stereo, and stereo
// when they can be set to values other than the default. // when they can be set to values other than the default.

View File

@@ -448,20 +448,12 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst,
// Checks if the bitrate is valid for the codec. // Checks if the bitrate is valid for the codec.
bool ACMCodecDB::IsRateValid(int codec_id, int rate) { bool ACMCodecDB::IsRateValid(int codec_id, int rate) {
if (database_[codec_id].rate == rate) { return database_[codec_id].rate == rate;
return true;
} else {
return false;
}
} }
// Checks if the bitrate is valid for iSAC. // Checks if the bitrate is valid for iSAC.
bool ACMCodecDB::IsISACRateValid(int rate) { bool ACMCodecDB::IsISACRateValid(int rate) {
if ((rate == -1) || ((rate <= 56000) && (rate >= 10000))) { return (rate == -1) || ((rate <= 56000) && (rate >= 10000));
return true;
} else {
return false;
}
} }
// Checks if the bitrate is valid for iLBC. // 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. // Checks if the bitrate is valid for Speex.
bool ACMCodecDB::IsSpeexRateValid(int rate) { bool ACMCodecDB::IsSpeexRateValid(int rate) {
if (rate > 2000) { return rate > 2000;
return true;
} else {
return false;
}
} }
// Checks if the bitrate is valid for Opus. // Checks if the bitrate is valid for Opus.
bool ACMCodecDB::IsOpusRateValid(int rate) { bool ACMCodecDB::IsOpusRateValid(int rate) {
if ((rate < 6000) || (rate > 510000)) { return (rate >= 6000) && (rate <= 510000);
return false;
}
return true;
} }
// Checks if the payload type is in the valid range. // Checks if the payload type is in the valid range.
bool ACMCodecDB::ValidPayloadType(int payload_type) { bool ACMCodecDB::ValidPayloadType(int payload_type) {
if ((payload_type < 0) || (payload_type > 127)) { return (payload_type >= 0) && (payload_type <= 127);
return false;
}
return true;
} }
bool ACMCodecDB::OwnsDecoder(int codec_id) { bool ACMCodecDB::OwnsDecoder(int codec_id) {

View File

@@ -507,7 +507,7 @@ int32_t AcmReceiver::AddCodec(int acm_codec_id,
// First unregister. Then register with new payload-type/channels. // First unregister. Then register with new payload-type/channels.
if (neteq_->RemovePayloadType(decoders_[acm_codec_id].payload_type) != if (neteq_->RemovePayloadType(decoders_[acm_codec_id].payload_type) !=
NetEq::kOK) { NetEq::kOK) {
LOG_F(LS_ERROR) << "Cannot remover payload " LOG_F(LS_ERROR) << "Cannot remove payload "
<< static_cast<int>(decoders_[acm_codec_id].payload_type); << static_cast<int>(decoders_[acm_codec_id].payload_type);
return -1; return -1;
} }

View File

@@ -240,8 +240,6 @@ class AudioCodingModuleImpl : public AudioCodingModule {
AudioDecodingCallStats* stats) const OVERRIDE; AudioDecodingCallStats* stats) const OVERRIDE;
private: private:
int UnregisterReceiveCodecSafe(int payload_type);
ACMGenericCodec* CreateCodec(const CodecInst& codec); ACMGenericCodec* CreateCodec(const CodecInst& codec);
int InitializeReceiverSafe() EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); int InitializeReceiverSafe() EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);

View File

@@ -332,7 +332,6 @@ TEST_F(InitialDelayManagerTest, NoLatePacketAfterCng) {
// Second packet as CNG. // Second packet as CNG.
NextRtpHeader(&rtp_info_, &rtp_receive_timestamp_); NextRtpHeader(&rtp_info_, &rtp_receive_timestamp_);
const uint8_t kCngPayloadType = 1; // Arbitrary.
rtp_info_.header.payloadType = kCngPayloadType; rtp_info_.header.payloadType = kCngPayloadType;
manager_->UpdateLastReceivedPacket(rtp_info_, rtp_receive_timestamp_, manager_->UpdateLastReceivedPacket(rtp_info_, rtp_receive_timestamp_,
InitialDelayManager::kCngPacket, false, InitialDelayManager::kCngPacket, false,

View File

@@ -66,7 +66,7 @@ class Channel : public AudioPacketizationCallback {
void Stats(uint32_t* numPackets); 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); void PrintStats(CodecInst& codecInst);

View File

@@ -43,21 +43,18 @@ void RTPStream::ParseRTPHeader(WebRtcRTPHeader* rtpInfo,
void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
int16_t seqNo, uint32_t timeStamp, int16_t seqNo, uint32_t timeStamp,
uint32_t ssrc) { uint32_t ssrc) {
rtpHeader[0] = (unsigned char) 0x80; rtpHeader[0] = 0x80;
rtpHeader[1] = (unsigned char) (payloadType & 0xFF); rtpHeader[1] = payloadType;
rtpHeader[2] = (unsigned char) ((seqNo >> 8) & 0xFF); rtpHeader[2] = (seqNo >> 8) & 0xFF;
rtpHeader[3] = (unsigned char) ((seqNo) & 0xFF); rtpHeader[3] = seqNo & 0xFF;
rtpHeader[4] = (unsigned char) ((timeStamp >> 24) & 0xFF); rtpHeader[4] = timeStamp >> 24;
rtpHeader[5] = (unsigned char) ((timeStamp >> 16) & 0xFF); rtpHeader[5] = (timeStamp >> 16) & 0xFF;
rtpHeader[6] = (timeStamp >> 8) & 0xFF;
rtpHeader[6] = (unsigned char) ((timeStamp >> 8) & 0xFF); rtpHeader[7] = timeStamp & 0xFF;
rtpHeader[7] = (unsigned char) (timeStamp & 0xFF); rtpHeader[8] = ssrc >> 24;
rtpHeader[9] = (ssrc >> 16) & 0xFF;
rtpHeader[8] = (unsigned char) ((ssrc >> 24) & 0xFF); rtpHeader[10] = (ssrc >> 8) & 0xFF;
rtpHeader[9] = (unsigned char) ((ssrc >> 16) & 0xFF); rtpHeader[11] = ssrc & 0xFF;
rtpHeader[10] = (unsigned char) ((ssrc >> 8) & 0xFF);
rtpHeader[11] = (unsigned char) (ssrc & 0xFF);
} }
RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo, RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,

View File

@@ -38,7 +38,7 @@ void DecoderDatabase::Reset() {
int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type, int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type,
NetEqDecoder codec_type) { NetEqDecoder codec_type) {
if (rtp_payload_type > kMaxRtpPayloadType) { if (rtp_payload_type > 0x7F) {
return kInvalidRtpPayloadType; return kInvalidRtpPayloadType;
} }
if (!CodecSupported(codec_type)) { if (!CodecSupported(codec_type)) {
@@ -74,8 +74,7 @@ int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type,
decoder->Init(); decoder->Init();
std::pair<DecoderMap::iterator, bool> ret; std::pair<DecoderMap::iterator, bool> ret;
DecoderInfo info(codec_type, fs_hz, decoder, true); DecoderInfo info(codec_type, fs_hz, decoder, true);
ret = decoders_.insert( ret = decoders_.insert(std::make_pair(rtp_payload_type, info));
std::pair<uint8_t, DecoderInfo>(rtp_payload_type, info));
if (ret.second == false) { if (ret.second == false) {
// Database already contains a decoder with type |rtp_payload_type|. // Database already contains a decoder with type |rtp_payload_type|.
return kDecoderExists; return kDecoderExists;

View File

@@ -57,7 +57,6 @@ class DecoderDatabase {
bool external; 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 // Maximum value for 8 bits, and an invalid RTP payload type (since it is
// only 7 bits). // only 7 bits).
static const uint8_t kRtpPayloadTypeError = 0xFF; static const uint8_t kRtpPayloadTypeError = 0xFF;

View File

@@ -422,8 +422,8 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
rtp_header.header.ssrc != ssrc_) { rtp_header.header.ssrc != ssrc_) {
// Even if |current_rtp_payload_type_| is 0xFF, sync-packet isn't // Even if |current_rtp_payload_type_| is 0xFF, sync-packet isn't
// accepted. // accepted.
LOG_F(LS_ERROR) << "Changing codec, SSRC or first packet " LOG_F(LS_ERROR)
"with sync-packet."; << "Changing codec, SSRC or first packet with sync-packet.";
return kSyncPacketNotAccepted; return kSyncPacketNotAccepted;
} }
} }

View File

@@ -352,82 +352,72 @@ bool NETEQTEST_RTPpacket::isLost() const
uint8_t NETEQTEST_RTPpacket::payloadType() const uint8_t NETEQTEST_RTPpacket::payloadType() const
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
if(_datagram && _datagramLen >= _kBasicHeaderLen) if(_datagram && _datagramLen >= _kBasicHeaderLen)
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo); parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.payloadType;
} }
else else
{ {
return 0; return 0;
} }
return tempRTPinfo.header.payloadType;
} }
uint16_t NETEQTEST_RTPpacket::sequenceNumber() const uint16_t NETEQTEST_RTPpacket::sequenceNumber() const
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
if(_datagram && _datagramLen >= _kBasicHeaderLen) if(_datagram && _datagramLen >= _kBasicHeaderLen)
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo); parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.sequenceNumber;
} }
else else
{ {
return 0; return 0;
} }
return tempRTPinfo.header.sequenceNumber;
} }
uint32_t NETEQTEST_RTPpacket::timeStamp() const uint32_t NETEQTEST_RTPpacket::timeStamp() const
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
if(_datagram && _datagramLen >= _kBasicHeaderLen) if(_datagram && _datagramLen >= _kBasicHeaderLen)
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo); parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.timestamp;
} }
else else
{ {
return 0; return 0;
} }
return tempRTPinfo.header.timestamp;
} }
uint32_t NETEQTEST_RTPpacket::SSRC() const uint32_t NETEQTEST_RTPpacket::SSRC() const
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
if(_datagram && _datagramLen >= _kBasicHeaderLen) if(_datagram && _datagramLen >= _kBasicHeaderLen)
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo); parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.ssrc;
} }
else else
{ {
return 0; return 0;
} }
return tempRTPinfo.header.ssrc;
} }
uint8_t NETEQTEST_RTPpacket::markerBit() const uint8_t NETEQTEST_RTPpacket::markerBit() const
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
if(_datagram && _datagramLen >= _kBasicHeaderLen) if(_datagram && _datagramLen >= _kBasicHeaderLen)
{ {
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo); parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.markerBit;
} }
else else
{ {
return 0; return 0;
} }
return tempRTPinfo.header.markerBit;
} }
@@ -445,7 +435,7 @@ int NETEQTEST_RTPpacket::setPayloadType(uint8_t pt)
_rtpInfo.header.payloadType = pt; _rtpInfo.header.payloadType = pt;
} }
_datagram[1]=(unsigned char)(pt & 0xFF); _datagram[1] = pt;
return 0; 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; rtp_data[0] = markerBit ? 0x81 : 0x80;
if (markerBit) rtp_data[1] = payloadType;
{ rtp_data[2] = seqNo >> 8;
rtp_data[0] |= 0x01; rtp_data[3] = seqNo & 0xFF;
} rtp_data[4] = timestamp >> 24;
else rtp_data[5] = (timestamp >> 16) & 0xFF;
{ rtp_data[6] = (timestamp >> 8) & 0xFF;
rtp_data[0] &= 0xFE; rtp_data[7] = timestamp & 0xFF;
} rtp_data[8] = ssrc >> 24;
rtp_data[1]=(unsigned char)(payloadType & 0xFF); rtp_data[9] = (ssrc >> 16) & 0xFF;
rtp_data[2]=(unsigned char)((seqNo>>8)&0xFF); rtp_data[10] = (ssrc >> 8) & 0xFF;
rtp_data[3]=(unsigned char)((seqNo)&0xFF); rtp_data[11] = ssrc & 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);
} }
uint16_t uint16_t NETEQTEST_RTPpacket::parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo,
NETEQTEST_RTPpacket::parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo,
uint8_t **payloadPtr) const 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; int i_P, i_X, i_CC;
assert(_datagramLen >= 12); assert(_datagramLen >= 12);
@@ -667,61 +650,54 @@ uint16_t
if (payloadPtr) 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, void NETEQTEST_RTPpacket::parseBasicHeader(webrtc::WebRtcRTPHeader* RTPinfo,
int *i_P, int *i_X, int *i_CC) const 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) if (_datagramLen < 12)
{ {
assert(false); assert(false);
return; return;
} }
*i_P=(((uint16_t)(rtp_data[0] & 0x20))>>5); /* Extract the P bit */ *i_P = (rtp_data[0] >> 5) & 0x01;
*i_X=(((uint16_t)(rtp_data[0] & 0x10))>>4); /* Extract the X bit */ *i_X = (rtp_data[0] >> 4) & 0x01;
*i_CC=(uint16_t)(rtp_data[0] & 0xF); /* Get the CC number */ *i_CC = rtp_data[0] & 0xF;
/* Get the marker bit */ RTPinfo->header.markerBit = (rtp_data[0] >> 15) & 0x01;
RTPinfo->header.markerBit = (uint8_t) ((rtp_data[0] >> 15) & 0x01); RTPinfo->header.payloadType = (rtp_data[0] >> 8) & 0x7F;
/* Get the coder type */
RTPinfo->header.payloadType = (uint8_t) ((rtp_data[0] >> 8) & 0x7F);
/* Get the packet number */
RTPinfo->header.sequenceNumber = RTPinfo->header.sequenceNumber =
((( ((uint16_t)rtp_data[1]) >> 8) & 0xFF) | (rtp_data[1] >> 8) | ((rtp_data[1] & 0xFF) << 8);
( ((uint16_t)(rtp_data[1] & 0xFF)) << 8)); RTPinfo->header.timestamp =
/* Get timestamp */ ((rtp_data[2] & 0xFF) << 24) | ((rtp_data[2] & 0xFF00) << 8) |
RTPinfo->header.timestamp = ((((uint16_t)rtp_data[2]) & 0xFF) << 24) | (rtp_data[3] >> 8) | ((rtp_data[3] & 0xFF) << 8);
((((uint16_t)rtp_data[2]) & 0xFF00) << 8) | RTPinfo->header.ssrc =
((((uint16_t)rtp_data[3]) >> 8) & 0xFF) | ((rtp_data[4] & 0xFF) << 24) | ((rtp_data[4] & 0xFF00) << 8) |
((((uint16_t)rtp_data[3]) & 0xFF) << 8); (rtp_data[5] >> 8) | ((rtp_data[5] & 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);
} }
int NETEQTEST_RTPpacket::calcHeaderLength(int i_X, int i_CC) const int NETEQTEST_RTPpacket::calcHeaderLength(int i_X, int i_CC) const
{ {
int i_extlength = 0; int i_extlength = 0;
int16_t *rtp_data = (int16_t *) _datagram; uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram);
if (i_X == 1) if (i_X == 1)
{ {
// Extension header exists. // Extension header exists.
// Find out how many int32_t it consists of. // Find out how many int32_t it consists of.
assert(_datagramLen > 2 * (7 + 2 * i_CC)); int offset = 7 + 2 * i_CC;
if (_datagramLen > 2 * (7 + 2 * i_CC)) assert(_datagramLen > 2 * offset);
if (_datagramLen > 2 * offset)
{ {
i_extlength = (((((uint16_t) rtp_data[7 + 2 * i_CC]) >> 8) i_extlength = 1 +
& 0xFF) | (((uint16_t) (rtp_data[7 + 2 * i_CC] & 0xFF)) (((rtp_data[offset]) >> 8) | ((rtp_data[offset] & 0xFF) << 8));
<< 8)) + 1;
} }
} }
@@ -730,7 +706,7 @@ int NETEQTEST_RTPpacket::calcHeaderLength(int i_X, int i_CC) const
int NETEQTEST_RTPpacket::calcPadLength(int i_P) 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) if (i_P == 1)
{ {
/* Padding exists. Find out how many bytes the padding consists of. */ /* Padding exists. Find out how many bytes the padding consists of. */
@@ -742,7 +718,7 @@ int NETEQTEST_RTPpacket::calcPadLength(int i_P) const
else else
{ {
/* even number of bytes => last byte in lower byte */ /* 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; return 0;
@@ -838,7 +814,7 @@ int NETEQTEST_RTPpacket::extractRED(int index, webrtc::WebRtcRTPHeader& red)
{ {
// Header found. // Header found.
red.header.payloadType = ptr[0] & 0x7F; 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.sequenceNumber = sequenceNumber();
red.header.timestamp = timeStamp() - offset; red.header.timestamp = timeStamp() - offset;
red.header.markerBit = markerBit(); red.header.markerBit = markerBit();

View File

@@ -36,7 +36,6 @@ public:
int readFixedFromFile(FILE *fp, size_t len); int readFixedFromFile(FILE *fp, size_t len);
virtual int writeToFile(FILE *fp); virtual int writeToFile(FILE *fp);
void blockPT(uint8_t pt); void blockPT(uint8_t pt);
//int16_t payloadType();
virtual void parseHeader(); virtual void parseHeader();
void parseHeader(webrtc::WebRtcRTPHeader* rtp_header); void parseHeader(webrtc::WebRtcRTPHeader* rtp_header);
const webrtc::WebRtcRTPHeader* RTPinfo() const; const webrtc::WebRtcRTPHeader* RTPinfo() const;

View File

@@ -71,15 +71,47 @@
/* Function declarations */ /* Function declarations */
/*************************/ /*************************/
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,
int NetEQTest_init_coders(webrtc::NetEqDecoder coder, int enc_frameSize, int bitrate, int sampfreq , int vad, int numChannels); webrtc::NetEqDecoder* codec,
void defineCodecs(webrtc::NetEqDecoder *usedCodec, int *noOfCodecs ); 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_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); int NetEQTest_encode(int coder,
void makeRTPheader(unsigned char* rtp_data, int payloadType, int seqNo, uint32_t timestamp, uint32_t ssrc); int16_t* indata,
int makeRedundantHeader(unsigned char* rtp_data, int *payloadType, int numPayloads, uint32_t *timestamp, uint16_t *blockLen, int frameLen,
int seqNo, uint32_t ssrc); unsigned char* encoded,
int makeDTMFpayload(unsigned char* payload_data, int Event, int End, int Volume, int Duration); 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 stereoDeInterleave(int16_t* audioSamples, int numSamples);
void stereoInterleave(unsigned char* data, int dataLen, int stride); void stereoInterleave(unsigned char* data, int dataLen, int stride);
@@ -789,7 +821,13 @@ int main(int argc, char* argv[])
/* Subfunctions */ /* 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 */ *bitrate = 0; /* Default bitrate setting */
*useRed = 0; /* Default no redundancy */ *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){ void makeRTPheader(unsigned char* rtp_data,
int payloadType,
rtp_data[0]=(unsigned char)0x80; int seqNo,
rtp_data[1]=(unsigned char)(payloadType & 0xFF); uint32_t timestamp,
rtp_data[2]=(unsigned char)((seqNo>>8)&0xFF); uint32_t ssrc) {
rtp_data[3]=(unsigned char)((seqNo)&0xFF); rtp_data[0] = 0x80;
rtp_data[4]=(unsigned char)((timestamp>>24)&0xFF); rtp_data[1] = payloadType & 0xFF;
rtp_data[5]=(unsigned char)((timestamp>>16)&0xFF); rtp_data[2] = (seqNo >> 8) & 0xFF;
rtp_data[3] = seqNo & 0xFF;
rtp_data[6]=(unsigned char)((timestamp>>8)&0xFF); rtp_data[4] = timestamp >> 24;
rtp_data[7]=(unsigned char)(timestamp & 0xFF); rtp_data[5] = (timestamp >> 16) & 0xFF;
rtp_data[6] = (timestamp >> 8) & 0xFF;
rtp_data[8]=(unsigned char)((ssrc>>24)&0xFF); rtp_data[7] = timestamp & 0xFF;
rtp_data[9]=(unsigned char)((ssrc>>16)&0xFF); rtp_data[8] = ssrc >> 24;
rtp_data[9] = (ssrc >> 16) & 0xFF;
rtp_data[10]=(unsigned char)((ssrc>>8)&0xFF); rtp_data[10] = (ssrc >> 8) & 0xFF;
rtp_data[11]=(unsigned char)(ssrc & 0xFF); rtp_data[11] = ssrc & 0xFF;
} }
int makeRedundantHeader(unsigned char* rtp_data, int *payloadType, int numPayloads, uint32_t *timestamp, uint16_t *blockLen, int makeRedundantHeader(unsigned char* rtp_data,
int seqNo, uint32_t ssrc) int* payloadType,
int numPayloads,
uint32_t* timestamp,
uint16_t* blockLen,
int seqNo,
uint32_t ssrc)
{ {
int i; int i;
unsigned char *rtpPointer; unsigned char* rtpPointer;
uint16_t offset; uint16_t offset;
/* first create "standard" RTP header */ /* 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]; rtpPointer = &rtp_data[12];
/* add one sub-header for each redundant payload (not the primary) */ /* 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| */ for (i = 0; i < numPayloads - 1; i++) {
if(blockLen[i] > 0) { if (blockLen[i] > 0) {
offset = (uint16_t) (timestamp[numPayloads-1] - timestamp[i]); offset = static_cast<uint16_t>(
timestamp[numPayloads - 1] - timestamp[i]);
rtpPointer[0] = (unsigned char) ( 0x80 | (0x7F & payloadType[i]) ); /* |F| block PT | */ // Byte |0| |1 2 | 3 |
rtpPointer[1] = (unsigned char) ((offset >> 6) & 0xFF); /* | timestamp- | */ // Bit |0|1234567|01234567012345|6701234567|
rtpPointer[2] = (unsigned char) ( ((offset & 0x3F)<<2) | // |F|payload| timestamp | block |
( (blockLen[i]>>8) & 0x03 ) ); /* | -offset |bl-| */ // | | type | offset | length |
rtpPointer[3] = (unsigned char) ( blockLen[i] & 0xFF ); /* | -ock 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; rtpPointer += 4;
} }
} }
/* last sub-header */ // Bit |0|1234567|
rtpPointer[0]= (unsigned char) (0x00 | (0x7F&payloadType[numPayloads-1]));/* |F| block PT | */ // |0|payload|
rtpPointer += 1; // | | 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
} }

View File

@@ -51,14 +51,14 @@ Packet* ConstantPcmPacketSource::NextPacket() {
void ConstantPcmPacketSource::WriteHeader(uint8_t* packet_memory) { void ConstantPcmPacketSource::WriteHeader(uint8_t* packet_memory) {
packet_memory[0] = 0x80; packet_memory[0] = 0x80;
packet_memory[1] = payload_type_ & 0xFF; packet_memory[1] = static_cast<uint8_t>(payload_type_);
packet_memory[2] = (seq_number_ >> 8) & 0xFF; packet_memory[2] = seq_number_ >> 8;
packet_memory[3] = seq_number_ & 0xFF; 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[5] = (timestamp_ >> 16) & 0xFF;
packet_memory[6] = (timestamp_ >> 8) & 0xFF; packet_memory[6] = (timestamp_ >> 8) & 0xFF;
packet_memory[7] = timestamp_ & 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[9] = (payload_ssrc_ >> 16) & 0xFF;
packet_memory[10] = (payload_ssrc_ >> 8) & 0xFF; packet_memory[10] = (payload_ssrc_ >> 8) & 0xFF;
packet_memory[11] = payload_ssrc_ & 0xFF; packet_memory[11] = payload_ssrc_ & 0xFF;

View File

@@ -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|. // Registers all decoders in |neteq|.
void RegisterPayloadTypes(NetEq* neteq) { void RegisterPayloadTypes(NetEq* neteq) {
assert(neteq); assert(neteq);
int error; RegisterPayloadType(neteq, webrtc::kDecoderPCMu, FLAGS_pcmu);
error = neteq->RegisterPayloadType(webrtc::kDecoderPCMu, RegisterPayloadType(neteq, webrtc::kDecoderPCMa, FLAGS_pcma);
static_cast<uint8_t>(FLAGS_pcmu)); RegisterPayloadType(neteq, webrtc::kDecoderILBC, FLAGS_ilbc);
if (error) { RegisterPayloadType(neteq, webrtc::kDecoderISAC, FLAGS_isac);
std::cerr << "Cannot register payload type " << FLAGS_pcmu << RegisterPayloadType(neteq, webrtc::kDecoderISACswb, FLAGS_isac_swb);
" as " << CodecName(webrtc::kDecoderPCMu).c_str() << std::endl; RegisterPayloadType(neteq, webrtc::kDecoderOpus, FLAGS_opus);
exit(1); RegisterPayloadType(neteq, webrtc::kDecoderPCM16B, FLAGS_pcm16b);
} RegisterPayloadType(neteq, webrtc::kDecoderPCM16Bwb, FLAGS_pcm16b_wb);
error = neteq->RegisterPayloadType(webrtc::kDecoderPCMa, RegisterPayloadType(neteq, webrtc::kDecoderPCM16Bswb32kHz,
static_cast<uint8_t>(FLAGS_pcma)); FLAGS_pcm16b_swb32);
if (error) { RegisterPayloadType(neteq, webrtc::kDecoderPCM16Bswb48kHz,
std::cerr << "Cannot register payload type " << FLAGS_pcma << FLAGS_pcm16b_swb48);
" as " << CodecName(webrtc::kDecoderPCMa).c_str() << std::endl; RegisterPayloadType(neteq, webrtc::kDecoderG722, FLAGS_g722);
exit(1); RegisterPayloadType(neteq, webrtc::kDecoderAVT, FLAGS_avt);
} RegisterPayloadType(neteq, webrtc::kDecoderRED, FLAGS_red);
error = neteq->RegisterPayloadType(webrtc::kDecoderILBC, RegisterPayloadType(neteq, webrtc::kDecoderCNGnb, FLAGS_cn_nb);
static_cast<uint8_t>(FLAGS_ilbc)); RegisterPayloadType(neteq, webrtc::kDecoderCNGwb, FLAGS_cn_wb);
if (error) { RegisterPayloadType(neteq, webrtc::kDecoderCNGswb32kHz, FLAGS_cn_swb32);
std::cerr << "Cannot register payload type " << FLAGS_ilbc << RegisterPayloadType(neteq, webrtc::kDecoderCNGswb48kHz, FLAGS_cn_swb48);
" as " << CodecName(webrtc::kDecoderILBC).c_str() << std::endl; }
exit(1);
} void PrintCodecMappingEntry(webrtc::NetEqDecoder codec, google::int32 flag) {
error = neteq->RegisterPayloadType(webrtc::kDecoderISAC, std::cout << CodecName(codec) << ": " << flag << std::endl;
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);
}
} }
void PrintCodecMapping() { void PrintCodecMapping() {
std::cout << CodecName(webrtc::kDecoderPCMu).c_str() << ": " << FLAGS_pcmu << PrintCodecMappingEntry(webrtc::kDecoderPCMu, FLAGS_pcmu);
std::endl; PrintCodecMappingEntry(webrtc::kDecoderPCMa, FLAGS_pcma);
std::cout << CodecName(webrtc::kDecoderPCMa).c_str() << ": " << FLAGS_pcma << PrintCodecMappingEntry(webrtc::kDecoderILBC, FLAGS_ilbc);
std::endl; PrintCodecMappingEntry(webrtc::kDecoderISAC, FLAGS_isac);
std::cout << CodecName(webrtc::kDecoderILBC).c_str() << ": " << FLAGS_ilbc << PrintCodecMappingEntry(webrtc::kDecoderISACswb, FLAGS_isac_swb);
std::endl; PrintCodecMappingEntry(webrtc::kDecoderOpus, FLAGS_opus);
std::cout << CodecName(webrtc::kDecoderISAC).c_str() << ": " << FLAGS_isac << PrintCodecMappingEntry(webrtc::kDecoderPCM16B, FLAGS_pcm16b);
std::endl; PrintCodecMappingEntry(webrtc::kDecoderPCM16Bwb, FLAGS_pcm16b_wb);
std::cout << CodecName(webrtc::kDecoderISACswb).c_str() << ": " << PrintCodecMappingEntry(webrtc::kDecoderPCM16Bswb32kHz, FLAGS_pcm16b_swb32);
FLAGS_isac_swb << std::endl; PrintCodecMappingEntry(webrtc::kDecoderPCM16Bswb48kHz, FLAGS_pcm16b_swb48);
std::cout << CodecName(webrtc::kDecoderOpus).c_str() << ": " << FLAGS_opus PrintCodecMappingEntry(webrtc::kDecoderG722, FLAGS_g722);
<< std::endl; PrintCodecMappingEntry(webrtc::kDecoderAVT, FLAGS_avt);
std::cout << CodecName(webrtc::kDecoderPCM16B).c_str() << ": " << PrintCodecMappingEntry(webrtc::kDecoderRED, FLAGS_red);
FLAGS_pcm16b << std::endl; PrintCodecMappingEntry(webrtc::kDecoderCNGnb, FLAGS_cn_nb);
std::cout << CodecName(webrtc::kDecoderPCM16Bwb).c_str() << ": " << PrintCodecMappingEntry(webrtc::kDecoderCNGwb, FLAGS_cn_wb);
FLAGS_pcm16b_wb << std::endl; PrintCodecMappingEntry(webrtc::kDecoderCNGswb32kHz, FLAGS_cn_swb32);
std::cout << CodecName(webrtc::kDecoderPCM16Bswb32kHz).c_str() << ": " << PrintCodecMappingEntry(webrtc::kDecoderCNGswb48kHz, FLAGS_cn_swb48);
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;
} }
bool IsComfortNosie(uint8_t payload_type) { bool IsComfortNoise(uint8_t payload_type) {
if (payload_type == FLAGS_cn_nb || return payload_type == FLAGS_cn_nb || payload_type == FLAGS_cn_wb ||
payload_type == FLAGS_cn_wb || payload_type == FLAGS_cn_swb32 || payload_type == FLAGS_cn_swb48;
payload_type == FLAGS_cn_swb32 ||
payload_type == FLAGS_cn_swb48) {
return true;
} else {
return false;
}
} }
int CodecSampleRate(uint8_t payload_type) { int CodecSampleRate(uint8_t payload_type) {
if (payload_type == FLAGS_pcmu || if (payload_type == FLAGS_pcmu || payload_type == FLAGS_pcma ||
payload_type == FLAGS_pcma || payload_type == FLAGS_ilbc || payload_type == FLAGS_pcm16b ||
payload_type == FLAGS_ilbc || payload_type == FLAGS_cn_nb)
payload_type == FLAGS_pcm16b ||
payload_type == FLAGS_cn_nb) {
return 8000; return 8000;
} else if (payload_type == FLAGS_isac || if (payload_type == FLAGS_isac || payload_type == FLAGS_pcm16b_wb ||
payload_type == FLAGS_pcm16b_wb || payload_type == FLAGS_g722 || payload_type == FLAGS_cn_wb)
payload_type == FLAGS_g722 ||
payload_type == FLAGS_cn_wb) {
return 16000; return 16000;
} else if (payload_type == FLAGS_isac_swb || if (payload_type == FLAGS_isac_swb || payload_type == FLAGS_pcm16b_swb32 ||
payload_type == FLAGS_pcm16b_swb32 || payload_type == FLAGS_cn_swb32)
payload_type == FLAGS_cn_swb32) {
return 32000; return 32000;
} else if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 || if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 ||
payload_type == FLAGS_cn_swb48) { payload_type == FLAGS_cn_swb48)
return 48000; return 48000;
} else if (payload_type == FLAGS_avt || if (payload_type == FLAGS_avt || payload_type == FLAGS_red)
payload_type == FLAGS_red) {
return 0; return 0;
} else {
return -1; return -1;
}
} }
int CodecTimestampRate(uint8_t payload_type) { int CodecTimestampRate(uint8_t payload_type) {
if (payload_type == FLAGS_g722) { return (payload_type == FLAGS_g722) ? 8000 : CodecSampleRate(payload_type);
return 8000;
} else {
return CodecSampleRate(payload_type);
}
} }
size_t ReplacePayload(webrtc::test::InputAudioFile* replacement_audio_file, 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) { const webrtc::test::Packet* next_packet) {
size_t payload_len = 0; size_t payload_len = 0;
// Check for CNG. // 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 CNG, simply insert a zero-energy one-byte payload.
if (*payload_mem_size_bytes < 1) { if (*payload_mem_size_bytes < 1) {
(*payload).reset(new uint8_t[1]); (*payload).reset(new uint8_t[1]);

View File

@@ -26,14 +26,14 @@ void MakeRtpHeader(int payload_type,
uint32_t ssrc, uint32_t ssrc,
uint8_t* rtp_data) { uint8_t* rtp_data) {
rtp_data[0] = 0x80; 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[2] = (seq_number >> 8) & 0xFF;
rtp_data[3] = (seq_number) & 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[5] = (timestamp >> 16) & 0xFF;
rtp_data[6] = (timestamp >> 8) & 0xFF; rtp_data[6] = (timestamp >> 8) & 0xFF;
rtp_data[7] = timestamp & 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[9] = (ssrc >> 16) & 0xFF;
rtp_data[10] = (ssrc >> 8) & 0xFF; rtp_data[10] = (ssrc >> 8) & 0xFF;
rtp_data[11] = ssrc & 0xFF; rtp_data[11] = ssrc & 0xFF;

View File

@@ -234,7 +234,9 @@ class MockRtpRtcp : public RtpRtcp {
MOCK_METHOD1(SetTargetSendBitrate, MOCK_METHOD1(SetTargetSendBitrate,
void(uint32_t bitrate_bps)); void(uint32_t bitrate_bps));
MOCK_METHOD3(SetGenericFECStatus, 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, MOCK_METHOD3(GenericFECStatus,
int32_t(bool& enable, uint8_t& payloadTypeRED, uint8_t& payloadTypeFEC)); int32_t(bool& enable, uint8_t& payloadTypeRED, uint8_t& payloadTypeFEC));
MOCK_METHOD2(SetFecParameters, MOCK_METHOD2(SetFecParameters,

View File

@@ -16,15 +16,9 @@
namespace webrtc { namespace webrtc {
enum { const uint8_t kFecPayloadType = 96;
kFecPayloadType = 96 const uint8_t kRedPayloadType = 97;
}; const uint8_t kVp8PayloadType = 120;
enum {
kRedPayloadType = 97
};
enum {
kVp8PayloadType = 120
};
typedef ForwardErrorCorrection::Packet Packet; typedef ForwardErrorCorrection::Packet Packet;

View File

@@ -185,23 +185,23 @@ TEST(NACKStringBuilderTest, TestCase13) {
EXPECT_EQ(std::string("5-6,9"), builder.GetResult()); 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 uint16_t seq_num, const uint32_t timestamp,
const uint32_t ssrc, uint8_t* array, const uint32_t ssrc, uint8_t* array,
size_t* cur_pos) { size_t* cur_pos) {
ASSERT_TRUE(payload <= 127); ASSERT_LE(payload_type, 127);
array[(*cur_pos)++] = 0x80; 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 >> 8;
array[(*cur_pos)++] = seq_num; array[(*cur_pos)++] = seq_num & 0xFF;
array[(*cur_pos)++] = timestamp >> 24; array[(*cur_pos)++] = timestamp >> 24;
array[(*cur_pos)++] = timestamp >> 16; array[(*cur_pos)++] = (timestamp >> 16) & 0xFF;
array[(*cur_pos)++] = timestamp >> 8; array[(*cur_pos)++] = (timestamp >> 8) & 0xFF;
array[(*cur_pos)++] = timestamp; array[(*cur_pos)++] = timestamp & 0xFF;
array[(*cur_pos)++] = ssrc >> 24; array[(*cur_pos)++] = ssrc >> 24;
array[(*cur_pos)++] = ssrc >> 16; array[(*cur_pos)++] = (ssrc >> 16) & 0xFF;
array[(*cur_pos)++] = ssrc >> 8; array[(*cur_pos)++] = (ssrc >> 8) & 0xFF;
array[(*cur_pos)++] = ssrc; array[(*cur_pos)++] = ssrc & 0xFF;
// VP8 payload header // VP8 payload header
array[(*cur_pos)++] = 0x90; // X bit = 1 array[(*cur_pos)++] = 0x90; // X bit = 1
array[(*cur_pos)++] = 0x20; // T bit = 1 array[(*cur_pos)++] = 0x20; // T bit = 1
@@ -353,19 +353,19 @@ TEST_F(RtcpSenderTest, IJStatus) {
TEST_F(RtcpSenderTest, TestCompound) { TEST_F(RtcpSenderTest, TestCompound) {
const bool marker_bit = false; const bool marker_bit = false;
const uint8_t payload = 100; const uint8_t payload_type = 100;
const uint16_t seq_num = 11111; const uint16_t seq_num = 11111;
const uint32_t timestamp = 1234567; const uint32_t timestamp = 1234567;
const uint32_t ssrc = 0x11111111; const uint32_t ssrc = 0x11111111;
size_t packet_length = 0; 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); &packet_length);
EXPECT_EQ(25u, packet_length); EXPECT_EQ(25u, packet_length);
VideoCodec codec_inst; VideoCodec codec_inst;
strncpy(codec_inst.plName, "VP8", webrtc::kPayloadNameSize - 1); strncpy(codec_inst.plName, "VP8", webrtc::kPayloadNameSize - 1);
codec_inst.codecType = webrtc::kVideoCodecVP8; codec_inst.codecType = webrtc::kVideoCodecVP8;
codec_inst.plType = payload; codec_inst.plType = payload_type;
EXPECT_EQ(0, rtp_receiver_->RegisterReceivePayload(codec_inst.plName, EXPECT_EQ(0, rtp_receiver_->RegisterReceivePayload(codec_inst.plName,
codec_inst.plType, codec_inst.plType,
90000, 90000,

View File

@@ -225,8 +225,7 @@ TEST_P(ParameterizedRtpPayloadRegistryTest,
bool ignored; bool ignored;
EXPECT_EQ(-1, rtp_payload_registry_->RegisterReceivePayload( EXPECT_EQ(-1, rtp_payload_registry_->RegisterReceivePayload(
"whatever", static_cast<uint8_t>(payload_type), 19, 1, 17, "whatever", static_cast<uint8_t>(payload_type), 19, 1, 17, &ignored));
&ignored));
} }
INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes, INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes,

View File

@@ -64,7 +64,7 @@ bool RTPReceiverAudio::TelephoneEventForwardToDecoder() const {
bool RTPReceiverAudio::TelephoneEventPayloadType( bool RTPReceiverAudio::TelephoneEventPayloadType(
int8_t payload_type) const { int8_t payload_type) const {
CriticalSectionScoped lock(crit_sect_.get()); 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, bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type,

View File

@@ -1614,9 +1614,9 @@ int32_t RTPSender::SetGenericFECStatus(bool enable,
payload_type_fec); payload_type_fec);
} }
int32_t RTPSender::GenericFECStatus( int32_t RTPSender::GenericFECStatus(bool* enable,
bool *enable, uint8_t *payload_type_red, uint8_t* payload_type_red,
uint8_t *payload_type_fec) const { uint8_t* payload_type_fec) const {
if (audio_configured_) { if (audio_configured_) {
return -1; return -1;
} }

View File

@@ -248,15 +248,13 @@ bool RtpHeaderParser::RTCP() const {
} }
const uint8_t payloadType = _ptrRTPDataBegin[1]; const uint8_t payloadType = _ptrRTPDataBegin[1];
bool RTCP = false;
switch (payloadType) { switch (payloadType) {
case 192: case 192:
RTCP = true; return true;
break;
case 193: case 193:
// not supported // not supported
// pass through and check for a potential RTP packet // pass through and check for a potential RTP packet
break; return false;
case 195: case 195:
case 200: case 200:
case 201: case 201:
@@ -266,10 +264,10 @@ bool RtpHeaderParser::RTCP() const {
case 205: case 205:
case 206: case 206:
case 207: case 207:
RTCP = true; return true;
break; default:
return false;
} }
return RTCP;
} }
bool RtpHeaderParser::ParseRtcp(RTPHeader* header) const { bool RtpHeaderParser::ParseRtcp(RTPHeader* header) const {

View File

@@ -22,6 +22,12 @@
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h"
namespace {
const unsigned char kPayloadType = 100;
};
namespace webrtc { namespace webrtc {
class RtpRtcpVideoTest : public ::testing::Test { class RtpRtcpVideoTest : public ::testing::Test {
@@ -136,7 +142,6 @@ class RtpRtcpVideoTest : public ::testing::Test {
uint8_t video_frame_[65000]; uint8_t video_frame_[65000];
size_t payload_data_length_; size_t payload_data_length_;
SimulatedClock fake_clock; SimulatedClock fake_clock;
enum { kPayloadType = 100 };
}; };
TEST_F(RtpRtcpVideoTest, BasicVideo) { TEST_F(RtpRtcpVideoTest, BasicVideo) {

View File

@@ -207,22 +207,9 @@ int32_t RtpDumpImpl::DumpPacket(const uint8_t* packet, size_t packetLength)
bool RtpDumpImpl::RTCP(const uint8_t* packet) const bool RtpDumpImpl::RTCP(const uint8_t* packet) const
{ {
const uint8_t payloadType = packet[1]; return packet[1] == 192 || packet[1] == 200 || packet[1] == 201 ||
bool is_rtcp = false; packet[1] == 202 || packet[1] == 203 || packet[1] == 204 ||
packet[1] == 205 || packet[1] == 206 || packet[1] == 207;
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;
} }
// TODO (hellner): why is TickUtil not used here? // TODO (hellner): why is TickUtil not used here?

View File

@@ -649,8 +649,8 @@ VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder(
return NULL; return NULL;
} }
VCMGenericDecoder* ptr_decoder = NULL; VCMGenericDecoder* ptr_decoder = NULL;
const VCMExtDecoderMapItem* external_dec_item = FindExternalDecoderItem( const VCMExtDecoderMapItem* external_dec_item =
payload_type); FindExternalDecoderItem(payload_type);
if (external_dec_item) { if (external_dec_item) {
// External codec. // External codec.
ptr_decoder = new VCMGenericDecoder( ptr_decoder = new VCMGenericDecoder(

View File

@@ -38,15 +38,13 @@ class VCMNTEncodeCompleteCallback : public webrtc::VCMPacketizationCallback
const webrtc::RTPFragmentationHeader& fragmentationHeader, const webrtc::RTPFragmentationHeader& fragmentationHeader,
const webrtc::RTPVideoHeader* videoHdr) OVERRIDE; const webrtc::RTPVideoHeader* videoHdr) OVERRIDE;
// Register exisitng VCM. // Register existing VCM.
// Currently - encode and decode with the same vcm module. // Currently - encode and decode with the same vcm module.
void RegisterReceiverVCM(webrtc::VideoCodingModule *vcm); void RegisterReceiverVCM(webrtc::VideoCodingModule *vcm);
// Return sum of encoded data (all frames in the sequence) // Return sum of encoded data (all frames in the sequence)
size_t EncodedBytes(); size_t EncodedBytes();
// return number of encoder-skipped frames // return number of encoder-skipped frames
uint32_t SkipCnt(); uint32_t SkipCnt();
// conversion function for payload type (needed for the callback function)
// RTPVideoVideoCodecTypes ConvertPayloadType(uint8_t payloadType);
private: private:
FILE* _encodedFile; FILE* _encodedFile;

View File

@@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include "webrtc/base/checks.h" #include "webrtc/base/checks.h"
#include "webrtc/base/format_macros.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.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 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(); for (SsrcMapIterator mit = packets_by_ssrc_.begin();
mit != packets_by_ssrc_.end(); ++mit) { mit != packets_by_ssrc_.end(); ++mit) {
uint32_t ssrc = mit->first; uint32_t ssrc = mit->first;
const std::vector<uint32_t>& packet_numbers = mit->second; const std::vector<uint32_t>& packet_numbers = mit->second;
uint8_t pt = packets_[packet_numbers[0]].rtp_header.payloadType; uint8_t pt = packets_[packet_numbers[0]].rtp_header.payloadType;
printf("SSRC: %08x, %d packets, pt=%d\n", ssrc, printf("SSRC: %08x, %" PRIuS " packets, pt=%d\n", ssrc,
static_cast<int>(packet_numbers.size()), pt); packet_numbers.size(), pt);
} }
// TODO(solenberg): Better validation of identified SSRC streams. // TODO(solenberg): Better validation of identified SSRC streams.

View File

@@ -138,7 +138,7 @@ void ViEAutoTest::PrintAudioCodec(const webrtc::CodecInst audioCodec)
ViETest::Log("\t: %u", audioCodec.pacsize); ViETest::Log("\t: %u", audioCodec.pacsize);
ViETest::Log("\t: %u", audioCodec.plfreq); ViETest::Log("\t: %u", audioCodec.plfreq);
ViETest::Log("\t: %s", audioCodec.plname); 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("\t: %u", audioCodec.rate);
ViETest::Log(""); ViETest::Log("");
} }

View File

@@ -33,9 +33,6 @@
#pragma warning(disable: 4355) // 'this' : used in base member initializer list #pragma warning(disable: 4355) // 'this' : used in base member initializer list
#endif #endif
const uint8_t kSenderReportPayloadType = 200;
const uint8_t kReceiverReportPayloadType = 201;
TbExternalTransport::TbExternalTransport( TbExternalTransport::TbExternalTransport(
webrtc::ViENetwork& vieNetwork, webrtc::ViENetwork& vieNetwork,
int sender_channel, int sender_channel,
@@ -496,8 +493,10 @@ bool TbExternalTransport::ViEExternalTransportProcess()
// Send to ViE // Send to ViE
if (packet) if (packet)
{ {
uint8_t pltype = static_cast<uint8_t>(packet->packetBuffer[1]); uint8_t packet_type = static_cast<uint8_t>(packet->packetBuffer[1]);
if (pltype == kSenderReportPayloadType) { const uint8_t kSenderReportPacketType = 200;
const uint8_t kReceiverReportPacketType = 201;
if (packet_type == kSenderReportPacketType) {
// Sender report. // Sender report.
if (receive_channels_) { if (receive_channels_) {
for (SsrcChannelMap::iterator it = receive_channels_->begin(); for (SsrcChannelMap::iterator it = receive_channels_->begin();
@@ -511,7 +510,7 @@ bool TbExternalTransport::ViEExternalTransportProcess()
packet->packetBuffer, packet->packetBuffer,
packet->length); packet->length);
} }
} else if (pltype == kReceiverReportPayloadType) { } else if (packet_type == kReceiverReportPacketType) {
// Receiver report. // Receiver report.
_vieNetwork.ReceivedRTCPPacket(sender_channel_, _vieNetwork.ReceivedRTCPPacket(sender_channel_,
packet->packetBuffer, packet->packetBuffer,

View File

@@ -650,7 +650,7 @@ bool ViECodecImpl::CodecValid(const VideoCodec& video_codec) {
} }
if (video_codec.plType == 0 || video_codec.plType > 127) { 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); << static_cast<int>(video_codec.plType);
return false; return false;
} }

View File

@@ -1513,7 +1513,7 @@ Channel::GetRecPayloadType(CodecInst& codec)
} }
codec.pltype = payloadType; codec.pltype = payloadType;
WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,_channelId), WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,_channelId),
"Channel::GetRecPayloadType() => pltype=%u", codec.pltype); "Channel::GetRecPayloadType() => pltype=%d", codec.pltype);
return 0; return 0;
} }

View File

@@ -931,9 +931,12 @@ void CTelephonyEvent::OnBnClickedButtonSetRxTelephonePt()
return; return;
CodecInst codec; CodecInst codec;
strcpy_s(codec.plname, 32, "telephone-event"); 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, 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() void CTelephonyEvent::OnBnClickedButtonSetTxTelephonePt()
@@ -943,7 +946,8 @@ void CTelephonyEvent::OnBnClickedButtonSetTxTelephonePt()
if (ret == FALSE || pt < 0 || pt > 127) if (ret == FALSE || pt < 0 || pt > 127)
return; return;
TEST2(_veDTMFPtr->SetSendTelephoneEventPayloadType(_channel, pt) == 0, 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() void CTelephonyEvent::OnBnClickedCheckDetectInband()