Title: [261942] branches/safari-609-branch/Source/WebCore

Diff

Modified: branches/safari-609-branch/Source/WebCore/ChangeLog (261941 => 261942)


--- branches/safari-609-branch/Source/WebCore/ChangeLog	2020-05-20 19:59:53 UTC (rev 261941)
+++ branches/safari-609-branch/Source/WebCore/ChangeLog	2020-05-20 20:12:28 UTC (rev 261942)
@@ -1,7 +1,3 @@
-2020-05-19  Russell Epstein  <[email protected]>
-
-        Revert r261582. rdar://problem/63156090
-
 2020-05-12  Alan Coon  <[email protected]>
 
         Cherry-pick r259853. rdar://problem/63156090

Modified: branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp (261941 => 261942)


--- branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp	2020-05-20 19:59:53 UTC (rev 261941)
+++ branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp	2020-05-20 20:12:28 UTC (rev 261942)
@@ -28,15 +28,14 @@
 
 #if USE(LIBWEBRTC)
 
-#include <wtf/MonotonicTime.h>
+#include "LibWebRTCAudioFormat.h"
+#include "Logging.h"
 
 namespace WebCore {
 
 LibWebRTCAudioModule::LibWebRTCAudioModule()
-    : m_audioTaskRunner(rtc::Thread::Create())
+    : m_queue(WorkQueue::create("WebKitWebRTCAudioModule", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive))
 {
-    m_audioTaskRunner->SetName("WebKitWebRTCAudioModule", nullptr);
-    m_audioTaskRunner->Start();
 }
 
 int32_t LibWebRTCAudioModule::RegisterAudioCallback(webrtc::AudioTransport* audioTransport)
@@ -45,18 +44,16 @@
     return 0;
 }
 
-void LibWebRTCAudioModule::OnMessage(rtc::Message* message)
+int32_t LibWebRTCAudioModule::StartPlayout()
 {
-    ASSERT_UNUSED(message, message->message_id == 1);
-    StartPlayoutOnAudioThread();
-}
+    if (m_isPlaying)
+        return 0;
 
-int32_t LibWebRTCAudioModule::StartPlayout()
-{
-    if (!m_isPlaying && m_audioTaskRunner) {
-        m_audioTaskRunner->Post(RTC_FROM_HERE, this, 1);
-        m_isPlaying = true;
-    }
+    m_isPlaying = true;
+    m_queue->dispatch([this] {
+        m_pollingTime = MonotonicTime::now();
+        pollAudioData();
+    });
     return 0;
 }
 
@@ -68,29 +65,33 @@
 }
 
 // libwebrtc uses 10ms frames.
-const unsigned samplingRate = 48000;
-const unsigned frameLengthMs = 10;
-const unsigned samplesPerFrame = samplingRate * frameLengthMs / 1000;
+const unsigned frameLengthMs = 1000 * LibWebRTCAudioFormat::chunkSampleCount / LibWebRTCAudioFormat::sampleRate;
 const unsigned pollSamples = 5;
 const unsigned pollInterval = 5 * frameLengthMs;
 const unsigned channels = 2;
-const unsigned bytesPerSample = 2;
 
-void LibWebRTCAudioModule::StartPlayoutOnAudioThread()
+void LibWebRTCAudioModule::pollAudioData()
 {
-    MonotonicTime startTime = MonotonicTime::now();
-    while (true) {
-        PollFromSource();
+    if (!m_isPlaying)
+        return;
 
-        MonotonicTime now = MonotonicTime::now();
-        double sleepFor = pollInterval - remainder((now - startTime).milliseconds(), pollInterval);
-        m_audioTaskRunner->SleepMs(sleepFor);
-        if (!m_isPlaying)
-            return;
+    pollFromSource();
+
+    auto now = MonotonicTime::now();
+    auto delayUntilNextPolling = m_pollingTime + Seconds::fromMilliseconds(pollInterval) - now;
+    if (delayUntilNextPolling.milliseconds() < 0) {
+        callOnMainThread([timeSpent = (now - m_pollingTime).milliseconds()] {
+            RELEASE_LOG(WebRTC, "LibWebRTCAudioModule::pollAudioData, polling took too much time: %d ms", (int)timeSpent);
+        });
+        delayUntilNextPolling = 0_s;
     }
+    m_pollingTime = now + delayUntilNextPolling;
+    m_queue->dispatchAfter(delayUntilNextPolling, [this] {
+        pollAudioData();
+    });
 }
 
-void LibWebRTCAudioModule::PollFromSource()
+void LibWebRTCAudioModule::pollFromSource()
 {
     if (!m_audioTransport)
         return;
@@ -98,8 +99,8 @@
     for (unsigned i = 0; i < pollSamples; i++) {
         int64_t elapsedTime = -1;
         int64_t ntpTime = -1;
-        char data[(bytesPerSample * channels * samplesPerFrame)];
-        m_audioTransport->PullRenderData(bytesPerSample * 8, samplingRate, channels, samplesPerFrame, data, &elapsedTime, &ntpTime);
+        char data[LibWebRTCAudioFormat::sampleByteSize * channels * LibWebRTCAudioFormat::chunkSampleCount];
+        m_audioTransport->PullRenderData(LibWebRTCAudioFormat::sampleByteSize * 8, LibWebRTCAudioFormat::sampleRate, channels, LibWebRTCAudioFormat::chunkSampleCount, data, &elapsedTime, &ntpTime);
     }
 }
 

Modified: branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h (261941 => 261942)


--- branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h	2020-05-20 19:59:53 UTC (rev 261941)
+++ branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h	2020-05-20 20:12:28 UTC (rev 261942)
@@ -32,8 +32,8 @@
 ALLOW_UNUSED_PARAMETERS_BEGIN
 
 #include <webrtc/modules/audio_device/include/audio_device.h>
-#include <webrtc/rtc_base/message_handler.h>
-#include <webrtc/rtc_base/thread.h>
+#include <wtf/MonotonicTime.h>
+#include <wtf/WorkQueue.h>
 
 ALLOW_UNUSED_PARAMETERS_END
 
@@ -40,7 +40,7 @@
 namespace WebCore {
 
 // LibWebRTCAudioModule is pulling streamed data to ensure audio data is passed to the audio track.
-class LibWebRTCAudioModule final : public webrtc::AudioDeviceModule, private rtc::MessageHandler {
+class LibWebRTCAudioModule final : public webrtc::AudioDeviceModule {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     LibWebRTCAudioModule();
@@ -54,7 +54,6 @@
 
     void AddRef() const final { }
     rtc::RefCountReleaseStatus Release() const final { return rtc::RefCountReleaseStatus::kOtherRefsRemained; }
-    void OnMessage(rtc::Message*);
 
     // webrtc::AudioDeviceModule API
     int32_t StartPlayout() final;
@@ -123,14 +122,13 @@
 #endif
 
 private:
-    void StartPlayoutOnAudioThread();
+    void pollAudioData();
+    void pollFromSource();
 
-    void PollFromSource();
-
-    std::unique_ptr<rtc::Thread> m_audioTaskRunner;
-
-    bool m_isPlaying = false;
-    webrtc::AudioTransport* m_audioTransport = nullptr;
+    Ref<WorkQueue> m_queue;
+    bool m_isPlaying { false };
+    webrtc::AudioTransport* m_audioTransport { nullptr };
+    MonotonicTime m_pollingTime;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to