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
avfcamera.mm
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd and/or its subsidiary(-ies).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "avfcamera_p.h"
5
6#include <camera/avfcamerasession_p.h>
7#include <camera/avfcameraservice_p.h>
8#include <camera/avfcamerarenderer_p.h>
9
10#include <QtMultimedia/qmediacapturesession.h>
11#include <QtMultimedia/private/qavfcameradebug_p.h>
12#include <QtMultimedia/private/qavfcamerautility_p.h>
13
14QT_USE_NAMESPACE
15
18{
19 Q_ASSERT(camera);
20}
21
22AVFCamera::~AVFCamera() = default;
23
25{
26 if (m_session)
27 m_session->setActive(active);
28 return {};
29}
30
32 const QCameraDevice &newCameraDevice,
33 const QCameraFormat &newFormat)
34{
35 // The incoming format should never be null if the incoming device is not null.
36 Q_ASSERT(newCameraDevice.isNull() || !newFormat.isNull());
37
38 if (newCameraDevice.isNull() || !checkCameraPermission())
39 return;
40
41 if (m_session) {
42 // TODO: In the future, we should pass the new format into setActiveCamera,
43 // and determine if we can keep the camera-stream active with the new
44 // device + format. Then we should propagate any errors up the call stack.
45 m_session->setActiveCamera(newCameraDevice);
46 m_session->setCameraFormat(newFormat);
47 }
48}
49
50bool AVFCamera::tryApplyCameraFormat(const QCameraFormat &newFormat)
51{
52 // TODO: In the future, we should be able to return false if we failed
53 // to apply the format.
54 if (m_session)
55 m_session->setCameraFormat(newFormat);
56 return true;
57}
58
59void AVFCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
60{
61 AVFCameraService *captureSession = static_cast<AVFCameraService *>(session);
62 if (m_service == captureSession)
63 return;
64
65 if (m_session) {
66 m_session->disconnect(this);
67 m_session->setActiveCamera({});
68 m_session->setCameraFormat({});
69 }
70
71 m_service = captureSession;
72 if (!m_service) {
73 m_session = nullptr;
74 return;
75 }
76
77 m_session = m_service->session();
78 Q_ASSERT(m_session);
79
80 m_session->setActiveCamera(m_cameraDevice);
81 m_session->setCameraFormat(m_cameraFormat);
82 m_session->setActive(m_active);
83}
84
85#include "moc_avfcamera_p.cpp"
QCamera * camera
AVFCameraSession * session() const
void onCameraDeviceChanged(const QCameraDevice &, const QCameraFormat &) override
Definition avfcamera.mm:31
void setCaptureSession(QPlatformMediaCaptureSession *) override
Definition avfcamera.mm:59
bool tryApplyCameraFormat(const QCameraFormat &) override
Definition avfcamera.mm:50
q23::expected< void, QString > onActiveChanged(bool active) override
Definition avfcamera.mm:24
The QCamera class provides interface for system camera devices.
Definition qcamera.h:25