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
8
9#include <QtMultimedia/qmediacapturesession.h>
10
12
13Q_LOGGING_CATEGORY(qLcWasmsSreenCapture, "qt.multimedia.wasm.screencapture")
14
15QWasmScreenCapture::QWasmScreenCapture(QScreenCapture *screenCap)
16 : QPlatformSurfaceCapture(ScreenSource{})
17{
18 m_screenCapture = screenCap;
19}
20
22
24{
25 return {};
26}
27
29{
30 if (active)
31 m_captureSession->setVideoSource("monitor");
32 else
33 m_captureSession->setVideoSource("");
34 return true;
35}
36
37void QWasmScreenCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
38{
39 m_captureSession = static_cast<QWasmMediaCaptureSession *>(session);
40}
41
42void QWasmScreenCapture::setVideoStream(emscripten::val stream)
43{
44 if (m_videoOutput) {
45 emscripten::val videoTracks = stream.call<emscripten::val>("getVideoTracks");
46 if (videoTracks.isNull() || videoTracks.isUndefined()) {
47 return;
48 }
49 emscripten::val videoSettings = videoTracks[0].call<emscripten::val>("getSettings");
50 float pixelRatio = emscripten::val::global("window")["devicePixelRatio"].as<float>();
51
52 if (!videoSettings.isNull() || !videoSettings.isUndefined()) {
53 // double fRate = videoSettings["frameRate"].as<double>(); TODO
54 int width = static_cast<int>(videoSettings["width"].as<int>() / pixelRatio);
55 int height = static_cast<int>(videoSettings["height"].as<int>() / pixelRatio);
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 if (videoElement.isUndefined()) {
65 qWarning() << "Could not find video element";
66 return;
67 }
68 videoElement.set("srcObject", stream);
69 m_videoOutput->start();
70 }
71}
72
74{
75 if (object)
76 m_videoOutput = object;
77}
78
79QT_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.