summaryrefslogtreecommitdiffstats
path: root/src/multimedia/windows/qwindowsresampler_p.h
blob: 4667a43866eaafcab381003207a05d2401057f7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only


#ifndef QT_QWINDOWSRESAMPLER_H
#define QT_QWINDOWSRESAMPLER_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 <qbytearray.h>
#include <qbytearrayview.h>
#include <qaudioformat.h>
#include <private/qwindowsiupointer_p.h>
#include <qt_windows.h>
#include <mftransform.h>

struct IMFSample;
struct IMFTransform;
class QWindowsMediaFoundation;

QT_BEGIN_NAMESPACE

class Q_MULTIMEDIA_EXPORT QWindowsResampler
{
public:
    QWindowsResampler();
    ~QWindowsResampler();

    bool setup(const QAudioFormat &in, const QAudioFormat &out);

    QByteArray resample(const QByteArrayView &in);
    QByteArray resample(IMFSample *sample);

    QAudioFormat inputFormat() const { return m_inputFormat; }
    QAudioFormat outputFormat() const { return m_outputFormat; }

    quint64 outputBufferSize(quint64 inputBufferSize) const;
    quint64 inputBufferSize(quint64 outputBufferSize) const;

    quint64 totalInputBytes() const { return m_totalInputBytes; }
    quint64 totalOutputBytes() const { return m_totalOutputBytes; }

private:
    HRESULT processInput(const QByteArrayView &in);
    HRESULT processOutput(QByteArray &out);

    QWindowsIUPointer<IMFTransform> m_resampler;
    QWindowsMediaFoundation *m_wmf = nullptr;

    bool m_resamplerNeedsSampleBuffer = false;
    quint64 m_totalInputBytes = 0;
    quint64 m_totalOutputBytes = 0;
    QAudioFormat m_inputFormat;
    QAudioFormat m_outputFormat;

    DWORD m_inputStreamID = 0;
};

QT_END_NAMESPACE

#endif // QT_QWINDOWSRESAMPLER_H