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
mfdecodersourcereader.cpp
Go to the documentation of this file.
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 <system_error>
5#include <mfapi.h>
6#include <mferror.h>
7#include <qlogging.h>
8#include <qdebug.h>
11
13
14ComPtr<IMFMediaType> MFDecoderSourceReader::setSource(IMFMediaSource *source, QAudioFormat::SampleFormat sampleFormat)
15{
16 ComPtr<IMFMediaType> mediaType;
17 m_sourceReader.Reset();
18
19 if (m_sourceReaderCallback) {
20 disconnect(m_sourceReaderCallback.Get());
21
22 m_sourceReaderCallback.Reset();
23 }
24
25 if (!source)
26 return mediaType;
27
28 m_sourceReaderCallback = makeComObject<MFSourceReaderCallback>();
29
30 connect(m_sourceReaderCallback.Get(), &MFSourceReaderCallback::finished, this,
31 &MFDecoderSourceReader::finished);
32 connect(m_sourceReaderCallback.Get(), &MFSourceReaderCallback::newSample, this,
33 &MFDecoderSourceReader::newSample);
34
35 ComPtr<IMFAttributes> attr;
36 MFCreateAttributes(attr.GetAddressOf(), 1);
37 if (FAILED(attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, m_sourceReaderCallback.Get())))
38 return mediaType;
39 if (FAILED(attr->SetUINT32(MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN, TRUE)))
40 return mediaType;
41
42 HRESULT hr = MFCreateSourceReaderFromMediaSource(source, attr.Get(), m_sourceReader.GetAddressOf());
43 if (FAILED(hr)) {
44 qWarning() << "MFDecoderSourceReader: failed to set up source reader: "
45 << std::system_category().message(hr).c_str();
46 return mediaType;
47 }
48
49 m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_ALL_STREAMS), FALSE);
50 m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
51
52 ComPtr<IMFMediaType> pPartialType;
53 MFCreateMediaType(pPartialType.GetAddressOf());
54 pPartialType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
55 pPartialType->SetGUID(MF_MT_SUBTYPE, sampleFormat == QAudioFormat::Float ? MFAudioFormat_Float : MFAudioFormat_PCM);
56 m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), nullptr, pPartialType.Get());
57 m_sourceReader->GetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), mediaType.GetAddressOf());
58 // Ensure the stream is selected.
59 m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
60
61 return mediaType;
62}
63
65{
66 if (m_sourceReader)
67 m_sourceReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, NULL, NULL, NULL, NULL);
68}
69
70QT_END_NAMESPACE
71
72#include "moc_mfdecodersourcereader_p.cpp"
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:170