1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
* Copyright (C) 2018 Metrological Group B.V.
* Author: Thibault Saunier <tsaunier@igalia.com>
* Author: Alejandro G. Castro <alex@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* aint with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#if ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
#include "DisplayCaptureManager.h"
#include "GRefPtrGStreamer.h"
#include "GStreamerCaptureDevice.h"
#include "GStreamerCapturer.h"
#include "GStreamerVideoCapturer.h"
#include "RealtimeMediaSourceCenter.h"
#include "RealtimeMediaSourceFactory.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
namespace WebCore {
using NodeAndFD = GStreamerVideoCapturer::NodeAndFD;
void teardownGStreamerCaptureDeviceManagers();
class GStreamerCaptureDeviceManager : public CaptureDeviceManager, public RealtimeMediaSourceCenterObserver {
WTF_MAKE_NONCOPYABLE(GStreamerCaptureDeviceManager)
public:
GStreamerCaptureDeviceManager();
~GStreamerCaptureDeviceManager();
std::optional<GStreamerCaptureDevice> gstreamerDeviceWithUID(const String&);
const Vector<CaptureDevice>& speakerDevices();
const Vector<CaptureDevice>& captureDevices() final;
virtual const OptionSet<CaptureDevice::DeviceType> deviceTypes() const = 0;
// RealtimeMediaSourceCenterObserver interface.
void devicesChanged() final;
void deviceWillBeRemoved(const String& persistentId) final;
void registerCapturer(RefPtr<GStreamerCapturer>&&);
void unregisterCapturer(const GStreamerCapturer&);
void stopCapturing(const String& persistentId);
void teardown();
private:
void addDevice(GRefPtr<GstDevice>&&);
void removeDevice(GRefPtr<GstDevice>&&);
void stopMonitor();
void refreshCaptureDevices();
GRefPtr<GstDeviceMonitor> m_deviceMonitor;
Vector<GStreamerCaptureDevice> m_gstreamerDevices;
Vector<CaptureDevice> m_devices;
Vector<RefPtr<GStreamerCapturer>> m_capturers;
bool m_isTearingDown { false };
Vector<CaptureDevice> m_speakerDevices;
};
class GStreamerAudioCaptureDeviceManager final : public GStreamerCaptureDeviceManager {
friend class NeverDestroyed<GStreamerAudioCaptureDeviceManager>;
public:
static GStreamerAudioCaptureDeviceManager& singleton();
const OptionSet<CaptureDevice::DeviceType> deviceTypes() const final { return { CaptureDevice::DeviceType::Microphone, CaptureDevice::DeviceType::Speaker }; }
// ref() and deref() do nothing because this object is a singleton.
void ref() const final { }
void deref() const final { }
private:
GStreamerAudioCaptureDeviceManager() = default;
};
class GStreamerVideoCaptureDeviceManager final : public GStreamerCaptureDeviceManager {
friend class NeverDestroyed<GStreamerVideoCaptureDeviceManager>;
public:
static GStreamerVideoCaptureDeviceManager& singleton();
const OptionSet<CaptureDevice::DeviceType> deviceTypes() const final { return { CaptureDevice::DeviceType::Camera }; }
// ref() and deref() do nothing because this object is a singleton.
void ref() const final { }
void deref() const final { }
static VideoCaptureFactory& videoFactory();
private:
GStreamerVideoCaptureDeviceManager() = default;
};
class GStreamerDisplayCaptureDeviceManager final : public DisplayCaptureManager {
friend class NeverDestroyed<GStreamerDisplayCaptureDeviceManager>;
public:
static GStreamerDisplayCaptureDeviceManager& singleton();
const Vector<CaptureDevice>& captureDevices() final { return m_devices; };
void computeCaptureDevices(CompletionHandler<void()>&&) final;
CaptureSourceOrError createDisplayCaptureSource(const CaptureDevice&, MediaDeviceHashSalts&&, const MediaConstraints*);
enum PipeWireOutputType {
Monitor = 1 << 0,
Window = 1 << 1
};
void stopSource(const String& persistentID);
// DisplayCaptureManager interface
bool requiresCaptureDevicesEnumeration() const final { return true; }
protected:
void notifyResponse(GVariant* parameters) { m_currentResponseCallback(parameters); }
private:
GStreamerDisplayCaptureDeviceManager();
~GStreamerDisplayCaptureDeviceManager();
using ResponseCallback = CompletionHandler<void(GVariant*)>;
void waitResponseSignal(const char* objectPath, ResponseCallback&& = [](GVariant*) { });
Vector<CaptureDevice> m_devices;
struct Session {
WTF_MAKE_STRUCT_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(Session);
Session(const NodeAndFD& nodeAndFd, String&& path)
: nodeAndFd(nodeAndFd)
, path(WTFMove(path)) { }
~Session()
{
close(nodeAndFd.second);
}
NodeAndFD nodeAndFd;
String path;
};
HashMap<String, std::unique_ptr<Session>> m_sessions;
GRefPtr<GDBusProxy> m_proxy;
ResponseCallback m_currentResponseCallback;
};
}
#endif // ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
|