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