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
qwasmjs_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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#ifndef QWASMJS_P_H
5#define QWASMJS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QObject>
19
20#include <emscripten.h>
21#include <emscripten/val.h>
22#include <emscripten/bind.h>
23#include <private/qstdweb_p.h>
24#include <private/qplatformmediarecorder_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QIODevice;
29
30class JsMediaRecorder final : public QIODevice
31{
33public:
35 JsMediaRecorder(const QIODevice *outputDevice);
36
37 void pauseStream();
38 void resumeStream();
39 void stopStream();
40 void startStreaming();
41
42 bool open(QIODeviceBase::OpenMode mode) override;
43 bool isSequential() const override;
44 qint64 size() const override;
45 bool seek(qint64 pos) override;
46 void setStream(emscripten::val stream);
47 qint64 bytesAvailable() const override;
48
49 void setNeedsCamera(bool hasCamera) { m_needsCamera = hasCamera; }
50 void setNeedsAudio(bool hasAudio) { m_needsAudio = hasAudio; }
51
52 QMediaRecorder::RecorderState currentState() { return m_currentState; }
53
55 void started();
56 void stopped();
57 void paused();
58 void resumed();
59 void streamError(QMediaRecorder::Error error, const QString &errorMessage);
60 void stateChanged(QMediaRecorder::RecorderState state);
61
62protected:
63 qint64 readData(char *data, qint64 maxSize) override;
64 qint64 writeData(const char *, qint64) override;
65
66private:
67 void audioDataAvailable(emscripten::val Blob, double timeCodeDifference);
68 void setTrackContraints(QMediaEncoderSettings &settings, emscripten::val stream);
69
70 emscripten::val m_mediaRecorder = emscripten::val::undefined();
71 emscripten::val m_mediaStream = emscripten::val::undefined();
72 QMediaEncoderSettings m_mediaSettings;
73 bool m_needsCamera = false;
74 bool m_needsAudio = false;
75
76 QMediaRecorder::RecorderState m_currentState = QMediaRecorder::StoppedState;
77 QByteArray m_buffer;
78
79 QScopedPointer<qstdweb::EventCallback> m_mediaStreamDataAvailable;
80 QScopedPointer<qstdweb::EventCallback> m_mediaStreamStopped;
81 QScopedPointer<qstdweb::EventCallback> m_mediaStreamError;
82 QScopedPointer<qstdweb::EventCallback> m_mediaStreamStart;
83 QScopedPointer<qstdweb::EventCallback> m_mediaStreamPause;
84 QScopedPointer<qstdweb::EventCallback> m_mediaStreamResume;
85};
86
88{
90public:
91 explicit JsMediaInputStream(QObject *parent = nullptr);
92
93 bool isActive() { return m_active; }
94
95 void setUseAudio(bool useAudio) { m_needsAudio = useAudio; }
96 void setUseVideo(bool useVideo) { m_needsVideo = useVideo; }
97 void setStreamDevice(const std::string &id);
98 emscripten::val getMediaStream() { return m_mediaStream; }
99
100signals:
102 void activated(bool active);
103
104private:
105 void setupMediaStream(emscripten::val mStream);
106 emscripten::val m_mediaStream = emscripten::val::undefined();
107 bool m_needsAudio = false;
108 bool m_needsVideo = false;
109 bool m_active = false;
110
111 QScopedPointer<qstdweb::EventCallback> m_activeStreamEvent;
112 QScopedPointer<qstdweb::EventCallback> m_inactiveStreamEvent;
113
114};
115
116#endif // QWASMJS_P_H
emscripten::val getMediaStream()
Definition qwasmjs_p.h:98
void setStreamDevice(const std::string &id)
Definition qwasmjs.cpp:358
void setUseAudio(bool useAudio)
Definition qwasmjs_p.h:95
void setUseVideo(bool useVideo)
Definition qwasmjs_p.h:96
void activated(bool active)
qint64 writeData(const char *, qint64) override
Writes up to maxSize bytes from data to the device.
Definition qwasmjs.cpp:45
void streamError(QMediaRecorder::Error error, const QString &errorMessage)
void startStreaming()
Definition qwasmjs.cpp:183
bool isSequential() const override
Returns true if this device is sequential; otherwise returns false.
Definition qwasmjs.cpp:20
qint64 size() const override
For open random-access devices, this function returns the size of the device.
Definition qwasmjs.cpp:25
void stopStream()
Definition qwasmjs.cpp:172
bool seek(qint64 pos) override
For random-access devices, this function sets the current position to pos, returning true on success,...
Definition qwasmjs.cpp:30
void setNeedsCamera(bool hasCamera)
Definition qwasmjs_p.h:49
qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
Definition qwasmjs.cpp:347
void setStream(emscripten::val stream)
Definition qwasmjs.cpp:195
void stateChanged(QMediaRecorder::RecorderState state)
JsMediaRecorder(const QIODevice *outputDevice)
bool open(QIODeviceBase::OpenMode mode) override
Opens the device and sets its OpenMode to mode.
Definition qwasmjs.cpp:13
void resumeStream()
Definition qwasmjs.cpp:162
qint64 readData(char *data, qint64 maxSize) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
Definition qwasmjs.cpp:37
void pauseStream()
Definition qwasmjs.cpp:153
QMediaRecorder::RecorderState currentState()
Definition qwasmjs_p.h:52
void setNeedsAudio(bool hasAudio)
Definition qwasmjs_p.h:50