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
qwasmvideooutput_p.h
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
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QWASMVIDEOOUTPUT_H
16#define QWASMVIDEOOUTPUT_H
17
18#include <QObject>
19
20#include <emscripten/val.h>
21#include <emscripten/html5_webgl.h>
22#include <emscripten/html5.h>
23
24#include <QMediaPlayer>
25#include <QVideoFrame>
26#include <QtMultimedia/qtvideo.h>
27
29#include "private/qwasmmediadevices_p.h"
31
32#include <private/qwasmjs_p.h>
33
34#include <QtCore/qloggingcategory.h>
35
36#include <private/qstdweb_p.h>
37#include <private/qwasmsuspendresumecontrol_p.h>
38
40
41Q_DECLARE_LOGGING_CATEGORY(qWasmMediaVideoOutput)
42
43class QVideoSink;
44
46{
48public:
53
54 explicit QWasmVideoOutput(QObject *parent = nullptr);
56
57 void setVideoSize(const QSize &);
58 void start();
59 void stop();
60 void reset();
61 void pause();
62
63 void setSurface(QVideoSink *surface);
65
66 bool isReady() const;
67
68 void setSource(const QUrl &url);
69 void setSource(QIODevice *stream);
70 void setVolume(qreal volume);
71 void setMuted(bool muted);
72
74 void seekTo(qint64 position);
75 bool isVideoSeekable();
76 void setPlaybackRate(qreal rate);
78
80 void newFrame(const QVideoFrame &newFrame);
81
82 void createVideoElement(const std::string &id);
83 void createOffscreenElement(const QSize &offscreenSize);
84 void doElementCallbacks();
85 void updateVideoElementGeometry(const QRect &windowGeometry);
86 void updateVideoElementSource(const QString &src);
87 void addCameraSourceElement(const std::string &id);
90 void setVideoConstraints(QSize resolution, float minFrameRate, float maxFrameRate);
91
92 void setHasAudio(bool needsAudio) { m_hasAudio = needsAudio; }
93
94 bool hasCapability(const QString &cap);
96 bool setDeviceSetting(const std::string &key, emscripten::val value);
97 bool isCameraReady() { return m_cameraIsReady; }
98 bool m_hasVideoFrame = false;
99
100 void videoFrameCallback(void *context);
102
103 void webglVideoFrameCallback(void *context);
104 void getWebGLContext();
105 bool m_hasWebGLContext = false;
107
108 // mediacapturesession has the videosink
110
112 m_video.isNull() || m_video.isUndefined() ? emscripten::val::null()
113 : m_video) ; }
114
116
117 static QVideoFrameFormat::PixelFormat fromJsPixelFormat(std::string_view videoFormat);
118
120
122 void readyChanged(bool);
123 void bufferingChanged(qint32 percent);
124 void errorOccured(qint32 code, const QString &message);
126 void progressChanged(qint32 position);
127 void durationChanged(qint64 duration);
128 void statusChanged(QMediaPlayer::MediaStatus status);
129 void sizeChange(qint32 width, qint32 height);
131 void seekableChanged(bool seekable);
132 void orientationChanged(int rotationIndex);
133
134private:
135 void checkNetworkState();
136 void videoComputeFrame(void *context);
137 void getDeviceSettings();
138 bool isPlatformiOs();
139
140 emscripten::val m_video = emscripten::val::undefined();
141 emscripten::val m_videoElementSource = emscripten::val::undefined();
142
143 QString m_source;
144 float m_requestedPosition = 0.0;
145 emscripten::val m_offscreen = emscripten::val::undefined();
147 QtVideo::Rotation m_rotateBy = QtVideo::Rotation::None;
148 int getCurrentOrientationIndex();
149
150
151 bool m_isStopped = false;
152 bool m_toBePaused = false;
153 bool m_isSeeking = false;
154 bool m_hasAudio = false;
155 bool m_cameraIsReady = false;
156 bool m_shouldBeStarted = false;
157 bool m_isSeekable = false;
158 bool m_useCameraRotation = false;
159
160 emscripten::val m_offscreenContext = emscripten::val::undefined();
161 QSize m_pendingVideoSize;
163 QMediaPlayer::MediaStatus m_currentMediaStatus;
164 qreal m_currentBufferedValue;
165 JsMediaInputStream *m_mediaInputStream = nullptr;
166
167 QScopedPointer<QWasmEventHandler> m_timeUpdateEvent;
168 QScopedPointer<QWasmEventHandler> m_playEvent;
169 QScopedPointer<QWasmEventHandler> m_endedEvent;
170 QScopedPointer<QWasmEventHandler> m_durationChangeEvent;
171 QScopedPointer<QWasmEventHandler> m_loadedDataEvent;
172 QScopedPointer<QWasmEventHandler> m_errorChangeEvent;
173 QScopedPointer<QWasmEventHandler> m_resizeChangeEvent;
174 QScopedPointer<QWasmEventHandler> m_loadedMetadataChangeEvent;
175 QScopedPointer<QWasmEventHandler> m_loadStartChangeEvent;
176 QScopedPointer<QWasmEventHandler> m_canPlayChangeEvent;
177 QScopedPointer<QWasmEventHandler> m_canPlayThroughChangeEvent;
178 QScopedPointer<QWasmEventHandler> m_seekingChangeEvent;
179 QScopedPointer<QWasmEventHandler> m_seekedChangeEvent;
180 QScopedPointer<QWasmEventHandler> m_emptiedChangeEvent;
181 QScopedPointer<QWasmEventHandler> m_stalledChangeEvent;
182 QScopedPointer<QWasmEventHandler> m_waitingChangeEvent;
183 QScopedPointer<QWasmEventHandler> m_playingChangeEvent;
184 QScopedPointer<QWasmEventHandler> m_progressChangeEvent;
185 QScopedPointer<QWasmEventHandler> m_pauseChangeEvent;
186 QScopedPointer<QWasmEventHandler> m_beforeUnloadEvent;
187
188 std::string m_cameraId;
189 QMetaObject::Connection m_connection;
190 QSize m_videoResolution;
191 float m_minFrameRate = 0;
192 float m_maxFrameRate = 0;
193 float m_streamFrameRate = 0;
194 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE m_glContextHandle = 0;
195 static bool orientationchangeCallback(int eventType, const EmscriptenOrientationChangeEvent *orientationChangeEvent, void *userData);
196};
197
198QT_END_NAMESPACE
199#endif // QWASMVIDEOOUTPUT_H
void addCameraSourceElement(const std::string &id)
void updateVideoElementGeometry(const QRect &windowGeometry)
bool setDeviceSetting(const std::string &key, emscripten::val value)
void sizeChange(qint32 width, qint32 height)
void newFrame(const QVideoFrame &newFrame)
emscripten::val surfaceElement()
void seekableChanged(bool seekable)
void durationChanged(qint64 duration)
emscripten::val getDeviceCapabilities()
void videoFrameCallback(void *context)
void setVideoSize(const QSize &)
void setMuted(bool muted)
emscripten::val currentVideoElement()
void setSource(const QUrl &url)
void setVideoMode(QWasmVideoOutput::WasmVideoMode mode)
void bufferingChanged(qint32 percent)
void setVideoConstraints(QSize resolution, float minFrameRate, float maxFrameRate)
void seekTo(qint64 position)
void webglVideoFrameCallback(void *context)
void orientationChanged(int rotationIndex)
void setVolume(qreal volume)
void createVideoElement(const std::string &id)
void stateChanged(QWasmMediaPlayer::QWasmMediaPlayerState newState)
void setSurface(QVideoSink *surface)
bool hasCapability(const QString &cap)
void updateVideoElementSource(const QString &src)
void removeSourceElement()
std::string m_videoSurfaceId
void statusChanged(QMediaPlayer::MediaStatus status)
static QVideoFrameFormat::PixelFormat fromJsPixelFormat(std::string_view videoFormat)
void progressChanged(qint32 position)
void errorOccured(qint32 code, const QString &message)
void setSource(QIODevice *stream)
void setPlaybackRate(qreal rate)
void setHasAudio(bool needsAudio)
void createOffscreenElement(const QSize &offscreenSize)
Combined button and popup list for selecting options.
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define GL_CLAMP_TO_EDGE
Definition qopenglext.h:100
static bool checkForVideoFrame()
EM_JS(void, em_texImage2DFromVideo,(const char *videoId, int *pW, int *pH), { var gl=GL.currentContext.GLctx;var video=document.getElementById(UTF8ToString(videoId));if(!video) { return;} var frame;try { frame=new VideoFrame(video);} catch(e) { return;} HEAP32[pW > > 2]=frame.displayWidth;HEAP32[pH > > 2]=frame.displayHeight;gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, frame);frame.close();})
EM_JS(EM_VAL, qt_st_sink_createWorkletNode,(EM_VAL ctxHandle, int callbackId, int channels), { var node=new AudioWorkletNode(Emval.toValue(ctxHandle), 'qt-audio-sink', { numberOfInputs:0, numberOfOutputs:1, outputChannelCounts:[channels], processorOptions:{ channels:channels } });node.port.onmessage=function() { Module._qt_sinkDeliverData(callbackId);};return Emval.toHandle(node);})