diff --git a/media/webrtc/signaling/gtest/rtpsources_unittests.cpp b/media/webrtc/signaling/gtest/rtpsources_unittests.cpp index 1f27ca637857..b1ea8fc75db0 100644 --- a/media/webrtc/signaling/gtest/rtpsources_unittests.cpp +++ b/media/webrtc/signaling/gtest/rtpsources_unittests.cpp @@ -265,14 +265,14 @@ public: bool ssrcFound = false; bool csrcFound = true; for (auto& entry : outLevels) { - if (entry.mSource.Value() == ssrc) { + if (entry.mSource == ssrc) { ssrcFound = true; - EXPECT_EQ(entry.mSourceType.Value(), + EXPECT_EQ(entry.mSourceType, dom::RTCRtpSourceEntryType::Synchronization); } - if (entry.mSource.Value() == csrc) { + if (entry.mSource == csrc) { csrcFound = true; - EXPECT_EQ(entry.mSourceType.Value(), + EXPECT_EQ(entry.mSourceType, dom::RTCRtpSourceEntryType::Contributing); } } @@ -305,19 +305,19 @@ public: bool csrc0Found = true; bool csrc1Found = true; for (auto& entry : outLevels) { - if (entry.mSource.Value() == ssrc) { + if (entry.mSource == ssrc) { ssrcFound = true; - EXPECT_EQ(entry.mSourceType.Value(), + EXPECT_EQ(entry.mSourceType, dom::RTCRtpSourceEntryType::Synchronization); } - if (entry.mSource.Value() == csrc0) { + if (entry.mSource == csrc0) { csrc0Found = true; - EXPECT_EQ(entry.mSourceType.Value(), + EXPECT_EQ(entry.mSourceType, dom::RTCRtpSourceEntryType::Contributing); } - if (entry.mSource.Value() == csrc1) { + if (entry.mSource == csrc1) { csrc1Found = true; - EXPECT_EQ(entry.mSourceType.Value(), + EXPECT_EQ(entry.mSourceType, dom::RTCRtpSourceEntryType::Contributing); } } diff --git a/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.cpp b/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.cpp index 3f4df8e13d9e..1606800ec7f8 100644 --- a/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.cpp +++ b/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.cpp @@ -7,6 +7,17 @@ namespace mozilla { using EntryType = dom::RTCRtpSourceEntryType; +double +RtpSourceObserver::RtpSourceEntry::ToLinearAudioLevel() const +{ + // Spec indicates that a value of 127 should be set to 0 + if (audioLevel == 127) { + return 0; + } + // All other values are calculated as 10^(-rfc_level/20) + return std::pow(10, -static_cast(audioLevel) / 20); +} + RtpSourceObserver::RtpSourceObserver() : mLevelGuard("RtpSourceObserver::mLevelGuard") {} @@ -51,11 +62,11 @@ RtpSourceObserver::GetRtpSources(const int64_t aTimeNow, const RtpSourceEntry* entry = it.second.FindClosestNotAfter(aTimeNow); if (entry) { dom::RTCRtpSourceEntry domEntry; - domEntry.mSource.Construct(GetSourceFromKey(it.first)); - domEntry.mSourceType.Construct(GetTypeFromKey(it.first)); - domEntry.mTimestamp.Construct(entry->jitterAdjustedTimestamp); + domEntry.mSource = GetSourceFromKey(it.first); + domEntry.mSourceType = GetTypeFromKey(it.first); + domEntry.mTimestamp = entry->jitterAdjustedTimestamp; if (entry->hasAudioLevel) { - domEntry.mAudioLevel.Construct(entry->audioLevel); + domEntry.mAudioLevel.Construct(entry->ToLinearAudioLevel()); } outSources.AppendElement(std::move(domEntry)); } diff --git a/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.h b/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.h index 66f47cb5f2cf..df446787d0bf 100644 --- a/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.h +++ b/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.h @@ -62,6 +62,9 @@ private: hasAudioLevel = aHasAudioLevel && !(aAudioLevel & 0x80); audioLevel = aAudioLevel; } + // Sets the audio level nullable according to the linear scale + // outlined in the webrtc-pc spec. + double ToLinearAudioLevel() const; // Time this information was received + jitter int64_t jitterAdjustedTimestamp = 0; bool hasAudioLevel = false;