test_peerConnection_audioSynchronizationSources.html (3492B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 <script type="application/javascript"> 9 createHTML({ 10 bug: "1363667", 11 title: "Test audio receiver getSynchronizationSources" 12 }); 13 14 var waitForSyncSources = async (test) => { 15 let receivers = [...test.pcRemote.getReceivers(), 16 ...test.pcLocal.getReceivers()]; 17 is(receivers.length, 2, "Expected number of receivers"); 18 // Wait for sync sources 19 while (true) { 20 if (receivers[0].getSynchronizationSources().length && 21 receivers[1].getSynchronizationSources().length) { 22 break; 23 } 24 await wait(250); 25 } 26 }; 27 28 var testGetSynchronizationSources = async (test) => { 29 await waitForSyncSources(test); 30 let receivers = [...test.pcRemote.getReceivers(), 31 ...test.pcLocal.getReceivers()]; 32 is(receivers.length, 2, 33 `Expected number of receivers is 2. (${receivers.length})`); 34 for (let recv of receivers) { 35 let syncSources = recv.getSynchronizationSources(); 36 ok(syncSources, 37 "Receiver has Synchronization sources " + JSON.stringify(syncSources)); 38 is(syncSources.length, 1, "Each receiver has only a single sync source"); 39 let source = recv.getSynchronizationSources()[0]; 40 ok(source.audioLevel !== null, 41 `Synchronization source has audio level. (${source.audioLevel})`); 42 ok(source.audioLevel >= 0.0, 43 `Synchronization source audio level >= 0.0 (${source.audioLevel})`); 44 ok(source.audioLevel <= 1.0, 45 `Synchronization source audio level <= 1.0 (${source.audioLevel})`); 46 ok(source.timestamp, 47 `Synchronization source has timestamp (${source.timestamp})`); 48 const ageSeconds = 49 (window.performance.now() + window.performance.timeOrigin - 50 source.timestamp) / 1000; 51 ok(ageSeconds >= 0, 52 `Synchronization source timestamp is in the past`); 53 ok(ageSeconds < 2.5, 54 `Synchronization source timestamp is close to now`); 55 is(source.voiceActivityFlag, undefined, 56 "Synchronization source unsupported voiceActivity is undefined"); 57 } 58 }; 59 60 var testSynchronizationSourceCached = async (test) => { 61 await waitForSyncSources(test); 62 let receivers = [...test.pcRemote.getReceivers(), 63 ...test.pcLocal.getReceivers()]; 64 is(receivers.length, 2, 65 `Expected number of receivers is 2. (${receivers.length})`); 66 let sourceSets = [[],[]]; 67 for (let sourceSet of sourceSets) { 68 for (let recv of receivers) { 69 let sources = recv.getSynchronizationSources(); 70 is(sources.length, 1, 71 `Expected number of sources is 1. (${sources.length})`); 72 sourceSet.push(sources); 73 } 74 // Busy wait 1s before trying again 75 let endTime = performance.now() + 1000; 76 while (performance.now() < endTime) {}; 77 } 78 is(JSON.stringify(sourceSets[0]), JSON.stringify(sourceSets[1]), 79 "Subsequent getSynchronizationSources calls are cached."); 80 }; 81 82 var test; 83 runNetworkTest(function(options) { 84 test = new PeerConnectionTest(options); 85 test.chain.insertAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW", 86 [testGetSynchronizationSources, 87 testSynchronizationSourceCached]); 88 test.setMediaConstraints([{audio: true}], [{audio: true}]); 89 test.pcLocal.audioElementsOnly = true; 90 return test.run(); 91 }); 92 </script> 93 </pre> 94 </body> 95 </html>