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
qwasmscreencapture.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
5
9
10#include <QtMultimedia/qmediacapturesession.h>
11
13
14Q_LOGGING_CATEGORY(qLcWasmsSreenCapture, "qt.multimedia.wasm.screencapture")
15
16QWasmScreenCapture::QWasmScreenCapture(QScreenCapture *screenCap)
17 : QPlatformSurfaceCapture(ScreenSource{})
18{
19 m_screenCapture = screenCap;
20}
21
23
25{
26 return {};
27}
28
30{
31 if (active)
32 m_captureSession->setVideoSource("monitor");
33 else
34 m_captureSession->setVideoSource("");
35 return true;
36}
37
38void QWasmScreenCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
39{
40 m_captureSession = static_cast<QWasmMediaCaptureSession *>(session);
41}
42
43void QWasmScreenCapture::setVideoStream(emscripten::val stream)
44{
45 if (m_videoOutput) {
46 emscripten::val videoTracks = stream.call<emscripten::val>("getVideoTracks");
47 if (videoTracks.isNull() || videoTracks.isUndefined()) {
48 return;
49 }
50 emscripten::val videoSettings = videoTracks[0].call<emscripten::val>("getSettings");
51 float pixelRatio = emscripten::val::global("window")["devicePixelRatio"].as<float>();
52
53 if (!videoSettings.isNull() || !videoSettings.isUndefined()) {
54 // double fRate = videoSettings["frameRate"].as<double>(); TODO
55 int width = static_cast<int>(videoSettings["width"].as<int>() / pixelRatio);
56 int height = static_cast<int>(videoSettings["height"].as<int>() / pixelRatio);
57
58 QSize initialSize(width, height);
59 QRect initialRect(QPoint(0, 0),initialSize);
60
61 m_videoOutput->updateVideoElementGeometry(initialRect);
62 }
63
64 emscripten::val videoElement = m_videoOutput->currentVideoElement();
65 if (videoElement.isUndefined()) {
66 qWarning() << "Could not find video element";
67 return;
68 }
69 videoElement.set("srcObject", stream);
70 m_videoOutput->start();
71 }
72}
73
75{
76 if (object)
77 m_videoOutput = object;
78}
79
80QT_END_NAMESPACE
void setVideoOutput(QWasmVideoOutput *output)
void setCaptureSession(QPlatformMediaCaptureSession *session) override
QVideoFrameFormat frameFormat() const override
bool setActiveInternal(bool) override
void setVideoStream(emscripten::val stream)
Combined button and popup list for selecting options.