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
qohoscamerasession_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 QOHOSCAMERASESSION_P_H
5#define QOHOSCAMERASESSION_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/qobject.h>
20#include <QtCore/qpointer.h>
21#include <QtCore/qurl.h>
22#include <QtMultimedia/qcameradevice.h>
23#include <QtMultimedia/qimagecapture.h>
24#include <QtMultimedia/qmediarecorder.h>
25#include <QtMultimedia/qvideosink.h>
26
27#include <private/qplatformimagecapture_p.h>
28#include <private/qplatformmediarecorder_p.h>
29
30#include <ohcamera/camera.h>
31#include <ohcamera/camera_input.h>
32#include <ohcamera/camera_manager.h>
33#include <ohcamera/capture_session.h>
34#include <ohcamera/photo_output.h>
35#include <ohcamera/preview_output.h>
36#include <ohcamera/video_output.h>
37
38#include <multimedia/image_framework/image/image_receiver_native.h>
39#include <multimedia/player_framework/avrecorder.h>
40#include <multimedia/player_framework/avrecorder_base.h>
41
42#include <atomic>
43#include <memory>
44#include <optional>
45
46QT_BEGIN_NAMESPACE
47
48class QOhosVideoOutput;
49
51{
53public:
54 explicit QOhosCameraSession(QObject *parent = nullptr);
56
57 void setCamera(const QCameraDevice &camera);
58 QCameraDevice camera() const { return m_cameraDevice; }
59
60 void setCameraFormat(const QCameraFormat &format);
61 QCameraFormat cameraFormat() const { return m_cameraFormat; }
62
63 void setVideoSink(QVideoSink *sink);
64 QVideoSink *videoSink() const { return m_videoSink; }
65
66 void setActive(bool active);
67 bool isActive() const { return m_active; }
68
69 bool isReadyForCapture() const { return m_active && m_photoOutput && !m_captureInProgress; }
70 int capture(const QString &fileName, bool toBuffer = false);
71
72 QImageEncoderSettings imageSettings() const { return m_imageSettings; }
73 void setImageSettings(const QImageEncoderSettings &settings);
74
75 QMediaRecorder::RecorderState recorderState() const { return m_recorderState; }
77 bool startRecording(const QMediaEncoderSettings &settings, const QString &location);
78 void pauseRecording();
79 void resumeRecording();
80 void stopRecording();
81
84 void errorOccurred(int code, const QString &message);
85 void readyForCaptureChanged(bool ready);
86 void imageExposed(int id);
87 void imageCaptured(int id, const QImage &preview);
88 void imageAvailable(int id, const QVideoFrame &frame);
89 void imageSaved(int id, const QString &fileName);
90 void imageCaptureError(int id, int error, const QString &message);
91
92 void recorderStateChanged(int state);
93 void recorderErrorOccurred(int code, const QString &message);
94 void recorderDurationChanged(qint64 ms);
95 void recorderActualLocationChanged(const QUrl &url);
96
97public slots:
99 void onRecorderStateNotification(int state);
100 void onRecorderErrorNotification(int code, const QString &message);
101
102private slots:
103 void onSurfaceReady();
104
105private:
106 void emitReadyForCaptureChanged();
107
108 bool startSession();
109 void stopSession();
110 void releaseSession();
111 bool ensureManager();
112 Camera_Device *findDevice(const QByteArray &id);
113 bool createPhotoPath(Camera_OutputCapability *caps, Camera_Profile *previewProfile);
114 void destroyPhotoPath();
115 bool attachVideoOutput(const Camera_VideoProfile &profile, const QByteArray &surfaceId);
116 void detachVideoOutput();
117 void destroyRecorder();
118 bool findVideoProfile(const QMediaEncoderSettings &settings, Camera_VideoProfile *out);
119
120 static void recorderStateCallback(OH_AVRecorder *recorder, OH_AVRecorder_State state,
121 OH_AVRecorder_StateChangeReason reason, void *userData);
122 static void recorderErrorCallback(OH_AVRecorder *recorder, int32_t errorCode,
123 const char *errorMsg, void *userData);
124
125 Camera_Manager *m_manager{ nullptr };
126 Camera_Device *m_supportedDevices{ nullptr };
127 uint32_t m_supportedDeviceCount{ 0 };
128
129 Camera_Input *m_cameraInput{ nullptr };
130 Camera_CaptureSession *m_captureSession{ nullptr };
131 Camera_PreviewOutput *m_previewOutput{ nullptr };
132 Camera_PhotoOutput *m_photoOutput{ nullptr };
133 Camera_VideoOutput *m_videoOutputCamera{ nullptr };
134
135 OH_ImageReceiverNative *m_imageReceiver{ nullptr };
136 OH_ImageReceiverOptions *m_imageReceiverOptions{ nullptr };
137
138 OH_AVRecorder *m_recorder{ nullptr };
139 OHNativeWindow *m_recorderWindow{ nullptr };
140 QMediaRecorder::RecorderState m_recorderState{ QMediaRecorder::StoppedState };
141 QUrl m_recorderActualLocation;
142 QElapsedTimer m_recorderTimer;
143 qint64 m_recorderPausedMs{ 0 };
144 qint64 m_recorderResumeStartMs{ 0 };
145
146 QCameraDevice m_cameraDevice;
147 QCameraFormat m_cameraFormat;
148 QPointer<QVideoSink> m_videoSink;
149 std::unique_ptr<QOhosVideoOutput> m_videoOutput;
150
151 QImageEncoderSettings m_imageSettings;
152 std::atomic<int> m_lastCaptureId{ 0 };
153 int m_pendingCaptureId{ 0 };
154 QString m_pendingCaptureFileName;
155 bool m_pendingCaptureToBuffer{ false };
156 bool m_captureInProgress{ false };
157
158 bool m_active{ false };
159 bool m_pendingStart{ false };
160 std::optional<bool> m_lastReadyForCapture;
161};
162
163QT_END_NAMESPACE
164
165#endif // QOHOSCAMERASESSION_P_H
The QCamera class provides interface for system camera devices.
Definition qcamera.h:25
int capture(const QString &fileName, bool toBuffer=false)
void recorderStateChanged(int state)
void setCamera(const QCameraDevice &camera)
void errorOccurred(int code, const QString &message)
qint64 recorderDuration() const
void imageCaptureError(int id, int error, const QString &message)
QImageEncoderSettings imageSettings() const
void imageSaved(int id, const QString &fileName)
void setActive(bool active)
void recorderErrorOccurred(int code, const QString &message)
QMediaRecorder::RecorderState recorderState() const
void onRecorderStateNotification(int state)
void setCameraFormat(const QCameraFormat &format)
void imageCaptured(int id, const QImage &preview)
void imageExposed(int id)
void readyForCaptureChanged(bool ready)
void recorderActualLocationChanged(const QUrl &url)
void onRecorderErrorNotification(int code, const QString &message)
QCameraDevice camera() const
QVideoSink * videoSink() const
QCameraFormat cameraFormat() const
void recorderDurationChanged(qint64 ms)
void setVideoSink(QVideoSink *sink)
bool startRecording(const QMediaEncoderSettings &settings, const QString &location)
void setImageSettings(const QImageEncoderSettings &settings)
void imageAvailable(int id, const QVideoFrame &frame)
bool setCameraFormat(const QCameraFormat &format) override
void setCaptureSession(QPlatformMediaCaptureSession *session) override
void setCamera(const QCameraDevice &camera) override
void setActive(bool active) override
bool isActive() const override
~QOhosCamera() override
QOhosCameraSession * session() const
Combined button and popup list for selecting options.