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.h>
22
23#include <QMediaPlayer>
24#include <QVideoFrame>
25#include <QtMultimedia/qtvideo.h>
26
28#include "private/qwasmmediadevices_p.h"
30
31#include <private/qwasmjs_p.h>
32
33#include <QtCore/qloggingcategory.h>
34
35#include <private/qstdweb_p.h>
36#include <private/qwasmsuspendresumecontrol_p.h>
37
39
40Q_DECLARE_LOGGING_CATEGORY(qWasmMediaVideoOutput)
41
42class QVideoSink;
43
45{
47public:
52
53 explicit QWasmVideoOutput(QObject *parent = nullptr);
55
56 void setVideoSize(const QSize &);
57 void start();
58 void stop();
59 void reset();
60 void pause();
61
62 void setSurface(QVideoSink *surface);
64
65 bool isReady() const;
66
67 void setSource(const QUrl &url);
68 void setSource(QIODevice *stream);
69 void setVolume(qreal volume);
70 void setMuted(bool muted);
71
73 void seekTo(qint64 position);
74 bool isVideoSeekable();
75 void setPlaybackRate(qreal rate);
77
79
80 void createVideoElement(const std::string &id);
81 void doElementCallbacks();
82 void updateVideoElementGeometry(const QRect &windowGeometry);
83 void updateVideoElementSource(const QString &src);
84 void addCameraSourceElement(const std::string &id);
86 void setVideoConstraints(QSize resolution, float minFrameRate, float maxFrameRate);
87
88 void setHasAudio(bool needsAudio) { m_hasAudio = needsAudio; }
89
91 bool setDeviceSetting(const std::string &key, emscripten::val value);
92 bool isCameraReady() { return m_cameraIsReady; }
93
94 // mediacapturesession has the videosink
96
98 m_video.isNull() || m_video.isUndefined() ? emscripten::val::null()
99 : m_video) ; }
100
102
104
106 void readyChanged(bool);
107 void bufferingChanged(qint32 percent);
108 void errorOccured(qint32 code, const QString &message);
110 void progressChanged(qint32 position);
111 void durationChanged(qint64 duration);
112 void statusChanged(QMediaPlayer::MediaStatus status);
113 void sizeChange(qint32 width, qint32 height);
115 void seekableChanged(bool seekable);
116 void orientationChanged(int rotationIndex);
117
118private:
119 void checkNetworkState();
120 void playVideoElement();
121 void videoComputeFrame(void *context);
122 void getDeviceSettings();
123 bool isPlatformiOs();
124 void detectIosCameraRotation();
125 void applyIosRotation(int orientationIndex);
126
127 emscripten::val m_video = emscripten::val::undefined();
128
129 QString m_source;
130 float m_requestedPosition = 0.0;
132 QtVideo::Rotation m_rotateBy = QtVideo::Rotation::None;
133 int getCurrentOrientationIndex();
134
135
136 bool m_isStopped = false;
137 bool m_toBePaused = false;
138 bool m_isSeeking = false;
139 bool m_hasAudio = false;
140 bool m_cameraIsReady = false;
141 bool m_shouldBeStarted = false;
142 bool m_streamStarted = false;
143 bool m_isSeekable = false;
144 bool m_useCameraRotation = false;
145
146 QSize m_pendingVideoSize;
148 QMediaPlayer::MediaStatus m_currentMediaStatus;
149 qreal m_currentBufferedValue;
150 JsMediaInputStream *m_mediaInputStream = nullptr;
151
152 QScopedPointer<QWasmEventHandler> m_timeUpdateEvent;
153 QScopedPointer<QWasmEventHandler> m_playEvent;
154 QScopedPointer<QWasmEventHandler> m_endedEvent;
155 QScopedPointer<QWasmEventHandler> m_durationChangeEvent;
156 QScopedPointer<QWasmEventHandler> m_loadedDataEvent;
157 QScopedPointer<QWasmEventHandler> m_errorChangeEvent;
158 QScopedPointer<QWasmEventHandler> m_resizeChangeEvent;
159 QScopedPointer<QWasmEventHandler> m_loadedMetadataChangeEvent;
160 QScopedPointer<QWasmEventHandler> m_loadStartChangeEvent;
161 QScopedPointer<QWasmEventHandler> m_canPlayChangeEvent;
162 QScopedPointer<QWasmEventHandler> m_canPlayThroughChangeEvent;
163 QScopedPointer<QWasmEventHandler> m_seekingChangeEvent;
164 QScopedPointer<QWasmEventHandler> m_seekedChangeEvent;
165 QScopedPointer<QWasmEventHandler> m_emptiedChangeEvent;
166 QScopedPointer<QWasmEventHandler> m_stalledChangeEvent;
167 QScopedPointer<QWasmEventHandler> m_waitingChangeEvent;
168 QScopedPointer<QWasmEventHandler> m_playingChangeEvent;
169 QScopedPointer<QWasmEventHandler> m_progressChangeEvent;
170 QScopedPointer<QWasmEventHandler> m_pauseChangeEvent;
171 QScopedPointer<QWasmEventHandler> m_beforeUnloadEvent;
172
173 std::string m_cameraId;
174 QMetaObject::Connection m_connection;
175 QSize m_videoResolution;
176 float m_minFrameRate = 0;
177 float m_maxFrameRate = 0;
178 float m_streamFrameRate = 0;
179 static bool orientationchangeCallback(int eventType, const EmscriptenOrientationChangeEvent *orientationChangeEvent, void *userData);
180
181 QWasmVideoFrameGrabber m_frameGrabber;
183};
184
185QT_END_NAMESPACE
186#endif // QWASMVIDEOOUTPUT_H
QWasmVideoFrameGrabber(QWasmVideoOutput *videoOutput)
static QVideoFrameFormat::PixelFormat fromJsPixelFormat(std::string_view videoFormat)
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)
emscripten::val surfaceElement()
void seekableChanged(bool seekable)
void durationChanged(qint64 duration)
emscripten::val getDeviceCapabilities()
void setVideoSize(const QSize &)
void setMuted(bool muted)
QVideoSink * m_wasmSink
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 orientationChanged(int rotationIndex)
void setVolume(qreal volume)
void createVideoElement(const std::string &id)
void stateChanged(QWasmMediaPlayer::QWasmMediaPlayerState newState)
void setSurface(QVideoSink *surface)
void updateVideoElementSource(const QString &src)
std::string m_videoSurfaceId
void statusChanged(QMediaPlayer::MediaStatus status)
void progressChanged(qint32 position)
void errorOccured(qint32 code, const QString &message)
void setSource(QIODevice *stream)
void setPlaybackRate(qreal rate)
void setHasAudio(bool needsAudio)
Combined button and popup list for selecting options.
#define GL_CLAMP_TO_EDGE
Definition qopenglext.h:100
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, outputChannelCount:[channels], processorOptions:{ channels:channels } });node.port.onmessage=function() { Module._qt_sinkDeliverData(callbackId);};return Emval.toHandle(node);})