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
qandroidcamera.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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#include <QtFFmpegMediaPluginImpl/private/qandroidcamera_p.h>
5
6#include <jni.h>
7
8#include <android/hardware_buffer.h>
9
10#include <atomic>
11#include <future>
12#include <limits>
13#include <memory>
14#include <mutex>
15#include <optional>
16
17#include <QtCore/qdebug.h>
18#include <QtCore/qloggingcategory.h>
19#include <QtCore/qmetaobject.h>
20#include <QtCore/qmutex.h>
21#include <QtCore/qpermissions.h>
22#include <QtCore/private/qandroidextras_p.h>
23
24#include <QtGui/qguiapplication.h>
25#include <QtGui/qscreen.h>
26
27#include <QtFFmpegMediaPluginImpl/private/qandroidimageregistry_p.h>
28#include <QtFFmpegMediaPluginImpl/private/qandroidvideoframefactory_p.h>
29#include <QtFFmpegMediaPluginImpl/private/qffmpegmediacapturesession_p.h>
30#include <QtFFmpegMediaPluginImpl/private/qffmpegvideobuffer_p.h>
31
32#include <QtMultimedia/private/qcameradevice_p.h>
33#include <QtMultimedia/private/qmultimediautils_p.h>
34
35extern "C" {
36#include "libavutil/hwcontext.h"
37}
38
40Q_STATIC_LOGGING_CATEGORY(qLCAndroidCamera, "qt.multimedia.ffmpeg.androidCamera");
41
42Q_DECLARE_JNI_CLASS(QtCameraActivation,
43 "org/qtproject/qt/android/multimedia/qffmpeg/QtCameraActivation")
44
45using namespace Qt::Literals::StringLiterals;
46
47// Typed so that callMethod() passes an android.view.Surface, matching prepareCamera().
48Q_DECLARE_JNI_CLASS(Surface, "android/view/Surface")
49
50namespace {
51
53{
54public:
55 using Result = q23::expected<void, QString>;
56
57 [[nodiscard]] std::future<Result> getFuture()
58 {
59 return m_promise.get_future();
60 }
61
62 void setResult(Result result)
63 {
64 [[maybe_unused]] bool wasSet = m_resultSet.exchange(true);
65 Q_ASSERT_X(!wasSet, "QAndroidCameraActivation::setResult",
66 "The result of a camera activation must only be set once");
67 m_promise.set_value(std::move(result));
68 }
69
70private:
71 std::promise<Result> m_promise;
72 std::atomic<bool> m_resultSet = false;
73};
74
75// The Java object owns a heap-allocated reference, released by onActivationFinished().
76[[nodiscard]] QtJniTypes::QtCameraActivation
77createJavaActivation(const std::shared_ptr<QAndroidCameraActivation> &activation)
78{
79 auto *activationRef = new std::shared_ptr<QAndroidCameraActivation>(activation);
80 QtJniTypes::QtCameraActivation javaActivation(
81 static_cast<jlong>(reinterpret_cast<uintptr_t>(activationRef)));
82 if (!javaActivation.isValid())
83 delete activationRef;
84 return javaActivation;
85}
86
87// TODO: Unify format selection with cross-platform layer
88QCameraFormat getDefaultCameraFormat(const QCameraDevice & cameraDevice)
89{
90 // default settings
91 const auto defaultFrameFormat = QVideoFrameFormat::Format_YUV420P;
92 const auto defaultResolution = QSize(1920, 1080);
93 QCameraFormatPrivate *defaultFormat = new QCameraFormatPrivate{
94 .pixelFormat = defaultFrameFormat,
95 .resolution = defaultResolution,
96 .minFrameRate = 12,
97 .maxFrameRate = 30,
98 };
99
100 QCameraFormat resultFormat = defaultFormat->create();
101 const auto &supportedFormats = cameraDevice.videoFormats();
102
103 if (supportedFormats.empty() || supportedFormats.contains(resultFormat))
104 return resultFormat;
105
106 auto pixelCount = [](const QSize& resolution) {
107 Q_ASSERT(resolution.isValid());
108 return resolution.width() * resolution.height();
109 };
110
111 const int defaultPixelCount = pixelCount(defaultResolution);
112
113 // The lower the score, the better the format suits
114 int differenceScore = std::numeric_limits<int>::max();
115
116 auto calcDifferenceScore = [defaultPixelCount, pixelCount](const QCameraFormat& format) {
117 const int pixelDifference = pixelCount(format.resolution()) - defaultPixelCount;
118 // prefer:
119 // 1. 'pixels count >= default' over 'pixels count < default'
120 // 2. lower abs(pixelDifference)
121 return pixelDifference < 0
122 ? -pixelDifference
123 : std::numeric_limits<int>::min() + pixelDifference;
124 };
125
126 for (const auto &supportedFormat : supportedFormats) {
127 if (supportedFormat.pixelFormat() == defaultFrameFormat) {
128 if (supportedFormat.resolution() == defaultResolution)
129 return supportedFormat;
130
131 const int currentDifferenceScore = calcDifferenceScore(supportedFormat);
132
133 if (currentDifferenceScore < differenceScore) {
134 differenceScore = currentDifferenceScore;
135 resultFormat = supportedFormat;
136 }
137 }
138 }
139
140 return resultFormat;
141}
142
144{
145 QCameraPermission permission;
146
147 const bool granted = qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
148 if (!granted)
149 qCWarning(qLCAndroidCamera) << "Access to camera not granted!";
150
151 return granted;
152}
153
154int sensorOrientation(QString cameraId)
155{
156 QJniObject deviceManager(QtJniTypes::Traits<QtJniTypes::QtVideoDeviceManager>::className(),
157 QNativeInterface::QAndroidApplication::context());
158
159 if (!deviceManager.isValid()) {
160 qCWarning(qLCAndroidCamera) << "Failed to connect to Qt Video Device Manager.";
161 return 0;
162 }
163
164 return deviceManager.callMethod<jint>("getSensorOrientation",
165 QJniObject::fromString(cameraId).object<jstring>());
166}
167
168// Returns the FocusModes that are available on the physical device, for which we also have
169// an implementation.
171 const QJniObject &deviceManager,
172 const QCameraDevice &cameraDevice)
173{
174 QList<QCamera::FocusMode> returnValue;
175
176 const QStringList focusModeStrings = deviceManager.callMethod<QStringList>(
177 "getSupportedQCameraFocusModesAsStrings",
178 QJniObject::fromString(QString::fromUtf8(cameraDevice.id())).object<jstring>());
179
180 // Translate the strings into enums if possible.
181 for (const QString &focusModeString : focusModeStrings) {
182 bool ok = false;
183 const auto focusMode = static_cast<QCamera::FocusMode>(
184 QMetaEnum::fromType<QCamera::FocusMode>()
185 .keyToValue(
186 focusModeString.toLatin1().data(),
187 &ok));
188 if (ok)
189 returnValue.push_back(focusMode);
190 else
191 qCDebug(qLCAndroidCamera) <<
192 "received a QCamera::FocusMode string from Android "
193 "QtVideoDeviceManager.java that was not recognized.";
194 }
195
196 return returnValue;
197}
198
199} // namespace
200
201namespace QFFmpeg {
202
203// The preview sink can run after QAndroidImageReader::setSink({}) has returned, so it cannot
204// capture the camera directly. It locks the mutex and checks the camera pointer instead; the
205// camera clears the pointer under the same mutex before it is destroyed.
211
212// QAndroidCamera
213
236
238{
239 // Flush queued events / frames and clear the reference back to this
240 // this instance. Blocking call.
241 m_jniCamera.callMethod<void>("destroy");
242 {
244 m_previewTarget->camera = nullptr;
245 }
248}
249
251{
252 const bool oldActive = isActive();
253 if (oldActive)
254 setActive(false);
255
256 // Reset all our control-members on the Java-side to default
257 // values. Then populate them again during updateCameraCharacteristics()
258 m_jniCamera.callMethod<void>("resetControlProperties");
259
263
264 if (oldActive)
265 setActive(true);
266}
267
269{
270 // Camera2 delivers YUV_420_888, a flexible format whose memory layout (YUV420P, NV12 or NV21)
271 // is chosen by the camera HAL. The layout can't be queried ahead of time, so we can't know
272 // the frame format until we receive the actual frame. We leave the format invalid, so that
273 // the recorder won't set anything up until it receives the first frame.
274 return {};
275}
276
277bool QAndroidCamera::acceptsFrames() const
278{
279 return m_state != State::Closed;
280}
281
282// Called by the Java-side processing background thread.
284{
285 // Frames may arrive while activating, before activeChanged(true). The capture session
286 // is connected ahead of time by onSourceActivating(), so they are not lost.
287 if (!acceptsFrames() || m_frameFactory == nullptr) {
288 image.callMethod<void>("close");
289 return;
290 }
291
293 if (!videoFrame.isValid())
294 return;
295
297}
298
300{
302
303 if (!takePhoto)
305 else
307}
308
310{
311 // If the camera is not attached to the main display, we don't want to apply rotation
312 // based on primary screen. We assume we are an external camera.
316 return QtVideo::Rotation::None;
317
322
323 // Display rotation is the opposite direction of the physical device rotation. We need the
324 // device rotation, that's why Landscape is 270 and InvertedLandscape is 90
325 int deviceOrientation = 0;
326 switch (screenOrientation) {
329 break;
331 deviceOrientation = 270;
332 break;
334 deviceOrientation = 180;
335 break;
338 break;
339 }
340
341 const int sign = (cameraPosition == QCameraDevice::Position::FrontFace) ? 1 : -1;
343 - deviceOrientation * sign + 360) % 360;
344
345 return QtVideo::Rotation(rotation);
346}
347
349{
351 if (isActive() == active)
352 return;
353
354 if (!m_jniCamera.isValid()) {
355 updateError(QCamera::CameraError, QStringLiteral("No connection to Android Camera2 API"));
356 return;
357 }
358
359 if (!active || !checkCameraPermission()) {
360 m_jniCamera.callMethod<void>("stopAndClose");
361 m_jniCamera.callMethod<void>("clearSurfaces");
364 return;
365 }
366
367 // Connect the capture session ahead of time, so frames delivered while activating
368 // are not dropped.
369 if (m_session)
371
373 if (!result) {
374 m_jniCamera.callMethod<void>("stopAndClose");
377 if (m_session)
380 return;
381 }
382
384}
385
391
393{
397
398 if (width < 0 || height < 0) {
402 }
403
406
408
409 // Create frameFactory when ImageReader is created;
411
417 if (!m_imageRegistry) {
419 return q23::unexpected{ u"Failed to create preview image reader"_s };
420 }
421
422 // The sink captures the registry, which holds the reader, which holds the sink. The cycle is
423 // broken by releaseImageReader().
426 // Wrapping the image first makes its slot close it on every path below.
428
431 if (!camera || !camera->acceptsFrames()) {
432 qCWarning(qLCAndroidCamera) << "Received preview frame when not active... ignoring";
433 return;
434 }
435
437 if (!videoFrame.isValid())
438 return;
439
442 });
443
444 // Most supported format combination for ImageReaders in a session is YUV_420_888 for
445 // preview/video, and JPEG for stills
446 // TODO: Set session combinations based on device capabilities:
447 // https://developer.android.com/reference/android/hardware/camera2/CameraDevice#regular-capture
449 // A plain QJniObject argument would be deduced as java.lang.Object, which does not match the
450 // android.view.Surface parameter of prepareCamera().
451 m_jniCamera.callMethod<void>("prepareCamera", static_cast<jint>(m_cameraFormat.minFrameRate()),
452 static_cast<jint>(m_cameraFormat.maxFrameRate()),
454 static_cast<jint>(m_stillReaderSize.width()),
455 static_cast<jint>(m_stillReaderSize.height()));
456
459
461 if (!javaActivation.isValid()) {
462 qCWarning(qLCAndroidCamera) << "Failed to create QtCameraActivation";
463 return q23::unexpected{ u"Failed to start camera"_s };
464 }
465
466 // Callbacks from the Java-side background thread must never wait for this thread.
468
469 // Assumes the Java side always reports a result.
470 return result.get();
471}
472
473// Call after stopAndClose(). Frames still in use keep the reader alive through their leases.
475{
476 if (m_imageReader)
478 if (m_imageRegistry)
482}
483
484// TODO: setState is currently being used by the C++ thread owning
485// the QCamera object, and the Java-side capture-processing background thread.
486// This can lead to race conditions and the m_state ending up in inconsistent states.
487// We should have a synchronization strategy in the future.
489{
490 if (newState == m_state)
491 return;
492
493 bool wasActive = isActive();
495
496 if (wasActive != isActive())
498}
499
501{
503
505 return true;
507 return false;
508
510
512
513 return true;
514}
515
517{
518 if (m_cameraDevice.id().isEmpty()) {
520 return;
521 }
522
525
526 if (!deviceManager.isValid()) {
527 qCWarning(qLCAndroidCamera) << "Failed to connect to Qt Video Device Manager.";
529 return;
530 }
531
532
533 // Gather capabilities.
535
536 float newMaxZoom = 1.f;
537 float newMinZoom = 1.f;
539 "getZoomRange",
541 if (newZoomRange.isValid() && newZoomRange.size() == 2) {
544 } else {
546 "received invalid float array when querying zoomRange from Android Camera2. "
547 "Likely Qt developer bug";
548 }
549
553 "getSupportedFlashModes",
555 for (const auto &flashMode : flashModes) {
556 if (flashMode == QLatin1String("auto"))
558 else if (flashMode == QLatin1String("on"))
560 }
561
563 "isTorchModeSupported",
565
569
572
573
574 // Signal capability changes
578
579
580 // Apply properties
581 if (minZoomFactor() < maxZoomFactor()) {
582 // New device supports zooming. Clamp it and apply it to new camera device.
585 }
586
589
592
595
596
597 // Reset properties if needed.
598 if (minZoomFactor() >= maxZoomFactor())
600
603
606
609}
610
611// Should only be called when the camera device is set to null.
613{
615 if (zoomFactor() != 1.0) {
616 zoomTo(1.0, -1.0);
617 }
618 if (torchMode() != QCamera::TorchOff) {
620 }
621 m_TorchModeSupported = false;
622
623 if (flashMode() != QCamera::FlashOff) {
625 }
628
629
630 // Reset focus mode.
634
636}
637
639{
641 return m_videoResolution; // Not set, will use video resolution
642
644
645 // Use as-is with empty list, might fail
648
650}
651
652// Restart camera now, must be called from owning thread
654{
655 if (!isActive())
656 return;
657
658 setActive(false);
659 setActive(true);
660}
661
662// Queue a camera restart, can be called from a background Java thread
664{
665 if (m_restartPending.exchange(true))
666 return;
667
668 // NOTE: Queued on event loop to avoid re-entering onVideoSourceChanged
670 this,
671 [this]() {
672 m_restartPending = false;
673 restartCamera(); // No-op if inactive
674 },
676}
677
679{
681 return;
682
685 Q_FUNC_INFO <<
686 "attmpted to set focus-distance on camera without support for FocusDistance feature";
687 return;
688 }
689
690 if (distance < 0 || distance > 1) {
692 Q_FUNC_INFO <<
693 "attempted to set camera focus-distance with out-of-bounds value";
694 return;
695 }
696
697 // focusDistance should only be applied if the focusMode is currently set to Manual.
698 // The Java function will handle this behavior. Either way, the value should be accepted so
699 // we can apply it if FocusModeManual is activated
700 m_jniCamera.callMethod<void>("setFocusDistance", distance);
701
703}
704
706{
707 if (focusMode() == mode)
708 return;
709
712 Q_FUNC_INFO <<
713 QLatin1String("attempted to set focus-mode '%1' on camera where it is unsupported.")
715 return;
716 }
717
718 // If the new focus-mode is Manual, then the focusDistance
719 // needs to be applied as well. The Java function handles this.
721 "setFocusMode",
722 static_cast<jint>(mode));
723
725}
726
728{
730 return;
731
733 switch (mode) {
734 case QCamera::FlashAuto:
735 flashMode = QLatin1String("auto");
736 break;
737 case QCamera::FlashOn:
738 flashMode = QLatin1String("on");
739 break;
740 case QCamera::FlashOff:
741 default:
742 flashMode = QLatin1String("off");
743 break;
744 }
745
748}
749
754
756{
757 // Android doesn't have an API for that.
758 // Only check if device supports more flash modes than just FlashOff.
759 return m_supportedFlashModes.size() > 1;
760}
761
766
768{
769 if (mode == QCamera::TorchOff)
770 return true;
771 else if (mode == QCamera::TorchOn)
773
774 return false;
775}
776
778{
779 bool torchMode;
780 if (mode == QCamera::TorchOff) {
781 torchMode = false;
782 } else if (mode == QCamera::TorchOn) {
783 torchMode = true;
784 } else {
785 qWarning() << "Unknown Torch mode";
786 return;
787 }
788 m_jniCamera.callMethod<void>("setTorchMode", jboolean(torchMode));
790}
791
792void QAndroidCamera::zoomTo(float factor, float rate)
793{
794 Q_UNUSED(rate);
795
796 if (!m_cameraDevice.id().isEmpty()) {
797 m_jniCamera.callMethod<void>("zoomTo", factor);
798 }
800}
801
803{
806 if (isActive()) {
807 setActive(false);
808 m_wasActive = true;
809 }
810 break;
811 case Qt::ApplicationActive:
812 if (m_wasActive) {
813 setActive(true);
814 m_wasActive = false;
815 }
816 break;
817 default:
818 break;
819 }
820}
821
822// Called by Java-side processing background thread.
824{
825 bool canStart = m_jniCamera.callMethod<jboolean>("start");
826 // While activating, Java reports the failure to the pending activation instead.
827 if (!canStart && isActive())
829}
830
831// Called by Java-side processing background thread.
836
837// Called by Java-side processing background thread.
838// The session rebuilt for a new still reader size failed. Fall back to a full restart.
843
844// Called by Java-side processing background thread.
846{
847 // Failures are reported to the pending activation by Java.
848 m_jniCamera.callMethod<jboolean>("createSession");
849}
850
851// Called by Java-side processing background thread.
856
857// Called by Java-side processing background thread.
859{
861 QString(u"Capture error with Camera %1. Camera2 Api error code: %2")
863 .arg(reason));
864}
865
866// Called by Java-side processing background thread.
871
873{
874 m_jniCamera.callMethod<void>("beginStillPhotoCapture");
875}
876
878{
879 m_jniCamera.callMethod<void>("saveExifToFile", QJniObject::fromString(filename).object<jstring>());
880}
881
883{
885
888 qCWarning(qLCAndroidCamera) << "Image capture resolution set to" << resolution
889 << "while list of valid photo resolutions is empty. Image "
890 "capture can fail if resolution is not supported by device.";
891 }
894}
895
897{
899
900 const QSize newSize = stillResolution();
901 // Not started: the next start uses the new size or re-runs this, see frameAvailable()
903 return;
904
905 if (m_jniCamera.callMethod<jboolean>("updateStillImageReader", newSize.width(),
906 newSize.height())) {
908 return;
909 }
910
912}
913
915{
917
919 QStringLiteral("Capture session failure with Camera %1. Camera2 Api error code: %2")
921 .arg(reason));
922}
923
924// Called by Java background thread if the on-going still-photo capture fails.
926{
927 // TODO: Emit a more descriptive error signal. At the time of writing, there is no
928 // suitable QImageCapture::Error enumerator for this scenario.
931 QStringLiteral("Unknown error"));
932}
933
934} // namespace QFFmpeg
935
936// JNI logic
937// The following static functions can only be called by the Java-side processing background
938// thread. They all assume that we are currently holding the mutex protecting the
939// QAndroidCamera reference on the Java-side.
940
941namespace {
942
943[[nodiscard]] QFFmpeg::QAndroidCamera& jLongToQAndroidCamera(jlong input)
944{
945 Q_ASSERT(input != 0);
946 return *reinterpret_cast<QFFmpeg::QAndroidCamera *>(static_cast<uintptr_t>(input));
947}
948
949} // Anonymous namespace
950
951static void onStillPhotoAvailable(JNIEnv *, jobject, jlong qAndroidCameraPtr,
952 QtJniTypes::Image image)
953{
954 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
955 camera.frameAvailable(QJniObject(image), true);
956}
957Q_DECLARE_JNI_NATIVE_METHOD(onStillPhotoAvailable)
958
959static void onCameraOpened(JNIEnv *, jobject, jlong qAndroidCameraPtr)
960{
961 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
962 camera.onCameraOpened();
963}
964Q_DECLARE_JNI_NATIVE_METHOD(onCameraOpened)
965
966static void onCameraDisconnect(JNIEnv *, jobject, jlong qAndroidCameraPtr)
967{
968 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
969 camera.onCameraDisconnect();
970}
971Q_DECLARE_JNI_NATIVE_METHOD(onCameraDisconnect)
972
973static void onCameraError(JNIEnv *, jobject, jlong qAndroidCameraPtr, jint error)
974{
975 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
976 camera.onCameraError(error);
977}
978Q_DECLARE_JNI_NATIVE_METHOD(onCameraError)
979
980static void onCaptureSessionConfigured(JNIEnv *, jobject, jlong qAndroidCameraPtr)
981{
982 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
983 camera.onCaptureSessionConfigured();
984}
985Q_DECLARE_JNI_NATIVE_METHOD(onCaptureSessionConfigured)
986
987static void onCaptureSessionConfigureFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
988{
989 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
990 camera.onCaptureSessionConfigureFailed();
991}
992Q_DECLARE_JNI_NATIVE_METHOD(onCaptureSessionConfigureFailed)
993
994static void onStillReaderSwapFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
995{
996 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
997 camera.onStillReaderSwapFailed();
998}
999Q_DECLARE_JNI_NATIVE_METHOD(onStillReaderSwapFailed)
1000
1001static void onSessionClosed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
1002{
1003 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
1004 camera.onSessionClosed();
1005}
1006Q_DECLARE_JNI_NATIVE_METHOD(onSessionClosed)
1007
1008static void onCaptureSessionFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr, jint reason,
1009 jlong framenumber)
1010{
1011 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
1012 camera.onCaptureSessionFailed(reason, framenumber);
1013}
1014Q_DECLARE_JNI_NATIVE_METHOD(onCaptureSessionFailed)
1015
1016static void onStillPhotoCaptureFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
1017{
1018 QFFmpeg::QAndroidCamera &camera = jLongToQAndroidCamera(qAndroidCameraPtr);
1019 camera.onStillPhotoCaptureFailed();
1020}
1021Q_DECLARE_JNI_NATIVE_METHOD(onStillPhotoCaptureFailed)
1022
1023// Called once per activation, from any thread.
1024static void onActivationFinished(JNIEnv *, jobject, jlong activationPtr, jboolean success,
1025 QString errorMessage)
1026{
1027 Q_ASSERT(activationPtr != 0);
1028 std::unique_ptr<std::shared_ptr<QAndroidCameraActivation>> activationRef(
1029 reinterpret_cast<std::shared_ptr<QAndroidCameraActivation> *>(
1030 static_cast<uintptr_t>(activationPtr)));
1031
1032 if (success)
1033 (*activationRef)->setResult({});
1034 else
1035 (*activationRef)->setResult(q23::unexpected{ std::move(errorMessage) });
1036}
1037Q_DECLARE_JNI_NATIVE_METHOD(onActivationFinished)
1038
1039bool QFFmpeg::QAndroidCamera::registerNativeMethods()
1040{
1041 static const bool registered = []() {
1042 bool activationRegistered = QtJniTypes::QtCameraActivation::registerNativeMethods({
1043 Q_JNI_NATIVE_METHOD(onActivationFinished),
1044 });
1045 if (!activationRegistered)
1046 return false;
1047
1048 return QtJniCamera2::registerNativeMethods({
1049 Q_JNI_NATIVE_METHOD(onCameraOpened),
1050 Q_JNI_NATIVE_METHOD(onCameraDisconnect),
1051 Q_JNI_NATIVE_METHOD(onCameraError),
1052 Q_JNI_NATIVE_METHOD(onCaptureSessionConfigured),
1053 Q_JNI_NATIVE_METHOD(onCaptureSessionConfigureFailed),
1054 Q_JNI_NATIVE_METHOD(onStillReaderSwapFailed),
1055 Q_JNI_NATIVE_METHOD(onCaptureSessionFailed),
1056 Q_JNI_NATIVE_METHOD(onStillPhotoAvailable),
1057 Q_JNI_NATIVE_METHOD(onSessionClosed),
1058 Q_JNI_NATIVE_METHOD(onStillPhotoCaptureFailed),
1059 });
1060 }();
1061 return registered;
1062}
1063
1064QT_END_NAMESPACE
static void onCaptureSessionFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr, jint reason, jlong framenumber)
static void onCameraOpened(JNIEnv *, jobject, jlong qAndroidCameraPtr)
static void onStillReaderSwapFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
static void onCaptureSessionConfigured(JNIEnv *, jobject, jlong qAndroidCameraPtr)
static void onActivationFinished(JNIEnv *, jobject, jlong activationPtr, jboolean success, QString errorMessage)
static void onCaptureSessionConfigureFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
static void onStillPhotoCaptureFailed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
static void onStillPhotoAvailable(JNIEnv *, jobject, jlong qAndroidCameraPtr, QtJniTypes::Image image)
static void onSessionClosed(JNIEnv *, jobject, jlong qAndroidCameraPtr)
static void onCameraError(JNIEnv *, jobject, jlong qAndroidCameraPtr, jint error)
static void onCameraDisconnect(JNIEnv *, jobject, jlong qAndroidCameraPtr)
int sensorOrientation(QString cameraId)
QtJniTypes::QtCameraActivation createJavaActivation(const std::shared_ptr< QAndroidCameraActivation > &activation)
static QList< QCamera::FocusMode > qGetSupportedFocusModesFromAndroidCamera(const QJniObject &deviceManager, const QCameraDevice &cameraDevice)
QCameraFormat getDefaultCameraFormat(const QCameraDevice &cameraDevice)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)