* 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

@ -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;

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|.
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]);

View File

@ -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;