Title: [211437] trunk/Source/WebCore
Revision
211437
Author
[email protected]
Date
2017-01-31 10:18:44 -0800 (Tue, 31 Jan 2017)

Log Message

[Mac] Add an audio stream description class
https://bugs.webkit.org/show_bug.cgi?id=167639

Reviewed by Youenn Fablet.

No new tests, the new class is not used yet.

* WebCore.xcodeproj/project.pbxproj:
* platform/audio/AudioStreamDescription.h: Added.
(WebCore::AudioStreamDescription::isPCM):
* platform/audio/mac/CAAudioStreamDescription.cpp: Added.
(WebCore::CAAudioStreamDescription::CAAudioStreamDescription):
(WebCore::CAAudioStreamDescription::platformDescription):
(WebCore::CAAudioStreamDescription::format):
(WebCore::toCAAudioStreamDescription):
(WebCore::CAAudioStreamDescription::operator==):
(WebCore::operator==):
* platform/audio/mac/CAAudioStreamDescription.h: Added.
(WebCore::operator!=):
(WebCore::CAAudioStreamDescription::bytesPerFrame):
(WebCore::CAAudioStreamDescription::bytesPerPacket):
(WebCore::CAAudioStreamDescription::formatFlags):
(WebCore::CAAudioStreamDescription::operator==):
(WebCore::CAAudioStreamDescription::operator!=):
(WebCore::CAAudioStreamDescription::streamDescription):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (211436 => 211437)


--- trunk/Source/WebCore/ChangeLog	2017-01-31 17:52:33 UTC (rev 211436)
+++ trunk/Source/WebCore/ChangeLog	2017-01-31 18:18:44 UTC (rev 211437)
@@ -1,3 +1,31 @@
+2017-01-31  Eric Carlson  <[email protected]>
+
+        [Mac] Add an audio stream description class
+        https://bugs.webkit.org/show_bug.cgi?id=167639
+
+        Reviewed by Youenn Fablet.
+
+        No new tests, the new class is not used yet.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/audio/AudioStreamDescription.h: Added.
+        (WebCore::AudioStreamDescription::isPCM):
+        * platform/audio/mac/CAAudioStreamDescription.cpp: Added.
+        (WebCore::CAAudioStreamDescription::CAAudioStreamDescription):
+        (WebCore::CAAudioStreamDescription::platformDescription):
+        (WebCore::CAAudioStreamDescription::format):
+        (WebCore::toCAAudioStreamDescription):
+        (WebCore::CAAudioStreamDescription::operator==):
+        (WebCore::operator==):
+        * platform/audio/mac/CAAudioStreamDescription.h: Added.
+        (WebCore::operator!=):
+        (WebCore::CAAudioStreamDescription::bytesPerFrame):
+        (WebCore::CAAudioStreamDescription::bytesPerPacket):
+        (WebCore::CAAudioStreamDescription::formatFlags):
+        (WebCore::CAAudioStreamDescription::operator==):
+        (WebCore::CAAudioStreamDescription::operator!=):
+        (WebCore::CAAudioStreamDescription::streamDescription):
+
 2017-01-31  Youenn Fablet  <[email protected]>
 
         RTCPeerConnection methods can take dictionaries as input

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211436 => 211437)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-31 17:52:33 UTC (rev 211436)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-31 18:18:44 UTC (rev 211437)
@@ -7218,6 +7218,9 @@
 		073794F819F5864E00E5A045 /* RTCNotifiersMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCNotifiersMock.h; sourceTree = "<group>"; };
 		07394EC71BAB2CCD00BE99CD /* MediaDevicesRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaDevicesRequest.cpp; sourceTree = "<group>"; };
 		07394EC91BAB2CD700BE99CD /* MediaDevicesRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaDevicesRequest.h; sourceTree = "<group>"; };
+		073B87561E40DCE50071C0EC /* AudioStreamDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioStreamDescription.h; sourceTree = "<group>"; };
+		073B87571E40DCFD0071C0EC /* CAAudioStreamDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CAAudioStreamDescription.cpp; sourceTree = "<group>"; };
+		073B87581E40DCFD0071C0EC /* CAAudioStreamDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CAAudioStreamDescription.h; sourceTree = "<group>"; };
 		073BE33E17D17E01002BD431 /* JSNavigatorUserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNavigatorUserMedia.cpp; sourceTree = "<group>"; };
 		073BE33F17D17E01002BD431 /* JSNavigatorUserMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNavigatorUserMedia.h; sourceTree = "<group>"; };
 		0744ECEB1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRealtimeAudioSourceMac.h; sourceTree = "<group>"; };
@@ -24784,6 +24787,7 @@
 		FD31604012B026A300C1A359 /* audio */ = {
 			isa = PBXGroup;
 			children = (
+				073B87561E40DCE50071C0EC /* AudioStreamDescription.h */,
 				CD669D651D232DF4004D1866 /* cocoa */,
 				CD0EEE0D14743E48003EAFA2 /* ios */,
 				FD3160B012B0270700C1A359 /* mac */,
@@ -24876,6 +24880,8 @@
 		FD3160B012B0270700C1A359 /* mac */ = {
 			isa = PBXGroup;
 			children = (
+				073B87571E40DCFD0071C0EC /* CAAudioStreamDescription.cpp */,
+				073B87581E40DCFD0071C0EC /* CAAudioStreamDescription.h */,
 				FD3160B512B0272A00C1A359 /* AudioBusMac.mm */,
 				FD3160B612B0272A00C1A359 /* AudioDestinationMac.cpp */,
 				FD3160B712B0272A00C1A359 /* AudioDestinationMac.h */,

Added: trunk/Source/WebCore/platform/audio/AudioStreamDescription.h (0 => 211437)


--- trunk/Source/WebCore/platform/audio/AudioStreamDescription.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/audio/AudioStreamDescription.h	2017-01-31 18:18:44 UTC (rev 211437)
@@ -0,0 +1,70 @@
+/*
+ * 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
+
+#include <wtf/Variant.h>
+
+typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
+
+namespace WebCore {
+
+struct PlatformDescription {
+    enum {
+        None,
+        CAAudioStreamBasicType,
+    } type;
+    Variant<std::nullptr_t, const AudioStreamBasicDescription*> description;
+};
+
+class AudioStreamDescription {
+public:
+    virtual ~AudioStreamDescription() = default;
+
+    virtual const PlatformDescription& platformDescription() const = 0;
+
+    enum PCMFormat {
+        None,
+        Int16,
+        Float32,
+        Float64
+    };
+    virtual PCMFormat format() const = 0;
+
+    virtual double sampleRate() const = 0;
+
+    virtual bool isPCM() const { return format() != None; }
+    virtual bool isInterleaved() const = 0;
+    virtual bool isSignedInteger() const = 0;
+    virtual bool isFloat() const = 0;
+    virtual bool isNativeEndian() const = 0;
+
+    virtual uint32_t numberOfInterleavedChannels() const = 0;
+    virtual uint32_t numberOfChannelStreams() const = 0;
+    virtual uint32_t numberOfChannels() const = 0;
+    virtual uint32_t sampleWordSize() const = 0;
+};
+
+}

Added: trunk/Source/WebCore/platform/audio/mac/CAAudioStreamDescription.cpp (0 => 211437)


--- trunk/Source/WebCore/platform/audio/mac/CAAudioStreamDescription.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/CAAudioStreamDescription.cpp	2017-01-31 18:18:44 UTC (rev 211437)
@@ -0,0 +1,148 @@
+/*
+ * 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 "config.h"
+#include "CAAudioStreamDescription.h"
+
+namespace WebCore {
+
+CAAudioStreamDescription::CAAudioStreamDescription(const AudioStreamBasicDescription &desc)
+    : m_streamDescription(desc)
+{
+}
+
+CAAudioStreamDescription::CAAudioStreamDescription(double sampleRate, UInt32 numChannels, PCMFormat format, bool isInterleaved)
+{
+    m_streamDescription.mFormatID = kAudioFormatLinearPCM;
+    m_streamDescription.mSampleRate = sampleRate;
+    m_streamDescription.mFramesPerPacket = 1;
+    m_streamDescription.mChannelsPerFrame = numChannels;
+    m_streamDescription.mBytesPerFrame = 0;
+    m_streamDescription.mBytesPerPacket = 0;
+    m_streamDescription.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
+    m_streamDescription.mReserved = 0;
+
+    int wordsize;
+    switch (format) {
+    case Float32:
+        wordsize = 4;
+        m_streamDescription.mFormatFlags |= kAudioFormatFlagIsFloat;
+        break;
+    case Float64:
+        wordsize = 8;
+        m_streamDescription.mFormatFlags |= kAudioFormatFlagIsFloat;
+        break;
+    case Int16:
+        wordsize = 2;
+        m_streamDescription.mFormatFlags |= kAudioFormatFlagIsSignedInteger;
+        break;
+    case None:
+        ASSERT_NOT_REACHED();
+    }
+
+    m_streamDescription.mBitsPerChannel = wordsize * 8;
+    if (isInterleaved)
+        m_streamDescription.mBytesPerFrame = m_streamDescription.mBytesPerPacket = wordsize * numChannels;
+    else {
+        m_streamDescription.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
+        m_streamDescription.mBytesPerFrame = m_streamDescription.mBytesPerPacket = wordsize;
+    }
+}
+
+const PlatformDescription& CAAudioStreamDescription::platformDescription() const
+{
+    m_platformDescription = { PlatformDescription::CAAudioStreamBasicType, &m_streamDescription };
+    return m_platformDescription;
+}
+
+AudioStreamDescription::PCMFormat CAAudioStreamDescription::format() const
+{
+    if (m_format != None)
+        return m_format;
+
+    if (m_streamDescription.mFormatID != kAudioFormatLinearPCM)
+        return None;
+    if (m_streamDescription.mFramesPerPacket != 1)
+        return None;
+    if (m_streamDescription.mBytesPerFrame != m_streamDescription.mBytesPerPacket)
+        return None;
+    if (m_streamDescription.mBitsPerChannel / sizeof(double) > m_streamDescription.mBytesPerFrame)
+        return None;
+    if (!m_streamDescription.mChannelsPerFrame)
+        return None;
+
+    unsigned wordsize = m_streamDescription.mBytesPerFrame;
+    if (isInterleaved()) {
+        if (wordsize % m_streamDescription.mChannelsPerFrame)
+            return None;
+
+        wordsize /= m_streamDescription.mChannelsPerFrame;
+    }
+
+    if (isNativeEndian() && wordsize * sizeof(double) == m_streamDescription.mBitsPerChannel) {
+        // Packed and native endian, good
+        if (m_streamDescription.mFormatFlags & kLinearPCMFormatFlagIsFloat) {
+            if (m_streamDescription.mFormatFlags & (kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagsSampleFractionMask))
+                return None;
+
+            if (wordsize == sizeof(float))
+                return m_format = Float32;
+            else if (wordsize == sizeof(double))
+                return m_format = Float64;
+
+            return None;
+        }
+
+        if (m_streamDescription.mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) {
+            unsigned fractionBits = (m_streamDescription.mFormatFlags & kLinearPCMFormatFlagsSampleFractionMask) >> kLinearPCMFormatFlagsSampleFractionShift;
+            if (wordsize == 2 && !fractionBits)
+                return m_format = Int16;
+        }
+    }
+
+    return None;
+}
+
+bool CAAudioStreamDescription::operator==(const AudioStreamDescription& other)
+{
+    if (other.platformDescription().type != PlatformDescription::CAAudioStreamBasicType)
+        return false;
+
+    return operator==(*WTF::get<const AudioStreamBasicDescription*>(other.platformDescription().description));
+}
+
+bool operator==(const AudioStreamBasicDescription& a, const AudioStreamBasicDescription& b)
+{
+    return a.mSampleRate == b.mSampleRate
+        && a.mFormatID == b.mFormatID
+        && a.mFormatFlags == b.mFormatFlags
+        && a.mBytesPerPacket == b.mBytesPerPacket
+        && a.mFramesPerPacket == b.mFramesPerPacket
+        && a.mBytesPerFrame == b.mBytesPerFrame
+        && a.mChannelsPerFrame == b.mChannelsPerFrame
+        && a.mBitsPerChannel == b.mBitsPerChannel;
+}
+
+}

Added: trunk/Source/WebCore/platform/audio/mac/CAAudioStreamDescription.h (0 => 211437)


--- trunk/Source/WebCore/platform/audio/mac/CAAudioStreamDescription.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/CAAudioStreamDescription.h	2017-01-31 18:18:44 UTC (rev 211437)
@@ -0,0 +1,83 @@
+/*
+ * 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
+
+#include "AudioStreamDescription.h"
+#include <CoreAudio/CoreAudioTypes.h>
+
+namespace WebCore {
+
+bool operator==(const AudioStreamBasicDescription&, const AudioStreamBasicDescription&);
+inline bool operator!=(const AudioStreamBasicDescription& a, const AudioStreamBasicDescription& b) { return !(a == b); }
+
+class CAAudioStreamDescription final : public AudioStreamDescription {
+public:
+    CAAudioStreamDescription(const AudioStreamBasicDescription&);
+    CAAudioStreamDescription(double, uint32_t, PCMFormat, bool);
+
+    const PlatformDescription& platformDescription() const final;
+
+    PCMFormat format() const final;
+
+    double sampleRate() const final { return m_streamDescription.mSampleRate; }
+
+    bool isInterleaved() const final { return !(m_streamDescription.mFormatFlags & kAudioFormatFlagIsNonInterleaved); }
+    bool isSignedInteger() const final { return isPCM() && (m_streamDescription.mFormatFlags & kAudioFormatFlagIsSignedInteger); }
+    bool isFloat() const final { return isPCM() && (m_streamDescription.mFormatFlags & kAudioFormatFlagIsFloat); }
+    bool isNativeEndian() const final { return isPCM() && (m_streamDescription.mFormatFlags & kAudioFormatFlagIsBigEndian) == kAudioFormatFlagsNativeEndian; }
+
+    uint32_t numberOfInterleavedChannels() const final { return isInterleaved() ? m_streamDescription.mChannelsPerFrame : 1; }
+    uint32_t numberOfChannelStreams() const final { return isInterleaved() ? 1 : m_streamDescription.mChannelsPerFrame; }
+    uint32_t numberOfChannels() const final { return m_streamDescription.mChannelsPerFrame; }
+    uint32_t sampleWordSize() const final {
+        return (m_streamDescription.mBytesPerFrame > 0 && numberOfInterleavedChannels()) ? m_streamDescription.mBytesPerFrame / numberOfInterleavedChannels() :  0;
+    }
+    uint32_t bytesPerFrame() const { return m_streamDescription.mBytesPerFrame; }
+    uint32_t bytesPerPacket() const { return m_streamDescription.mBytesPerPacket; }
+    uint32_t formatFlags() const { return m_streamDescription.mFormatFlags; }
+
+    bool operator==(const AudioStreamBasicDescription& other) { return m_streamDescription == other; }
+    bool operator!=(const AudioStreamBasicDescription& other) { return !operator == (other); }
+    bool operator==(const AudioStreamDescription&);
+    bool operator!=(const AudioStreamDescription& other) { return !operator == (other); }
+
+    const AudioStreamBasicDescription& streamDescription() { return m_streamDescription; }
+
+private:
+    void calculateFormat();
+
+    AudioStreamBasicDescription m_streamDescription;
+    mutable PlatformDescription m_platformDescription;
+    mutable PCMFormat m_format { None };
+};
+
+inline CAAudioStreamDescription toCAAudioStreamDescription(const AudioStreamDescription& description)
+{
+    ASSERT(description.platformDescription().type == PlatformDescription::CAAudioStreamBasicType);
+    return CAAudioStreamDescription(*WTF::get<const AudioStreamBasicDescription*>(description.platformDescription().description));
+}
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to