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
qandroidmultimediautils.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
6
7#include <qlist.h>
8#include <QtCore/qcoreapplication.h>
9#include <QtCore/qpermissions.h>
10#include <QtCore/private/qandroidextras_p.h>
11
13
14int qt_findClosestValue(const QList<int> &list, int value)
15{
16 if (list.size() < 2)
17 return 0;
18
19 int begin = 0;
20 int end = list.size() - 1;
21 int pivot = begin + (end - begin) / 2;
22 int v = list.at(pivot);
23
24 while (end - begin > 1) {
25 if (value == v)
26 return pivot;
27
28 if (value > v)
29 begin = pivot;
30 else
31 end = pivot;
32
33 pivot = begin + (end - begin) / 2;
34 v = list.at(pivot);
35 }
36
37 return value - v >= list.at(pivot + 1) - value ? pivot + 1 : pivot;
38}
39
40bool qt_sizeLessThan(const QSize &s1, const QSize &s2)
41{
42 return s1.width() * s1.height() < s2.width() * s2.height();
43}
44
46{
47 switch (f) {
48 case AndroidCamera::NV21:
49 return QVideoFrameFormat::Format_NV21;
50 case AndroidCamera::YV12:
51 return QVideoFrameFormat::Format_YV12;
52 case AndroidCamera::YUY2:
53 return QVideoFrameFormat::Format_YUYV;
54 case AndroidCamera::JPEG:
55 return QVideoFrameFormat::Format_Jpeg;
56 default:
57 return QVideoFrameFormat::Format_Invalid;
58 }
59}
60
62{
63 switch (f) {
64 case QVideoFrameFormat::Format_NV21:
65 return AndroidCamera::NV21;
66 case QVideoFrameFormat::Format_YV12:
67 return AndroidCamera::YV12;
68 case QVideoFrameFormat::Format_YUYV:
69 return AndroidCamera::YUY2;
70 case QVideoFrameFormat::Format_Jpeg:
71 return AndroidCamera::JPEG;
72 default:
73 return AndroidCamera::UnknownImageFormat;
74 }
75}
76
77static bool androidRequestPermission(const QString &permission)
78{
79 if (QNativeInterface::QAndroidApplication::sdkVersion() < 23)
80 return true;
81
82 // Permission already granted?
83 if (QtAndroidPrivate::checkPermission(permission).result() == QtAndroidPrivate::Authorized)
84 return true;
85
86 if (QtAndroidPrivate::requestPermission(permission).result() != QtAndroidPrivate::Authorized)
87 return false;
88
89 return true;
90}
91
92static bool androidCheckPermission(const QPermission &permission)
93{
94 return qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
95}
96
98{
99 const QCameraPermission permission;
100 const auto granted = androidCheckPermission(permission);
101 if (!granted)
102 qCDebug(qtAndroidMediaPlugin, "Camera permission not granted!");
103 return granted;
104}
105
107{
108 const QMicrophonePermission permission;
109 const auto granted = androidCheckPermission(permission);
110 if (!granted)
111 qCDebug(qtAndroidMediaPlugin, "Microphone permission not granted!");
112 return granted;
113}
114
116{
117 if (!androidRequestPermission(QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE"))) {
118 qCDebug(qtAndroidMediaPlugin, "Storage permission denied by user!");
119 return false;
120 }
121
122 return true;
123}
124
125QT_END_NAMESPACE
Definition qlist.h:80
QT_BEGIN_NAMESPACE int qt_findClosestValue(const QList< int > &list, int value)
AndroidCamera::ImageFormat qt_androidImageFormatFromPixelFormat(QVideoFrameFormat::PixelFormat f)
bool qt_androidCheckMicrophonePermission()
QVideoFrameFormat::PixelFormat qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat f)
bool qt_androidRequestWriteStoragePermission()
static bool androidRequestPermission(const QString &permission)
bool qt_androidCheckCameraPermission()
static bool androidCheckPermission(const QPermission &permission)
bool qt_sizeLessThan(const QSize &s1, const QSize &s2)