diff options
author | Artem Dyomin <artem.dyomin@qt.io> | 2024-01-18 09:53:08 +0100 |
---|---|---|
committer | Artem Dyomin <artem.dyomin@qt.io> | 2024-01-21 17:54:21 +0000 |
commit | 2d19467fba0f2ad72d033cfd9b7230cc78d65b7a (patch) | |
tree | ffd4144b612ccd70a079b8f5c1ba510a1048966f /src/multimedia/platform | |
parent | b2b1d2b1784cb0af37e0d9b9b128f6d44bdbf30e (diff) |
Implement lazy initialization of VideoDevices
As we extend the usage of QPlatformMediaIntegration, adding it in
QSoundEffect, we should make the initialization of not necessary
things lazy.
VideoDevices might run their own cameras tracking pipeline, so we fix
video devices firstly.
Pick-to: 6.7 6.6 6.5
Change-Id: I8e447452b4b02247c0708569539d7f9c35b47799
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia/platform')
-rw-r--r-- | src/multimedia/platform/qplatformmediaintegration.cpp | 10 | ||||
-rw-r--r-- | src/multimedia/platform/qplatformmediaintegration_p.h | 10 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/multimedia/platform/qplatformmediaintegration.cpp b/src/multimedia/platform/qplatformmediaintegration.cpp index 1fe5e1cd1..5abed10f4 100644 --- a/src/multimedia/platform/qplatformmediaintegration.cpp +++ b/src/multimedia/platform/qplatformmediaintegration.cpp @@ -121,7 +121,8 @@ void QPlatformMediaIntegration::setPlatformFactory(Factory factory) QList<QCameraDevice> QPlatformMediaIntegration::videoInputs() { - return m_videoDevices ? m_videoDevices->videoDevices() : QList<QCameraDevice>{}; + auto devices = videoDevices(); + return devices ? devices->videoDevices() : QList<QCameraDevice>{}; } QMaybe<QPlatformAudioInput *> QPlatformMediaIntegration::createAudioInput(QAudioInput *q) @@ -158,6 +159,13 @@ QPlatformMediaFormatInfo *QPlatformMediaIntegration::createFormatInfo() return new QPlatformMediaFormatInfo; } +QPlatformVideoDevices *QPlatformMediaIntegration::videoDevices() +{ + std::call_once(m_videoDevicesOnceFlag, + [this]() { m_videoDevices.reset(createVideoDevices()); }); + return m_videoDevices.get(); +} + QPlatformMediaIntegration::QPlatformMediaIntegration() = default; QPlatformMediaIntegration::~QPlatformMediaIntegration() = default; diff --git a/src/multimedia/platform/qplatformmediaintegration_p.h b/src/multimedia/platform/qplatformmediaintegration_p.h index 3fc97a1ce..6755797d9 100644 --- a/src/multimedia/platform/qplatformmediaintegration_p.h +++ b/src/multimedia/platform/qplatformmediaintegration_p.h @@ -82,11 +82,13 @@ public: QList<QCapturableWindow> capturableWindows(); bool isCapturableWindowValid(const QCapturableWindowPrivate &); - QPlatformVideoDevices *videoDevices() { return m_videoDevices.get(); } + QPlatformVideoDevices *videoDevices(); protected: virtual QPlatformMediaFormatInfo *createFormatInfo(); + virtual QPlatformVideoDevices *createVideoDevices() { return nullptr; } + private: friend class QMockIntegrationFactory; // API to be able to test with a mock backend @@ -95,9 +97,13 @@ private: static void setPlatformFactory(Factory factory); protected: - std::unique_ptr<QPlatformVideoDevices> m_videoDevices; + // TODO: initialize via once_flag and move to private std::unique_ptr<QPlatformCapturableWindows> m_capturableWindows; +private: + std::unique_ptr<QPlatformVideoDevices> m_videoDevices; + std::once_flag m_videoDevicesOnceFlag; + mutable std::unique_ptr<QPlatformMediaFormatInfo> m_formatInfo; mutable std::once_flag m_formatInfoOnceFlg; }; |