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#define AVMediaType XAVMediaType
24#include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_p.h>
25#undef AVMediaType
26#include <QtFFmpegMediaPluginImpl/private/qavfsamplebufferdelegate_p.h>
27
28#include <QtMultimedia/private/qavfcamerautility_p.h>
29
30#import <AVFoundation/AVFoundation.h>
31#include <dispatch/dispatch.h>
32
33QT_BEGIN_NAMESPACE
34
35namespace QFFmpeg {
36
38{
40
41public:
42 explicit QAVFCamera(QCamera &parent);
43 ~QAVFCamera();
44
45 void setCaptureSession(QPlatformMediaCaptureSession *) override;
46
47 std::optional<int> ffmpegHWPixelFormat() const override;
48
49 int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat pixelFmt,
50 QVideoFrameFormat::ColorRange colorRange) const override;
51
52 QVideoFrameFormat frameFormat() const override;
53
54protected:
55 void onActiveChanged(bool active) override;
56 void onCameraDeviceChanged(const QCameraDevice &device) override;
57 bool tryApplyCameraFormat(const QCameraFormat&) override;
58
59private:
60 void clearAvCaptureSessionInputDevice();
61 [[nodiscard]] q23::expected<void, QString> setupAvCaptureSessionInputDevice(AVCaptureDevice *);
62 void clearAvCaptureVideoDataOutput();
63 [[nodiscard]] q23::expected<void, QString> setupAvCaptureVideoDataOutput(AVCaptureDevice *);
64 [[nodiscard]] q23::expected<void, QString> tryApplyFormatToCaptureSession(
65 AVCaptureDevice *,
66 AVCaptureDeviceFormat *,
67 const QCameraFormat &);
68 void clearRotationTracking();
69 void setupRotationTracking(AVCaptureDevice *);
70 void clearCaptureSessionConfiguration();
71 [[nodiscard]] q23::expected<void, QString> tryConfigureCaptureSession(
72 const QCameraDevice &,
73 const QCameraFormat &);
74 [[nodiscard]] q23::expected<void, QString> tryConfigureCaptureSession(
75 AVCaptureDevice *,
76 const QCameraFormat &);
77 [[nodiscard]] q23::expected<void, QString> tryConfigureCaptureSession(
78 AVCaptureDevice *,
79 AVCaptureDeviceFormat *,
80 const QCameraFormat &);
81
82 [[nodiscard]] QSize adjustedResolution(const QCameraFormat& format) const;
83
84 [[nodiscard]] int getCurrentRotationAngleDegrees() const;
85
86 QMediaCaptureSession *m_qMediaCaptureSession = nullptr;
87 AVCaptureSession *m_avCaptureSession = nullptr;
88 AVCaptureDeviceInput *m_avCaptureDeviceVideoInput = nullptr;
89 AVCaptureVideoDataOutput *m_avCaptureVideoDataOutput = nullptr;
90 QAVFSampleBufferDelegate *m_qAvfSampleBufferDelegate = nullptr;
91 AVPixelFormat m_hwPixelFormat = AV_PIX_FMT_NONE;
92 // The current CVPixelFormat used by the AVCaptureVideoDataOutput.
93 // This can in some cases be different from the AVCaptureDeviceFormat
94 // used by the camera.
95 uint32_t m_cvPixelFormat = 0;
96
97 std::optional<QFFmpeg::AvfCameraRotationTracker> m_qAvfCameraRotationTracker;
98
99 AVFScopedPointer<dispatch_queue_t> m_delegateQueue;
100};
101
102} // namespace QFFmpeg
103
104QT_END_NAMESPACE
105
106#endif // QAVFCAMERA_P_H
bool tryApplyCameraFormat(const QCameraFormat &) override
std::optional< int > ffmpegHWPixelFormat() const override
QVideoFrameFormat frameFormat() const override
int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat pixelFmt, QVideoFrameFormat::ColorRange colorRange) const override
void onActiveChanged(bool active) override
void onCameraDeviceChanged(const QCameraDevice &device) override
void setCaptureSession(QPlatformMediaCaptureSession *) override
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType