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
qohosmediarecorder_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QOHOSMEDIARECORDER_P_H
5#define QOHOSMEDIARECORDER_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 <QtCore/qelapsedtimer.h>
19#include <QtCore/qpointer.h>
20#include <QtCore/qtimer.h>
21#include <QtCore/qurl.h>
22#include <QtMultimedia/qaudioformat.h>
23#include <QtMultimedia/qaudiosource.h>
24#include <QtMultimedia/qmediametadata.h>
25#include <QtMultimedia/qmediarecorder.h>
26
27#include <private/qplatformmediacapture_p.h>
28#include <private/qplatformmediarecorder_p.h>
29
30#include <multimedia/player_framework/avrecorder.h>
31#include <multimedia/player_framework/avrecorder_base.h>
32
33#include <memory>
34
36
37class QFile;
40
42{
44public:
47
48 bool isLocationWritable(const QUrl &location) const override;
49
50 QMediaRecorder::RecorderState state() const override;
51 qint64 duration() const override;
52
53 void record(QMediaEncoderSettings &settings) override;
54 void pause() override;
55 void resume() override;
56 void stop() override;
57
58 void setMetaData(const QMediaMetaData &metaData) override;
59 QMediaMetaData metaData() const override { return m_metaData; }
60
61 void setCaptureSession(QPlatformMediaCaptureSession *session);
62
63private:
64 void onRecorderStateChanged(int state);
65 void onRecorderError(int code, const QString &message);
66 void onRecorderDuration(qint64 ms);
67 void onRecorderActualLocation(const QUrl &url);
68
69 void onAudioOnlyStateNotification(int state);
70 void onAudioOnlyErrorNotification(int code, const QString &message);
71
72 void connectToSession();
73 void disconnectFromSession();
74
75 bool recordAudioOnly(const QMediaEncoderSettings &settings, const QString &location);
76 void stopAudioOnly();
77 void pauseAudioOnly();
78 void resumeAudioOnly();
79 void destroyAudioOnlyRecorder();
80
81 // Wave/PCM recording bypasses OH_AVRecorder (which has no PCM codec) and
82 // writes a RIFF/WAVE container from raw QAudioSource frames.
83 bool recordWave(const QMediaEncoderSettings &settings, const QString &location);
84 void stopWave();
85 void pauseWave();
86 void resumeWave();
87 void destroyWaveRecorder();
88
89 static void audioOnlyStateCallback(OH_AVRecorder *recorder, OH_AVRecorder_State state,
90 OH_AVRecorder_StateChangeReason reason, void *userData);
91 static void audioOnlyErrorCallback(OH_AVRecorder *recorder, int32_t errorCode,
92 const char *errorMsg, void *userData);
93
94 QPointer<QOhosMediaCaptureSession> m_service;
95 QPointer<QOhosCameraSession> m_session;
96
97 QMediaMetaData m_metaData;
98
99 OH_AVRecorder *m_audioOnlyRecorder{ nullptr };
100 int m_audioOnlyFd{ -1 };
101 QMediaRecorder::RecorderState m_audioOnlyState{ QMediaRecorder::StoppedState };
102 QUrl m_audioOnlyActualLocation;
103 QElapsedTimer m_audioOnlyTimer;
104 qint64 m_audioOnlyPausedMs{ 0 };
105 qint64 m_audioOnlyResumeStartMs{ 0 };
106 QTimer m_audioOnlyDurationTimer;
107
108 // Wave/PCM path
109 std::unique_ptr<QAudioSource> m_waveSource;
110 std::unique_ptr<QFile> m_waveFile;
111 QMediaRecorder::RecorderState m_waveState{ QMediaRecorder::StoppedState };
112 QUrl m_waveActualLocation;
113 QAudioFormat m_waveFormat;
114 QElapsedTimer m_waveTimer;
115 qint64 m_wavePausedMs{ 0 };
116 qint64 m_waveResumeStartMs{ 0 };
117};
118
119QT_END_NAMESPACE
120
121#endif // QOHOSMEDIARECORDER_P_H
void setCamera(QPlatformCamera *camera) override
void setAudioInput(QPlatformAudioInput *input) override
void setImageCapture(QPlatformImageCapture *imageCapture) override
void setVideoPreview(QVideoSink *sink) override
QPlatformCamera * camera() override
void setAudioOutput(QPlatformAudioOutput *output) override
void setMediaRecorder(QPlatformMediaRecorder *recorder) override
QOhosCameraSession * cameraSession() const
QPlatformMediaRecorder * mediaRecorder() override
QPlatformImageCapture * imageCapture() override
~QOhosMediaCaptureSession() override
QMediaMetaData metaData() const override
void setMetaData(const QMediaMetaData &metaData) override
QMediaRecorder::RecorderState state() const override
qint64 duration() const override
bool isLocationWritable(const QUrl &location) const override
void record(QMediaEncoderSettings &settings) override
void setCaptureSession(QPlatformMediaCaptureSession *session)
Combined button and popup list for selecting options.