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 <QtMultimedia/private/qavfcameradebug_p.h>
5#include "avfcamera_p.h"
8#include <QtMultimedia/private/qavfcamerautility_p.h>
10#include <qmediacapturesession.h>
11
12QT_USE_NAMESPACE
13
15 : QAVFCameraBase(camera)
16{
17 Q_ASSERT(camera);
18}
19
20AVFCamera::~AVFCamera() = default;
21
22void AVFCamera::onActiveChanged(bool active)
23{
24 if (m_session)
25 m_session->setActive(active);
26}
27
28void AVFCamera::onCameraDeviceChanged(const QCameraDevice &device)
29{
30 if (device.isNull() || !checkCameraPermission())
31 return;
32
33 if (m_session)
34 m_session->setActiveCamera(m_cameraDevice);
35}
36
37bool AVFCamera::tryApplyCameraFormat(const QCameraFormat &newFormat)
38{
39 // TODO: In the future, we should be able to return false if we failed
40 // to apply the format.
41 if (m_session)
42 m_session->setCameraFormat(newFormat);
43 return true;
44}
45
46void AVFCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
47{
48 AVFCameraService *captureSession = static_cast<AVFCameraService *>(session);
49 if (m_service == captureSession)
50 return;
51
52 if (m_session) {
53 m_session->disconnect(this);
54 m_session->setActiveCamera({});
55 m_session->setCameraFormat({});
56 }
57
58 m_service = captureSession;
59 if (!m_service) {
60 m_session = nullptr;
61 return;
62 }
63
64 m_session = m_service->session();
65 Q_ASSERT(m_session);
66
67 m_session->setActiveCamera(m_cameraDevice);
68 m_session->setCameraFormat(m_cameraFormat);
69 m_session->setActive(m_active);
70}
71
72#include "moc_avfcamera_p.cpp"
AVFCameraSession * session() const
void onActiveChanged(bool active) override
Definition avfcamera.mm:22
bool tryApplyCameraFormat(const QCameraFormat &) override
Definition avfcamera.mm:37
The QCamera class provides interface for system camera devices.
Definition qcamera.h:25