15#ifndef QWASMVIDEOOUTPUT_H
16#define QWASMVIDEOOUTPUT_H
20#include <emscripten/val.h>
21#include <emscripten/html5_webgl.h>
22#include <emscripten/html5.h>
24#include <QMediaPlayer>
26#include <QtMultimedia/qtvideo.h>
29#include "private/qwasmmediadevices_p.h"
32#include <private/qwasmjs_p.h>
34#include <QtCore/qloggingcategory.h>
36#include <private/qstdweb_p.h>
37#include <private/qwasmsuspendresumecontrol_p.h>
41Q_DECLARE_LOGGING_CATEGORY(qWasmMediaVideoOutput)
74 void seekTo(qint64 position);
80 void newFrame(
const QVideoFrame &newFrame);
91 void setHasAudio(
bool needsAudio) { m_hasAudio = needsAudio; }
110 m_video.isNull() || m_video.isUndefined() ? emscripten::val::null()
133 void checkNetworkState();
134 void videoComputeFrame(
void *context);
135 void getDeviceSettings();
136 bool isPlatformiOs();
142 float m_requestedPosition = 0.0;
148 bool m_isStopped =
false;
149 bool m_toBePaused =
false;
150 bool m_isSeeking =
false;
151 bool m_hasAudio =
false;
152 bool m_cameraIsReady =
false;
153 bool m_shouldBeStarted =
false;
154 bool m_isSeekable =
false;
155 bool m_useCameraRotation =
false;
158 QSize m_pendingVideoSize;
160 QMediaPlayer::MediaStatus m_currentMediaStatus;
161 qreal m_currentBufferedValue;
162 JsMediaInputStream *m_mediaInputStream =
nullptr;
164 QScopedPointer<QWasmEventHandler> m_timeUpdateEvent;
165 QScopedPointer<QWasmEventHandler> m_playEvent;
166 QScopedPointer<QWasmEventHandler> m_endedEvent;
167 QScopedPointer<QWasmEventHandler> m_durationChangeEvent;
168 QScopedPointer<QWasmEventHandler> m_loadedDataEvent;
169 QScopedPointer<QWasmEventHandler> m_errorChangeEvent;
170 QScopedPointer<QWasmEventHandler> m_resizeChangeEvent;
171 QScopedPointer<QWasmEventHandler> m_loadedMetadataChangeEvent;
172 QScopedPointer<QWasmEventHandler> m_loadStartChangeEvent;
173 QScopedPointer<QWasmEventHandler> m_canPlayChangeEvent;
174 QScopedPointer<QWasmEventHandler> m_canPlayThroughChangeEvent;
175 QScopedPointer<QWasmEventHandler> m_seekingChangeEvent;
176 QScopedPointer<QWasmEventHandler> m_seekedChangeEvent;
177 QScopedPointer<QWasmEventHandler> m_emptiedChangeEvent;
178 QScopedPointer<QWasmEventHandler> m_stalledChangeEvent;
179 QScopedPointer<QWasmEventHandler> m_waitingChangeEvent;
180 QScopedPointer<QWasmEventHandler> m_playingChangeEvent;
181 QScopedPointer<QWasmEventHandler> m_progressChangeEvent;
182 QScopedPointer<QWasmEventHandler> m_pauseChangeEvent;
183 QScopedPointer<QWasmEventHandler> m_beforeUnloadEvent;
185 std::string m_cameraId;
186 QMetaObject::Connection m_connection;
187 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE m_glContextHandle = 0;
189 static bool orientationchangeCallback(
int eventType,
const EmscriptenOrientationChangeEvent *orientationChangeEvent,
void *userData);
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 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 removeCurrentVideoElement()
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)
qint64 getCurrentPosition()
void setPlaybackRate(qreal rate)
void setHasAudio(bool needsAudio)
void doElementCallbacks()
void createOffscreenElement(const QSize &offscreenSize)
void videoFrameTimerCallback()
Combined button and popup list for selecting options.
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
static bool checkForVideoFrame()
EM_JS(void, qt_st_sink_loadWorkletModule,(EM_VAL ctxHandle, int callbackId, int channels), { var ctx=Emval.toValue(ctxHandle);var code=[ 'class QtSink extends AudioWorkletProcessor {', ' constructor(opts) {', ' super(opts);', ' this._numChannels=opts.processorOptions.channels|0;', ' this._queue=[];', ' this._pos=0;', ' this.port.onmessage=(e)=> { this._queue.push(e.data);};', ' }', ' process(inputs, outputs) {', ' var out=outputs[0];', ' if(!out||!out.length) return true;', ' var samplesPerChannel=out[0].length;', ' for(var i=0;i< samplesPerChannel;i++) {', ' while(this._queue.length > 0 &&this._pos >=this._queue[0].samplesPerChannel) {', ' this._queue.shift();', ' this._pos=0;', ' }', ' if(this._queue.length===0) break;', ' var frame=this._queue[0];', ' for(var channel=0;channel< out.length &&channel< frame.numChannels;channel++)', ' out[channel][i]=frame.data[channel *frame.samplesPerChannel+this._pos];', ' this._pos++;', ' }', ' this.port.postMessage(null);', ' return true;', ' }', '}', 'registerProcessor("qt-audio-sink", QtSink);'].join('\n');var blob=new Blob([code], { type:'application/javascript' });var url=URL.createObjectURL(blob);ctx.audioWorklet.addModule(url).then(function() { URL.revokeObjectURL(url);Module._qt_sinkWorkletReady(callbackId);});})