Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5#include "qandroidglobal_p.h"
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
60
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
Access the camera for taking pictures or videos.
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
Access the microphone for monitoring or recording sound.
\inmodule QtCore \inheaderfile QPermissions
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
PixelFormat
Enumerates video data types.
Combined button and popup list for selecting options.
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)
#define qApp
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCDebug(category,...)
GLsizei const GLfloat * v
[13]
GLuint GLuint end
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLfloat GLfloat f
GLuint64EXT * result
[6]
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QStringLiteral(str)
#define s2
QList< int > list
[14]