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
qwindowsresampler_p.h
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
4
5#ifndef QT_QWINDOWSRESAMPLER_H
6#define QT_QWINDOWSRESAMPLER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qbytearray.h>
20#include <QtCore/qbytearrayview.h>
21#include <QtCore/private/qcomptr_p.h>
22#include <QtCore/private/qexpected_p.h>
23#include <QtMultimedia/qaudioformat.h>
24#include <QtMultimedia/private/qplatformaudioresampler_p.h>
25#include <QtMultimedia/private/qwindowsmediafoundation_p.h>
26
27#include <mftransform.h>
28
29#include <memory_resource>
30
31struct IMFSample;
32struct IMFTransform;
33
34QT_BEGIN_NAMESPACE
35
36class QWindowsMediaFoundation;
37
38class Q_MULTIMEDIA_EXPORT QWindowsResampler : public QPlatformAudioResampler
39{
40public:
41 static bool isAvailable();
42
43 QWindowsResampler();
44 ~QWindowsResampler();
45
46 bool setup(const QAudioFormat &in, const QAudioFormat &out);
47 void setStartTimeOffset(std::chrono::microseconds); // for QPlatformAudioResampler
48
49 QByteArray resample(QByteArray);
50 QByteArray resample(const QByteArrayView &);
51 QByteArray resample(const ComPtr<IMFSample> &);
52
53 QAudioBuffer resample(const char *data, size_t size) override;
54
55 // Caveat: the memory resource needs outlive the QWindowsResampler instance (the IMFTransform
56 // API does not rule out that the input buffers are kept alive)
57 std::pmr::vector<std::byte> resample(QSpan<const std::byte>, std::pmr::memory_resource *);
58
59 QAudioFormat inputFormat() const { return m_inputFormat; }
60 QAudioFormat outputFormat() const { return m_outputFormat; }
61
62 quint64 outputBufferSize(quint64 inputBufferSize) const;
63 quint64 inputBufferSize(quint64 outputBufferSize) const;
64
65 quint64 totalInputBytes() const { return m_totalInputBytes; }
66 quint64 totalOutputBytes() const { return m_totalOutputBytes; }
67
68private:
69 qsizetype overAllocatedOutputBufferSize();
70 template <typename Functor>
71 auto processOutput(ComPtr<IMFMediaBuffer> buffer, Functor &&f)
72 -> std::invoke_result_t<Functor, const ComPtr<IMFMediaBuffer> &>;
73
74 q23::expected<QByteArray, HRESULT> processOutput();
75
76 QWindowsMediaFoundation *m_wmf{ QWindowsMediaFoundation::instance() };
77 QMFRuntimeInit m_wmfRuntime{ m_wmf };
78 ComPtr<IMFTransform> m_resampler;
79 ComPtr<IMFSample> m_inputSample;
80 ComPtr<IMFSample> m_outputSample;
81
82 quint64 m_totalInputBytes = 0;
83 quint64 m_totalOutputBytes = 0;
84 QAudioFormat m_inputFormat;
85 QAudioFormat m_outputFormat;
86
87 DWORD m_inputStreamID = 0;
88
89 std::chrono::microseconds m_startTimeOffset;
90};
91
92QT_END_NAMESPACE
93
94#endif // QT_QWINDOWSRESAMPLER_H
Combined button and popup list for selecting options.