summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/peerconnection_audio_forced_sample_rate.js
blob: d0c647be0ddad03a5815953e172b192595509065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This function takes a sample-rate, and tests that audio flows correctly when
// the sampling-rate at which the MTG runs is not one of the sampling-rates that
// the MediaPipeline can work with.
// It is in a separate file because we have an MTG per document, and we want to
// test multiple sample-rates, so we include it in multiple HTML mochitest
// files.
async function test_peerconnection_audio_forced_sample_rate(forcedSampleRate) {
  await scriptsReady;
  await pushPrefs(["media.cubeb.force_sample_rate", forcedSampleRate]);
  await runNetworkTest(function (options) {
    const test = new PeerConnectionTest(options);
    const ac = new AudioContext();
    test.setMediaConstraints([{ audio: true }], []);
    test.chain.replace("PC_LOCAL_GUM", [
      function PC_LOCAL_WEBAUDIO_SOURCE(test) {
        const oscillator = ac.createOscillator();
        oscillator.type = "sine";
        oscillator.frequency.value = 700;
        oscillator.start();
        const dest = ac.createMediaStreamDestination();
        oscillator.connect(dest);
        test.pcLocal.attachLocalStream(dest.stream);
      },
    ]);
    test.chain.append([
      function CHECK_REMOTE_AUDIO_FLOW(test) {
        return test.pcRemote.checkReceivingToneFrom(ac, test.pcLocal);
      },
    ]);
    return test.run();
  });
}