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