[MediaSource] Push capabilities across process boundary during UIProcess capture.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Apr 2017 16:04:52 +0000 (16:04 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Apr 2017 16:04:52 +0000 (16:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170814

Reviewed by Eric Carlson.

Source/WebCore:

There's no real reason for RealtimeMediaSourceCapabilities to be RefCounted nor to keep them from
being created on the stack. So in addition to making that class coder-compliant, change all the
classes that vend capabilities to use a unique_ptr<> instead of a RefPtr<>.

* Modules/mediastream/CanvasCaptureMediaStreamTrack.h:
* Modules/webaudio/MediaStreamAudioSource.cpp:
(WebCore::MediaStreamAudioSource::capabilities):
* Modules/webaudio/MediaStreamAudioSource.h:
* platform/mediastream/MediaEndpoint.cpp:
* platform/mediastream/MediaStreamTrackPrivate.cpp:
(WebCore::MediaStreamTrackPrivate::capabilities):
* platform/mediastream/MediaStreamTrackPrivate.h:
* platform/mediastream/RealtimeMediaSource.h:
* platform/mediastream/RealtimeMediaSourceCapabilities.h:
(WebCore::CapabilityValueOrRange::encode):
(WebCore::CapabilityValueOrRange::decode):
(WebCore::RealtimeMediaSourceCapabilities::RealtimeMediaSourceCapabilities):
(WebCore::RealtimeMediaSourceCapabilities::supportedConstraints):
(WebCore::RealtimeMediaSourceCapabilities::setSupportedConstraints):
(WebCore::RealtimeMediaSourceCapabilities::encode):
(WebCore::RealtimeMediaSourceCapabilities::decode):
(WebCore::RealtimeMediaSourceCapabilities::create): Deleted.
* platform/mediastream/RealtimeMediaSourceSettings.h:
* platform/mediastream/mac/AVMediaCaptureSource.h:
* platform/mediastream/mac/AVMediaCaptureSource.mm:
(WebCore::AVMediaCaptureSource::initializeCapabilities):
(WebCore::AVMediaCaptureSource::capabilities):
* platform/mediastream/mac/CoreAudioCaptureSource.cpp:
(WebCore::CoreAudioCaptureSource::capabilities):
* platform/mediastream/mac/CoreAudioCaptureSource.h:
* platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
(WebCore::RealtimeIncomingAudioSource::capabilities):
* platform/mediastream/mac/RealtimeIncomingAudioSource.h:
* platform/mediastream/mac/RealtimeIncomingVideoSource.cpp:
(WebCore::RealtimeIncomingVideoSource::capabilities):
* platform/mediastream/mac/RealtimeIncomingVideoSource.h:
* platform/mock/MockRealtimeMediaSource.cpp:
(WebCore::MockRealtimeMediaSource::initializeCapabilities):
(WebCore::MockRealtimeMediaSource::capabilities):
* platform/mock/MockRealtimeMediaSource.h:
* platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h:

Source/WebKit2:

Make a new synchronous getter for capabilities(), moderated by only requesting the capabilities() cross-process
the first time called.

* UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
(WebKit::UserMediaCaptureManagerProxy::capabilities):
(WebKit::UserMediaCaptureManagerProxy::supportedConstraints):
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in:
* WebProcess/cocoa/UserMediaCaptureManager.cpp:
(WebKit::UserMediaCaptureManager::Source::setCapabilities):
(WebKit::UserMediaCaptureManager::capabilities):
* WebProcess/cocoa/UserMediaCaptureManager.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215362 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.h
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/webaudio/MediaStreamAudioSource.cpp
Source/WebCore/Modules/webaudio/MediaStreamAudioSource.h
Source/WebCore/platform/mediastream/MediaEndpoint.cpp
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/RealtimeMediaSourceCapabilities.h
Source/WebCore/platform/mediastream/RealtimeMediaSourceSettings.h
Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h
Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm
Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp
Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h
Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h
Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSource.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp
Source/WebKit2/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h
Source/WebKit2/UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in
Source/WebKit2/WebProcess/cocoa/UserMediaCaptureManager.cpp
Source/WebKit2/WebProcess/cocoa/UserMediaCaptureManager.h

index ad59574..7b9bc4c 100644 (file)
@@ -1,3 +1,52 @@
+2017-04-14  Jer Noble  <jer.noble@apple.com>
+
+        [MediaSource] Push capabilities across process boundary during UIProcess capture.
+        https://bugs.webkit.org/show_bug.cgi?id=170814
+
+        Reviewed by Eric Carlson.
+
+        There's no real reason for RealtimeMediaSourceCapabilities to be RefCounted nor to keep them from
+        being created on the stack. So in addition to making that class coder-compliant, change all the
+        classes that vend capabilities to use a unique_ptr<> instead of a RefPtr<>.
+
+        * Modules/mediastream/CanvasCaptureMediaStreamTrack.h:
+        * Modules/webaudio/MediaStreamAudioSource.cpp:
+        (WebCore::MediaStreamAudioSource::capabilities):
+        * Modules/webaudio/MediaStreamAudioSource.h:
+        * platform/mediastream/MediaEndpoint.cpp:
+        * platform/mediastream/MediaStreamTrackPrivate.cpp:
+        (WebCore::MediaStreamTrackPrivate::capabilities):
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        * platform/mediastream/RealtimeMediaSource.h:
+        * platform/mediastream/RealtimeMediaSourceCapabilities.h:
+        (WebCore::CapabilityValueOrRange::encode):
+        (WebCore::CapabilityValueOrRange::decode):
+        (WebCore::RealtimeMediaSourceCapabilities::RealtimeMediaSourceCapabilities):
+        (WebCore::RealtimeMediaSourceCapabilities::supportedConstraints):
+        (WebCore::RealtimeMediaSourceCapabilities::setSupportedConstraints):
+        (WebCore::RealtimeMediaSourceCapabilities::encode):
+        (WebCore::RealtimeMediaSourceCapabilities::decode):
+        (WebCore::RealtimeMediaSourceCapabilities::create): Deleted.
+        * platform/mediastream/RealtimeMediaSourceSettings.h:
+        * platform/mediastream/mac/AVMediaCaptureSource.h:
+        * platform/mediastream/mac/AVMediaCaptureSource.mm:
+        (WebCore::AVMediaCaptureSource::initializeCapabilities):
+        (WebCore::AVMediaCaptureSource::capabilities):
+        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+        (WebCore::CoreAudioCaptureSource::capabilities):
+        * platform/mediastream/mac/CoreAudioCaptureSource.h:
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
+        (WebCore::RealtimeIncomingAudioSource::capabilities):
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.h:
+        * platform/mediastream/mac/RealtimeIncomingVideoSource.cpp:
+        (WebCore::RealtimeIncomingVideoSource::capabilities):
+        * platform/mediastream/mac/RealtimeIncomingVideoSource.h:
+        * platform/mock/MockRealtimeMediaSource.cpp:
+        (WebCore::MockRealtimeMediaSource::initializeCapabilities):
+        (WebCore::MockRealtimeMediaSource::capabilities):
+        * platform/mock/MockRealtimeMediaSource.h:
+        * platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h:
+
 2017-04-13  Saam Barati  <sbarati@apple.com>
 
         WebAssembly: We should be able to postMessage a JSWebAssemblyModule
index 167002b..ad25ade 100644 (file)
@@ -63,7 +63,7 @@ private:
         void startProducingData() final;
         void stopProducingData()  final;
         bool isProducingData() const { return m_isProducingData; }
-        RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final { return nullptr; }
+        const RealtimeMediaSourceCapabilities& capabilities() const final { return RealtimeMediaSourceCapabilities::emptyCapabilities(); }
         const RealtimeMediaSourceSettings& settings() const final { return m_settings; }
         bool applySize(const IntSize&) final { return true; }
 
index 03ed872..33a4358 100644 (file)
@@ -216,28 +216,28 @@ MediaStreamTrack::TrackCapabilities MediaStreamTrack::getCapabilities() const
 {
     auto capabilities = m_private->capabilities();
     TrackCapabilities result;
-    if (capabilities->supportsWidth())
-        result.width = capabilityIntRange(capabilities->width());
-    if (capabilities->supportsHeight())
-        result.height = capabilityIntRange(capabilities->height());
-    if (capabilities->supportsAspectRatio())
-        result.aspectRatio = capabilityDoubleRange(capabilities->aspectRatio());
-    if (capabilities->supportsFrameRate())
-        result.frameRate = capabilityDoubleRange(capabilities->frameRate());
-    if (capabilities->supportsFacingMode())
-        result.facingMode = capabilityStringVector(capabilities->facingMode());
-    if (capabilities->supportsVolume())
-        result.volume = capabilityDoubleRange(capabilities->volume());
-    if (capabilities->supportsSampleRate())
-        result.sampleRate = capabilityIntRange(capabilities->sampleRate());
-    if (capabilities->supportsSampleSize())
-        result.sampleSize = capabilityIntRange(capabilities->sampleSize());
-    if (capabilities->supportsEchoCancellation())
-        result.echoCancellation = capabilityBooleanVector(capabilities->echoCancellation());
-    if (capabilities->supportsDeviceId())
-        result.deviceId = capabilities->deviceId();
-    if (capabilities->supportsGroupId())
-        result.groupId = capabilities->groupId();
+    if (capabilities.supportsWidth())
+        result.width = capabilityIntRange(capabilities.width());
+    if (capabilities.supportsHeight())
+        result.height = capabilityIntRange(capabilities.height());
+    if (capabilities.supportsAspectRatio())
+        result.aspectRatio = capabilityDoubleRange(capabilities.aspectRatio());
+    if (capabilities.supportsFrameRate())
+        result.frameRate = capabilityDoubleRange(capabilities.frameRate());
+    if (capabilities.supportsFacingMode())
+        result.facingMode = capabilityStringVector(capabilities.facingMode());
+    if (capabilities.supportsVolume())
+        result.volume = capabilityDoubleRange(capabilities.volume());
+    if (capabilities.supportsSampleRate())
+        result.sampleRate = capabilityIntRange(capabilities.sampleRate());
+    if (capabilities.supportsSampleSize())
+        result.sampleSize = capabilityIntRange(capabilities.sampleSize());
+    if (capabilities.supportsEchoCancellation())
+        result.echoCancellation = capabilityBooleanVector(capabilities.echoCancellation());
+    if (capabilities.supportsDeviceId())
+        result.deviceId = capabilities.deviceId();
+    if (capabilities.supportsGroupId())
+        result.groupId = capabilities.groupId();
     return result;
 }
 
index d472190..4fb32e9 100644 (file)
@@ -44,12 +44,12 @@ MediaStreamAudioSource::MediaStreamAudioSource()
 {
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> MediaStreamAudioSource::capabilities() const
+const RealtimeMediaSourceCapabilities& MediaStreamAudioSource::capabilities() const
 {
     // FIXME: implement this.
     // https://bugs.webkit.org/show_bug.cgi?id=122430
     notImplemented();
-    return nullptr;
+    return RealtimeMediaSourceCapabilities::emptyCapabilities();
 }
 
 const RealtimeMediaSourceSettings& MediaStreamAudioSource::settings() const
index 9ec7c28..d15a6ab 100644 (file)
@@ -46,7 +46,7 @@ public:
 
     ~MediaStreamAudioSource() { }
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final;
+    const RealtimeMediaSourceCapabilities& capabilities() const final;
     const RealtimeMediaSourceSettings& settings() const final;
 
     const String& deviceId() const { return m_deviceId; }
index e6fdc20..d1375fd 100644 (file)
@@ -46,7 +46,7 @@ public:
 private:
     EmptyRealtimeMediaSource() : RealtimeMediaSource(emptyString(), Type::None, emptyString()) { }
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final { return nullptr; }
+    const RealtimeMediaSourceCapabilities& capabilities() const final { return RealtimeMediaSourceCapabilities::emptyCapabilities(); }
     const RealtimeMediaSourceSettings& settings() const final { return m_sourceSettings; }
 
     RealtimeMediaSourceSettings m_sourceSettings;
index d4c2db1..d87ee5f 100644 (file)
@@ -136,7 +136,7 @@ const RealtimeMediaSourceSettings& MediaStreamTrackPrivate::settings() const
     return m_source->settings();
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> MediaStreamTrackPrivate::capabilities() const
+const RealtimeMediaSourceCapabilities& MediaStreamTrackPrivate::capabilities() const
 {
     return m_source->capabilities();
 }
index 699bc5c..4d783e0 100644 (file)
@@ -87,7 +87,7 @@ public:
     void removeObserver(Observer&);
 
     const RealtimeMediaSourceSettings& settings() const;
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const;
+    const RealtimeMediaSourceCapabilities& capabilities() const;
 
     void applyConstraints(const MediaConstraints&, RealtimeMediaSource::SuccessHandler, RealtimeMediaSource::FailureHandler);
 
index 411ba82..b0d29e0 100644 (file)
@@ -184,8 +184,7 @@ bool RealtimeMediaSource::supportsSizeAndFrameRate(std::optional<IntConstraint>
     if (!widthConstraint && !heightConstraint && !frameRateConstraint)
         return true;
 
-    ASSERT(this->capabilities());
-    RealtimeMediaSourceCapabilities& capabilities = *this->capabilities();
+    auto& capabilities = this->capabilities();
 
     distance = std::numeric_limits<double>::infinity();
 
@@ -244,8 +243,7 @@ bool RealtimeMediaSource::supportsSizeAndFrameRate(std::optional<IntConstraint>
 
 double RealtimeMediaSource::fitnessDistance(const MediaConstraint& constraint)
 {
-    ASSERT(this->capabilities());
-    RealtimeMediaSourceCapabilities& capabilities = *this->capabilities();
+    auto& capabilities = this->capabilities();
 
     switch (constraint.constraintType()) {
     case MediaConstraintType::Width: {
@@ -388,7 +386,7 @@ void RealtimeMediaSource::applySizeAndFrameRate(std::optional<int> width, std::o
 
 void RealtimeMediaSource::applyConstraint(const MediaConstraint& constraint)
 {
-    RealtimeMediaSourceCapabilities& capabilities = *this->capabilities();
+    auto& capabilities = this->capabilities();
     switch (constraint.constraintType()) {
     case MediaConstraintType::Width: {
         ASSERT(constraint.isInt());
@@ -612,8 +610,7 @@ bool RealtimeMediaSource::selectSettings(const MediaConstraints& constraints, Fl
 
 bool RealtimeMediaSource::supportsConstraint(const MediaConstraint& constraint) const
 {
-    ASSERT(this->capabilities());
-    RealtimeMediaSourceCapabilities& capabilities = *this->capabilities();
+    auto& capabilities = this->capabilities();
 
     switch (constraint.constraintType()) {
     case MediaConstraintType::Width:
@@ -697,7 +694,7 @@ void RealtimeMediaSource::applyConstraints(const FlattenedConstraint& constraint
 
     beginConfiguration();
 
-    RealtimeMediaSourceCapabilities& capabilities = *this->capabilities();
+    auto& capabilities = this->capabilities();
 
     std::optional<int> width;
     if (const MediaConstraint* constraint = constraints.find(MediaConstraintType::Width)) {
index 07b021f..70d65ef 100644 (file)
@@ -107,7 +107,7 @@ public:
     
     virtual unsigned fitnessScore() const { return m_fitnessScore; }
 
-    virtual RefPtr<RealtimeMediaSourceCapabilities> capabilities() const = 0;
+    virtual const RealtimeMediaSourceCapabilities& capabilities() const = 0;
     virtual const RealtimeMediaSourceSettings& settings() const = 0;
 
     using SuccessHandler = std::function<void()>;
index 2f22d48..141ed11 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(MEDIA_STREAM)
 
 #include "RealtimeMediaSourceSettings.h"
+#include <wtf/NeverDestroyed.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 #include <wtf/text/AtomicString.h>
@@ -101,51 +102,77 @@ public:
         return m_minOrValue;
     }
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static bool decode(Decoder&, CapabilityValueOrRange&);
+
 private:
     ValueUnion m_minOrValue;
     ValueUnion m_max;
     Type m_type;
 };
 
-class RealtimeMediaSourceCapabilities : public RefCounted<RealtimeMediaSourceCapabilities> {
+template<class Encoder>
+void CapabilityValueOrRange::encode(Encoder& encoder) const
+{
+    encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(&m_minOrValue), sizeof(ValueUnion), alignof(ValueUnion));
+    encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(&m_max), sizeof(ValueUnion), alignof(ValueUnion));
+    encoder.encodeEnum(m_type);
+}
+
+template<class Decoder>
+bool CapabilityValueOrRange::decode(Decoder& decoder, CapabilityValueOrRange& valueOrRange)
+{
+    return decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(&valueOrRange.m_minOrValue), sizeof(ValueUnion), alignof(ValueUnion))
+        && decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(&valueOrRange.m_max), sizeof(ValueUnion), alignof(ValueUnion))
+        && decoder.decodeEnum(valueOrRange.m_type);
+}
+
+class RealtimeMediaSourceCapabilities {
 public:
-    static PassRefPtr<RealtimeMediaSourceCapabilities> create(const RealtimeMediaSourceSupportedConstraints& supportedConstraints)
+    RealtimeMediaSourceCapabilities() = default;
+    RealtimeMediaSourceCapabilities(const RealtimeMediaSourceSupportedConstraints& supportedConstraints)
+        : m_supportedConstraints(supportedConstraints)
     {
-        return adoptRef(new RealtimeMediaSourceCapabilities(supportedConstraints));
     }
 
-    ~RealtimeMediaSourceCapabilities() { }
+    ~RealtimeMediaSourceCapabilities() = default;
+
+    static const RealtimeMediaSourceCapabilities& emptyCapabilities()
+    {
+        static NeverDestroyed<RealtimeMediaSourceCapabilities> emptyCapabilities;
+        return emptyCapabilities;
+    }
 
     bool supportsWidth() const { return m_supportedConstraints.supportsWidth(); }
-    const CapabilityValueOrRange& width() { return m_width; }
+    const CapabilityValueOrRange& width() const { return m_width; }
     void setWidth(const CapabilityValueOrRange& width) { m_width = width; }
 
     bool supportsHeight() const { return m_supportedConstraints.supportsHeight(); }
-    const CapabilityValueOrRange& height() { return m_height; }
+    const CapabilityValueOrRange& height() const { return m_height; }
     void setHeight(const CapabilityValueOrRange& height) { m_height = height; }
 
     bool supportsFrameRate() const { return m_supportedConstraints.supportsFrameRate(); }
-    const CapabilityValueOrRange& frameRate() { return m_frameRate; }
+    const CapabilityValueOrRange& frameRate() const { return m_frameRate; }
     void setFrameRate(const CapabilityValueOrRange& frameRate) { m_frameRate = frameRate; }
 
     bool supportsFacingMode() const { return m_supportedConstraints.supportsFacingMode(); }
-    const Vector<RealtimeMediaSourceSettings::VideoFacingMode>& facingMode() { return m_facingMode; }
+    const Vector<RealtimeMediaSourceSettings::VideoFacingMode>& facingMode() const { return m_facingMode; }
     void addFacingMode(RealtimeMediaSourceSettings::VideoFacingMode mode) { m_facingMode.append(mode); }
 
     bool supportsAspectRatio() const { return m_supportedConstraints.supportsAspectRatio(); }
-    const CapabilityValueOrRange& aspectRatio() { return m_aspectRatio; }
+    const CapabilityValueOrRange& aspectRatio() const { return m_aspectRatio; }
     void setAspectRatio(const CapabilityValueOrRange& aspectRatio) { m_aspectRatio = aspectRatio; }
 
     bool supportsVolume() const { return m_supportedConstraints.supportsVolume(); }
-    const CapabilityValueOrRange& volume() { return m_volume; }
+    const CapabilityValueOrRange& volume() const { return m_volume; }
     void setVolume(const CapabilityValueOrRange& volume) { m_volume = volume; }
 
     bool supportsSampleRate() const { return m_supportedConstraints.supportsSampleRate(); }
-    const CapabilityValueOrRange& sampleRate() { return m_sampleRate; }
+    const CapabilityValueOrRange& sampleRate() const { return m_sampleRate; }
     void setSampleRate(const CapabilityValueOrRange& sampleRate) { m_sampleRate = sampleRate; }
 
     bool supportsSampleSize() const { return m_supportedConstraints.supportsSampleSize(); }
-    const CapabilityValueOrRange& sampleSize() { return m_sampleSize; }
+    const CapabilityValueOrRange& sampleSize() const { return m_sampleSize; }
     void setSampleSize(const CapabilityValueOrRange& sampleSize) { m_sampleSize = sampleSize; }
 
     enum class EchoCancellation {
@@ -153,23 +180,24 @@ public:
         ReadWrite = 1,
     };
     bool supportsEchoCancellation() const { return m_supportedConstraints.supportsEchoCancellation(); }
-    EchoCancellation echoCancellation() { return m_echoCancellation; }
+    EchoCancellation echoCancellation() const { return m_echoCancellation; }
     void setEchoCancellation(EchoCancellation echoCancellation) { m_echoCancellation = echoCancellation; }
 
     bool supportsDeviceId() const { return m_supportedConstraints.supportsDeviceId(); }
-    const AtomicString& deviceId() { return m_deviceId; }
+    const AtomicString& deviceId() const { return m_deviceId; }
     void setDeviceId(const AtomicString& id)  { m_deviceId = id; }
 
     bool supportsGroupId() const { return m_supportedConstraints.supportsGroupId(); }
-    const AtomicString& groupId() { return m_groupId; }
+    const AtomicString& groupId() const { return m_groupId; }
     void setGroupId(const AtomicString& id)  { m_groupId = id; }
     
-private:
-    RealtimeMediaSourceCapabilities(const RealtimeMediaSourceSupportedConstraints& supportedConstraints)
-        : m_supportedConstraints(supportedConstraints)
-    {
-    }
+    const RealtimeMediaSourceSupportedConstraints& supportedConstraints() const { return m_supportedConstraints; }
+    void setSupportedConstraints(const RealtimeMediaSourceSupportedConstraints& constraints) { m_supportedConstraints = constraints; }
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static bool decode(Decoder&, RealtimeMediaSourceCapabilities&);
+
+private:
     CapabilityValueOrRange m_width;
     CapabilityValueOrRange m_height;
     CapabilityValueOrRange m_aspectRatio;
@@ -182,9 +210,43 @@ private:
     AtomicString m_deviceId;
     AtomicString m_groupId;
 
-    const RealtimeMediaSourceSupportedConstraints& m_supportedConstraints;
+    RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
 };
 
+template<class Encoder>
+void RealtimeMediaSourceCapabilities::encode(Encoder& encoder) const
+{
+    encoder << m_width
+        << m_height
+        << m_aspectRatio
+        << m_frameRate
+        << m_facingMode
+        << m_volume
+        << m_sampleRate
+        << m_sampleSize
+        << m_deviceId
+        << m_groupId
+        << m_supportedConstraints;
+    encoder.encodeEnum(m_echoCancellation);
+}
+
+template<class Decoder>
+bool RealtimeMediaSourceCapabilities::decode(Decoder& decoder, RealtimeMediaSourceCapabilities& capabilities)
+{
+    return decoder.decode(capabilities.m_width)
+        && decoder.decode(capabilities.m_height)
+        && decoder.decode(capabilities.m_aspectRatio)
+        && decoder.decode(capabilities.m_frameRate)
+        && decoder.decode(capabilities.m_facingMode)
+        && decoder.decode(capabilities.m_volume)
+        && decoder.decode(capabilities.m_sampleRate)
+        && decoder.decode(capabilities.m_sampleSize)
+        && decoder.decode(capabilities.m_deviceId)
+        && decoder.decode(capabilities.m_groupId)
+        && decoder.decode(capabilities.m_supportedConstraints)
+        && decoder.decodeEnum(capabilities.m_echoCancellation);
+}
+
 } // namespace WebCore
 
 #endif // RealtimeMediaSourceCapabilities_h
index 5a4c9a5..e1fd16f 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(MEDIA_STREAM)
 
 #include "RealtimeMediaSourceSupportedConstraints.h"
+#include <wtf/EnumTraits.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 #include <wtf/text/AtomicString.h>
@@ -150,6 +151,21 @@ bool RealtimeMediaSourceSettings::decode(Decoder& decoder, RealtimeMediaSourceSe
 
 } // namespace WebCore
 
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::RealtimeMediaSourceSettings::VideoFacingMode> {
+    using values = EnumValues<
+        WebCore::RealtimeMediaSourceSettings::VideoFacingMode,
+        WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Unknown,
+        WebCore::RealtimeMediaSourceSettings::VideoFacingMode::User,
+        WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Environment,
+        WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Left,
+        WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Right
+    >;
+};
+
+}
+
 #endif // RealtimeMediaSourceSettings_h
 
 #endif
index ed13b42..f849010 100644 (file)
@@ -84,7 +84,7 @@ protected:
     AVCaptureDevice *device() const { return m_device.get(); }
 
     RealtimeMediaSourceSupportedConstraints& supportedConstraints();
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final;
+    const RealtimeMediaSourceCapabilities& capabilities() const final;
 
     void setVideoSampleBufferDelegate(AVCaptureVideoDataOutput*);
     void setAudioSampleBufferDelegate(AVCaptureAudioDataOutput*);
@@ -104,7 +104,7 @@ private:
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
     RetainPtr<WebCoreAVMediaCaptureSourceObserver> m_objcObserver;
-    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+    std::unique_ptr<RealtimeMediaSourceCapabilities> m_capabilities;
     RetainPtr<AVCaptureSession> m_session;
     RetainPtr<AVCaptureDevice> m_device;
     InterruptionReason m_interruption { InterruptionReason::None };
index 5fef44f..e99c784 100644 (file)
@@ -229,17 +229,17 @@ RealtimeMediaSourceSupportedConstraints& AVMediaCaptureSource::supportedConstrai
 
 void AVMediaCaptureSource::initializeCapabilities()
 {
-    m_capabilities = RealtimeMediaSourceCapabilities::create(supportedConstraints());
+    m_capabilities = std::make_unique<RealtimeMediaSourceCapabilities>(supportedConstraints());
     m_capabilities->setDeviceId(id());
 
     initializeCapabilities(*m_capabilities.get());
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> AVMediaCaptureSource::capabilities() const
+const RealtimeMediaSourceCapabilities& AVMediaCaptureSource::capabilities() const
 {
     if (!m_capabilities)
         const_cast<AVMediaCaptureSource&>(*this).initializeCapabilities();
-    return m_capabilities;
+    return *m_capabilities;
 }
 
 void AVMediaCaptureSource::setupSession()
index 29c7011..788a222 100644 (file)
@@ -488,22 +488,22 @@ OSStatus CoreAudioCaptureSource::resume()
     return err;
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> CoreAudioCaptureSource::capabilities() const
+const RealtimeMediaSourceCapabilities& CoreAudioCaptureSource::capabilities() const
 {
     if (m_capabilities)
-        return m_capabilities;
+        return *m_capabilities;
 
     m_supportedConstraints.setSupportsDeviceId(true);
     m_supportedConstraints.setSupportsEchoCancellation(true);
     m_supportedConstraints.setSupportsVolume(true);
 
     // FIXME: finish this.
-    m_capabilities = RealtimeMediaSourceCapabilities::create(m_supportedConstraints);
+    m_capabilities = std::make_unique<RealtimeMediaSourceCapabilities>(m_supportedConstraints);
     m_capabilities->setDeviceId(id());
     m_capabilities->setEchoCancellation(RealtimeMediaSourceCapabilities::EchoCancellation::ReadWrite);
     m_capabilities->setVolume(CapabilityValueOrRange(0.0, 1.0));
 
-    return m_capabilities;
+    return *m_capabilities;
 }
 
 const RealtimeMediaSourceSettings& CoreAudioCaptureSource::settings() const
index 66768be..a5f5297 100644 (file)
@@ -78,7 +78,7 @@ private:
     OSStatus suspend();
     OSStatus resume();
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final;
+    const RealtimeMediaSourceCapabilities& capabilities() const final;
     const RealtimeMediaSourceSettings& settings() const final;
 
     OSStatus setupAudioUnits();
@@ -129,7 +129,7 @@ private:
     Lock m_pendingSourceQueueLock;
     Lock m_internalStateLock;
 
-    mutable RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+    mutable std::unique_ptr<RealtimeMediaSourceCapabilities> m_capabilities;
     mutable RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
     RealtimeMediaSourceSettings m_currentSettings;
 };
index ecfd78e..a4f9b38 100644 (file)
@@ -140,9 +140,9 @@ void RealtimeIncomingAudioSource::setSourceTrack(rtc::scoped_refptr<webrtc::Audi
         m_audioTrack->AddSink(this);
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> RealtimeIncomingAudioSource::capabilities() const
+const RealtimeMediaSourceCapabilities& RealtimeIncomingAudioSource::capabilities() const
 {
-    return m_capabilities;
+    return RealtimeMediaSourceCapabilities::emptyCapabilities();
 }
 
 const RealtimeMediaSourceSettings& RealtimeIncomingAudioSource::settings() const
index 7ddbf22..852ce97 100644 (file)
@@ -61,7 +61,7 @@ private:
     void startProducingData() final;
     void stopProducingData()  final;
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final;
+    const RealtimeMediaSourceCapabilities& capabilities() const final;
     const RealtimeMediaSourceSettings& settings() const final;
 
     MediaConstraints& constraints() { return *m_constraints.get(); }
@@ -73,7 +73,6 @@ private:
 
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
-    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
     RefPtr<MediaConstraints> m_constraints;
     bool m_isProducingData { false };
     rtc::scoped_refptr<webrtc::AudioTrackInterface> m_audioTrack;
index db9fd09..f5096fb 100644 (file)
@@ -207,9 +207,9 @@ void RealtimeIncomingVideoSource::processNewSample(CMSampleBufferRef sample, uns
     videoSampleAvailable(MediaSampleAVFObjC::create(sample, rotation));
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> RealtimeIncomingVideoSource::capabilities() const
+const RealtimeMediaSourceCapabilities& RealtimeIncomingVideoSource::capabilities() const
 {
-    return m_capabilities;
+    return RealtimeMediaSourceCapabilities::emptyCapabilities();
 }
 
 const RealtimeMediaSourceSettings& RealtimeIncomingVideoSource::settings() const
index 3be0d54..42f926f 100644 (file)
@@ -58,7 +58,7 @@ private:
     void startProducingData() final;
     void stopProducingData()  final;
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final;
+    const RealtimeMediaSourceCapabilities& capabilities() const final;
     const RealtimeMediaSourceSettings& settings() const final;
 
     MediaConstraints& constraints() { return *m_constraints.get(); }
@@ -77,7 +77,6 @@ private:
     RefPtr<Image> m_currentImage;
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
-    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
     RefPtr<MediaConstraints> m_constraints;
     bool m_isProducingData { false };
     rtc::scoped_refptr<webrtc::VideoTrackInterface> m_videoTrack;
index a8f78e2..3ae3762 100644 (file)
@@ -72,7 +72,7 @@ RealtimeMediaSourceOwr(const String& id, RealtimeMediaSource::Type type, const S
         setMuted(false);
     }
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override { return m_capabilities; }
+    const RealtimeMediaSourceCapabilities& capabilities() const override { return m_capabilities; }
     const RealtimeMediaSourceSettings& settings() const override;
 
     OwrMediaSource* mediaSource() const { return m_mediaSource; }
@@ -86,7 +86,7 @@ protected:
 
 private:
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
-    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+    RealtimeMediaSourceCapabilities m_capabilities;
     OwrMediaSource* m_mediaSource;
 };
 
index 7790ce9..7595cfc 100644 (file)
@@ -83,16 +83,16 @@ MockRealtimeMediaSource::MockRealtimeMediaSource(const String& id, RealtimeMedia
 
 void MockRealtimeMediaSource::initializeCapabilities()
 {
-    m_capabilities = RealtimeMediaSourceCapabilities::create(supportedConstraints());
+    m_capabilities = std::make_unique<RealtimeMediaSourceCapabilities>(supportedConstraints());
     m_capabilities->setDeviceId(id());
     initializeCapabilities(*m_capabilities.get());
 }
 
-RefPtr<RealtimeMediaSourceCapabilities> MockRealtimeMediaSource::capabilities() const
+const RealtimeMediaSourceCapabilities& MockRealtimeMediaSource::capabilities() const
 {
     if (!m_capabilities)
         const_cast<MockRealtimeMediaSource&>(*this).initializeCapabilities();
-    return m_capabilities;
+    return *m_capabilities;
 }
 
 void MockRealtimeMediaSource::initializeSettings()
index cdc331d..9a5ad1d 100644 (file)
@@ -68,7 +68,7 @@ protected:
     void startProducingData() override;
     void stopProducingData() override;
 
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override;
+    const RealtimeMediaSourceCapabilities& capabilities() const override;
     const RealtimeMediaSourceSettings& settings() const override;
 
     MediaConstraints& constraints() { return *m_constraints.get(); }
@@ -88,7 +88,7 @@ private:
 
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
-    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+    std::unique_ptr<RealtimeMediaSourceCapabilities> m_capabilities;
     RefPtr<MediaConstraints> m_constraints;
     unsigned m_deviceIndex { 0 };
     bool m_isProducingData { false };
index 47b4349..69d6f04 100644 (file)
@@ -1,3 +1,23 @@
+2017-04-14  Jer Noble  <jer.noble@apple.com>
+
+        [MediaSource] Push capabilities across process boundary during UIProcess capture.
+        https://bugs.webkit.org/show_bug.cgi?id=170814
+
+        Reviewed by Eric Carlson.
+
+        Make a new synchronous getter for capabilities(), moderated by only requesting the capabilities() cross-process
+        the first time called.
+
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+        (WebKit::UserMediaCaptureManagerProxy::capabilities):
+        (WebKit::UserMediaCaptureManagerProxy::supportedConstraints):
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in:
+        * WebProcess/cocoa/UserMediaCaptureManager.cpp:
+        (WebKit::UserMediaCaptureManager::Source::setCapabilities):
+        (WebKit::UserMediaCaptureManager::capabilities):
+        * WebProcess/cocoa/UserMediaCaptureManager.h:
+
 2017-04-13  Dan Bernstein  <mitz@apple.com>
 
         [Cocoa] Allow clients to specify in _WKProcessPoolConfiguration additional directory sandbox extensions
index c6f7ae9..f83fcc7 100644 (file)
@@ -130,7 +130,7 @@ void UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstrai
     auto constraints = MediaConstraintsImpl::create(constraintsData);
     auto source = RealtimeMediaSourceCenter::singleton().audioFactory()->createMediaSourceForCaptureDeviceWithConstraints(device, constraints.ptr(), invalidConstraints);
     succeeded = !!source;
-    
+
     if (source)
         m_proxies.set(id, std::make_unique<SourceProxy>(id, *this, source.releaseNonNull()));
 }
@@ -149,6 +149,13 @@ void UserMediaCaptureManagerProxy::stopProducingData(uint64_t id)
         iter->value->source().stopProducingData();
 }
 
+void UserMediaCaptureManagerProxy::capabilities(uint64_t id, WebCore::RealtimeMediaSourceCapabilities& capabilities)
+{
+    auto iter = m_proxies.find(id);
+    if (iter != m_proxies.end())
+        capabilities = iter->value->source().capabilities();
+}
+    
 }
 
 #endif
index 811321d..dc5fef1 100644 (file)
@@ -52,6 +52,7 @@ private:
     void createMediaSourceForCaptureDeviceWithConstraints(uint64_t id, const WebCore::CaptureDevice&, const WebCore::MediaConstraintsData&, bool& succeeded, String& invalidConstraints);
     void startProducingData(uint64_t);
     void stopProducingData(uint64_t);
+    void capabilities(uint64_t, WebCore::RealtimeMediaSourceCapabilities&);
 
     class SourceProxy;
     friend class SourceProxy;
index 74b8cbb..6c7d813 100644 (file)
@@ -25,4 +25,5 @@ messages -> UserMediaCaptureManagerProxy {
     CreateMediaSourceForCaptureDeviceWithConstraints(uint64_t id, WebCore::CaptureDevice device, struct WebCore::MediaConstraintsData constraints) -> (bool success, String invalidConstraints)
     StartProducingData(uint64_t id)
     StopProducingData(uint64_t id)
+    Capabilities(uint64_t id) -> (WebCore::RealtimeMediaSourceCapabilities capabilities)
 }
index d4ee1c4..23e997e 100644 (file)
@@ -66,8 +66,11 @@ public:
     }
 
     SharedRingBufferStorage& storage() { return static_cast<SharedRingBufferStorage&>(m_ringBuffer.storage()); }
-    RefPtr<RealtimeMediaSourceCapabilities> capabilities() const final { return m_capabilities; }
-    void setCapabilities(RefPtr<RealtimeMediaSourceCapabilities> capabilities) { m_capabilities = capabilities; }
+    const RealtimeMediaSourceCapabilities& capabilities() const final {
+        if (!m_capabilities)
+            m_capabilities = m_manager.capabilities(m_id);
+        return m_capabilities.value();
+    }
 
     const RealtimeMediaSourceSettings& settings() const final { return m_settings; }
     void setSettings(const RealtimeMediaSourceSettings& settings)
@@ -131,7 +134,7 @@ private:
 
     uint64_t m_id;
     UserMediaCaptureManager& m_manager;
-    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+    mutable std::optional<RealtimeMediaSourceCapabilities> m_capabilities;
     RealtimeMediaSourceSettings m_settings;
     CAAudioStreamDescription m_description;
     CARingBuffer m_ringBuffer;
@@ -234,6 +237,13 @@ void UserMediaCaptureManager::stopProducingData(uint64_t id)
     m_process.send(Messages::UserMediaCaptureManagerProxy::StopProducingData(id), 0);
 }
 
+WebCore::RealtimeMediaSourceCapabilities&& UserMediaCaptureManager::capabilities(uint64_t id)
+{
+    WebCore::RealtimeMediaSourceCapabilities capabilities;
+    m_process.sendSync(Messages::UserMediaCaptureManagerProxy::Capabilities(id), Messages::UserMediaCaptureManagerProxy::Capabilities::Reply(capabilities), 0);
+    return WTFMove(capabilities);
+}
+
 }
 
 #endif
index 6a32666..bd2ef43 100644 (file)
@@ -70,6 +70,7 @@ private:
 
     void startProducingData(uint64_t);
     void stopProducingData(uint64_t);
+    WebCore::RealtimeMediaSourceCapabilities&& capabilities(uint64_t);
 
     class Source;
     friend class Source;