summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-05-12 10:54:38 +0200
committerLars Knoll <lars.knoll@qt.io>2021-05-12 13:31:30 +0000
commit755e23ea8ef02e4b54b10a84d150dd69575068b4 (patch)
tree61f535ea9f4f871856380969fa1e5643f53d6794
parent15aa7f7ea87c98642257bbea8833636621956e2e (diff)
Make QMediaFormat movable
The d-pointer is only a reserved placeholder, but make it a QExplicitlySharedDataPointer anyway. The default constructor just initializes to zero, so the overhead is marginal, but makes it safe to extend in the future if needed. Change-Id: Ib6269f59b59af05647c0f9295ce634d5c327339e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/multimedia/qmediaformat.cpp34
-rw-r--r--src/multimedia/qmediaformat.h13
2 files changed, 41 insertions, 6 deletions
diff --git a/src/multimedia/qmediaformat.cpp b/src/multimedia/qmediaformat.cpp
index 4c239e78f..ccf926026 100644
--- a/src/multimedia/qmediaformat.cpp
+++ b/src/multimedia/qmediaformat.cpp
@@ -67,6 +67,11 @@ const char *mimeTypeForFormat[QMediaFormat::LastFileFormat + 2] =
}
+class QMediaFormatPrivate : public QSharedData
+{};
+
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QMediaFormatPrivate);
+
/*! \enum QMediaFormat::FileFormat
Describes the container format used in a multimedia file or stream.
@@ -91,16 +96,39 @@ const char *mimeTypeForFormat[QMediaFormat::LastFileFormat + 2] =
*/
// these are non inline to make a possible future addition of a d pointer binary compatible
+
+/*!
+ Constucts a QMediaFormat object for \a format.
+*/
QMediaFormat::QMediaFormat(FileFormat format)
: fmt(format)
{
- Q_UNUSED(d);
}
+/*!
+ Destroys the QMediaFormat object.
+*/
QMediaFormat::~QMediaFormat() = default;
-QMediaFormat::QMediaFormat(const QMediaFormat &other) = default;
-QMediaFormat &QMediaFormat::operator=(const QMediaFormat &other) = default;
+/*!
+ Constructs a QMediaFormat object by copying from \a other.
+*/
+QMediaFormat::QMediaFormat(const QMediaFormat &other) noexcept = default;
+
+/*!
+ Copies \a other into this QMediaFormat object.
+*/
+QMediaFormat &QMediaFormat::operator=(const QMediaFormat &other) noexcept = default;
+
+/*! \fn QMediaFormat::QMediaFormat(QMediaFormat &&other)
+
+ Constructs a QMediaFormat objects by moving from \a other.
+*/
+
+/*! \fn QMediaFormat &QMediaFormat::operator=(QMediaFormat &&other)
+
+ Moves \a other into this QMediaFormat objects.
+*/
/*! \fn void QMediaFormat::setMediaContainer(QMediaFormat::FileFormat container)
diff --git a/src/multimedia/qmediaformat.h b/src/multimedia/qmediaformat.h
index addd25a51..c8bfaf6c5 100644
--- a/src/multimedia/qmediaformat.h
+++ b/src/multimedia/qmediaformat.h
@@ -50,6 +50,8 @@ class QMediaFormat;
class QMediaEncoderSettings;
class QMediaFormatPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QMediaFormatPrivate, Q_MULTIMEDIA_EXPORT)
+
class Q_MULTIMEDIA_EXPORT QMediaFormat
{
public:
@@ -110,8 +112,13 @@ public:
QMediaFormat(FileFormat format = UnspecifiedFormat);
~QMediaFormat();
- QMediaFormat(const QMediaFormat &other);
- QMediaFormat &operator=(const QMediaFormat &other);
+ QMediaFormat(const QMediaFormat &other) noexcept;
+ QMediaFormat &operator=(const QMediaFormat &other) noexcept;
+
+ QMediaFormat(QMediaFormat &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMediaFormat)
+ void swap(QMediaFormat &other) noexcept
+ { qSwap(d, other.d); }
FileFormat format() const { return fmt; }
void setFormat(FileFormat f) { fmt = f; }
@@ -147,7 +154,7 @@ protected:
FileFormat fmt;
AudioCodec audio = AudioCodec::Unspecified;
VideoCodec video = VideoCodec::Unspecified;
- QMediaFormatPrivate *d = nullptr;
+ QExplicitlySharedDataPointer<QMediaFormatPrivate> d;
};
QT_END_NAMESPACE