- Change argument type to int for SetSendTelephoneEventPayloadType()

BUG=webrtc:4690

Review URL: https://codereview.webrtc.org/1798903002

Cr-Commit-Position: refs/heads/master@{#11980}
This commit is contained in:
solenberg 2016-03-14 08:00:37 -07:00 committed by Commit bot
parent d67717f9ad
commit 31642aa8f9
4 changed files with 37 additions and 13 deletions

View File

@ -99,6 +99,9 @@ const int kMaxTelephoneEventCode = 255;
const int kMinTelephoneEventDuration = 100;
const int kMaxTelephoneEventDuration = 60000; // Actual limit is 2^16
const int kMinPayloadType = 0;
const int kMaxPayloadType = 127;
class ProxySink : public webrtc::AudioSinkInterface {
public:
ProxySink(AudioSinkInterface* sink) : sink_(sink) { RTC_DCHECK(sink); }
@ -1549,12 +1552,16 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs(
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
// TODO(solenberg): Validate input - that payload types don't overlap, are
// within range, filter out codecs we don't support,
// redundant codecs etc.
// redundant codecs etc - the same way it is done for
// RtpHeaderExtensions.
// Find the DTMF telephone event "codec" payload type.
dtmf_payload_type_ = rtc::Optional<int>();
for (const AudioCodec& codec : codecs) {
if (IsCodec(codec, kDtmfCodecName)) {
if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) {
return false;
}
dtmf_payload_type_ = rtc::Optional<int>(codec.id);
break;
}

View File

@ -1661,6 +1661,27 @@ TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
EXPECT_TRUE(channel_->CanInsertDtmf());
}
// Test that payload type range is limited for telephone-event codec.
TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFPayloadTypeOutOfRange) {
EXPECT_TRUE(SetupEngineWithSendStream());
cricket::AudioSendParameters parameters;
parameters.codecs.push_back(kTelephoneEventCodec);
parameters.codecs.push_back(kIsacCodec);
parameters.codecs[0].id = 0; // DTMF
parameters.codecs[1].id = 96;
EXPECT_TRUE(channel_->SetSendParameters(parameters));
EXPECT_TRUE(channel_->CanInsertDtmf());
parameters.codecs[0].id = 128; // DTMF
EXPECT_FALSE(channel_->SetSendParameters(parameters));
EXPECT_FALSE(channel_->CanInsertDtmf());
parameters.codecs[0].id = 127;
EXPECT_TRUE(channel_->SetSendParameters(parameters));
EXPECT_TRUE(channel_->CanInsertDtmf());
parameters.codecs[0].id = -1; // DTMF
EXPECT_FALSE(channel_->SetSendParameters(parameters));
EXPECT_FALSE(channel_->CanInsertDtmf());
}
// Test that we can set send codecs even with CN codec as the first
// one on the list.
TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {

View File

@ -361,7 +361,7 @@ void Channel::OnPlayTelephoneEvent(uint8_t event,
" volume=%u)",
event, lengthMs, volume);
if (!_playOutbandDtmfEvent || (event > 15)) {
if (!_playOutbandDtmfEvent || event > 15) {
// Ignore callback since feedback is disabled or event is not a
// Dtmf tone event.
return;
@ -2227,18 +2227,14 @@ int Channel::SendTelephoneEventOutband(int event, int duration_ms) {
return 0;
}
int Channel::SetSendTelephoneEventPayloadType(unsigned char type) {
int Channel::SetSendTelephoneEventPayloadType(int payload_type) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::SetSendTelephoneEventPayloadType()");
if (type > 127) {
_engineStatisticsPtr->SetLastError(
VE_INVALID_ARGUMENT, kTraceError,
"SetSendTelephoneEventPayloadType() invalid type");
return -1;
}
CodecInst codec = {};
RTC_DCHECK_LE(0, payload_type);
RTC_DCHECK_GE(127, payload_type);
CodecInst codec = {0};
codec.plfreq = 8000;
codec.pltype = type;
codec.pltype = payload_type;
memcpy(codec.plname, "telephone-event", 16);
if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
_rtpRtcpModule->DeRegisterSendPayload(codec.pltype);

View File

@ -294,9 +294,9 @@ class Channel
// VoEVideoSyncExtended
int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
// VoEDtmf
// DTMF
int SendTelephoneEventOutband(int event, int duration_ms);
int SetSendTelephoneEventPayloadType(unsigned char type);
int SetSendTelephoneEventPayloadType(int payload_type);
// VoEAudioProcessingImpl
int UpdateRxVadDetection(AudioFrame& audioFrame);