Modified: branches/safari-609-branch/Source/WebCore/ChangeLog (261866 => 261867)
--- branches/safari-609-branch/Source/WebCore/ChangeLog 2020-05-19 16:28:14 UTC (rev 261866)
+++ branches/safari-609-branch/Source/WebCore/ChangeLog 2020-05-19 16:29:40 UTC (rev 261867)
@@ -1,3 +1,7 @@
+2020-05-19 Russell Epstein <repst...@apple.com>
+
+ Revert r261582. rdar://problem/63156090
+
2020-05-12 Alan Coon <alanc...@apple.com>
Cherry-pick r259853. rdar://problem/63156090
Modified: branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp (261866 => 261867)
--- branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp 2020-05-19 16:28:14 UTC (rev 261866)
+++ branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp 2020-05-19 16:29:40 UTC (rev 261867)
@@ -28,14 +28,15 @@
#if USE(LIBWEBRTC)
-#include "LibWebRTCAudioFormat.h"
-#include "Logging.h"
+#include <wtf/MonotonicTime.h>
namespace WebCore {
LibWebRTCAudioModule::LibWebRTCAudioModule()
- : m_queue(WorkQueue::create("WebKitWebRTCAudioModule", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive))
+ : m_audioTaskRunner(rtc::Thread::Create())
{
+ m_audioTaskRunner->SetName("WebKitWebRTCAudioModule", nullptr);
+ m_audioTaskRunner->Start();
}
int32_t LibWebRTCAudioModule::RegisterAudioCallback(webrtc::AudioTransport* audioTransport)
@@ -44,16 +45,18 @@
return 0;
}
+void LibWebRTCAudioModule::OnMessage(rtc::Message* message)
+{
+ ASSERT_UNUSED(message, message->message_id == 1);
+ StartPlayoutOnAudioThread();
+}
+
int32_t LibWebRTCAudioModule::StartPlayout()
{
- if (m_isPlaying)
- return 0;
-
- m_isPlaying = true;
- m_queue->dispatch([this] {
- m_pollingTime = MonotonicTime::now();
- pollAudioData();
- });
+ if (!m_isPlaying && m_audioTaskRunner) {
+ m_audioTaskRunner->Post(RTC_FROM_HERE, this, 1);
+ m_isPlaying = true;
+ }
return 0;
}
@@ -65,33 +68,29 @@
}
// libwebrtc uses 10ms frames.
-const unsigned frameLengthMs = 1000 * LibWebRTCAudioFormat::chunkSampleCount / LibWebRTCAudioFormat::sampleRate;
+const unsigned samplingRate = 48000;
+const unsigned frameLengthMs = 10;
+const unsigned samplesPerFrame = samplingRate * frameLengthMs / 1000;
const unsigned pollSamples = 5;
const unsigned pollInterval = 5 * frameLengthMs;
const unsigned channels = 2;
+const unsigned bytesPerSample = 2;
-void LibWebRTCAudioModule::pollAudioData()
+void LibWebRTCAudioModule::StartPlayoutOnAudioThread()
{
- if (!m_isPlaying)
- return;
+ MonotonicTime startTime = MonotonicTime::now();
+ while (true) {
+ PollFromSource();
- 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;
+ MonotonicTime now = MonotonicTime::now();
+ double sleepFor = pollInterval - remainder((now - startTime).milliseconds(), pollInterval);
+ m_audioTaskRunner->SleepMs(sleepFor);
+ if (!m_isPlaying)
+ return;
}
- m_pollingTime = now + delayUntilNextPolling;
- m_queue->dispatchAfter(delayUntilNextPolling, [this] {
- pollAudioData();
- });
}
-void LibWebRTCAudioModule::pollFromSource()
+void LibWebRTCAudioModule::PollFromSource()
{
if (!m_audioTransport)
return;
@@ -99,8 +98,8 @@
for (unsigned i = 0; i < pollSamples; i++) {
int64_t elapsedTime = -1;
int64_t ntpTime = -1;
- char data[LibWebRTCAudioFormat::sampleByteSize * channels * LibWebRTCAudioFormat::chunkSampleCount];
- m_audioTransport->PullRenderData(LibWebRTCAudioFormat::sampleByteSize * 8, LibWebRTCAudioFormat::sampleRate, channels, LibWebRTCAudioFormat::chunkSampleCount, data, &elapsedTime, &ntpTime);
+ char data[(bytesPerSample * channels * samplesPerFrame)];
+ m_audioTransport->PullRenderData(bytesPerSample * 8, samplingRate, channels, samplesPerFrame, data, &elapsedTime, &ntpTime);
}
}
Modified: branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h (261866 => 261867)
--- branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h 2020-05-19 16:28:14 UTC (rev 261866)
+++ branches/safari-609-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h 2020-05-19 16:29:40 UTC (rev 261867)
@@ -32,8 +32,8 @@
ALLOW_UNUSED_PARAMETERS_BEGIN
#include <webrtc/modules/audio_device/include/audio_device.h>
-#include <wtf/MonotonicTime.h>
-#include <wtf/WorkQueue.h>
+#include <webrtc/rtc_base/message_handler.h>
+#include <webrtc/rtc_base/thread.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 {
+class LibWebRTCAudioModule final : public webrtc::AudioDeviceModule, private rtc::MessageHandler {
WTF_MAKE_FAST_ALLOCATED;
public:
LibWebRTCAudioModule();
@@ -54,6 +54,7 @@
void AddRef() const final { }
rtc::RefCountReleaseStatus Release() const final { return rtc::RefCountReleaseStatus::kOtherRefsRemained; }
+ void OnMessage(rtc::Message*);
// webrtc::AudioDeviceModule API
int32_t StartPlayout() final;
@@ -122,13 +123,14 @@
#endif
private:
- void pollAudioData();
- void pollFromSource();
+ void StartPlayoutOnAudioThread();
- Ref<WorkQueue> m_queue;
- bool m_isPlaying { false };
- webrtc::AudioTransport* m_audioTransport { nullptr };
- MonotonicTime m_pollingTime;
+ void PollFromSource();
+
+ std::unique_ptr<rtc::Thread> m_audioTaskRunner;
+
+ bool m_isPlaying = false;
+ webrtc::AudioTransport* m_audioTransport = nullptr;
};
} // namespace WebCore