summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2021-08-30 14:57:47 +0200
committerPiotr Srebrny <piotr.srebrny@qt.io>2021-09-03 18:53:55 +0200
commit62aaed9c5937377eb0dee66f9cc6f4d8069d7571 (patch)
tree18f2d543f3f4bc0061b42bfa4af97ec3b170722b /src/multimedia
parentbfee0f9398afddd27a522102c73ee5327a388b25 (diff)
Remove duplicated media storage location implementations
The implementation of media storage location resolver has been copied with slight modifications to each platfrom depenedent code. This patch removes these copies and establishes common naming scheme for all media captures. The feature to specify the default directory for a given media type has been removed as it was only used by Android. However, default directories for media on Android are properly resolved with QStandardPaths::writableLocation() Android specific implementation. Using mutex on the filename generator is unncessary as this function is not access concurrently. Holding a counter to generate the name for the next recording does not help to speed up name generation, since the code checks anyway with the file system if the generated name file does clash with the existing files. It is better to scan the directory in one go to check for the name. Pick-to: 6.2 Change-Id: Ibf8d91ea1bacdb3cf347e2097bf065ce715c9157 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/CMakeLists.txt4
-rw-r--r--src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp13
-rw-r--r--src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h3
-rw-r--r--src/multimedia/platform/android/mediacapture/qandroidcapturesession.cpp28
-rw-r--r--src/multimedia/platform/android/mediacapture/qandroidcapturesession_p.h4
-rw-r--r--src/multimedia/platform/darwin/camera/avfimagecapture.mm7
-rw-r--r--src/multimedia/platform/darwin/camera/avfimagecapture_p.h2
-rw-r--r--src/multimedia/platform/darwin/camera/avfmediaencoder.mm8
-rw-r--r--src/multimedia/platform/darwin/camera/avfmediaencoder_p.h4
-rw-r--r--src/multimedia/platform/darwin/camera/avfstoragelocation.mm138
-rw-r--r--src/multimedia/platform/darwin/camera/avfstoragelocation_p.h88
-rw-r--r--src/multimedia/platform/gstreamer/mediacapture/qgstreamerimagecapture.cpp46
-rw-r--r--src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder.cpp53
-rw-r--r--src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder_p.h2
-rw-r--r--src/multimedia/platform/qnx/camera/bbcamerasession.cpp13
-rw-r--r--src/multimedia/platform/qnx/camera/bbcamerasession_p.h4
-rw-r--r--src/multimedia/platform/qnx/camera/bbmediastoragelocation.cpp118
-rw-r--r--src/multimedia/platform/qnx/camera/bbmediastoragelocation_p.h75
-rw-r--r--src/multimedia/platform/windows/mediacapture/qwindowsimagecapture.cpp6
-rw-r--r--src/multimedia/platform/windows/mediacapture/qwindowsimagecapture_p.h3
-rw-r--r--src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder.cpp8
-rw-r--r--src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder_p.h3
-rw-r--r--src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation.cpp128
-rw-r--r--src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation_p.h87
-rw-r--r--src/multimedia/qmediastoragelocation.cpp109
-rw-r--r--src/multimedia/qmediastoragelocation_p.h29
26 files changed, 81 insertions, 902 deletions
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt
index 5d2d6bc3a..13e166a93 100644
--- a/src/multimedia/CMakeLists.txt
+++ b/src/multimedia/CMakeLists.txt
@@ -161,8 +161,6 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_wmf
platform/windows/mediacapture/qwindowsmediaencoder.cpp
platform/windows/mediacapture/qwindowsmediaencoder_p.h
platform/windows/qwindowsmediadevices.cpp platform/windows/qwindowsmediadevices_p.h
- platform/windows/mediacapture/qwindowsstoragelocation.cpp
- platform/windows/mediacapture/qwindowsstoragelocation_p.h
platform/windows/qwindowsformatinfo.cpp platform/windows/qwindowsformatinfo_p.h
platform/windows/qwindowsintegration.cpp platform/windows/qwindowsintegration_p.h
platform/windows/sourceresolver.cpp platform/windows/sourceresolver_p.h
@@ -394,7 +392,6 @@ qt_internal_extend_target(Multimedia CONDITION APPLE AND NOT TVOS AND NOT WATCHO
platform/darwin/camera/avfcamerasession.mm platform/darwin/camera/avfcamerasession_p.h
platform/darwin/camera/avfcamerautility.mm platform/darwin/camera/avfcamerautility_p.h
platform/darwin/camera/avfimagecapture.mm platform/darwin/camera/avfimagecapture_p.h
- platform/darwin/camera/avfstoragelocation.mm platform/darwin/camera/avfstoragelocation_p.h
)
qt_internal_extend_target(Multimedia CONDITION APPLE AND NOT TVOS AND NOT WATCHOS
@@ -436,7 +433,6 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_mmrenderer
platform/qnx/camera/bbcameraservice.cpp platform/qnx/camera/bbcameraservice_p.h
platform/qnx/camera/bbcamerasession.cpp platform/qnx/camera/bbcamerasession_p.h
platform/qnx/camera/bbcameravideoencodersettingscontrol.cpp platform/qnx/camera/bbcameravideoencodersettingscontrol_p.h
- platform/qnx/camera/bbmediastoragelocation.cpp platform/qnx/camera/bbmediastoragelocation_p.h
platform/qnx/camera/bbvideorenderercontrol.cpp platform/qnx/camera/bbvideorenderercontrol_p.h
platform/qnx/common/windowgrabber.cpp platform/qnx/common/windowgrabber_p.h
platform/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp platform/qnx/mediaplayer/mmrenderermediaplayercontrol_p.h
diff --git a/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp b/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp
index d635ef1bb..ecd04b5e1 100644
--- a/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp
+++ b/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp
@@ -53,6 +53,7 @@
#include <private/qplatformimagecapture_p.h>
#include <private/qmemoryvideobuffer_p.h>
#include <private/qcameradevice_p.h>
+#include <private/qmediastoragelocation_p.h>
QT_BEGIN_NAMESPACE
@@ -72,10 +73,6 @@ QAndroidCameraSession::QAndroidCameraSession(QObject *parent)
, m_previewCallback(0)
, m_keepActive(false)
{
- m_mediaStorageLocation.addStorageLocation(
- QMediaStorageLocation::Pictures,
- AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM));
-
if (qApp) {
connect(qApp, &QGuiApplication::applicationStateChanged,
this, &QAndroidCameraSession::onApplicationStateChanged);
@@ -660,10 +657,7 @@ void QAndroidCameraSession::processCapturedImage(int id,
if (!captureToBuffer) {
- const QString actualFileName = m_mediaStorageLocation.generateFileName(fileName,
- QMediaStorageLocation::Pictures,
- QLatin1String("IMG_"),
- QLatin1String("jpg"));
+ const QString actualFileName = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, QLatin1String("jpg"));
QFile file(actualFileName);
if (file.open(QFile::WriteOnly)) {
@@ -671,8 +665,7 @@ void QAndroidCameraSession::processCapturedImage(int id,
// if the picture is saved into the standard picture location, register it
// with the Android media scanner so it appears immediately in apps
// such as the gallery.
- QString standardLoc = AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM);
- if (actualFileName.startsWith(standardLoc))
+ if (fileName.isEmpty() || QFileInfo(fileName).isRelative())
AndroidMultimediaUtils::registerMediaFile(actualFileName);
emit imageSaved(id, actualFileName);
diff --git a/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h b/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h
index 2eafb1509..83228b692 100644
--- a/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h
+++ b/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h
@@ -56,7 +56,6 @@
#include <QImageCapture>
#include <QSet>
#include <QMutex>
-#include <private/qmediastoragelocation_p.h>
#include <private/qplatformimagecapture_p.h>
#include "androidcamera_p.h"
@@ -182,8 +181,6 @@ private:
int m_currentImageCaptureId;
QString m_currentImageCaptureFileName;
- QMediaStorageLocation m_mediaStorageLocation;
-
QMutex m_videoFrameCallbackMutex;
PreviewCallback *m_previewCallback;
bool m_keepActive;
diff --git a/src/multimedia/platform/android/mediacapture/qandroidcapturesession.cpp b/src/multimedia/platform/android/mediacapture/qandroidcapturesession.cpp
index 0768faf66..80d77062a 100644
--- a/src/multimedia/platform/android/mediacapture/qandroidcapturesession.cpp
+++ b/src/multimedia/platform/android/mediacapture/qandroidcapturesession.cpp
@@ -49,6 +49,7 @@
#include <private/qplatformaudioinput_p.h>
#include <private/qplatformaudiooutput_p.h>
#include <private/qmediarecorder_p.h>
+#include <private/qmediastoragelocation_p.h>
#include <QtCore/qmimetype.h>
#include <algorithm>
@@ -65,14 +66,6 @@ QAndroidCaptureSession::QAndroidCaptureSession()
, m_audioEncoder(AndroidMediaRecorder::DefaultAudioEncoder)
, m_videoEncoder(AndroidMediaRecorder::DefaultVideoEncoder)
{
- m_mediaStorageLocation.addStorageLocation(
- QMediaStorageLocation::Movies,
- AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM));
-
- m_mediaStorageLocation.addStorageLocation(
- QMediaStorageLocation::Sounds,
- AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::Sounds));
-
m_notifyTimer.setInterval(1000);
connect(&m_notifyTimer, &QTimer::timeout, this, &QAndroidCaptureSession::updateDuration);
}
@@ -190,16 +183,12 @@ void QAndroidCaptureSession::start(QMediaEncoderSettings &settings, const QUrl &
QString extension = settings.mimeType().preferredSuffix();
// Set output file
- QString filePath = m_mediaStorageLocation.generateFileName(
- outputLocation.isLocalFile() ? outputLocation.toLocalFile()
- : outputLocation.toString(),
- m_cameraSession ? QMediaStorageLocation::Movies
- : QMediaStorageLocation::Sounds,
- m_cameraSession ? QLatin1String("VID_")
- : QLatin1String("REC_"),
- extension);
+ auto location = outputLocation.toString(QUrl::PreferLocalFile);
+ auto filePath = QMediaStorageLocation::generateFileName(
+ location, m_cameraSession ? QStandardPaths::MoviesLocation : QStandardPaths::MusicLocation, extension);
m_usedOutputLocation = QUrl::fromLocalFile(filePath);
+ m_outputLocationIsStandard = location.isEmpty() || QFileInfo(location).isRelative();
m_mediaRecorder->setOutputFile(filePath);
// Even though the Android doc explicitly says that calling MediaRecorder.setPreviewDisplay()
@@ -269,11 +258,8 @@ void QAndroidCaptureSession::stop(bool error)
// if the media is saved into the standard media location, register it
// with the Android media scanner so it appears immediately in apps
// such as the gallery.
- QString mediaPath = m_usedOutputLocation.toLocalFile();
- QString standardLoc = m_cameraSession ? AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM)
- : AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::Sounds);
- if (mediaPath.startsWith(standardLoc))
- AndroidMultimediaUtils::registerMediaFile(mediaPath);
+ if (m_outputLocationIsStandard)
+ AndroidMultimediaUtils::registerMediaFile(m_usedOutputLocation.toLocalFile());
emit actualLocationChanged(m_usedOutputLocation);
}
diff --git a/src/multimedia/platform/android/mediacapture/qandroidcapturesession_p.h b/src/multimedia/platform/android/mediacapture/qandroidcapturesession_p.h
index ca6209ac5..16b3c8481 100644
--- a/src/multimedia/platform/android/mediacapture/qandroidcapturesession_p.h
+++ b/src/multimedia/platform/android/mediacapture/qandroidcapturesession_p.h
@@ -56,7 +56,6 @@
#include <qurl.h>
#include <qelapsedtimer.h>
#include <qtimer.h>
-#include <private/qmediastoragelocation_p.h>
#include "androidmediarecorder_p.h"
#include "qandroidmediaencoder_p.h"
@@ -162,14 +161,13 @@ private:
QPlatformAudioInput *m_audioInput = nullptr;
QPlatformAudioOutput *m_audioOutput = nullptr;
- QMediaStorageLocation m_mediaStorageLocation;
-
QElapsedTimer m_elapsedTime;
QTimer m_notifyTimer;
qint64 m_duration;
QMediaRecorder::RecorderState m_state;
QUrl m_usedOutputLocation;
+ bool m_outputLocationIsStandard = false;
CaptureProfile m_defaultSettings;
diff --git a/src/multimedia/platform/darwin/camera/avfimagecapture.mm b/src/multimedia/platform/darwin/camera/avfimagecapture.mm
index ace8035b6..a397fe418 100644
--- a/src/multimedia/platform/darwin/camera/avfimagecapture.mm
+++ b/src/multimedia/platform/darwin/camera/avfimagecapture.mm
@@ -44,6 +44,7 @@
#include "avfcamera_p.h"
#include "avfcamerasession_p.h"
#include "avfcamerarenderer_p.h"
+#include "qmediastoragelocation_p.h"
#include <private/qplatformimagecapture_p.h>
#include <private/qmemoryvideobuffer_p.h>
@@ -195,11 +196,7 @@ int AVFImageCapture::doCapture(const QString &actualFileName)
int AVFImageCapture::capture(const QString &fileName)
{
- QString actualFileName;
- actualFileName = m_storageLocation.generateFileName(fileName,
- AVFStorageLocation::Image,
- QLatin1String("img_"),
- QLatin1String("jpg"));
+ auto actualFileName = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, QLatin1String("jpg"));
qDebugCamera() << "Capture image to" << actualFileName;
return doCapture(actualFileName);
diff --git a/src/multimedia/platform/darwin/camera/avfimagecapture_p.h b/src/multimedia/platform/darwin/camera/avfimagecapture_p.h
index 1ac22810b..ef11bd70f 100644
--- a/src/multimedia/platform/darwin/camera/avfimagecapture_p.h
+++ b/src/multimedia/platform/darwin/camera/avfimagecapture_p.h
@@ -58,7 +58,6 @@
#include <QtCore/qsharedpointer.h>
#include <private/qplatformimagecapture_p.h>
#include "avfcamerasession_p.h"
-#include "avfstoragelocation_p.h"
QT_BEGIN_NAMESPACE
@@ -105,7 +104,6 @@ private:
int m_lastCaptureId = 0;
AVCaptureStillImageOutput *m_stillImageOutput;
AVCaptureConnection *m_videoConnection = nullptr;
- AVFStorageLocation m_storageLocation;
QMutex m_requestsMutex;
QQueue<CaptureRequest> m_captureRequests;
diff --git a/src/multimedia/platform/darwin/camera/avfmediaencoder.mm b/src/multimedia/platform/darwin/camera/avfmediaencoder.mm
index d218b137a..875074c28 100644
--- a/src/multimedia/platform/darwin/camera/avfmediaencoder.mm
+++ b/src/multimedia/platform/darwin/camera/avfmediaencoder.mm
@@ -45,9 +45,10 @@
#include "avfcameraservice_p.h"
#include "avfcameradebug_p.h"
#include "avfcamerautility_p.h"
-
#include "qaudiodevice.h"
+
#include "qmediadevices.h"
+#include "qmediastoragelocation_p.h"
#include "private/qmediarecorder_p.h"
#include "private/qdarwinformatsinfo_p.h"
#include "private/qplatformaudiooutput_p.h"
@@ -494,9 +495,8 @@ void AVFMediaEncoder::record(QMediaEncoderSettings &settings)
const QString path(outputLocation().scheme() == QLatin1String("file") ?
outputLocation().path() : outputLocation().toString());
- const QUrl fileURL(QUrl::fromLocalFile(m_storageLocation.generateFileName(path,
- audioOnly ? AVFStorageLocation::Audio : AVFStorageLocation::Video,
- QLatin1String("clip_"),
+ const QUrl fileURL(QUrl::fromLocalFile(QMediaStorageLocation::generateFileName(path,
+ audioOnly ? QStandardPaths::MusicLocation : QStandardPaths::MoviesLocation,
settings.mimeType().preferredSuffix())));
NSURL *nsFileURL = fileURL.toNSURL();
diff --git a/src/multimedia/platform/darwin/camera/avfmediaencoder_p.h b/src/multimedia/platform/darwin/camera/avfmediaencoder_p.h
index 4dea1f69a..8bb05926a 100644
--- a/src/multimedia/platform/darwin/camera/avfmediaencoder_p.h
+++ b/src/multimedia/platform/darwin/camera/avfmediaencoder_p.h
@@ -52,11 +52,11 @@
//
#include "avfmediaassetwriter_p.h"
-#include "avfstoragelocation_p.h"
#include "avfcamerautility_p.h"
#include "qaudiodevice.h"
#include <private/qplatformmediaencoder_p.h>
+#include <private/qplatformmediacapture_p.h>
#include <private/qvideooutputorientationhandler_p.h>
#include <QtMultimedia/qmediametadata.h>
@@ -117,8 +117,6 @@ private:
AVFCameraService *m_service = nullptr;
AVFScopedPointer<QT_MANGLE_NAMESPACE(AVFMediaAssetWriter)> m_writer;
- AVFStorageLocation m_storageLocation;
-
QMediaRecorder::RecorderState m_state;
QMediaMetaData m_metaData;
diff --git a/src/multimedia/platform/darwin/camera/avfstoragelocation.mm b/src/multimedia/platform/darwin/camera/avfstoragelocation.mm
deleted file mode 100644
index 0d37ffad5..000000000
--- a/src/multimedia/platform/darwin/camera/avfstoragelocation.mm
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfstoragelocation_p.h"
-#include "QtCore/qstandardpaths.h"
-
-
-QT_BEGIN_NAMESPACE
-
-
-AVFStorageLocation::AVFStorageLocation()
-{
-}
-
-AVFStorageLocation::~AVFStorageLocation()
-{
-}
-
-/*!
- * Generate the actual file name from user requested one.
- * requestedName may be either empty (the default dir and naming theme is used),
- * points to existing dir (the default name used)
- * or specify the full actual path.
- */
-QString AVFStorageLocation::generateFileName(const QString &requestedName,
- Mode mode,
- const QString &prefix,
- const QString &ext) const
-{
- if (requestedName.isEmpty())
- return generateFileName(prefix, defaultDir(mode), ext);
-
- if (QFileInfo(requestedName).isDir())
- return generateFileName(prefix, QDir(requestedName), ext);
-
- return requestedName;
-}
-
-QDir AVFStorageLocation::defaultDir(Mode mode) const
-{
- QStringList dirCandidates;
-
- if (mode == Video) {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- } else if (mode == Image) {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- } else {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
- }
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
- }
-
- return QDir();
-}
-
-QString AVFStorageLocation::generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const
-{
- QString lastClipKey = dir.absolutePath()+QLatin1Char(' ')+prefix+QLatin1Char(' ')+ext;
- int lastClip = m_lastUsedIndex.value(lastClipKey, 0);
-
- if (lastClip == 0) {
- //first run, find the maximum clip number during the fist capture
- const auto list = dir.entryList(QStringList() << QString::fromUtf8("%1*.%2").arg(prefix).arg(ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
- }
-
-
- //don't just rely on cached lastClip value,
- //someone else may create a file after camera started
- while (true) {
- QString name = QString::fromUtf8("%1%2.%3").arg(prefix)
- .arg(lastClip+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0'))
- .arg(ext);
-
- QString path = dir.absoluteFilePath(name);
- if (!QFileInfo(path).exists()) {
- m_lastUsedIndex[lastClipKey] = lastClip+1;
- return path;
- }
-
- lastClip++;
- }
-
- return QString();
-}
-
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/platform/darwin/camera/avfstoragelocation_p.h b/src/multimedia/platform/darwin/camera/avfstoragelocation_p.h
deleted file mode 100644
index ec0b82426..000000000
--- a/src/multimedia/platform/darwin/camera/avfstoragelocation_p.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFSTORAGE_H
-#define AVFSTORAGE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtmultimediaglobal.h"
-
-#include <QtCore/qdir.h>
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFStorageLocation
-{
-public:
- AVFStorageLocation();
- ~AVFStorageLocation();
-
- enum Mode {
- Image,
- Video,
- Audio
- };
-
- QString generateFileName(const QString &requestedName,
- Mode mode,
- const QString &prefix,
- const QString &ext) const;
-
-
- QDir defaultDir(Mode mode) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const;
-
-private:
- mutable QMap<QString, int> m_lastUsedIndex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamerimagecapture.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamerimagecapture.cpp
index 86c5d9349..f4434e549 100644
--- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamerimagecapture.cpp
+++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamerimagecapture.cpp
@@ -44,6 +44,7 @@
#include <private/qgstutils_p.h>
#include <private/qgstreamermetadata_p.h>
#include <qvideoframeformat.h>
+#include "qmediastoragelocation_p.h"
#include <QtCore/QDebug>
#include <QtCore/QDir>
@@ -95,52 +96,9 @@ bool QGstreamerImageCapture::isReadyForCapture() const
return m_session && !passImage && cameraActive;
}
-
-static QDir defaultDir()
-{
- QStringList dirCandidates;
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- QDir dir(path);
- if (dir.exists() && QFileInfo(path).isWritable())
- return dir;
- }
-
- return QDir();
-}
-
-QString generateFileName(const QDir &dir, const QString &ext)
-{
- int lastClip = 0;
- const auto list = dir.entryList(QStringList() << QString::fromLatin1("img_*.%1").arg(ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(5, fileName.size()-6-ext.length()).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
-
- QString name = QString::fromLatin1("img_%1.%2")
- .arg(lastClip+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0'))
- .arg(ext);
-
- return dir.absoluteFilePath(name);
-}
-
-
int QGstreamerImageCapture::capture(const QString &fileName)
{
- QString path = fileName;
- if (path.isEmpty())
- path = generateFileName(defaultDir(), QLatin1String("jpg"));
-
+ QString path = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, QLatin1String("jpg"));
return doCapture(path);
}
diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder.cpp
index facc58bcd..7fba45341 100644
--- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder.cpp
+++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder.cpp
@@ -43,6 +43,7 @@
#include "private/qgstpipeline_p.h"
#include "private/qgstreamermessage_p.h"
#include "qaudiodevice.h"
+#include "qmediastoragelocation_p.h"
#include <qdebug.h>
#include <qstandardpaths.h>
@@ -284,12 +285,10 @@ void QGstreamerMediaEncoder::record(QMediaEncoderSettings &settings)
const auto audioOnly = settings.videoCodec() == QMediaFormat::VideoCodec::Unspecified;
- // create new encoder
- QString location = outputLocation().toLocalFile();
- if (outputLocation().isEmpty()) {
- QString container = settings.mimeType().preferredSuffix();
- location = generateFileName(defaultDir(audioOnly), container);
- }
+ auto primaryLocation = audioOnly ? QStandardPaths::MusicLocation : QStandardPaths::MoviesLocation;
+ auto container = settings.mimeType().preferredSuffix();
+ auto location = QMediaStorageLocation::generateFileName(outputLocation().toLocalFile(), primaryLocation, container);
+
QUrl actualSink = QUrl::fromLocalFile(QDir::currentPath()).resolved(location);
qCDebug(qLcMediaEncoder) << "recording new video to" << actualSink;
@@ -442,45 +441,3 @@ void QGstreamerMediaEncoder::setCaptureSession(QPlatformMediaCaptureSession *ses
gstPipeline.set("message-forward", true);
gstPipeline.installMessageFilter(this);
}
-
-QDir QGstreamerMediaEncoder::defaultDir(bool audioOnly) const
-{
- QStringList dirCandidates;
-
- if (!audioOnly)
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- else
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- QDir dir(path);
- if (dir.exists() && QFileInfo(path).isWritable())
- return dir;
- }
-
- return QDir();
-}
-
-QString QGstreamerMediaEncoder::generateFileName(const QDir &dir, const QString &ext) const
-{
- int lastClip = 0;
- const auto list = dir.entryList(QStringList() << QString::fromLatin1("clip_*.%1").arg(ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(5, fileName.size()-6-ext.length()).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
-
- QString name = QString::fromLatin1("clip_%1.%2")
- .arg(lastClip+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0'))
- .arg(ext);
-
- return dir.absoluteFilePath(name);
-}
diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder_p.h b/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder_p.h
index 1fd2d9690..7570a939b 100644
--- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder_p.h
+++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamermediaencoder_p.h
@@ -108,8 +108,6 @@ private:
void handleSessionError(QMediaRecorder::Error code, const QString &description);
void finalize();
- QDir defaultDir(bool audioOnly) const;
- QString generateFileName(const QDir &dir, const QString &ext) const;
QGstreamerMediaCapture *m_session = nullptr;
QGstreamerMetaData m_metaData;
diff --git a/src/multimedia/platform/qnx/camera/bbcamerasession.cpp b/src/multimedia/platform/qnx/camera/bbcamerasession.cpp
index 7d4f4f075..d82cbe482 100644
--- a/src/multimedia/platform/qnx/camera/bbcamerasession.cpp
+++ b/src/multimedia/platform/qnx/camera/bbcamerasession.cpp
@@ -49,6 +49,7 @@
#include <qmath.h>
#include <private/qmediarecorder_p.h>
#include <private/qplatformimagecapture_p.h>
+#include <private/qmediastoragelocation_p.h>
#include <algorithm>
@@ -618,14 +619,10 @@ void BbCameraSession::imageCaptured(int requestId, const QImage &rawImage, const
QVideoFrame frame(image);
emit imageAvailable(requestId, frame);
} else {
- const QString actualFileName = m_mediaStorageLocation.generateFileName(fileName,
- QCamera::CaptureStillImage,
- QLatin1String("IMG_"),
- QLatin1String("jpg"));
-
+ const QString actualFileName = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, QLatin1String("jpg"));
QFile file(actualFileName);
if (file.open(QFile::WriteOnly)) {
- if (image.save(&file, "JPG")) {
+ if (image.save(&file, "jpg")) {
emit imageSaved(requestId, actualFileName);
} else {
emit imageCaptureError(requestId, QImageCapture::OutOfSpaceError, file.errorString());
@@ -940,9 +937,7 @@ void BbCameraSession::startVideoRecording(const QUrl &outputLocation)
m_videoRecordingDuration.invalidate();
- QString videoOutputLocation = outputLocation.toLocalFile();
- if (videoOutputLocation.isEmpty())
- videoOutputLocation = m_mediaStorageLocation.generateFileName(QLatin1String("VID_"), m_mediaStorageLocation.defaultDir(QCamera::CaptureVideo), QLatin1String("mp4"));
+ auto videoOutputLocation = QMediaStorageLocation::generateFileName(outputLocation.toLocalFile(), QStandardPaths::MoviesLocation, QLatin1String("mp4"));
emit actualLocationChanged(videoOutputLocation);
diff --git a/src/multimedia/platform/qnx/camera/bbcamerasession_p.h b/src/multimedia/platform/qnx/camera/bbcamerasession_p.h
index 74c2ecfa3..4ea7110e7 100644
--- a/src/multimedia/platform/qnx/camera/bbcamerasession_p.h
+++ b/src/multimedia/platform/qnx/camera/bbcamerasession_p.h
@@ -50,8 +50,6 @@
// We mean it.
//
-#include "bbmediastoragelocation_p.h"
-
#include <QCamera>
#include <QImageCapture>
#include <QElapsedTimer>
@@ -192,8 +190,6 @@ private:
QVideoEncoderSettings m_videoEncoderSettings;
QAudioEncoderSettings m_audioEncoderSettings;
- BbMediaStorageLocation m_mediaStorageLocation;
-
camera_handle_t m_handle;
WindowGrabber* m_windowGrabber;
diff --git a/src/multimedia/platform/qnx/camera/bbmediastoragelocation.cpp b/src/multimedia/platform/qnx/camera/bbmediastoragelocation.cpp
deleted file mode 100644
index 3b8eac160..000000000
--- a/src/multimedia/platform/qnx/camera/bbmediastoragelocation.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbmediastoragelocation_p.h"
-
-#include <QStandardPaths>
-
-QT_BEGIN_NAMESPACE
-
-BbMediaStorageLocation::BbMediaStorageLocation()
-{
-}
-
-QDir BbMediaStorageLocation::defaultDir(QCamera::CaptureMode mode) const
-{
- QStringList dirCandidates;
-
- dirCandidates << QLatin1String("shared/camera");
-
- if (mode == QCamera::CaptureVideo) {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- } else {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- }
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
- }
-
- return QDir();
-}
-
-QString BbMediaStorageLocation::generateFileName(const QString &requestedName, QCamera::CaptureMode mode, const QString &prefix, const QString &extension) const
-{
- if (requestedName.isEmpty())
- return generateFileName(prefix, defaultDir(mode), extension);
-
- if (QFileInfo(requestedName).isDir())
- return generateFileName(prefix, QDir(requestedName), extension);
-
- return requestedName;
-}
-
-QString BbMediaStorageLocation::generateFileName(const QString &prefix, const QDir &dir, const QString &extension) const
-{
- const QString lastMediaKey = dir.absolutePath() + QLatin1Char(' ') + prefix + QLatin1Char(' ') + extension;
- qint64 lastMediaIndex = m_lastUsedIndex.value(lastMediaKey, 0);
-
- if (lastMediaIndex == 0) {
- // first run, find the maximum media number during the fist capture
- const auto list = dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(extension));
- for (const QString &fileName : list) {
- const qint64 mediaIndex = QStringView{fileName}.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
- lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
- }
- }
-
- // don't just rely on cached lastMediaIndex value,
- // someone else may create a file after camera started
- while (true) {
- const QString name = QString("%1%2.%3").arg(prefix)
- .arg(lastMediaIndex + 1, 8, 10, QLatin1Char('0'))
- .arg(extension);
-
- const QString path = dir.absoluteFilePath(name);
- if (!QFileInfo(path).exists()) {
- m_lastUsedIndex[lastMediaKey] = lastMediaIndex + 1;
- return path;
- }
-
- lastMediaIndex++;
- }
-
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/platform/qnx/camera/bbmediastoragelocation_p.h b/src/multimedia/platform/qnx/camera/bbmediastoragelocation_p.h
deleted file mode 100644
index 3ea1bfbf0..000000000
--- a/src/multimedia/platform/qnx/camera/bbmediastoragelocation_p.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBMEDIASTORAGELOCATION_H
-#define BBMEDIASTORAGELOCATION_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QCamera>
-#include <QDir>
-#include <QHash>
-
-QT_BEGIN_NAMESPACE
-
-class BbMediaStorageLocation
-{
-public:
- BbMediaStorageLocation();
-
- QDir defaultDir(QCamera::CaptureMode mode) const;
-
- QString generateFileName(const QString &requestedName, QCamera::CaptureMode mode, const QString &prefix, const QString &extension) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &extension) const;
-
-private:
- mutable QHash<QString, qint64> m_lastUsedIndex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture.cpp b/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture.cpp
index 0c5e188ca..f24823401 100644
--- a/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture.cpp
+++ b/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture.cpp
@@ -41,6 +41,7 @@
#include "qwindowsmediadevicesession_p.h"
#include "qwindowsmediacapture_p.h"
+#include "qmediastoragelocation_p.h"
#include <QtConcurrent/qtconcurrentrun.h>
#include <QtGui/qimagewriter.h>
@@ -63,9 +64,8 @@ bool QWindowsImageCapture::isReadyForCapture() const
int QWindowsImageCapture::capture(const QString &fileName)
{
- QString ext = writerFormat(m_settings.format());
- QString path = m_storageLocation.generateFileName(fileName, QWindowsStorageLocation::Image,
- QLatin1String("img_"), ext);
+ auto ext = writerFormat(m_settings.format());
+ auto path = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, ext);
return doCapture(path);
}
diff --git a/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture_p.h b/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture_p.h
index cafc71087..c862dc914 100644
--- a/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture_p.h
+++ b/src/multimedia/platform/windows/mediacapture/qwindowsimagecapture_p.h
@@ -51,8 +51,6 @@
// We mean it.
//
-#include "qwindowsstoragelocation_p.h"
-
#include <private/qplatformimagecapture_p.h>
QT_BEGIN_NAMESPACE
@@ -92,7 +90,6 @@ private:
QWindowsMediaCaptureService *m_captureService = nullptr;
QWindowsMediaDeviceSession *m_mediaDeviceSession = nullptr;
QImageEncoderSettings m_settings;
- QWindowsStorageLocation m_storageLocation;
int m_captureId = 0;
bool m_capturing = false;
QString m_fileName;
diff --git a/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder.cpp b/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder.cpp
index 84c520444..555d5bbda 100644
--- a/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder.cpp
+++ b/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder.cpp
@@ -41,6 +41,7 @@
#include "qwindowsmediadevicesession_p.h"
#include "qwindowsmediacapture_p.h"
+#include "qmediastoragelocation_p.h"
#include "mfmetadata_p.h"
#include <QtCore/QUrl>
#include <QtCore/QMimeType>
@@ -93,10 +94,9 @@ void QWindowsMediaEncoder::record(QMediaEncoderSettings &settings)
const QString path = (outputLocation().scheme() == QLatin1String("file") ?
outputLocation().path() : outputLocation().toString());
- m_fileName = m_storageLocation.generateFileName(path, audioOnly
- ? QWindowsStorageLocation::Audio
- : QWindowsStorageLocation::Video,
- QLatin1String("clip_"),
+ m_fileName = QMediaStorageLocation::generateFileName(path, audioOnly
+ ? QStandardPaths::MusicLocation
+ : QStandardPaths::MoviesLocation,
settings.mimeType().preferredSuffix());
if (m_mediaDeviceSession->startRecording(settings, m_fileName, audioOnly)) {
diff --git a/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder_p.h b/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder_p.h
index 199561b86..c7b9d8931 100644
--- a/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder_p.h
+++ b/src/multimedia/platform/windows/mediacapture/qwindowsmediaencoder_p.h
@@ -51,8 +51,6 @@
#ifndef QWINDOWSMEDIAENCODER_H
#define QWINDOWSMEDIAENCODER_H
-#include "qwindowsstoragelocation_p.h"
-
#include <private/qplatformmediaencoder_p.h>
#include <QtCore/qglobal.h>
@@ -98,7 +96,6 @@ private:
QWindowsMediaCaptureService *m_captureService = nullptr;
QWindowsMediaDeviceSession *m_mediaDeviceSession = nullptr;
QMediaRecorder::RecorderState m_state = QMediaRecorder::StoppedState;
- QWindowsStorageLocation m_storageLocation;
QString m_fileName;
QMediaMetaData m_metaData;
qint64 m_duration = 0;
diff --git a/src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation.cpp b/src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation.cpp
deleted file mode 100644
index 75a72e795..000000000
--- a/src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwindowsstoragelocation_p.h"
-#include "QtCore/qstandardpaths.h"
-
-
-QT_BEGIN_NAMESPACE
-
-QWindowsStorageLocation::QWindowsStorageLocation()
-{
-}
-
-QWindowsStorageLocation::~QWindowsStorageLocation()
-{
-}
-
-/*!
- * Generate the actual file name from user-requested one.
- * requestedName may be either empty (the default dir and naming theme is used),
- * point to existing dir (the default name used), or specify the full actual path.
- */
-QString QWindowsStorageLocation::generateFileName(const QString &requestedName, Mode mode,
- const QString &prefix, const QString &ext) const
-{
- if (requestedName.isEmpty())
- return generateFileName(prefix, defaultDir(mode), ext);
-
- if (QFileInfo(requestedName).isDir())
- return generateFileName(prefix, QDir(requestedName), ext);
-
- return requestedName;
-}
-
-QDir QWindowsStorageLocation::defaultDir(Mode mode) const
-{
- QStringList dirCandidates;
-
- if (mode == Video)
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- else if (mode == Image)
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- else if (mode == Audio)
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
- }
-
- return QDir();
-}
-
-QString QWindowsStorageLocation::generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const
-{
- QString lastClipKey = dir.absolutePath() + QLatin1Char(' ') + prefix + QLatin1Char(' ') + ext;
- int lastClip = m_lastUsedIndex.value(lastClipKey, 0);
-
- if (lastClip == 0) {
- //first run, find the maximum clip number during the fist capture
- const auto list = dir.entryList(QStringList() << QString::fromUtf8("%1*.%2").arg(prefix, ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(prefix.length(),
- fileName.size() - prefix.length() - ext.length() - 1).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
- }
-
- //don't just rely on cached lastClip value,
- //someone else may create a file after camera started
- while (true) {
- QString name = QString::fromUtf8("%1%2.%3").arg(prefix)
- .arg(lastClip + 1, 4, 10, QLatin1Char('0'))
- .arg(ext);
-
- QString path = dir.absoluteFilePath(name);
-
- if (!QFileInfo::exists(path)) {
- m_lastUsedIndex[lastClipKey] = lastClip + 1;
- return path;
- }
- lastClip++;
- }
-
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation_p.h b/src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation_p.h
deleted file mode 100644
index 44e27bd62..000000000
--- a/src/multimedia/platform/windows/mediacapture/qwindowsstoragelocation_p.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QWINDOWSSTORAGELOCATION_H
-#define QWINDOWSSTORAGELOCATION_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtmultimediaglobal.h"
-
-#include <QtCore/qdir.h>
-#include <qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-// Copy/paste from AVFStorageLocation.
-// Consider moving to platform-independent code.
-class QWindowsStorageLocation
-{
-public:
- QWindowsStorageLocation();
- ~QWindowsStorageLocation();
-
- enum Mode {
- Image,
- Video,
- Audio
- };
-
- QString generateFileName(const QString &requestedName, Mode mode,
- const QString &prefix, const QString &ext) const;
-
- QDir defaultDir(Mode mode) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const;
-
-private:
- mutable QMap<QString, int> m_lastUsedIndex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/multimedia/qmediastoragelocation.cpp b/src/multimedia/qmediastoragelocation.cpp
index dd80ae483..2c30562ee 100644
--- a/src/multimedia/qmediastoragelocation.cpp
+++ b/src/multimedia/qmediastoragelocation.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -43,59 +43,69 @@
QT_BEGIN_NAMESPACE
-QMediaStorageLocation::QMediaStorageLocation() = default;
-
-void QMediaStorageLocation::addStorageLocation(MediaType type, const QString &location)
-{
- m_customLocations[type].append(location);
-}
-
-QDir QMediaStorageLocation::defaultLocation(MediaType type) const
+QDir QMediaStorageLocation::defaultDirectory(QStandardPaths::StandardLocation type)
{
QStringList dirCandidates;
- dirCandidates << m_customLocations.value(type);
-
- switch (type) {
- case Movies:
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- break;
- case Music:
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
- break;
- case Pictures:
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- default:
- break;
- }
+#if QT_CONFIG(mmrenderer)
+ dirCandidates << QLatin1String("shared/camera");
+#endif
+ dirCandidates << QStandardPaths::writableLocation(type);
+ dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
dirCandidates << QDir::homePath();
dirCandidates << QDir::currentPath();
dirCandidates << QDir::tempPath();
for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
+ QDir dir(path);
+ if (dir.exists() && QFileInfo(path).isWritable())
+ return dir;
}
return QDir();
}
+static QString generateFileName(const QDir &dir, const QString &prefix, const QString &extension)
+{
+ auto lastMediaIndex = 0;
+ const auto list = dir.entryList({ QString::fromLatin1("%1*.%2").arg(prefix, extension) });
+ for (const QString &fileName : list) {
+ auto mediaIndex = QStringView{fileName}.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
+ lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
+ }
+
+ const QString name = QString::fromLatin1("%1%2.%3")
+ .arg(prefix)
+ .arg(lastMediaIndex + 1, 4, 10, QLatin1Char('0'))
+ .arg(extension);
+
+ return dir.absoluteFilePath(name);
+}
+
+
QString QMediaStorageLocation::generateFileName(const QString &requestedName,
- MediaType type,
- const QString &prefix,
- const QString &extension) const
+ QStandardPaths::StandardLocation type,
+ const QString &extension)
{
+ auto prefix = QLatin1String("clip_");
+ switch (type) {
+ case QStandardPaths::PicturesLocation: prefix = QLatin1String("image_"); break;
+ case QStandardPaths::MoviesLocation: prefix = QLatin1String("video_"); break;
+ case QStandardPaths::MusicLocation: prefix = QLatin1String("record_"); break;
+ default: break;
+ }
+
if (requestedName.isEmpty())
- return generateFileName(prefix, defaultLocation(type), extension);
+ return generateFileName(defaultDirectory(type), prefix, extension);
QString path = requestedName;
if (QFileInfo(path).isRelative())
- path = defaultLocation(type).absoluteFilePath(path);
+ path = defaultDirectory(type).absoluteFilePath(path);
if (QFileInfo(path).isDir())
- return generateFileName(prefix, QDir(path), extension);
+ return generateFileName(QDir(path), prefix, extension);
if (!path.endsWith(extension))
path.append(QString(QLatin1String(".%1")).arg(extension));
@@ -103,41 +113,4 @@ QString QMediaStorageLocation::generateFileName(const QString &requestedName,
return path;
}
-QString QMediaStorageLocation::generateFileName(const QString &prefix,
- const QDir &dir,
- const QString &extension) const
-{
- QMutexLocker lock(&m_mutex);
-
- const QString lastMediaKey = dir.absolutePath() + QLatin1Char(' ') + prefix + QLatin1Char(' ') + extension;
- qint64 lastMediaIndex = m_lastUsedIndex.value(lastMediaKey, 0);
-
- if (lastMediaIndex == 0) {
- // first run, find the maximum media number during the fist capture
- const auto list = dir.entryList(QStringList() << QString(QLatin1String("%1*.%2")).arg(prefix).arg(extension));
- for (const QString &fileName : list) {
- const qint64 mediaIndex = QStringView{fileName}.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
- lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
- }
- }
-
- // don't just rely on cached lastMediaIndex value,
- // someone else may create a file after camera started
- while (true) {
- const QString name = QString(QLatin1String("%1%2.%3")).arg(prefix)
- .arg(lastMediaIndex + 1, 8, 10, QLatin1Char('0'))
- .arg(extension);
-
- const QString path = dir.absoluteFilePath(name);
- if (!QFileInfo::exists(path)) {
- m_lastUsedIndex[lastMediaKey] = lastMediaIndex + 1;
- return path;
- }
-
- lastMediaIndex++;
- }
-
- return QString();
-}
-
QT_END_NAMESPACE
diff --git a/src/multimedia/qmediastoragelocation_p.h b/src/multimedia/qmediastoragelocation_p.h
index 13399b54d..ec32cfdbe 100644
--- a/src/multimedia/qmediastoragelocation_p.h
+++ b/src/multimedia/qmediastoragelocation_p.h
@@ -52,36 +52,15 @@
//
#include <qtmultimediaglobal.h>
+#include <QStandardPaths>
#include <QDir>
-#include <QMap>
-#include <QHash>
-#include <QMutex>
QT_BEGIN_NAMESPACE
-class Q_MULTIMEDIA_EXPORT QMediaStorageLocation
+namespace QMediaStorageLocation
{
-public:
- enum MediaType {
- Movies,
- Music,
- Pictures,
- Sounds
- };
-
- QMediaStorageLocation();
-
- void addStorageLocation(MediaType type, const QString &location);
-
- QDir defaultLocation(MediaType type) const;
-
- QString generateFileName(const QString &requestedName, MediaType type, const QString &prefix, const QString &extension) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &extension) const;
-
-private:
- mutable QMutex m_mutex;
- mutable QHash<QString, qint64> m_lastUsedIndex;
- QMap<MediaType, QStringList> m_customLocations;
+ QDir defaultDirectory(QStandardPaths::StandardLocation type);
+ QString generateFileName(const QString &requestedName, QStandardPaths::StandardLocation type, const QString &extension);
};
QT_END_NAMESPACE