Bug 1419093 - P2 - update rtp source impl & unit tests
Update the c++ side with the new WebIDL definitions, note that
many fields are now required. See P1 for more details.
MozReview-Commit-ID: FKHi86Nj7UO
--- a/media/webrtc/signaling/gtest/rtpsources_unittests.cpp
+++ b/media/webrtc/signaling/gtest/rtpsources_unittests.cpp
@@ -260,24 +260,24 @@ public:
// One for the SSRC, one for the CSRC
EXPECT_EQ(observer.mRtpSources.size(), static_cast<size_t>(2));
nsTArray<dom::RTCRtpSourceEntry> outLevels;
observer.GetRtpSources(timestamp, outLevels);
EXPECT_EQ(outLevels.Length(), static_cast<size_t>(2));
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);
}
}
EXPECT_TRUE(ssrcFound);
EXPECT_TRUE(csrcFound);
}
// Observer a header with two CSRCs
@@ -300,29 +300,29 @@ public:
EXPECT_EQ(observer.mRtpSources.size(), static_cast<size_t>(3));
nsTArray<dom::RTCRtpSourceEntry> outLevels;
observer.GetRtpSources(timestamp, outLevels);
EXPECT_EQ(outLevels.Length(), static_cast<size_t>(3));
bool ssrcFound = false;
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);
}
}
EXPECT_TRUE(ssrcFound);
EXPECT_TRUE(csrc0Found);
EXPECT_TRUE(csrc1Found);
}
--- a/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.cpp
+++ b/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.cpp
@@ -2,16 +2,27 @@
#include "nsThreadUtils.h"
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/modules/include/module_common_types.h"
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<double>(audioLevel) / 20);
+}
+
RtpSourceObserver::RtpSourceObserver() :
mLevelGuard("RtpSourceObserver::mLevelGuard") {}
void
RtpSourceObserver::OnRtpPacket(const webrtc::WebRtcRTPHeader* aHeader,
const int64_t aTimestamp,
const uint32_t aJitter)
{
@@ -46,21 +57,21 @@ RtpSourceObserver::GetRtpSources(const i
nsTArray<dom::RTCRtpSourceEntry>& outSources) const
{
MutexAutoLock lock(mLevelGuard);
outSources.Clear();
for (const auto& it : mRtpSources) {
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));
}
}
}
int64_t RtpSourceObserver::NowInReportClockTime() {
return webrtc::Clock::GetRealTimeClock()->TimeInMilliseconds();
--- a/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.h
+++ b/media/webrtc/signaling/src/media-conduit/RtpSourceObserver.h
@@ -57,16 +57,19 @@ private:
void Update(const int64_t aTimestamp,
const bool aHasAudioLevel,
const uint8_t aAudioLevel) {
jitterAdjustedTimestamp = aTimestamp;
// Audio level range is 0 - 127 inclusive
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;
uint8_t audioLevel = 0;
};
/* Maintains a history of packets for reporting with getContributingSources
* and getSynchronizationSources. It is expected that entries will not always
* be observed in chronological order, and that the correct entry for a query