Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmmediadevices_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWASMMEDIADEVICES_H
5#define QWASMMEDIADEVICES_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qplatformaudiodevices_p.h>
19
20#include <private/qplatformvideodevices_p.h>
21#include "qwasmjs_p.h"
22
23#include <QtCore/private/qstdweb_p.h>
24#include <qaudio.h>
25#include <qaudiodevice.h>
26#include <qcameradevice.h>
27#include <qset.h>
28#include <QtCore/qloggingcategory.h>
29
30#include <emscripten.h>
31#include <emscripten/val.h>
32#include <emscripten/bind.h>
33
34#include <memory>
35#include <string_view>
36#include <vector>
37
39
41
42class QWasmAudioEngine;
44
46{
48public:
50
52
53protected:
54 QList<QCameraDevice> findVideoInputs() const override;
55 void connectNotify(const QMetaMethod &signal) override;
56
57private:
58 // weak
59 QWasmMediaDevices *m_mediaDevices;
60};
61
63{
64public:
66
67 QPlatformAudioSource *createAudioSource(const QAudioDevice &, const QAudioFormat &,
68 QObject *parent) override;
69 QPlatformAudioSink *createAudioSink(const QAudioDevice &, const QAudioFormat &,
70 QObject *parent) override;
71
72 bool hasCallbackApi() const override { return true; }
73
74 QLatin1String backendName() const override { return QLatin1String{ "WebAssembly" }; }
77
78protected:
79 QList<QAudioDevice> findAudioInputs() const override;
80 QList<QAudioDevice> findAudioOutputs() const override;
81 void connectNotify(const QMetaMethod &signal) override;
82
83};
84
86{
87public:
91
94
95 void initDevices();
96 void getMediaDevices();
97
98private:
99 void updateCameraDevices();
100 void enumerateDevices();
101 void watchPermission(const char *permissionName);
102 void parseDevices(emscripten::val devices);
103 void insertFallbackAudioOutput();
104 QByteArray findDefaultDeviceId(emscripten::val devices, std::string_view deviceKind) const;
105 static void applyDefaultDevice(QList<QAudioDevice> &audioDevices,
106 const QByteArray &defaultDeviceId);
107 static void applyDefaultDevice(QList<QCameraDevice> &cameraDevices,
108 const QByteArray &defaultDeviceId);
109
110 // insertion order, stable across hot-plug
111 QList<QAudioDevice> m_audioOutputs;
112 QList<QAudioDevice> m_audioInputs;
113 QList<QCameraDevice> m_cameraDevices;
114
115 std::unique_ptr<qstdweb::EventCallback> m_deviceChangedCallback;
116 std::vector<std::unique_ptr<qstdweb::EventCallback>> m_permissionChangedCallbacks;
117 bool m_permissionWatchStarted = false;
118
119 bool m_videoInputsAdded = false;
120 bool m_audioInputsAdded = false;
121 bool m_audioOutputsAdded = false;
122 emscripten::val m_jsMediaDevicesInterface = emscripten::val::undefined();
123 bool m_initDone = false;
124 emscripten::val devicesList;
125};
126
127QT_END_NAMESPACE
128
129#endif
The QAudioDevice class provides an information about audio devices and their functionality.
The QCameraDevice class provides general information about camera devices.
QPlatformAudioSink * createAudioSink(const QAudioDevice &, const QAudioFormat &, QObject *parent) override
QList< QAudioDevice > findAudioOutputs() const override
QList< QAudioDevice > findAudioInputs() const override
QPlatformAudioSource * createAudioSource(const QAudioDevice &, const QAudioFormat &, QObject *parent) override
void connectNotify(const QMetaMethod &signal) override
QLatin1String backendName() const override
bool hasCallbackApi() const override
void connectNotify(const QMetaMethod &signal) override
QList< QCameraDevice > findVideoInputs() const override
QList< QCameraDevice > videoInputs() const
static QWasmMediaDevices * instance()
QList< QAudioDevice > audioOutputs() const
QList< QAudioDevice > audioInputs() const
std::string effectiveDeviceId(const std::string &deviceId, const std::string &deviceKind)
bool containsDeviceId(const DeviceList &devices, const QByteArray &deviceId)
constexpr std::string_view s_communicationsDeviceId
constexpr std::string_view s_defaultDeviceId
std::string stringProperty(const emscripten::val &mediaDevice, const char *property)
bool isAliasDeviceId(std::string_view deviceId)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)
static QWasmMediaDevices * s_mediaDevicesInstance
EM_JS(void, setupAudioOutputSelector,(), { const overlay=document.createElement('div');overlay.style.cssText='position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.5);z-index:9999;display:flex;align-items:center;justify-content:center;';const dialog=document.createElement('div');dialog.style.cssText='background:white;padding:24px;border-radius:8px;text-align:center;font-family:sans-serif;min-width:240px;';const message=document.createElement('p');message.textContent='Select an audio output device to continue.';message.style.cssText='margin:0 0 16px 0;font-size:14px;';const button=document.createElement('button');button.textContent='Select Audio Output';button.style.cssText='padding:8px 16px;font-size:14px;cursor:pointer;';button.addEventListener('click', async()=> { document.body.removeChild(overlay);try { const deviceInfo=await navigator.mediaDevices.selectAudioOutput();console.log("Selected device: ", deviceInfo.label);Module._qtMediaDevicesOnAudioOutputSelected();} catch(err) { console.error(err);} }, { once:true });dialog.appendChild(message);dialog.appendChild(button);overlay.appendChild(dialog);document.body.appendChild(overlay);})
static bool s_constructingInstance
EMSCRIPTEN_KEEPALIVE void qtMediaDevicesOnAudioOutputSelected()
bool isFirefox()