Title: [269631] trunk
Revision
269631
Author
jer.no...@apple.com
Date
2020-11-10 11:10:31 -0800 (Tue, 10 Nov 2020)

Log Message

Add support for AudioConfiguration.spatialRendering
https://bugs.webkit.org/show_bug.cgi?id=218727
<rdar://problem/71213348>

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/mediacapabilities/mock-decodingInfo-spatialRendering.html

Add support for spatialRendring. On Cocoa ports, this will query AVAudioContext for spatial rendering support.

Drive-by fix: The AudioConfiguration.idl marks sampleRate, bitrate, and channels as optional; those need to
be reflected in the C++ struct.

* Modules/mediacapabilities/AudioConfiguration.idl:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::exernalDeviceDisplayNameForPlayer):
* platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp:
(WebCore::createMediaPlayerDecodingConfigurationCocoa):
* platform/mediacapabilities/AudioConfiguration.h:
* platform/mediacapabilities/MediaCapabilitiesLogging.cpp:
(WebCore::toJSONObject):
* platform/mock/MediaEngineConfigurationFactoryMock.cpp:
(WebCore::canDecodeMedia):
(WebCore::canSmoothlyDecodeMedia):
(WebCore::canPowerEfficientlyDecodeMedia):
(WebCore::canSmoothlyEncodeMedia):
(WebCore::canPowerEfficientlyEncodeMedia):

Source/WebCore/PAL:

* PAL.xcodeproj/project.pbxproj:
* pal/avfoundation/OutputContext.h: Copied from Source/WebCore/platform/mediacapabilities/AudioConfiguration.h.
(PAL::OutputContext::platformContext const):
* pal/avfoundation/OutputContext.mm: Added.
(PAL::OutputContext::OutputContext):
(PAL::OutputContext::sharedAudioPresentationOutputContext):
(PAL::OutputContext::supportsMultipleOutputDevices):
(PAL::OutputContext::deviceName):
(PAL::OutputContext::outputDevices const):
* pal/avfoundation/OutputDevice.h: Copied from Source/WebCore/platform/mediacapabilities/AudioConfiguration.h.
(PAL::OutputDevice::platformDevice const):
* pal/avfoundation/OutputDevice.mm: Copied from Source/WebCore/platform/mediacapabilities/AudioConfiguration.h.
(PAL::OutputDevice::OutputDevice):
(PAL::OutputDevice::name const):
(PAL::OutputDevice::deviceFeatures const):
(PAL::OutputDevice::supportsSpatialAudio const):
* pal/spi/cocoa/AVFoundationSPI.h:

LayoutTests:

* media/mediacapabilities/mock-decodingInfo-spatialRendering-expected.txt: Added.
* media/mediacapabilities/mock-decodingInfo-spatialRendering.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (269630 => 269631)


--- trunk/LayoutTests/ChangeLog	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/LayoutTests/ChangeLog	2020-11-10 19:10:31 UTC (rev 269631)
@@ -1,3 +1,14 @@
+2020-11-10  Jer Noble  <jer.no...@apple.com>
+
+        Add support for AudioConfiguration.spatialRendering
+        https://bugs.webkit.org/show_bug.cgi?id=218727
+        <rdar://problem/71213348>
+
+        Reviewed by Eric Carlson.
+
+        * media/mediacapabilities/mock-decodingInfo-spatialRendering-expected.txt: Added.
+        * media/mediacapabilities/mock-decodingInfo-spatialRendering.html: Added.
+
 2020-11-10  Ryan Haddad  <ryanhad...@apple.com>
 
         [Debug] imported/w3c/web-platform-tests/html/canvas/element/path-objects/2d.path.ellipse.basics.html is asserting

Added: trunk/LayoutTests/media/mediacapabilities/mock-decodingInfo-spatialRendering-expected.txt (0 => 269631)


--- trunk/LayoutTests/media/mediacapabilities/mock-decodingInfo-spatialRendering-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/mediacapabilities/mock-decodingInfo-spatialRendering-expected.txt	2020-11-10 19:10:31 UTC (rev 269631)
@@ -0,0 +1,20 @@
+RUN(internals.enableMockMediaCapabilities())
+RUN(internals.settings.setMediaCapabilitiesExtensionsEnabled(true))
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs="mp4a.40.2"', channels: '5.1', bitrate: 1000, samplerate: 44100 } });)
+Promise resolved OK
+EXPECTED (info.supported == 'true') OK
+EXPECTED (typeof info.supportedConfiguration.audio.spatialRendering == 'undefined') OK
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs="mp4a.40.2"', channels: '5.1', bitrate: 1000, samplerate: 44100, spatialRendering: true } });)
+Promise resolved OK
+EXPECTED (info.supported == 'true') OK
+EXPECTED (info.supportedConfiguration.audio.spatialRendering == 'true') OK
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs="mp4a.40.2"', channels: '2', bitrate: 1000, samplerate: 44100, spatialRendering: true } });)
+Promise resolved OK
+EXPECTED (info.supported == 'false') OK
+EXPECTED (info.supportedConfiguration.audio.spatialRendering == 'true') OK
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs="mp4a.40.2"', channels: '2', bitrate: 1000, samplerate: 44100, spatialRendering: false } });)
+Promise resolved OK
+EXPECTED (info.supported == 'true') OK
+EXPECTED (info.supportedConfiguration.audio.spatialRendering == 'false') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/mediacapabilities/mock-decodingInfo-spatialRendering.html (0 => 269631)


--- trunk/LayoutTests/media/mediacapabilities/mock-decodingInfo-spatialRendering.html	                        (rev 0)
+++ trunk/LayoutTests/media/mediacapabilities/mock-decodingInfo-spatialRendering.html	2020-11-10 19:10:31 UTC (rev 269631)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script type="text/_javascript_">
+    var promise;
+    var info;
+
+    async function doTest()
+    {
+        if (!window.internals) {
+            failTest("Internals is required for this test.")
+            return;
+        }
+
+        run('internals.enableMockMediaCapabilities()');
+        run('internals.settings.setMediaCapabilitiesExtensionsEnabled(true)');
+
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs=\"mp4a.40.2\"', channels: '5.1', bitrate: 1000, samplerate: 44100 } });");
+
+        info = await shouldResolve(promise);
+        testExpected('info.supported', true);
+        testExpected('typeof info.supportedConfiguration.audio.spatialRendering', 'undefined');
+
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs=\"mp4a.40.2\"', channels: '5.1', bitrate: 1000, samplerate: 44100, spatialRendering: true } });");
+
+        info = await shouldResolve(promise);
+        testExpected('info.supported', true);
+        testExpected('info.supportedConfiguration.audio.spatialRendering', true);
+
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs=\"mp4a.40.2\"', channels: '2', bitrate: 1000, samplerate: 44100, spatialRendering: true } });");
+
+        info = await shouldResolve(promise);
+        testExpected('info.supported', false);
+        testExpected('info.supportedConfiguration.audio.spatialRendering', true);
+
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'file', audio: { contentType: 'audio/mp4; codecs=\"mp4a.40.2\"', channels: '2', bitrate: 1000, samplerate: 44100, spatialRendering: false } });");
+
+        info = await shouldResolve(promise);
+        testExpected('info.supported', true);
+        testExpected('info.supportedConfiguration.audio.spatialRendering', false);
+
+        endTest();
+    }
+    </script>
+</head>
+<body _onload_="doTest()" />
+</html>

Modified: trunk/Source/WebCore/ChangeLog (269630 => 269631)


--- trunk/Source/WebCore/ChangeLog	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/ChangeLog	2020-11-10 19:10:31 UTC (rev 269631)
@@ -1,3 +1,33 @@
+2020-11-10  Jer Noble  <jer.no...@apple.com>
+
+        Add support for AudioConfiguration.spatialRendering
+        https://bugs.webkit.org/show_bug.cgi?id=218727
+        <rdar://problem/71213348>
+
+        Reviewed by Eric Carlson.
+
+        Test: media/mediacapabilities/mock-decodingInfo-spatialRendering.html
+
+        Add support for spatialRendring. On Cocoa ports, this will query AVAudioContext for spatial rendering support.
+
+        Drive-by fix: The AudioConfiguration.idl marks sampleRate, bitrate, and channels as optional; those need to
+        be reflected in the C++ struct.
+
+        * Modules/mediacapabilities/AudioConfiguration.idl:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::exernalDeviceDisplayNameForPlayer):
+        * platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp:
+        (WebCore::createMediaPlayerDecodingConfigurationCocoa):
+        * platform/mediacapabilities/AudioConfiguration.h:
+        * platform/mediacapabilities/MediaCapabilitiesLogging.cpp:
+        (WebCore::toJSONObject):
+        * platform/mock/MediaEngineConfigurationFactoryMock.cpp:
+        (WebCore::canDecodeMedia):
+        (WebCore::canSmoothlyDecodeMedia):
+        (WebCore::canPowerEfficientlyDecodeMedia):
+        (WebCore::canSmoothlyEncodeMedia):
+        (WebCore::canPowerEfficientlyEncodeMedia):
+
 2020-11-10  Chris Dumez  <cdu...@apple.com>
 
         [GPUProcess] Regression(r268632) Garbage is rendered on speakers when using WebAudio

Modified: trunk/Source/WebCore/Modules/mediacapabilities/AudioConfiguration.idl (269630 => 269631)


--- trunk/Source/WebCore/Modules/mediacapabilities/AudioConfiguration.idl	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/Modules/mediacapabilities/AudioConfiguration.idl	2020-11-10 19:10:31 UTC (rev 269631)
@@ -31,4 +31,5 @@
   DOMString channels;
   unsigned long long bitrate;
   unsigned long samplerate;
+  boolean spatialRendering;
 };

Modified: trunk/Source/WebCore/PAL/ChangeLog (269630 => 269631)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-11-10 19:10:31 UTC (rev 269631)
@@ -1,3 +1,29 @@
+2020-11-10  Jer Noble  <jer.no...@apple.com>
+
+        Add support for AudioConfiguration.spatialRendering
+        https://bugs.webkit.org/show_bug.cgi?id=218727
+        <rdar://problem/71213348>
+
+        Reviewed by Eric Carlson.
+
+        * PAL.xcodeproj/project.pbxproj:
+        * pal/avfoundation/OutputContext.h: Copied from Source/WebCore/platform/mediacapabilities/AudioConfiguration.h.
+        (PAL::OutputContext::platformContext const):
+        * pal/avfoundation/OutputContext.mm: Added.
+        (PAL::OutputContext::OutputContext):
+        (PAL::OutputContext::sharedAudioPresentationOutputContext):
+        (PAL::OutputContext::supportsMultipleOutputDevices):
+        (PAL::OutputContext::deviceName):
+        (PAL::OutputContext::outputDevices const):
+        * pal/avfoundation/OutputDevice.h: Copied from Source/WebCore/platform/mediacapabilities/AudioConfiguration.h.
+        (PAL::OutputDevice::platformDevice const):
+        * pal/avfoundation/OutputDevice.mm: Copied from Source/WebCore/platform/mediacapabilities/AudioConfiguration.h.
+        (PAL::OutputDevice::OutputDevice):
+        (PAL::OutputDevice::name const):
+        (PAL::OutputDevice::deviceFeatures const):
+        (PAL::OutputDevice::supportsSpatialAudio const):
+        * pal/spi/cocoa/AVFoundationSPI.h:
+
 2020-11-04  David Kilzer  <ddkil...@apple.com>
 
         WebKit should remove unused debug variant support

Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (269630 => 269631)


--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2020-11-10 19:10:31 UTC (rev 269631)
@@ -181,6 +181,10 @@
 		A3C66CDD1F462D6A009E6EE9 /* SessionID.h in Headers */ = {isa = PBXBuildFile; fileRef = A3C66CDB1F462D6A009E6EE9 /* SessionID.h */; };
 		ABCA536824895DB900361BFF /* CoreMotionSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = ABCA536724895DB900361BFF /* CoreMotionSPI.h */; };
 		C15CBB3523F3548A00300CC7 /* NSUserDefaultsSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = C15CBB3223F34A1200300CC7 /* NSUserDefaultsSPI.h */; };
+		CD6122CC2559B6AC00FC657A /* OutputContext.h in Headers */ = {isa = PBXBuildFile; fileRef = CD6122CA2559B6AC00FC657A /* OutputContext.h */; };
+		CD6122CD2559B6AC00FC657A /* OutputContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD6122CB2559B6AC00FC657A /* OutputContext.mm */; };
+		CD6122D02559B8F200FC657A /* OutputDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = CD6122CE2559B8F200FC657A /* OutputDevice.h */; };
+		CD6122D12559B8F200FC657A /* OutputDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD6122CF2559B8F200FC657A /* OutputDevice.mm */; };
 		CDACB3602387425B0018D7CE /* MediaToolboxSoftLink.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDACB35E23873E480018D7CE /* MediaToolboxSoftLink.cpp */; };
 		CDACB361238742740018D7CE /* MediaToolboxSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = CDACB35F23873E480018D7CE /* MediaToolboxSoftLink.h */; };
 		CDF91113220E4EEC001EA39E /* CelestialSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF91112220E4EEC001EA39E /* CelestialSPI.h */; };
@@ -377,6 +381,10 @@
 		C138EA1A2436447200656DF1 /* CoreServicesSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreServicesSPI.h; sourceTree = "<group>"; };
 		C15CBB3223F34A1200300CC7 /* NSUserDefaultsSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSUserDefaultsSPI.h; sourceTree = "<group>"; };
 		C2147A4A1EFD0AA600056FA5 /* CopyPALHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyPALHeaders.xcconfig; sourceTree = "<group>"; };
+		CD6122CA2559B6AC00FC657A /* OutputContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OutputContext.h; sourceTree = "<group>"; };
+		CD6122CB2559B6AC00FC657A /* OutputContext.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = OutputContext.mm; sourceTree = "<group>"; };
+		CD6122CE2559B8F200FC657A /* OutputDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OutputDevice.h; sourceTree = "<group>"; };
+		CD6122CF2559B8F200FC657A /* OutputDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = OutputDevice.mm; sourceTree = "<group>"; };
 		CDACB35E23873E480018D7CE /* MediaToolboxSoftLink.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MediaToolboxSoftLink.cpp; sourceTree = "<group>"; };
 		CDACB35F23873E480018D7CE /* MediaToolboxSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaToolboxSoftLink.h; sourceTree = "<group>"; };
 		CDF91112220E4EEC001EA39E /* CelestialSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CelestialSPI.h; sourceTree = "<group>"; };
@@ -406,6 +414,10 @@
 			children = (
 				0C00CFD11F68CE4600AAC26D /* MediaTimeAVFoundation.cpp */,
 				0C00CFD21F68CE4600AAC26D /* MediaTimeAVFoundation.h */,
+				CD6122CA2559B6AC00FC657A /* OutputContext.h */,
+				CD6122CB2559B6AC00FC657A /* OutputContext.mm */,
+				CD6122CE2559B8F200FC657A /* OutputDevice.h */,
+				CD6122CF2559B8F200FC657A /* OutputDevice.mm */,
 			);
 			path = avfoundation;
 			sourceTree = "<group>";
@@ -874,6 +886,8 @@
 				570AB8F920AF6E3D00B8BE87 /* NSXPCConnectionSPI.h in Headers */,
 				0C5AF91F1F43A4C7002EAC02 /* OpenGLESSPI.h in Headers */,
 				31647FB1251759EF0010F8FB /* OpenGLSoftLinkCocoa.h in Headers */,
+				CD6122CC2559B6AC00FC657A /* OutputContext.h in Headers */,
+				CD6122D02559B8F200FC657A /* OutputDevice.h in Headers */,
 				A169B041248EF05200EE8B7B /* PassKitInstallmentsSPI.h in Headers */,
 				A1F63C9F21A4DBF7006FB43B /* PassKitSoftLink.h in Headers */,
 				0C2DA1551F3BEB4900DBC317 /* PassKitSPI.h in Headers */,
@@ -1011,6 +1025,8 @@
 				0CF99CA41F736375007EE793 /* MediaTimeAVFoundation.cpp in Sources */,
 				CDACB3602387425B0018D7CE /* MediaToolboxSoftLink.cpp in Sources */,
 				31647FB0251759DD0010F8FB /* OpenGLSoftLinkCocoa.mm in Sources */,
+				CD6122CD2559B6AC00FC657A /* OutputContext.mm in Sources */,
+				CD6122D12559B8F200FC657A /* OutputDevice.mm in Sources */,
 				A1F63CA021A4DBF7006FB43B /* PassKitSoftLink.mm in Sources */,
 				A1175B4F1F6B337300C4B9F0 /* PopupMenu.mm in Sources */,
 				4450FC9F21F5F602004DFA56 /* QuickLookSoftLink.mm in Sources */,

Copied: trunk/Source/WebCore/PAL/pal/avfoundation/OutputContext.h (from rev 269630, trunk/Source/WebCore/platform/mediacapabilities/AudioConfiguration.h) (0 => 269631)


--- trunk/Source/WebCore/PAL/pal/avfoundation/OutputContext.h	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/avfoundation/OutputContext.h	2020-11-10 19:10:31 UTC (rev 269631)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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(AVFOUNDATION)
+
+#include <wtf/text/WTFString.h>
+
+OBJC_CLASS AVOutputContext;
+
+namespace PAL {
+
+class OutputDevice;
+
+class OutputContext {
+public:
+    static Optional<OutputContext>& sharedAudioPresentationOutputContext();
+
+    bool supportsMultipleOutputDevices();
+    String deviceName();
+
+    Vector<OutputDevice> outputDevices() const;
+
+    AVOutputContext* platformContext() const { return m_context.get(); }
+private:
+    friend class NeverDestroyed<OutputContext>;
+    OutputContext(RetainPtr<AVOutputContext>&&);
+
+    RetainPtr<AVOutputContext> m_context;
+};
+
+}
+
+#endif

Added: trunk/Source/WebCore/PAL/pal/avfoundation/OutputContext.mm (0 => 269631)


--- trunk/Source/WebCore/PAL/pal/avfoundation/OutputContext.mm	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/avfoundation/OutputContext.mm	2020-11-10 19:10:31 UTC (rev 269631)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2020 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 "config.h"
+#include "OutputContext.h"
+
+#if USE(AVFOUNDATION)
+
+#include "OutputDevice.h"
+#include <mutex>
+#include <pal/spi/cocoa/AVFoundationSPI.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/text/StringBuilder.h>
+
+#include <pal/cocoa/AVFoundationSoftLink.h>
+
+namespace PAL {
+
+OutputContext::OutputContext(RetainPtr<AVOutputContext>&& context)
+    : m_context(WTFMove(context))
+{
+}
+
+Optional<OutputContext>& OutputContext::sharedAudioPresentationOutputContext()
+{
+    static NeverDestroyed<Optional<OutputContext>> sharedAudioPresentationOutputContext = [] () -> Optional<OutputContext> {
+        if (![PAL::getAVOutputContextClass() respondsToSelector:@selector(sharedAudioPresentationOutputContext)])
+            return WTF::nullopt;
+
+        auto context = [getAVOutputContextClass() sharedAudioPresentationOutputContext];
+        if (!context)
+            return WTF::nullopt;
+
+        return OutputContext(retainPtr(context));
+    }();
+    return sharedAudioPresentationOutputContext;
+}
+
+bool OutputContext::supportsMultipleOutputDevices()
+{
+    return [m_context respondsToSelector:@selector(supportsMultipleOutputDevices)]
+        && [m_context respondsToSelector:@selector(outputDevices)]
+        && [m_context supportsMultipleOutputDevices];
+}
+
+String OutputContext::deviceName()
+{
+    if (!supportsMultipleOutputDevices())
+        return [m_context deviceName];
+
+    StringBuilder builder;
+    auto devices = outputDevices();
+    auto iterator = devices.begin();
+
+    while (iterator != devices.end()) {
+        builder.append(iterator->name());
+
+        if (++iterator != devices.end())
+            builder.append(" + ");
+    }
+
+    return builder.toString();
+}
+
+Vector<OutputDevice> OutputContext::outputDevices() const
+{
+    if (![m_context respondsToSelector:@selector(outputDevices)]) {
+        if (auto *outputDevice = [m_context outputDevice])
+            return { retainPtr(outputDevice) };
+        return { };
+    }
+
+    auto *avOutputDevices = [m_context outputDevices];
+    Vector<OutputDevice> outputDevices;
+    outputDevices.reserveInitialCapacity(avOutputDevices.count);
+    for (AVOutputDevice *device in avOutputDevices)
+        outputDevices.uncheckedAppend({ retainPtr(device) });
+    return outputDevices;
+}
+
+
+}
+
+#endif

Copied: trunk/Source/WebCore/PAL/pal/avfoundation/OutputDevice.h (from rev 269630, trunk/Source/WebCore/platform/mediacapabilities/AudioConfiguration.h) (0 => 269631)


--- trunk/Source/WebCore/PAL/pal/avfoundation/OutputDevice.h	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/avfoundation/OutputDevice.h	2020-11-10 19:10:31 UTC (rev 269631)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2020 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(AVFOUNDATION)
+
+OBJC_CLASS AVOutputDevice;
+
+#include <wtf/text/WTFString.h>
+
+namespace PAL {
+
+class OutputDevice {
+public:
+    String name() const;
+
+    enum class DeviceFeatures : uint8_t {
+        Audio = 1 << 0,
+        Screen = 1 << 1,
+        Video = 1 << 2,
+    };
+    uint8_t deviceFeatures() const;
+
+    bool supportsSpatialAudio() const;
+
+    AVOutputDevice* platformDevice() const { return m_device.get(); }
+private:
+    friend class OutputContext;
+    OutputDevice(RetainPtr<AVOutputDevice>&&);
+
+    RetainPtr<AVOutputDevice> m_device;
+};
+
+}
+
+#endif

Copied: trunk/Source/WebCore/PAL/pal/avfoundation/OutputDevice.mm (from rev 269630, trunk/Source/WebCore/platform/mediacapabilities/AudioConfiguration.h) (0 => 269631)


--- trunk/Source/WebCore/PAL/pal/avfoundation/OutputDevice.mm	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/avfoundation/OutputDevice.mm	2020-11-10 19:10:31 UTC (rev 269631)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2020 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 "config.h"
+#include "OutputDevice.h"
+
+#if USE(AVFOUNDATION)
+
+#include <pal/spi/cocoa/AVFoundationSPI.h>
+
+#include <pal/cocoa/AVFoundationSoftLink.h>
+
+namespace PAL {
+
+OutputDevice::OutputDevice(RetainPtr<AVOutputDevice>&& device)
+    : m_device(WTFMove(device))
+{
+}
+
+String OutputDevice::name() const
+{
+    return [m_device name];
+}
+
+uint8_t OutputDevice::deviceFeatures() const
+{
+    auto avDeviceFeatures = [m_device deviceFeatures];
+    uint8_t deviceFeatures { 0 };
+    if (avDeviceFeatures & AVOutputDeviceFeatureAudio)
+        deviceFeatures |= (uint8_t)DeviceFeatures::Audio;
+    if (avDeviceFeatures & AVOutputDeviceFeatureScreen)
+        deviceFeatures |= (uint8_t)DeviceFeatures::Screen;
+    if (avDeviceFeatures & AVOutputDeviceFeatureVideo)
+        deviceFeatures |= (uint8_t)DeviceFeatures::Video;
+    return deviceFeatures;
+}
+
+bool OutputDevice::supportsSpatialAudio() const
+{
+    return [m_device respondsToSelector:@selector(supportsHeadTrackedSpatialAudio)]
+        && [m_device supportsHeadTrackedSpatialAudio];
+}
+
+}
+
+#endif

Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h (269630 => 269631)


--- trunk/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h	2020-11-10 19:10:31 UTC (rev 269631)
@@ -102,6 +102,7 @@
 @property (nonatomic, readonly) NSString *name;
 @property (nonatomic, readonly) NSString *deviceName;
 @property (nonatomic, readonly) AVOutputDeviceFeatures deviceFeatures;
+@property (nonatomic, readonly) BOOL supportsHeadTrackedSpatialAudio;
 @end
 
 #if !PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (269630 => 269631)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2020-11-10 19:10:31 UTC (rev 269631)
@@ -86,6 +86,7 @@
 #import <functional>
 #import <objc/runtime.h>
 #import <pal/avfoundation/MediaTimeAVFoundation.h>
+#import <pal/avfoundation/OutputContext.h>
 #import <pal/spi/cocoa/AVFoundationSPI.h>
 #import <pal/spi/cocoa/QuartzCoreSPI.h>
 #import <wtf/BlockObjCExceptions.h>
@@ -2745,25 +2746,9 @@
     if (!PAL::isAVFoundationFrameworkAvailable())
         return nil;
 
-    if ([PAL::getAVOutputContextClass() respondsToSelector:@selector(sharedAudioPresentationOutputContext)]) {
-        AVOutputContext *outputContext = [PAL::getAVOutputContextClass() sharedAudioPresentationOutputContext];
+    if (auto context = OutputContext::sharedAudioPresentationOutputContext())
+        return context->deviceName();
 
-        if (![outputContext respondsToSelector:@selector(supportsMultipleOutputDevices)]
-            || ![outputContext supportsMultipleOutputDevices]
-            || ![outputContext respondsToSelector:@selector(outputDevices)])
-            return [outputContext deviceName];
-
-        auto outputDeviceNames = adoptNS([[NSMutableArray alloc] init]);
-        for (AVOutputDevice *outputDevice in [outputContext outputDevices]) {
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-            auto outputDeviceName = adoptNS([[outputDevice name] copy]);
-ALLOW_DEPRECATED_DECLARATIONS_END
-            [outputDeviceNames addObject:outputDeviceName.get()];
-        }
-
-        return [outputDeviceNames componentsJoinedByString:@" + "];
-    }
-
     if (player.externalPlaybackType != AVPlayerExternalPlaybackTypeAirPlay)
         return nil;
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp (269630 => 269631)


--- trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp	2020-11-10 19:10:31 UTC (rev 269631)
@@ -33,6 +33,8 @@
 #include "MediaDecodingConfiguration.h"
 #include "MediaPlayer.h"
 #include "VP9UtilitiesCocoa.h"
+#include <pal/avfoundation/OutputContext.h>
+#include <pal/avfoundation/OutputDevice.h>
 
 #include "VideoToolboxSoftLink.h"
 
@@ -125,6 +127,26 @@
             callback({{ }, WTFMove(configuration)});
             return;
         }
+
+        if (configuration.audio->spatialRendering) {
+            auto context = PAL::OutputContext::sharedAudioPresentationOutputContext();
+            if (!context || !WTF::allOf(context->outputDevices(), [] (auto& device) {
+                return device.supportsSpatialAudio();
+            })) {
+                callback({{ }, WTFMove(configuration)});
+                return;
+            }
+
+            // Only multichannel audio can be spatially rendered.
+            if (!configuration.audio->channels.isNull()) {
+                bool isOk = false;
+                auto parsedChannels = configuration.audio->channels.toDouble(&isOk);
+                if (!isOk || parsedChannels <= 2) {
+                    callback({{ }, WTFMove(configuration)});
+                    return;
+                }
+            }
+        }
         info.supported = true;
     }
 

Modified: trunk/Source/WebCore/platform/mediacapabilities/AudioConfiguration.h (269630 => 269631)


--- trunk/Source/WebCore/platform/mediacapabilities/AudioConfiguration.h	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/platform/mediacapabilities/AudioConfiguration.h	2020-11-10 19:10:31 UTC (rev 269631)
@@ -32,8 +32,9 @@
 struct AudioConfiguration {
     String contentType;
     String channels;
-    uint64_t bitrate;
-    uint32_t samplerate;
+    Optional<uint64_t> bitrate;
+    Optional<uint32_t> samplerate;
+    Optional<bool> spatialRendering;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/mediacapabilities/MediaCapabilitiesLogging.cpp (269630 => 269631)


--- trunk/Source/WebCore/platform/mediacapabilities/MediaCapabilitiesLogging.cpp	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/platform/mediacapabilities/MediaCapabilitiesLogging.cpp	2020-11-10 19:10:31 UTC (rev 269631)
@@ -66,9 +66,14 @@
 {
     auto object = JSON::Object::create();
     object->setString("contentType"_s, configuration.contentType);
-    object->setString("channels"_s, configuration.channels);
-    object->setInteger("bitrate"_s, static_cast<int>(configuration.bitrate));
-    object->setDouble("samplerate"_s, configuration.samplerate);
+    if (!configuration.channels.isNull())
+        object->setString("channels"_s, configuration.channels);
+    if (configuration.bitrate)
+        object->setInteger("bitrate"_s, static_cast<int>(configuration.bitrate.value()));
+    if (configuration.samplerate)
+        object->setDouble("samplerate"_s, configuration.samplerate.value());
+    if (configuration.spatialRendering)
+        object->setBoolean("spatialRendering"_s, configuration.spatialRendering.value());
     return object;
 }
 

Modified: trunk/Source/WebCore/platform/mock/MediaEngineConfigurationFactoryMock.cpp (269630 => 269631)


--- trunk/Source/WebCore/platform/mock/MediaEngineConfigurationFactoryMock.cpp	2020-11-10 18:51:46 UTC (rev 269630)
+++ trunk/Source/WebCore/platform/mock/MediaEngineConfigurationFactoryMock.cpp	2020-11-10 19:10:31 UTC (rev 269631)
@@ -61,9 +61,15 @@
 
     // Audio decoding support limited to audio/mp4.
     auto audioConfig = configuration.audio;
-    if (audioConfig)
-        return ContentType(audioConfig->contentType).containerType() == "audio/mp4";
+    if (audioConfig) {
+        if (ContentType(audioConfig->contentType).containerType() != "audio/mp4")
+            return false;
 
+        // Can only support spatial rendering of tracks with multichannel audio:
+        if (audioConfig->spatialRendering.valueOr(false) && audioConfig->channels.toDouble() <= 2)
+            return false;
+    }
+
     return true;
 }
 
@@ -74,7 +80,7 @@
         return false;
 
     auto audioConfig = configuration.audio;
-    if (audioConfig)
+    if (audioConfig && !audioConfig->channels.isNull())
         return audioConfig->channels == "2";
 
     return true;
@@ -87,8 +93,8 @@
         return false;
 
     auto audioConfig = configuration.audio;
-    if (audioConfig)
-        return audioConfig->bitrate <= 1000;
+    if (audioConfig && audioConfig->bitrate)
+        return audioConfig->bitrate.value() <= 1000;
 
     return true;
 }
@@ -125,7 +131,7 @@
         return false;
 
     auto audioConfig = configuration.audio;
-    if (audioConfig && audioConfig->channels != "2")
+    if (audioConfig && !audioConfig->channels.isNull() && audioConfig->channels != "2")
         return false;
 
     return true;
@@ -138,7 +144,7 @@
         return false;
 
     auto audioConfig = configuration.audio;
-    if (audioConfig && audioConfig->bitrate > 1000)
+    if (audioConfig && audioConfig->bitrate && audioConfig->bitrate.value() > 1000)
         return false;
 
     return true;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to