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
17 : QAVFCameraBase(camera)
18{
19 Q_ASSERT(camera);
20}
21
22AVFCamera::~AVFCamera() = default;
23
24void AVFCamera::onActiveChanged(bool active)
25{
26 if (m_session)
27 m_session->setActive(active);
28}
29
31 const QCameraDevice &newCameraDevice,
32 const QCameraFormat &newFormat)
33{
34 // The incoming format should never be null if the incoming device is not null.
35 Q_ASSERT(newCameraDevice.isNull() || !newFormat.isNull());
36
37 if (newCameraDevice.isNull() || !checkCameraPermission())
38 return;
39
40 if (m_session) {
41 // TODO: In the future, we should pass the new format into setActiveCamera,
42 // and determine if we can keep the camera-stream active with the new
43 // device + format. Then we should propagate any errors up the call stack.
44 m_session->setActiveCamera(newCameraDevice);
45 m_session->setCameraFormat(newFormat);
46 }
47}
48
49bool AVFCamera::tryApplyCameraFormat(const QCameraFormat &newFormat)
50{
51 // TODO: In the future, we should be able to return false if we failed
52 // to apply the format.
53 if (m_session)
54 m_session->setCameraFormat(newFormat);
55 return true;
56}
57
58void AVFCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
59{
60 AVFCameraService *captureSession = static_cast<AVFCameraService *>(session);
61 if (m_service == captureSession)
62 return;
63
64 if (m_session) {
65 m_session->disconnect(this);
66 m_session->setActiveCamera({});
67 m_session->setCameraFormat({});
68 }
69
70 m_service = captureSession;
71 if (!m_service) {
72 m_session = nullptr;
73 return;
74 }
75
76 m_session = m_service->session();
77 Q_ASSERT(m_session);
78
79 m_session->setActiveCamera(m_cameraDevice);
80 m_session->setCameraFormat(m_cameraFormat);
81 m_session->setActive(m_active);
82}
83
84#include "moc_avfcamera_p.cpp"
AVFCameraSession * session() const
void onCameraDeviceChanged(const QCameraDevice &, const QCameraFormat &) override
Definition avfcamera.mm:30
void onActiveChanged(bool active) override
Definition avfcamera.mm:24
void setCaptureSession(QPlatformMediaCaptureSession *) override
Definition avfcamera.mm:58
bool tryApplyCameraFormat(const QCameraFormat &) override
Definition avfcamera.mm:49
The QCamera class provides interface for system camera devices.
Definition qcamera.h:25