1// Copyright (C) 2016 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 "qplatformmediarecorder_p.h"
5#include "qstandardpaths.h"
6#include "qmediastoragelocation_p.h"
7#include <QObject>
8
9QT_BEGIN_NAMESPACE
10
11QPlatformMediaRecorder::QPlatformMediaRecorder(QMediaRecorder *parent)
12 : q(parent)
13{
14}
15
16void QPlatformMediaRecorder::pause()
17{
18 updateError(error: QMediaRecorder::FormatError, errorString: QMediaRecorder::tr(s: "Pause not supported"));
19}
20
21void QPlatformMediaRecorder::resume()
22{
23 updateError(error: QMediaRecorder::FormatError, errorString: QMediaRecorder::tr(s: "Resume not supported"));
24}
25
26void QPlatformMediaRecorder::stateChanged(QMediaRecorder::RecorderState state)
27{
28 if (m_state == state)
29 return;
30 m_state = state;
31 emit q->recorderStateChanged(state);
32}
33
34void QPlatformMediaRecorder::durationChanged(qint64 duration)
35{
36 if (m_duration == duration)
37 return;
38 m_duration = duration;
39 emit q->durationChanged(duration);
40}
41
42void QPlatformMediaRecorder::actualLocationChanged(const QUrl &location)
43{
44 if (m_actualLocation == location)
45 return;
46 m_actualLocation = location;
47 emit q->actualLocationChanged(location);
48}
49
50void QPlatformMediaRecorder::updateError(QMediaRecorder::Error error, const QString &errorString)
51{
52 m_error.setAndNotify(code: error, description: errorString, notifier&: *q);
53}
54
55void QPlatformMediaRecorder::metaDataChanged()
56{
57 emit q->metaDataChanged();
58}
59
60QString QPlatformMediaRecorder::findActualLocation(const QMediaEncoderSettings &settings) const
61{
62 const auto audioOnly = settings.videoCodec() == QMediaFormat::VideoCodec::Unspecified;
63
64 const auto primaryLocation =
65 audioOnly ? QStandardPaths::MusicLocation : QStandardPaths::MoviesLocation;
66 const QMimeType mimeType = settings.mimeType();
67 const QString suffix = mimeType.preferredSuffix();
68 QString location = QMediaStorageLocation::generateFileName(
69 requestedName: outputLocation().toString(options: QUrl::PreferLocalFile), type: primaryLocation, extension: suffix);
70
71 Q_ASSERT(!location.isEmpty());
72
73 return location;
74}
75
76QT_END_NAMESPACE
77

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtmultimedia/src/multimedia/platform/qplatformmediarecorder.cpp