Title: [279459] trunk
Revision
279459
Author
[email protected]
Date
2021-07-01 03:19:25 -0700 (Thu, 01 Jul 2021)

Log Message

RealtimeIncomingAudioSourceCocoa should support other sample rate than 48000
https://bugs.webkit.org/show_bug.cgi?id=227439

Reviewed by Eric Carlson.

Source/WebCore:

We reduced memory allocations by early allocating buffers for the most often used sample rate (48000), but this broke other sample rates, like for G722.
Make sure to update sample rate and buffers if it is not 48000.
Since the initial OnData call is often with a sample rate of 16000 and switches to 48000 after a few calls, early return for a few initial calls (20) or if sample rate is not 16000.
Covered by updated test.

* platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp:
(WebCore::RealtimeIncomingAudioSourceCocoa::OnData):
* platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h:

LayoutTests:

Improve test to validate received audio is not silence.

* webrtc/audio-peer-connection-g722-expected.txt:
* webrtc/audio-peer-connection-g722.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279458 => 279459)


--- trunk/LayoutTests/ChangeLog	2021-07-01 09:10:25 UTC (rev 279458)
+++ trunk/LayoutTests/ChangeLog	2021-07-01 10:19:25 UTC (rev 279459)
@@ -1,3 +1,15 @@
+2021-07-01  Youenn Fablet  <[email protected]>
+
+        RealtimeIncomingAudioSourceCocoa should support other sample rate than 48000
+        https://bugs.webkit.org/show_bug.cgi?id=227439
+
+        Reviewed by Eric Carlson.
+
+        Improve test to validate received audio is not silence.
+
+        * webrtc/audio-peer-connection-g722-expected.txt:
+        * webrtc/audio-peer-connection-g722.html:
+
 2021-07-01  Tim Nguyen  <[email protected]>
 
         Unreviewed, unskip web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-form-submission.html

Modified: trunk/LayoutTests/webrtc/audio-peer-connection-g722-expected.txt (279458 => 279459)


--- trunk/LayoutTests/webrtc/audio-peer-connection-g722-expected.txt	2021-07-01 09:10:25 UTC (rev 279458)
+++ trunk/LayoutTests/webrtc/audio-peer-connection-g722-expected.txt	2021-07-01 10:19:25 UTC (rev 279459)
@@ -1,3 +1,5 @@
 
 PASS Basic G722 audio playback through a peer connection
+PASS Mute remote track
+PASS Unmute remote track
 

Modified: trunk/LayoutTests/webrtc/audio-peer-connection-g722.html (279458 => 279459)


--- trunk/LayoutTests/webrtc/audio-peer-connection-g722.html	2021-07-01 09:10:25 UTC (rev 279458)
+++ trunk/LayoutTests/webrtc/audio-peer-connection-g722.html	2021-07-01 10:19:25 UTC (rev 279459)
@@ -2,7 +2,7 @@
 <html>
 <head>
     <meta charset="utf-8">
-    <title>Testing local audio capture playback causes "playing" event to fire</title>
+    <title>Testing G722 webrtc support</title>
     <script src=""
     <script src=""
     <script src =""
@@ -10,34 +10,9 @@
 var context = new AudioContext();
 var remoteStream;
 
-async function checkForHumBipBop(stream, previousResults, counter)
-{
-    if (!previousResults)
-        previousResults = {
-            heardHum : false,
-            heardBip : false,
-            heardBop : false
-    };
-    if (!counter)
-        counter = 1;
-    else if (++counter > 4)
-        return Promise.resolve(false);
-    results = await analyseAudio(stream, 1000, context);
-    previousResults.heardHum |= results.heardHum;
-    previousResults.heardBip |= results.heardBip;
-    previousResults.heardBop |= results.heardBop;
-    if (previousResults.heardHum && previousResults.heardBip && previousResults.heardBop)
-        return Promise.resolve(true);
-    var results = await checkForHumBipBop(stream, previousResults, counter);
-    return results;
-}
-
 promise_test(async (test) => {
-    if (window.testRunner)
-        testRunner.setUserMediaPermission(true);
-
     const stream = await navigator.mediaDevices.getUserMedia({audio: true});
-    const remoteStream = new Promise((resolve, reject) => {
+    remoteStream = await new Promise((resolve, reject) => {
         createConnections((firstConnection) => {
             firstConnection.addTrack(stream.getAudioTracks()[0], stream);
         }, (secondConnection) => {
@@ -50,10 +25,22 @@
         setTimeout(() => reject("Test timed out"), 5000);
     });
 
-    const results = await checkForHumBipBop(stream);
-    assert_true(results, "heard hum bip bop");
+    const result = await doHumAnalysis(remoteStream, true);
+    assert_true(result, "heard hum bip bop");
+}, "Basic G722 audio playback through a peer connection");
+
+promise_test(async (test) => {
+    remoteStream.getAudioTracks()[0].enabled = false;
+    const result = await doHumAnalysis(remoteStream, false);
+    assert_true(result, "did not hear hum");
+}, "Mute remote track");
+
+promise_test(async (test) => {
+    remoteStream.getAudioTracks()[0].enabled = true;
+    const result = await doHumAnalysis(remoteStream, true);
+    assert_true(result, "heard hum");
     context.close();
-}, "Basic G722 audio playback through a peer connection");
+}, "Unmute remote track");
     </script>
 </head>
 <body>

Modified: trunk/Source/WebCore/ChangeLog (279458 => 279459)


--- trunk/Source/WebCore/ChangeLog	2021-07-01 09:10:25 UTC (rev 279458)
+++ trunk/Source/WebCore/ChangeLog	2021-07-01 10:19:25 UTC (rev 279459)
@@ -1,3 +1,19 @@
+2021-07-01  Youenn Fablet  <[email protected]>
+
+        RealtimeIncomingAudioSourceCocoa should support other sample rate than 48000
+        https://bugs.webkit.org/show_bug.cgi?id=227439
+
+        Reviewed by Eric Carlson.
+
+        We reduced memory allocations by early allocating buffers for the most often used sample rate (48000), but this broke other sample rates, like for G722.
+        Make sure to update sample rate and buffers if it is not 48000.
+        Since the initial OnData call is often with a sample rate of 16000 and switches to 48000 after a few calls, early return for a few initial calls (20) or if sample rate is not 16000.
+        Covered by updated test.
+
+        * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp:
+        (WebCore::RealtimeIncomingAudioSourceCocoa::OnData):
+        * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h:
+
 2021-07-01  Emilio Cobos Álvarez  <[email protected]>
 
         Support unprefixed :autofill pseudo-class.

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp (279458 => 279459)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp	2021-07-01 09:10:25 UTC (rev 279458)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp	2021-07-01 10:19:25 UTC (rev 279459)
@@ -104,15 +104,17 @@
 
 void RealtimeIncomingAudioSourceCocoa::OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames)
 {
-    if (sampleRate != m_sampleRate)
+    ++m_chunksReceived;
+
+    static constexpr size_t initialSampleRate = 16000;
+    static constexpr size_t initialChunksReceived = 20;
+    // We usually receive some initial callbacks with no data at 16000, then we got real data at the actual sample rate.
+    // To limit reallocations, let's skip these initial calls.
+    if (m_chunksReceived < initialChunksReceived && sampleRate == initialSampleRate)
         return;
 
+    if (!m_audioBufferList || m_numberOfChannels != numberOfChannels || m_sampleRate != sampleRate) {
 #if !RELEASE_LOG_DISABLED
-    ++m_chunksReceived;
-#endif
-
-    if (!m_audioBufferList || m_numberOfChannels != numberOfChannels) {
-#if !RELEASE_LOG_DISABLED
         m_audioFormatChanged = true;
 #endif
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h (279458 => 279459)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h	2021-07-01 09:10:25 UTC (rev 279458)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h	2021-07-01 10:19:25 UTC (rev 279459)
@@ -65,8 +65,8 @@
     size_t m_numberOfChannels { 0 };
     CAAudioStreamDescription m_streamDescription;
     std::unique_ptr<WebAudioBufferList> m_audioBufferList;
+    size_t m_chunksReceived { 0 };
 #if !RELEASE_LOG_DISABLED
-    size_t m_chunksReceived { 0 };
     size_t m_lastChunksReceived { 0 };
     bool m_audioFormatChanged { false };
     Timer m_logTimer;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to