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
qavfcamera_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QAVFCAMERA_P_H
5#define QAVFCAMERA_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 <QtMultimedia/private/qavfcamerabase_p.h>
19
20#include <QtCore/private/qexpected_p.h>
21
22#include <QtFFmpegMediaPluginImpl/private/qavfcamerarotationtracker_p.h>
23#include <QtFFmpegMediaPluginImpl/private/qavfcapturephotooutputdelegate_p.h>
24#include <QtFFmpegMediaPluginImpl/private/qavfsamplebufferdelegate_p.h>
25#define AVMediaType XAVMediaType
26#include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_p.h>
27#undef AVMediaType
28
29#include <QtMultimedia/private/qavfcamerautility_p.h>
30#include <QtMultimedia/private/qplatformmediacapture_p.h>
31#include <QtMultimedia/qimagecapture.h>
32
33#import <dispatch/dispatch.h>
34
35#include <optional>
36
37QT_BEGIN_NAMESPACE
38
39namespace QFFmpeg {
40
42{
44
45public:
46 explicit QAVFCamera(QCamera &parent);
47 ~QAVFCamera();
48
49 void setCaptureSession(QPlatformMediaCaptureSession *) override;
50
51 std::optional<int> ffmpegHWPixelFormat() const override;
52
53 int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat pixelFmt,
54 QVideoFrameFormat::ColorRange colorRange) const override;
55
56 QVideoFrameFormat frameFormat() const override;
57
59
62 void stillPhotoFailed(QImageCapture::Error error, QString errorMsg);
63
64protected:
65 void onActiveChanged(bool active) override;
66 void onCameraDeviceChanged(const QCameraDevice &, const QCameraFormat &) override;
67 bool tryApplyCameraFormat(const QCameraFormat&) override;
68
69private:
70 void clearAvCaptureSessionInputDevice();
71 [[nodiscard]] q23::expected<void, QString> setupAvCaptureSessionInputDevice(AVCaptureDevice *);
72 void clearAvCaptureVideoDataOutput();
73 [[nodiscard]] q23::expected<void, QString> setupAvCaptureVideoDataOutput(AVCaptureDevice *);
74 [[nodiscard]] q23::expected<void, QString> tryApplyFormatToCaptureSession(
75 AVCaptureDevice *,
76 AVCaptureDeviceFormat *,
77 const QCameraFormat &);
78 void clearRotationTracking();
79 void setupRotationTracking(AVCaptureDevice *);
80 void clearCaptureSessionConfiguration();
81 [[nodiscard]] q23::expected<void, QString> tryConfigureCaptureSession(
82 const QCameraDevice &,
83 const QCameraFormat &);
84 [[nodiscard]] q23::expected<void, QString> tryConfigureCaptureSession(
85 AVCaptureDevice *,
86 const QCameraFormat &);
87 [[nodiscard]] q23::expected<void, QString> tryConfigureCaptureSession(
88 AVCaptureDevice *,
89 AVCaptureDeviceFormat *,
90 const QCameraFormat &);
91
92 void onStillPhotoDelegateSucceeded(const QVideoFrame &image);
93 void onStillPhotoDelegateFailed(QImageCapture::Error errType, const QString &errMsg);
94
95 [[nodiscard]] QSize adjustedResolution(const QCameraFormat& format) const;
96
97 [[nodiscard]] int getCurrentRotationAngleDegrees() const;
98
99 QMediaCaptureSession *m_qMediaCaptureSession = nullptr;
100 AVCaptureSession *m_avCaptureSession = nullptr;
101 AVFScopedPointer<AVCapturePhotoOutput> m_avCapturePhotoOutput;
102 AVCaptureDeviceInput *m_avCaptureDeviceVideoInput = nullptr;
103 AVCaptureVideoDataOutput *m_avCaptureVideoDataOutput = nullptr;
104 QAVFSampleBufferDelegate *m_qAvfSampleBufferDelegate = nullptr;
105 AVPixelFormat m_hwPixelFormat = AV_PIX_FMT_NONE;
106 // The current CVPixelFormat used by the AVCaptureVideoDataOutput.
107 // This can in some cases be different from the AVCaptureDeviceFormat
108 // used by the camera.
109 uint32_t m_cvPixelFormat = 0;
110
111 std::optional<QFFmpeg::AvfCameraRotationTracker> m_qAvfCameraRotationTracker;
112
113 // Will be non-null whenever a still photo is in progress.
114 //
115 // TODO: It can be problematic if we change QMediaCaptureSession in the midst of a capture.
116 // We might end up signaling a different QImageCapture than the one that requested
117 // the capture. We should likely cancel any on-going still photo captures when this
118 // happens.
119 AVFScopedPointer<QT_MANGLE_NAMESPACE(QAVFCapturePhotoOutputDelegate)> m_qAvfCapturePhotoOutputDelegate;
120 [[nodiscard]] bool stillPhotoCaptureInProgress() const
121 {
122 return m_qAvfCapturePhotoOutputDelegate.data();
123 }
124
125 AVFScopedPointer<dispatch_queue_t> m_delegateQueue;
126};
127
128} // namespace QFFmpeg
129
130QT_END_NAMESPACE
131
132#endif // QAVFCAMERA_P_H
q23::expected< void, QString > requestStillPhotoCapture()
bool tryApplyCameraFormat(const QCameraFormat &) override
std::optional< int > ffmpegHWPixelFormat() const override
QVideoFrameFormat frameFormat() const override
void stillPhotoFailed(QImageCapture::Error error, QString errorMsg)
int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat pixelFmt, QVideoFrameFormat::ColorRange colorRange) const override
void onActiveChanged(bool active) override
void onCameraDeviceChanged(const QCameraDevice &, const QCameraFormat &) override
void setCaptureSession(QPlatformMediaCaptureSession *) override
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType