Title: [219377] trunk/Source/WebCore
Revision
219377
Author
[email protected]
Date
2017-07-11 17:25:38 -0700 (Tue, 11 Jul 2017)

Log Message

RealtimeOutgoingAudioSource should not push more audio data if the WebRTC thread is not able to process it
https://bugs.webkit.org/show_bug.cgi?id=174383

Patch by Youenn Fablet <[email protected]> on 2017-07-11
Reviewed by Eric Carlson.

This patch adds support to check for pending-processing audio data.
If the amount of audio data is bigger than a high water mark of 0.5 seconds,
we stop pushing new audio data until buffered audio data is lower than a low water mark of 0.1 seconds.
Patch is tested by adding breakpoints to trigger the high water mark, verifying that low water mark is triggered
and receiving audio is fine on the other connection endpoint.

* platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp:
(WebCore::RealtimeOutgoingAudioSource::isReachingBufferedAudioDataHighLimit):
(WebCore::RealtimeOutgoingAudioSource::isReachingBufferedAudioDataLowLimit):
(WebCore::RealtimeOutgoingAudioSource::audioSamplesAvailable):
* platform/mediastream/mac/RealtimeOutgoingAudioSource.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (219376 => 219377)


--- trunk/Source/WebCore/ChangeLog	2017-07-12 00:24:44 UTC (rev 219376)
+++ trunk/Source/WebCore/ChangeLog	2017-07-12 00:25:38 UTC (rev 219377)
@@ -1,3 +1,22 @@
+2017-07-11  Youenn Fablet  <[email protected]>
+
+        RealtimeOutgoingAudioSource should not push more audio data if the WebRTC thread is not able to process it
+        https://bugs.webkit.org/show_bug.cgi?id=174383
+
+        Reviewed by Eric Carlson.
+
+        This patch adds support to check for pending-processing audio data.
+        If the amount of audio data is bigger than a high water mark of 0.5 seconds,
+        we stop pushing new audio data until buffered audio data is lower than a low water mark of 0.1 seconds.
+        Patch is tested by adding breakpoints to trigger the high water mark, verifying that low water mark is triggered
+        and receiving audio is fine on the other connection endpoint.
+
+        * platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp:
+        (WebCore::RealtimeOutgoingAudioSource::isReachingBufferedAudioDataHighLimit):
+        (WebCore::RealtimeOutgoingAudioSource::isReachingBufferedAudioDataLowLimit):
+        (WebCore::RealtimeOutgoingAudioSource::audioSamplesAvailable):
+        * platform/mediastream/mac/RealtimeOutgoingAudioSource.h:
+
 2017-07-11  Dean Jackson  <[email protected]>
 
         Rolling out r219372.

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp (219376 => 219377)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp	2017-07-12 00:24:44 UTC (rev 219376)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp	2017-07-12 00:25:38 UTC (rev 219377)
@@ -88,6 +88,24 @@
     m_sampleConverter->setMuted(m_muted || !m_enabled);
 }
 
+bool RealtimeOutgoingAudioSource::isReachingBufferedAudioDataHighLimit()
+{
+    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
+    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
+
+    ASSERT(writtenAudioDuration >= readAudioDuration);
+    return writtenAudioDuration > readAudioDuration + 0.5;
+}
+
+bool RealtimeOutgoingAudioSource::isReachingBufferedAudioDataLowLimit()
+{
+    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
+    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
+
+    ASSERT(writtenAudioDuration >= readAudioDuration);
+    return writtenAudioDuration < readAudioDuration + 0.1;
+}
+
 void RealtimeOutgoingAudioSource::audioSamplesAvailable(const MediaTime&, const PlatformAudioData& audioData, const AudioStreamDescription& streamDescription, size_t sampleCount)
 {
     if (m_inputStreamDescription != streamDescription) {
@@ -99,7 +117,17 @@
         status = m_sampleConverter->setOutputFormat(m_outputStreamDescription.streamDescription());
         ASSERT(!status);
     }
-    
+
+    // Let's skip pushing samples if we are too slow pulling them.
+    if (m_skippingAudioData) {
+        if (!isReachingBufferedAudioDataLowLimit())
+            return;
+        m_skippingAudioData = false;
+    } else if (isReachingBufferedAudioDataHighLimit()) {
+        m_skippingAudioData = true;
+        return;
+    }
+
     // If we change the audio track or its sample rate changes, the timestamp based on m_writeCount may be wrong.
     // FIXME: We should update m_writeCount to be valid according the new sampleRate.
     m_sampleConverter->pushSamples(MediaTime(m_writeCount, static_cast<uint32_t>(m_inputStreamDescription.sampleRate())), audioData, sampleCount);

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h (219376 => 219377)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h	2017-07-12 00:24:44 UTC (rev 219376)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h	2017-07-12 00:25:38 UTC (rev 219377)
@@ -70,6 +70,9 @@
     void sourceEnabledChanged();
     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t);
 
+    bool isReachingBufferedAudioDataHighLimit();
+    bool isReachingBufferedAudioDataLowLimit();
+
     // MediaStreamTrackPrivate::Observer API
     void trackMutedChanged(MediaStreamTrackPrivate&) final { sourceMutedChanged(); }
     void trackEnabledChanged(MediaStreamTrackPrivate&) final { sourceEnabledChanged(); }
@@ -92,6 +95,7 @@
     uint64_t m_writeCount { 0 };
     bool m_muted { false };
     bool m_enabled { true };
+    bool m_skippingAudioData { false };
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to