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
20
21#include <QtMultimedia/qmediaplayer.h>
22#include <QtMultimedia/qtvideo.h>
23#include <QtMultimedia/qvideoframe.h>
24#include <QtMultimedia/private/qwasmjs_p.h>
25#include <QtMultimedia/private/qwasmmediadevices_p.h>
26#include <QtCore/qloggingcategory.h>
27#include <QtCore/qobject.h>
28#include <QtCore/private/qstdweb_p.h>
29#include <QtCore/private/qwasmsuspendresumecontrol_p.h>
30
31#include <emscripten/val.h>
32#include <emscripten/html5.h>
33
35
36Q_DECLARE_LOGGING_CATEGORY(qWasmMediaVideoOutput)
37
38class QVideoSink;
39
41{
43public:
48
49 explicit QWasmVideoOutput(QObject *parent = nullptr);
51
52 void setVideoSize(const QSize &);
53 void start();
54 void stop();
55 void reset();
56 void pause();
57
58 void setSurface(QVideoSink *surface);
60
61 bool isReady() const;
62
63 void setSource(const QUrl &url);
64 void setSource(QIODevice *stream);
65 void setVolume(qreal volume);
66 void setMuted(bool muted);
67
69 void seekTo(qint64 position);
70 bool isVideoSeekable();
71 void setPlaybackRate(qreal rate);
73
75
76 void createVideoElement(const std::string &id);
77 void doElementCallbacks();
78 void updateVideoElementGeometry(const QRect &windowGeometry);
79 void updateVideoElementSource(const QString &src);
80 void addCameraSourceElement(const std::string &id);
82 void setVideoConstraints(QSize resolution, float minFrameRate, float maxFrameRate);
83
84 void setHasAudio(bool needsAudio) { m_hasAudio = needsAudio; }
85
87 bool setDeviceSetting(const std::string &key, emscripten::val value);
88 bool isCameraReady() { return m_cameraIsReady; }
89
90 // mediacapturesession has the videosink
92
94 m_video.isNull() || m_video.isUndefined() ? emscripten::val::null()
95 : m_video) ; }
96
98
100
102 void readyChanged(bool);
103 void bufferingChanged(qint32 percent);
104 void errorOccured(qint32 code, const QString &message);
106 void progressChanged(qint32 position);
107 void durationChanged(qint64 duration);
108 void statusChanged(QMediaPlayer::MediaStatus status);
109 void sizeChange(qint32 width, qint32 height);
111 void seekableChanged(bool seekable);
112 void orientationChanged(int rotationIndex);
113
114private:
115 void checkNetworkState();
116 void playVideoElement();
117 void videoComputeFrame(void *context);
118 void getDeviceSettings();
119 bool isPlatformiOs();
120 void detectIosCameraRotation();
121 void applyIosRotation(int orientationIndex);
122
123 emscripten::val m_video = emscripten::val::undefined();
124
125 QString m_source;
126 float m_requestedPosition = 0.0;
128 QtVideo::Rotation m_rotateBy = QtVideo::Rotation::None;
129 int getCurrentOrientationIndex();
130
131
132 bool m_isStopped = false;
133 bool m_toBePaused = false;
134 bool m_isSeeking = false;
135 bool m_hasAudio = false;
136 bool m_cameraIsReady = false;
137 bool m_shouldBeStarted = false;
138 bool m_streamStarted = false;
139 bool m_isSeekable = false;
140 bool m_useCameraRotation = false;
141
142 QSize m_pendingVideoSize;
144 QMediaPlayer::MediaStatus m_currentMediaStatus;
145 qreal m_currentBufferedValue;
146 JsMediaInputStream *m_mediaInputStream = nullptr;
147
148 QScopedPointer<QWasmEventHandler> m_timeUpdateEvent;
149 QScopedPointer<QWasmEventHandler> m_playEvent;
150 QScopedPointer<QWasmEventHandler> m_endedEvent;
151 QScopedPointer<QWasmEventHandler> m_durationChangeEvent;
152 QScopedPointer<QWasmEventHandler> m_loadedDataEvent;
153 QScopedPointer<QWasmEventHandler> m_errorChangeEvent;
154 QScopedPointer<QWasmEventHandler> m_resizeChangeEvent;
155 QScopedPointer<QWasmEventHandler> m_loadedMetadataChangeEvent;
156 QScopedPointer<QWasmEventHandler> m_loadStartChangeEvent;
157 QScopedPointer<QWasmEventHandler> m_canPlayChangeEvent;
158 QScopedPointer<QWasmEventHandler> m_canPlayThroughChangeEvent;
159 QScopedPointer<QWasmEventHandler> m_seekingChangeEvent;
160 QScopedPointer<QWasmEventHandler> m_seekedChangeEvent;
161 QScopedPointer<QWasmEventHandler> m_emptiedChangeEvent;
162 QScopedPointer<QWasmEventHandler> m_stalledChangeEvent;
163 QScopedPointer<QWasmEventHandler> m_waitingChangeEvent;
164 QScopedPointer<QWasmEventHandler> m_playingChangeEvent;
165 QScopedPointer<QWasmEventHandler> m_progressChangeEvent;
166 QScopedPointer<QWasmEventHandler> m_pauseChangeEvent;
167 QScopedPointer<QWasmEventHandler> m_beforeUnloadEvent;
168
169 std::string m_cameraId;
170 QMetaObject::Connection m_connection;
171 QSize m_videoResolution;
172 float m_minFrameRate = 0;
173 float m_maxFrameRate = 0;
174 float m_streamFrameRate = 0;
175 static bool orientationchangeCallback(int eventType, const EmscriptenOrientationChangeEvent *orientationChangeEvent, void *userData);
176
177 QWasmVideoFrameGrabber m_frameGrabber;
179};
180
181QT_END_NAMESPACE
182#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 *widthOut, int *heightOut), { videoId=Number(videoId);widthOut=Number(widthOut);heightOut=Number(heightOut);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[widthOut/4]=frame.displayWidth;HEAP32[heightOut/4]=frame.displayHeight;gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, frame);frame.close();})