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
qwasmwindowcapture.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
8#include <QMediaCaptureSession>
9
11
12Q_LOGGING_CATEGORY(qLcWasmWindowcapture, "qt.multimedia.wasm.windowcapture")
13
14QWasmWindowCapture::QWasmWindowCapture(QWindowCapture *winCap) :
15 QPlatformSurfaceCapture(WindowSource{})
16{
17 setCaptureSession(dynamic_cast<QPlatformMediaCaptureSession *>(winCap->captureSession()));
18}
19
21
23{
24 return {};
25}
26
28{
29 if (active)
30 m_captureSession->setVideoSource("window");
31 else
32 m_captureSession->setVideoSource("");
33
34 return true;
35}
36void QWasmWindowCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
37{
38 m_captureSession = dynamic_cast<QWasmMediaCaptureSession *>(session);
39}
40
41void QWasmWindowCapture::setVideoStream(emscripten::val stream)
42{
43 if (m_videoOutput) {
44 emscripten::val videoTracks = stream.call<emscripten::val>("getVideoTracks");
45 if (videoTracks.isNull() || videoTracks.isUndefined()) {
46 qWarning() << Q_FUNC_INFO << "videoTracks is null";
47
48 return;
49 }
50
51 emscripten::val videoSettings = videoTracks[0].call<emscripten::val>("getSettings");
52
53 if (!videoSettings.isNull() || !videoSettings.isUndefined()) {
54 int width = videoSettings["width"].as<int>();
55 int height = videoSettings["height"].as<int>();
56
57 QSize initialSize(width, height);
58 QRect initialRect(QPoint(0, 0),initialSize);
59
60 m_videoOutput->updateVideoElementGeometry(initialRect);
61
62 }
63 emscripten::val videoElement = m_videoOutput->currentVideoElement();
64
65 videoElement.set("srcObject", stream);
66 m_videoOutput->start();
67 }
68}
69
71{
72 if (object)
73 m_videoOutput = object;
74}
75
76QT_END_NAMESPACE
\inmodule QtCore
Definition qsize.h:26
QVideoFrameFormat frameFormat() const override
bool setActiveInternal(bool) override
void setCaptureSession(QPlatformMediaCaptureSession *session) override
void setVideoStream(emscripten::val stream)
void setVideoOutput(QWasmVideoOutput *object)