<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211439] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211439">211439</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-01-31 10:57:57 -0800 (Tue, 31 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WebRTC] Add a libwebrtc AudioModule specific to WebKit
https://bugs.webkit.org/show_bug.cgi?id=167572

Patch by Youenn Fablet &lt;youenn@apple.com&gt; on 2017-01-31
Reviewed by Alex Christensen.

To be covered by webrtc audio tests.
Adding an AudioModule to circumvent the default LibWebRTC Audio Module which does the audio directly.
The implementation of the AudioModule is restricted to enable fueling the incoming audio tracks with incoming data.
Code inspired from https://chromium.googlesource.com/chromium/src/+/master/remoting/protocol/webrtc_audio_module.h

* WebCore.xcodeproj/project.pbxproj:
* platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp: Added.
(WebCore::LibWebRTCAudioModule::LibWebRTCAudioModule):
(WebCore::LibWebRTCAudioModule::RegisterAudioCallback):
(WebCore::LibWebRTCAudioModule::OnMessage):
(WebCore::LibWebRTCAudioModule::StartPlayout):
(WebCore::LibWebRTCAudioModule::StopPlayout):
(WebCore::LibWebRTCAudioModule::StartPlayoutOnAudioThread):
(WebCore::LibWebRTCAudioModule::PollFromSource):
* platform/mediastream/libwebrtc/LibWebRTCAudioModule.h: Added.
* platform/mediastream/libwebrtc/LibWebRTCUtils.cpp:
(WebCore::ThreadMessageData::ThreadMessageData):
(WebCore::initializePeerConnectionFactoryAndThreads):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreamlibwebrtcLibWebRTCUtilscpp">trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCUtils.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformmediastreamlibwebrtcLibWebRTCAudioModulecpp">trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreamlibwebrtcLibWebRTCAudioModuleh">trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211438 => 211439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-31 18:41:54 UTC (rev 211438)
+++ trunk/Source/WebCore/ChangeLog        2017-01-31 18:57:57 UTC (rev 211439)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2017-01-31  Youenn Fablet  &lt;youenn@apple.com&gt;
+
+        [WebRTC] Add a libwebrtc AudioModule specific to WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=167572
+
+        Reviewed by Alex Christensen.
+
+        To be covered by webrtc audio tests.
+        Adding an AudioModule to circumvent the default LibWebRTC Audio Module which does the audio directly.
+        The implementation of the AudioModule is restricted to enable fueling the incoming audio tracks with incoming data.
+        Code inspired from https://chromium.googlesource.com/chromium/src/+/master/remoting/protocol/webrtc_audio_module.h
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp: Added.
+        (WebCore::LibWebRTCAudioModule::LibWebRTCAudioModule):
+        (WebCore::LibWebRTCAudioModule::RegisterAudioCallback):
+        (WebCore::LibWebRTCAudioModule::OnMessage):
+        (WebCore::LibWebRTCAudioModule::StartPlayout):
+        (WebCore::LibWebRTCAudioModule::StopPlayout):
+        (WebCore::LibWebRTCAudioModule::StartPlayoutOnAudioThread):
+        (WebCore::LibWebRTCAudioModule::PollFromSource):
+        * platform/mediastream/libwebrtc/LibWebRTCAudioModule.h: Added.
+        * platform/mediastream/libwebrtc/LibWebRTCUtils.cpp:
+        (WebCore::ThreadMessageData::ThreadMessageData):
+        (WebCore::initializePeerConnectionFactoryAndThreads):
+
</ins><span class="cx"> 2017-01-31  Jessie Berlin  &lt;jberlin@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Build fix.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211438 => 211439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-31 18:41:54 UTC (rev 211438)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-31 18:57:57 UTC (rev 211439)
</span><span class="lines">@@ -1535,6 +1535,8 @@
</span><span class="cx">                 414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */ = {isa = PBXBuildFile; fileRef = 414B82031D6DF0D90077EBE3 /* StructuredClone.h */; };
</span><span class="cx">                 415071571685067300C3C7B3 /* SelectorFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 415071551685067300C3C7B3 /* SelectorFilter.cpp */; };
</span><span class="cx">                 415071581685067300C3C7B3 /* SelectorFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 415071561685067300C3C7B3 /* SelectorFilter.h */; };
</span><ins>+                415080361E3F00AD0051D75D /* LibWebRTCAudioModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 415080341E3F00AA0051D75D /* LibWebRTCAudioModule.cpp */; };
+                415080371E3F00B00051D75D /* LibWebRTCAudioModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */; };
</ins><span class="cx">                 4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */; };
</span><span class="cx">                 4150F9F212B6E0E70008C860 /* SliderThumbElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4150F9F012B6E0E70008C860 /* SliderThumbElement.cpp */; };
</span><span class="cx">                 415670471DBE1533009AC3BB /* PeerConnectionStates.h in Headers */ = {isa = PBXBuildFile; fileRef = 415670461DBE1524009AC3BB /* PeerConnectionStates.h */; };
</span><span class="lines">@@ -8744,6 +8746,8 @@
</span><span class="cx">                 414B82031D6DF0D90077EBE3 /* StructuredClone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructuredClone.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 415071551685067300C3C7B3 /* SelectorFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorFilter.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 415071561685067300C3C7B3 /* SelectorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorFilter.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                415080341E3F00AA0051D75D /* LibWebRTCAudioModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCAudioModule.cpp; path = libwebrtc/LibWebRTCAudioModule.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCAudioModule.h; path = libwebrtc/LibWebRTCAudioModule.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderThumbElement.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 4150F9F012B6E0E70008C860 /* SliderThumbElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SliderThumbElement.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 415670461DBE1524009AC3BB /* PeerConnectionStates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeerConnectionStates.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -16709,6 +16713,8 @@
</span><span class="cx">                 415747421E38698000E914D8 /* libwebrtc */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                415080341E3F00AA0051D75D /* LibWebRTCAudioModule.cpp */,
+                                415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */,
</ins><span class="cx">                                 415747431E38699E00E914D8 /* LibWebRTCMacros.h */,
</span><span class="cx">                                 415747441E38699E00E914D8 /* LibWebRTCProvider.h */,
</span><span class="cx">                                 415747451E38699E00E914D8 /* LibWebRTCUtils.cpp */,
</span><span class="lines">@@ -26226,6 +26232,7 @@
</span><span class="cx">                                 0F8B45721DC3FBA300443C3F /* IntersectionObserverCallback.h in Headers */,
</span><span class="cx">                                 0F4710DF1DB6FE22002DCEC3 /* IntersectionObserverEntry.h in Headers */,
</span><span class="cx">                                 B27535720B053814002CE64F /* IntPoint.h in Headers */,
</span><ins>+                                415080371E3F00B00051D75D /* LibWebRTCAudioModule.h in Headers */,
</ins><span class="cx">                                 E462A4A1113E71BE004A4220 /* IntPointHash.h in Headers */,
</span><span class="cx">                                 B27535740B053814002CE64F /* IntRect.h in Headers */,
</span><span class="cx">                                 A2B9217316C5CC420041DCD9 /* IntRectExtent.h in Headers */,
</span><span class="lines">@@ -31669,6 +31676,7 @@
</span><span class="cx">                                 B2227A080D00BF220071B782 /* SVGFETurbulenceElement.cpp in Sources */,
</span><span class="cx">                                 845E72FB0FD2623900A87D79 /* SVGFilter.cpp in Sources */,
</span><span class="cx">                                 081EBF3A0FD34F4100DA7559 /* SVGFilterBuilder.cpp in Sources */,
</span><ins>+                                415080361E3F00AD0051D75D /* LibWebRTCAudioModule.cpp in Sources */,
</ins><span class="cx">                                 B2227A0B0D00BF220071B782 /* SVGFilterElement.cpp in Sources */,
</span><span class="cx">                                 B2227A0E0D00BF220071B782 /* SVGFilterPrimitiveStandardAttributes.cpp in Sources */,
</span><span class="cx">                                 B2227A110D00BF220071B782 /* SVGFitToViewBox.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamlibwebrtcLibWebRTCAudioModulecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp (0 => 211439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.cpp        2017-01-31 18:57:57 UTC (rev 211439)
</span><span class="lines">@@ -0,0 +1,101 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;LibWebRTCAudioModule.h&quot;
+
+#if USE(LIBWEBRTC)
+
+namespace WebCore {
+
+LibWebRTCAudioModule::LibWebRTCAudioModule()
+    : m_audioTaskRunner(rtc::Thread::Create())
+{
+    m_audioTaskRunner-&gt;Start();
+}
+
+int32_t LibWebRTCAudioModule::RegisterAudioCallback(webrtc::AudioTransport* audioTransport)
+{
+    m_audioTransport = audioTransport;
+    return 0;
+}
+
+void LibWebRTCAudioModule::OnMessage(rtc::Message* message)
+{
+    ASSERT(message-&gt;message_id == 1);
+    StartPlayoutOnAudioThread();
+}
+
+int32_t LibWebRTCAudioModule::StartPlayout()
+{
+    if (!m_isPlaying &amp;&amp; m_audioTaskRunner) {
+        m_audioTaskRunner-&gt;Post(RTC_FROM_HERE, this, 1);
+        m_isPlaying = true;
+    }
+    return 0;
+}
+
+int32_t LibWebRTCAudioModule::StopPlayout()
+{
+    if (m_isPlaying)
+        m_isPlaying = false;
+    return 0;
+}
+
+// libwebrtc uses 10ms frames.
+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::StartPlayoutOnAudioThread()
+{
+    while (true) {
+        PollFromSource();
+        m_audioTaskRunner-&gt;SleepMs(pollInterval);
+        if (!m_isPlaying)
+            return;
+    }
+}
+
+void LibWebRTCAudioModule::PollFromSource()
+{
+    if (!m_audioTransport)
+        return;
+
+    for (unsigned i = 0; i &lt; pollSamples; i++) {
+        int64_t elapsedTime = -1;
+        int64_t ntpTime = -1;
+        char data[(bytesPerSample * channels * samplesPerFrame)];
+        m_audioTransport-&gt;PullRenderData(bytesPerSample * 8, samplingRate, channels, samplesPerFrame, data, &amp;elapsedTime, &amp;ntpTime);
+    }
+}
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamlibwebrtcLibWebRTCAudioModuleh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h (0 => 211439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h                                (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCAudioModule.h        2017-01-31 18:57:57 UTC (rev 211439)
</span><span class="lines">@@ -0,0 +1,162 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include &quot;LibWebRTCMacros.h&quot;
+#include &lt;webrtc/base/messagehandler.h&gt;
+#include &lt;webrtc/base/thread.h&gt;
+#include &lt;webrtc/modules/audio_device/include/audio_device.h&gt;
+
+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 {
+public:
+    LibWebRTCAudioModule();
+
+private:
+    template&lt;typename U&gt; U shouldNotBeCalled(U value) const
+    {
+        ASSERT_NOT_REACHED();
+        return value;
+    }
+
+    int32_t AddRef() const final { return 1; }
+    int32_t Release() const final { return 1; }
+    void OnMessage(rtc::Message*);
+
+    // webrtc::AudioDeviceModule API
+    int32_t StartPlayout() final;
+    int32_t StopPlayout() final;
+    int32_t RegisterAudioCallback(webrtc::AudioTransport*) final;
+    bool Playing() const final { return m_isPlaying; }
+
+    int64_t TimeUntilNextProcess() final { return std::numeric_limits&lt;int64_t&gt;::max(); }
+    void Process() final { }
+    int32_t ActiveAudioLayer(AudioLayer*) const final { return shouldNotBeCalled(-1); }
+    ErrorCode LastError() const final { return kAdmErrNone; }
+    int32_t RegisterEventObserver(webrtc::AudioDeviceObserver*) final { return 0; }
+    int32_t Init() final { return 0; }
+    int32_t Terminate() final { return 0; }
+    bool Initialized() const final { return true; }
+    int16_t PlayoutDevices() final { return 0; }
+    int16_t RecordingDevices() final { return 0; }
+    int32_t PlayoutDeviceName(uint16_t, char[webrtc::kAdmMaxDeviceNameSize], char[webrtc::kAdmMaxGuidSize]) final { return 0; }
+    int32_t RecordingDeviceName(uint16_t, char[webrtc::kAdmMaxDeviceNameSize], char[webrtc::kAdmMaxGuidSize]) final { return 0; }
+    int32_t SetPlayoutDevice(uint16_t) final { return 0; }
+    int32_t SetPlayoutDevice(WindowsDeviceType) final { return 0; }
+    int32_t SetRecordingDevice(uint16_t) final { return 0; }
+    int32_t SetRecordingDevice(WindowsDeviceType) final { return 0; }
+    int32_t PlayoutIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t InitPlayout() final { return 0; }
+    bool PlayoutIsInitialized() const final { return true; }
+    int32_t RecordingIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t InitRecording() final { return 0; }
+    bool RecordingIsInitialized() const final { return false; }
+    int32_t StartRecording() final { return 0; }
+    int32_t StopRecording() final { return 0;  }
+    bool Recording() const final { return 0;  }
+    int32_t SetAGC(bool) final { return 0;  }
+    bool AGC() const final { return shouldNotBeCalled(0);  }
+    int32_t SetWaveOutVolume(uint16_t, uint16_t) final { return shouldNotBeCalled(-1); }
+    int32_t WaveOutVolume(uint16_t*, uint16_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t InitSpeaker() final { return 0; }
+    bool SpeakerIsInitialized() const final { return false; }
+    int32_t InitMicrophone() final { return 0; }
+    bool MicrophoneIsInitialized() const final { return false; }
+    int32_t SpeakerVolumeIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t SetSpeakerVolume(uint32_t) final { return shouldNotBeCalled(-1); }
+    int32_t SpeakerVolume(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t MaxSpeakerVolume(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t MinSpeakerVolume(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t SpeakerVolumeStepSize(uint16_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneVolumeIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t SetMicrophoneVolume(uint32_t) final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneVolume(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t MaxMicrophoneVolume(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t MinMicrophoneVolume(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneVolumeStepSize(uint16_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t SpeakerMuteIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t SetSpeakerMute(bool) final { return shouldNotBeCalled(-1); }
+    int32_t SpeakerMute(bool*) const final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneMuteIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t SetMicrophoneMute(bool) final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneMute(bool*) const final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneBoostIsAvailable(bool*) final { return shouldNotBeCalled(-1); }
+    int32_t SetMicrophoneBoost(bool) final { return shouldNotBeCalled(-1); }
+    int32_t MicrophoneBoost(bool*) const final { return shouldNotBeCalled(-1); }
+    int32_t StereoPlayoutIsAvailable(bool* available) const final { *available = false; return 0; }
+    int32_t SetStereoPlayout(bool) final { return 0; }
+    int32_t StereoPlayout(bool*) const final { return shouldNotBeCalled(-1); }
+    int32_t StereoRecordingIsAvailable(bool* available) const final { *available = false; return 0;  }
+    int32_t SetStereoRecording(bool) final { return 0;  }
+    int32_t StereoRecording(bool*) const final { return shouldNotBeCalled(-1); }
+    int32_t SetRecordingChannel(const ChannelType) final { return 0; }
+    int32_t RecordingChannel(ChannelType*) const final { return shouldNotBeCalled(-1); }
+    int32_t SetPlayoutBuffer(const BufferType, uint16_t) final { return shouldNotBeCalled(-1); }
+    int32_t PlayoutBuffer(BufferType*, uint16_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t PlayoutDelay(uint16_t* delay) const final { *delay = 0; return 0; }
+    int32_t RecordingDelay(uint16_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t CPULoad(uint16_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t StartRawOutputFileRecording(const char[webrtc::kAdmMaxFileNameSize]) final { return shouldNotBeCalled(-1); }
+    int32_t StopRawOutputFileRecording() final { return shouldNotBeCalled(-1); }
+    int32_t StartRawInputFileRecording(const char[webrtc::kAdmMaxFileNameSize]) final { return shouldNotBeCalled(-1); }
+    int32_t StopRawInputFileRecording() final { return shouldNotBeCalled(-1); }
+    int32_t SetRecordingSampleRate(const uint32_t) final { return shouldNotBeCalled(-1); }
+    int32_t RecordingSampleRate(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t SetPlayoutSampleRate(const uint32_t) final { return shouldNotBeCalled(-1); }
+    int32_t PlayoutSampleRate(uint32_t*) const final { return shouldNotBeCalled(-1); }
+    int32_t ResetAudioDevice() final { return shouldNotBeCalled(-1); }
+    int32_t SetLoudspeakerStatus(bool) final { return shouldNotBeCalled(-1); }
+    int32_t GetLoudspeakerStatus(bool*) const final { return shouldNotBeCalled(-1); }
+    bool BuiltInAECIsAvailable() const final { return false; }
+    bool BuiltInAGCIsAvailable() const final { return false;  }
+    bool BuiltInNSIsAvailable() const final { return false;  }
+    int32_t EnableBuiltInAEC(bool) final { return shouldNotBeCalled(-1); }
+    int32_t EnableBuiltInAGC(bool) final { return shouldNotBeCalled(-1); }
+    int32_t EnableBuiltInNS(bool) final { return shouldNotBeCalled(-1); }
+
+#if defined(WEBRTC_IOS)
+    int GetPlayoutAudioParameters(webrtc::AudioParameters*) const final { return shouldNotBeCalled(-1); }
+    int GetRecordAudioParameters(webrtc::AudioParameters*) const final { return shouldNotBeCalled(-1); }
+#endif
+
+private:
+    void StartPlayoutOnAudioThread();
+
+    void PollFromSource();
+
+    std::unique_ptr&lt;rtc::Thread&gt; m_audioTaskRunner;
+
+    bool m_isPlaying = false;
+    webrtc::AudioTransport* m_audioTransport = nullptr;
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamlibwebrtcLibWebRTCUtilscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCUtils.cpp (211438 => 211439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCUtils.cpp        2017-01-31 18:41:54 UTC (rev 211438)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCUtils.cpp        2017-01-31 18:57:57 UTC (rev 211439)
</span><span class="lines">@@ -1,29 +1,26 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2017 Apple Inc.
</del><ins>+ * Copyright (C) 2017 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><del>- * modification, are permitted, provided that the following conditions
- * are required to be met:
</del><ins>+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
</ins><span class="cx">  *
</span><del>- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- * 3.  Neither the name of Apple Inc. nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</del><ins>+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="lines">@@ -31,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(LIBWEBRTC)
</span><span class="cx"> 
</span><ins>+#include &quot;LibWebRTCAudioModule.h&quot;
</ins><span class="cx"> #include &lt;webrtc/api/peerconnectionfactoryproxy.h&gt;
</span><span class="cx"> #include &lt;webrtc/api/peerconnectionfactory.h&gt;
</span><span class="cx"> #include &lt;webrtc/base/physicalsocketserver.h&gt;
</span><span class="lines">@@ -42,6 +40,7 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> struct PeerConnectionFactoryAndThreads : public rtc::MessageHandler {
</span><ins>+    std::unique_ptr&lt;LibWebRTCAudioModule&gt; audioDeviceModule;
</ins><span class="cx">     std::unique_ptr&lt;rtc::Thread&gt; networkThread;
</span><span class="cx">     std::unique_ptr&lt;rtc::Thread&gt; signalingThread;
</span><span class="cx">     rtc::scoped_refptr&lt;webrtc::PeerConnectionFactoryInterface&gt; factory;
</span><span class="lines">@@ -96,8 +95,10 @@
</span><span class="cx">     result = factoryAndThreads.signalingThread-&gt;Start();
</span><span class="cx">     ASSERT(result);
</span><span class="cx"> 
</span><del>-    factoryAndThreads.factory = webrtc::CreatePeerConnectionFactory(factoryAndThreads.networkThread.get(), factoryAndThreads.networkThread.get(), factoryAndThreads.signalingThread.get(), nullptr, new webrtc::VideoToolboxVideoEncoderFactory() , new webrtc::VideoToolboxVideoDecoderFactory());
</del><ins>+    factoryAndThreads.audioDeviceModule = std::make_unique&lt;LibWebRTCAudioModule&gt;();
</ins><span class="cx"> 
</span><ins>+    factoryAndThreads.factory = webrtc::CreatePeerConnectionFactory(factoryAndThreads.networkThread.get(), factoryAndThreads.networkThread.get(), factoryAndThreads.signalingThread.get(), factoryAndThreads.audioDeviceModule.get(), new webrtc::VideoToolboxVideoEncoderFactory(), new webrtc::VideoToolboxVideoDecoderFactory());
+
</ins><span class="cx">     ASSERT(factoryAndThreads.factory);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>