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 <QMediaPlayer>
22#include <QVideoFrame>
23
25#include "private/qwasmmediadevices_p.h"
26#include <private/qwasmjs_p.h>
27
28#include <QtCore/qloggingcategory.h>
29
30#include <private/qstdweb_p.h>
31#include <private/qwasmsuspendresumecontrol_p.h>
32
34
35Q_DECLARE_LOGGING_CATEGORY(qWasmMediaVideoOutput)
36
37class QVideoSink;
38
40{
42public:
46
47 explicit QWasmVideoOutput(QObject *parent = nullptr);
49
50 void setVideoSize(const QSize &);
51 void start();
52 void stop();
53 void reset();
54 void pause();
55
56 void setSurface(QVideoSink *surface);
58
59 bool isReady() const;
60
61 void setSource(const QUrl &url);
62 void setSource(QIODevice *stream);
63 void setVolume(qreal volume);
64 void setMuted(bool muted);
65
67 void seekTo(qint64 position);
68 bool isVideoSeekable();
69 void setPlaybackRate(qreal rate);
71
73 void newFrame(const QVideoFrame &newFrame);
74
75 void createVideoElement(const std::string &id);
76 void createOffscreenElement(const QSize &offscreenSize);
77 void doElementCallbacks();
78 void updateVideoElementGeometry(const QRect &windowGeometry);
79 void updateVideoElementSource(const QString &src);
80 void addCameraSourceElement(const std::string &id);
83
84 void setHasAudio(bool needsAudio) { m_hasAudio = needsAudio; }
85
86 bool hasCapability(const QString &cap);
88 bool setDeviceSetting(const std::string &key, emscripten::val value);
89 bool isCameraReady() { return m_cameraIsReady; }
90 bool m_hasVideoFrame = false;
91
92 void videoFrameCallback(void *context);
94 // mediacapturesession has the videosink
96
98 m_video.isNull() || m_video.isUndefined() ? emscripten::val::null()
99 : m_video) ; }
100
102
103 static QVideoFrameFormat::PixelFormat fromJsPixelFormat(std::string videoFormat);
104
106
108 void readyChanged(bool);
109 void bufferingChanged(qint32 percent);
110 void errorOccured(qint32 code, const QString &message);
112 void progressChanged(qint32 position);
113 void durationChanged(qint64 duration);
114 void statusChanged(QMediaPlayer::MediaStatus status);
115 void sizeChange(qint32 width, qint32 height);
117 void seekableChanged(bool seekable);
118
119private:
120 void checkNetworkState();
121 void videoComputeFrame(void *context);
122 void getDeviceSettings();
123
124
125 emscripten::val m_video = emscripten::val::undefined();
126 emscripten::val m_videoElementSource = emscripten::val::undefined();
127
128 QString m_source;
129 float m_requestedPosition = 0.0;
130 emscripten::val m_offscreen = emscripten::val::undefined();
131
132 bool m_shouldStop = 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_isSeekable = false;
139
140 emscripten::val m_offscreenContext = emscripten::val::undefined();
141 QSize m_pendingVideoSize;
143 QMediaPlayer::MediaStatus m_currentMediaStatus;
144 qreal m_currentBufferedValue;
145 std::unique_ptr<JsMediaInputStream> m_mediaInputStream;
146
147 QScopedPointer<QWasmEventHandler> m_timeUpdateEvent;
148 QScopedPointer<QWasmEventHandler> m_playEvent;
149 QScopedPointer<QWasmEventHandler> m_endedEvent;
150 QScopedPointer<QWasmEventHandler> m_durationChangeEvent;
151 QScopedPointer<QWasmEventHandler> m_loadedDataEvent;
152 QScopedPointer<QWasmEventHandler> m_errorChangeEvent;
153 QScopedPointer<QWasmEventHandler> m_resizeChangeEvent;
154 QScopedPointer<QWasmEventHandler> m_loadedMetadataChangeEvent;
155 QScopedPointer<QWasmEventHandler> m_loadStartChangeEvent;
156 QScopedPointer<QWasmEventHandler> m_canPlayChangeEvent;
157 QScopedPointer<QWasmEventHandler> m_canPlayThroughChangeEvent;
158 QScopedPointer<QWasmEventHandler> m_seekingChangeEvent;
159 QScopedPointer<QWasmEventHandler> m_seekedChangeEvent;
160 QScopedPointer<QWasmEventHandler> m_emptiedChangeEvent;
161 QScopedPointer<QWasmEventHandler> m_stalledChangeEvent;
162 QScopedPointer<QWasmEventHandler> m_waitingChangeEvent;
163 QScopedPointer<QWasmEventHandler> m_playingChangeEvent;
164 QScopedPointer<QWasmEventHandler> m_progressChangeEvent;
165 QScopedPointer<QWasmEventHandler> m_pauseChangeEvent;
166 QScopedPointer<QWasmEventHandler> m_beforeUnloadEvent;
167};
168
169QT_END_NAMESPACE
170#endif // QWASMVIDEOOUTPUT_H
void addCameraSourceElement(const std::string &id)
static QVideoFrameFormat::PixelFormat fromJsPixelFormat(std::string videoFormat)
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)
QVideoSink * m_wasmSink
emscripten::val currentVideoElement()
void setSource(const QUrl &url)
void setVideoMode(QWasmVideoOutput::WasmVideoMode mode)
void bufferingChanged(qint32 percent)
void seekTo(qint64 position)
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)
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)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
static bool checkForVideoFrame()