Bug 1419093 - P3 - update rtp source js & mochi tests
MozReview-Commit-ID: LqI3WG4cgtu
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -2136,21 +2136,27 @@ class RTCRtpReceiver {
_getRtpSourcesByType(type) {
this._fetchRtpSources();
// Only return the values from within the last 10 seconds as per the spec
let cutoffTime = this._rtpSourcesJsTimestamp - 10 * 1000;
let sources = [...this._rtpSources.values()].filter(
(entry) => {
return entry.sourceType == type &&
(entry.timestamp + entry.sourceClockOffset) >= cutoffTime;
- }).map(e => ({
- source: e.source,
- timestamp: e.timestamp + e.sourceClockOffset,
- audioLevel: e.audioLevel,
- }));
+ }).map(e => {
+ let newEntry = {
+ source: e.source,
+ timestamp: e.timestamp + e.sourceClockOffset,
+ audioLevel: e.audioLevel,
+ };
+ if (e.voiceActivityFlag !== undefined) {
+ Object.assign(newEntry, {voiceActivityFlag: e.voiceActivityFlag});
+ }
+ return newEntry;
+ });
return sources;
}
getContributingSources() {
return this._getRtpSourcesByType("contributing");
}
getSynchronizationSources() {
--- a/dom/media/tests/mochitest/test_peerConnection_audioContributingSources.html
+++ b/dom/media/tests/mochitest/test_peerConnection_audioContributingSources.html
@@ -10,21 +10,21 @@
bug: "1363667",
title: "Test audio receiver getContributingSources"
});
var SpWrap = (pc) => SpecialPowers.wrap(pc._pc);
var SpRtpSourceNowTimestamp = (pc) => {
return SpecialPowers.wrap(pc._pc).mozGetNowInRtpSourceReferenceTime();
- }
+ };
var SpInsertLevelForContributingSource = (pc, ...args) => {
return SpecialPowers.wrap(pc._pc).mozInsertLevelForContributingSource(
...args);
- }
+ };
// test_peerConnection_audioSynchronizationSources.html tests
// much of the functionality of getContributingSources as the implementation
// is shared.
var testGetContributingSources = async (test) => {
let remoteReceiver = test.pcRemote.getReceivers()[0];
let localReceiver = test.pcLocal.getReceivers()[0];
// Check that getContributingSources is empty as there is no MCU
@@ -34,17 +34,20 @@
"local contributing sources is empty");
// Wait for the next JS event loop iteration, to clear the cache
await Promise.resolve().then();
// Insert new entries as if there were an MCU
let csrc0 = 124756;
let timestamp0 = SpWrap(test.pcRemote).mozGetNowInRtpSourceReferenceTime();
let timestampOffset = new Date().getTime() - timestamp0;
let hasAudioLevel0 = true;
+ // Audio level as expected to be received in RTP
let audioLevel0 = 34;
+ // Audio level as expected to be returned
+ let expectedAudioLevel0 = 10 ** (-audioLevel0 / 20);
SpWrap(test.pcRemote).mozInsertAudioLevelForContributingSource(
remoteReceiver,
csrc0,
timestamp0,
hasAudioLevel0,
audioLevel0);
@@ -55,47 +58,65 @@
SpWrap(test.pcRemote).mozInsertAudioLevelForContributingSource(
remoteReceiver,
csrc1,
timestamp1,
hasAudioLevel1,
audioLevel1);
+ let csrc2 = 93487;
+ let timestamp2 = timestamp0 - 200;
+ let hasAudioLevel2 = true;
+ let audioLevel2 = 127;
+
+ SpWrap(test.pcRemote).mozInsertAudioLevelForContributingSource(
+ remoteReceiver,
+ csrc2,
+ timestamp2,
+ hasAudioLevel2,
+ audioLevel2);
+
let contributingSources = remoteReceiver.getContributingSources();
- is(contributingSources.length, 2,
+ is(contributingSources.length, 3,
"Expected number of contributing sources");
// Check that both inserted were returned
let source0 = contributingSources.find(c => c.source == csrc0);
ok(source0, "first csrc was found");
let source1 = contributingSources.find(c => c.source == csrc1);
ok(source1, "second csrsc was found");
// Add a small margin of error in the timestamps
let compareTimestamps = (ts1, ts2) => Math.abs(ts1 - ts2) < 100;
// Check the CSRC with audioLevel
- is(source0.audioLevel, audioLevel0,
+ let isWithinErr = Math.abs(source0.audioLevel - expectedAudioLevel0)
+ < expectedAudioLevel0 / 50;
+ ok(isWithinErr,
`Contributing source has correct audio level. (${source0.audioLevel})`);
ok(compareTimestamps(source0.timestamp, timestamp0 + timestampOffset),
`Contributing source has correct timestamp (${source0.timestamp})`);
// Check the CSRC without audioLevel
is(source1.audioLevel, undefined,
`Contributing source has no audio level. (${source1.audioLevel})`);
ok(compareTimestamps(source1.timestamp, timestamp1 + timestampOffset),
`Contributing source has correct timestamp (${source1.timestamp})`);
-
+ // Check that a received RTP audio level 127 is exactly 0
+ let source2 = contributingSources.find(c => c.source == csrc2);
+ ok(source2, "third csrc was found");
+ is(source2.audioLevel, 0,
+ `Contributing source has audio level of 0 when RTP audio level is 127`);
// Check caching
is(JSON.stringify(contributingSources),
JSON.stringify(remoteReceiver.getContributingSources()),
"getContributingSources is cached");
- }
+ };
var test;
runNetworkTest(function(options) {
test = new PeerConnectionTest(options);
test.chain.insertAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW",
[testGetContributingSources]);
test.setMediaConstraints([{audio: true}], [{audio: true}]);
test.pcLocal.audioElementsOnly = true;
--- a/dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
+++ b/dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
@@ -18,52 +18,52 @@
// Wait for sync sources
while (true) {
if (receivers[0].getSynchronizationSources().length > 0 &&
receivers[1].getSynchronizationSources().length > 0) {
break;
}
await wait(250);
}
- }
+ };
var testGetSynchronizationSources = async (test) => {
await waitForSyncSources(test);
let receivers = [...test.pcRemote.getReceivers(),
...test.pcLocal.getReceivers()];
for (let recv of receivers) {
let syncSources = recv.getSynchronizationSources();
ok(syncSources,
"Receiver has Synchronization sources " + JSON.stringify(syncSources));
is(syncSources.length, 1, "Each receiver has only a single sync source");
let source = recv.getSynchronizationSources()[0];
ok(source.audioLevel,
`Synchronization source has audio level. (${source.audioLevel})`);
ok(source.audioLevel < 128,
`Synchronization source audio level < 128. (${source.audioLevel})`);
- ok(Number.isInteger(source.audioLevel),
- `Synchronization source audio level is int. (${source.audioLevel})`);
ok(source.timestamp,
`Synchronization source has timestamp (${source.timestamp})`);
ok(Number.isInteger(source.timestamp),
`Synchronization source timestamp is int (${source.timestamp})`);
+ is(source.voiceActivityFlag, undefined,
+ "Synchronization source unsupported voiceActivity is undefined");
}
- }
+ };
var testSynchronizationSourceCached = async (test) => {
await waitForSyncSources(test);
let receivers = [...test.pcRemote.getReceivers(),
...test.pcLocal.getReceivers()];
is(receivers.length, 2, "Expected number of receivers");
for (let recv of receivers) {
is(JSON.stringify(recv.getSynchronizationSources()),
JSON.stringify(recv.getSynchronizationSources()),
"Subsequent getSynchronizationSources calls are cached.");
}
- }
+ };
var test;
runNetworkTest(function(options) {
test = new PeerConnectionTest(options);
test.chain.insertAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW",
[testGetSynchronizationSources,
testSynchronizationSourceCached]);
test.setMediaConstraints([{audio: true}], [{audio: true}]);