Make RtpHeaderExtensionMap::Register and ::Deregister idempotent.

This CL changes the return code of these methods to indicate
success instead of failure when there is nothing to change.

This change appears to resolve an issue where enabling the
timestamp offset extension via SDP would result in a failure if
that extension had already been enabled.
Review URL: https://webrtc-codereview.appspot.com/1118008

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3588 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bemasc@google.com 2013-03-01 17:03:02 +00:00
parent 78693fe37c
commit 603ae3ece2
2 changed files with 17 additions and 5 deletions

View File

@ -39,7 +39,14 @@ int32_t RtpHeaderExtensionMap::Register(const RTPExtensionType type,
std::map<uint8_t, HeaderExtension*>::iterator it =
extensionMap_.find(id);
if (it != extensionMap_.end()) {
return -1;
if (it->second->type != type) {
// An extension is already registered with the same id
// but a different type, so return failure.
return -1;
}
// This extension type is already registered with this id,
// so return success.
return 0;
}
extensionMap_[id] = new HeaderExtension(type);
return 0;
@ -52,9 +59,7 @@ int32_t RtpHeaderExtensionMap::Deregister(const RTPExtensionType type) {
}
std::map<uint8_t, HeaderExtension*>::iterator it =
extensionMap_.find(id);
if (it == extensionMap_.end()) {
return -1;
}
assert(it != extensionMap_.end());
delete it->second;
extensionMap_.erase(it);
return 0;

View File

@ -44,9 +44,16 @@ TEST_F(RtpHeaderExtensionTest, RegisterIllegalArg) {
EXPECT_EQ(-1, map_.Register(kRtpExtensionTransmissionTimeOffset, 15));
}
TEST_F(RtpHeaderExtensionTest, Idempotent) {
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
EXPECT_EQ(0, map_.Deregister(kRtpExtensionTransmissionTimeOffset));
EXPECT_EQ(0, map_.Deregister(kRtpExtensionTransmissionTimeOffset));
}
TEST_F(RtpHeaderExtensionTest, NonUniqueId) {
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
EXPECT_EQ(-1, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
EXPECT_EQ(-1, map_.Register(kRtpExtensionAudioLevel, kId));
}
TEST_F(RtpHeaderExtensionTest, GetTotalLength) {