summaryrefslogtreecommitdiffstats
path: root/src/multimedia/windows/qwindowsresampler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/windows/qwindowsresampler.cpp')
-rw-r--r--src/multimedia/windows/qwindowsresampler.cpp100
1 files changed, 34 insertions, 66 deletions
diff --git a/src/multimedia/windows/qwindowsresampler.cpp b/src/multimedia/windows/qwindowsresampler.cpp
index 5b09830cc..3c50c0c19 100644
--- a/src/multimedia/windows/qwindowsresampler.cpp
+++ b/src/multimedia/windows/qwindowsresampler.cpp
@@ -1,59 +1,26 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// 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
#include "qwindowsresampler_p.h"
#include <qwindowsaudioutils_p.h>
#include <qloggingcategory.h>
+#include <QUuid>
-#include <Wmcodecdsp.h>
+#include <wmcodecdsp.h>
#include <mftransform.h>
-#include <mfapi.h>
#include <mferror.h>
QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(qLcAudioResampler, "qt.multimedia.audioresampler")
+QUuid qIID_IMFTransform(0xbf94c121, 0x5b05, 0x4e6f, 0x80,0x00, 0xba,0x59,0x89,0x61,0x41,0x4d);
+QUuid qCLSID_CResamplerMediaObject("f447b69e-1884-4a7e-8055-346f74d6edb3");
+
+static Q_LOGGING_CATEGORY(qLcAudioResampler, "qt.multimedia.audioresampler")
QWindowsResampler::QWindowsResampler()
{
- CoCreateInstance(CLSID_CResamplerMediaObject, nullptr, CLSCTX_INPROC_SERVER,
- IID_IMFTransform, (LPVOID*)(m_resampler.address()));
+ CoCreateInstance(qCLSID_CResamplerMediaObject, nullptr, CLSCTX_INPROC_SERVER,
+ qIID_IMFTransform, (LPVOID*)(m_resampler.GetAddressOf()));
if (m_resampler)
m_resampler->AddInputStreams(1, &m_inputStreamID);
}
@@ -78,13 +45,13 @@ quint64 QWindowsResampler::inputBufferSize(quint64 outputBufferSize) const
HRESULT QWindowsResampler::processInput(const QByteArrayView &in)
{
- QWindowsIUPointer<IMFSample> sample;
- HRESULT hr = MFCreateSample(sample.address());
+ ComPtr<IMFSample> sample;
+ HRESULT hr = m_wmf->mfCreateSample(sample.GetAddressOf());
if (FAILED(hr))
return hr;
- QWindowsIUPointer<IMFMediaBuffer> buffer;
- hr = MFCreateMemoryBuffer(in.size(), buffer.address());
+ ComPtr<IMFMediaBuffer> buffer;
+ hr = m_wmf->mfCreateMemoryBuffer(in.size(), buffer.GetAddressOf());
if (FAILED(hr))
return hr;
@@ -105,29 +72,29 @@ HRESULT QWindowsResampler::processInput(const QByteArrayView &in)
if (FAILED(hr))
return hr;
- hr = sample->AddBuffer(buffer.get());
+ hr = sample->AddBuffer(buffer.Get());
if (FAILED(hr))
return hr;
- return m_resampler->ProcessInput(m_inputStreamID, sample.get(), 0);
+ return m_resampler->ProcessInput(m_inputStreamID, sample.Get(), 0);
}
HRESULT QWindowsResampler::processOutput(QByteArray &out)
{
- QWindowsIUPointer<IMFSample> sample;
- QWindowsIUPointer<IMFMediaBuffer> buffer;
+ ComPtr<IMFSample> sample;
+ ComPtr<IMFMediaBuffer> buffer;
if (m_resamplerNeedsSampleBuffer) {
- HRESULT hr = MFCreateSample(sample.address());
+ HRESULT hr = m_wmf->mfCreateSample(sample.GetAddressOf());
if (FAILED(hr))
return hr;
auto expectedOutputSize = outputBufferSize(m_totalInputBytes) - m_totalOutputBytes;
- hr = MFCreateMemoryBuffer(expectedOutputSize, buffer.address());
+ hr = m_wmf->mfCreateMemoryBuffer(expectedOutputSize, buffer.GetAddressOf());
if (FAILED(hr))
return hr;
- hr = sample->AddBuffer(buffer.get());
+ hr = sample->AddBuffer(buffer.Get());
if (FAILED(hr))
return hr;
}
@@ -139,12 +106,12 @@ HRESULT QWindowsResampler::processOutput(QByteArray &out)
do {
outputDataBuffer.pEvents = nullptr;
outputDataBuffer.dwStatus = 0;
- outputDataBuffer.pSample = m_resamplerNeedsSampleBuffer ? sample.get() : nullptr;
+ outputDataBuffer.pSample = m_resamplerNeedsSampleBuffer ? sample.Get() : nullptr;
DWORD status = 0;
hr = m_resampler->ProcessOutput(0, 1, &outputDataBuffer, &status);
if (SUCCEEDED(hr)) {
- QWindowsIUPointer<IMFMediaBuffer> outputBuffer;
- outputDataBuffer.pSample->ConvertToContiguousBuffer(outputBuffer.address());
+ ComPtr<IMFMediaBuffer> outputBuffer;
+ outputDataBuffer.pSample->ConvertToContiguousBuffer(outputBuffer.GetAddressOf());
DWORD len = 0;
BYTE *data = nullptr;
hr = outputBuffer->Lock(&data, nullptr, &len);
@@ -169,7 +136,7 @@ QByteArray QWindowsResampler::resample(const QByteArrayView &in)
return {in.data(), in.size()};
} else {
- Q_ASSERT(m_resampler);
+ Q_ASSERT(m_resampler && m_wmf);
QByteArray out;
HRESULT hr = processInput(in);
@@ -198,8 +165,8 @@ QByteArray QWindowsResampler::resample(IMFSample *sample)
QByteArray out;
if (m_inputFormat == m_outputFormat) {
- QWindowsIUPointer<IMFMediaBuffer> outputBuffer;
- sample->ConvertToContiguousBuffer(outputBuffer.address());
+ ComPtr<IMFMediaBuffer> outputBuffer;
+ sample->ConvertToContiguousBuffer(outputBuffer.GetAddressOf());
DWORD len = 0;
BYTE *data = nullptr;
hr = outputBuffer->Lock(&data, nullptr, &len);
@@ -208,7 +175,7 @@ QByteArray QWindowsResampler::resample(IMFSample *sample)
outputBuffer->Unlock();
} else {
- Q_ASSERT(m_resampler);
+ Q_ASSERT(m_resampler && m_wmf);
hr = m_resampler->ProcessInput(m_inputStreamID, sample, 0);
if (SUCCEEDED(hr))
@@ -237,18 +204,19 @@ bool QWindowsResampler::setup(const QAudioFormat &fin, const QAudioFormat &fout)
return true;
}
- Q_ASSERT(m_resampler);
+ if (!m_resampler || !m_wmf)
+ return false;
- QWindowsIUPointer<IMFMediaType> min = QWindowsAudioUtils::formatToMediaType(fin);
- QWindowsIUPointer<IMFMediaType> mout = QWindowsAudioUtils::formatToMediaType(fout);
+ ComPtr<IMFMediaType> min = QWindowsAudioUtils::formatToMediaType(*m_wmf, fin);
+ ComPtr<IMFMediaType> mout = QWindowsAudioUtils::formatToMediaType(*m_wmf, fout);
- HRESULT hr = m_resampler->SetInputType(m_inputStreamID, min.get(), 0);
+ HRESULT hr = m_resampler->SetInputType(m_inputStreamID, min.Get(), 0);
if (FAILED(hr)) {
qCWarning(qLcAudioResampler) << "Failed to set input type" << hr;
return false;
}
- hr = m_resampler->SetOutputType(0, mout.get(), 0);
+ hr = m_resampler->SetOutputType(0, mout.Get(), 0);
if (FAILED(hr)) {
qCWarning(qLcAudioResampler) << "Failed to set output type" << hr;
return false;