Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 <mferror.h>
6#include <qlogging.h>
7#include <qdebug.h>
9
11
12ComPtr<IMFMediaType> MFDecoderSourceReader::setSource(IMFMediaSource *source, QAudioFormat::SampleFormat sampleFormat)
13{
14 ComPtr<IMFMediaType> mediaType;
15 m_sourceReader.Reset();
16
17 if (!source)
18 return mediaType;
19
20 ComPtr<IMFAttributes> attr;
21 MFCreateAttributes(attr.GetAddressOf(), 1);
22 if (FAILED(attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, this)))
23 return mediaType;
24 if (FAILED(attr->SetUINT32(MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN, TRUE)))
25 return mediaType;
26
27 HRESULT hr = MFCreateSourceReaderFromMediaSource(source, attr.Get(), m_sourceReader.GetAddressOf());
28 if (FAILED(hr)) {
29 qWarning() << "MFDecoderSourceReader: failed to set up source reader: "
30 << std::system_category().message(hr).c_str();
31 return mediaType;
32 }
33
34 m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_ALL_STREAMS), FALSE);
35 m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
36
37 ComPtr<IMFMediaType> pPartialType;
38 MFCreateMediaType(pPartialType.GetAddressOf());
39 pPartialType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
40 pPartialType->SetGUID(MF_MT_SUBTYPE, sampleFormat == QAudioFormat::Float ? MFAudioFormat_Float : MFAudioFormat_PCM);
41 m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), nullptr, pPartialType.Get());
42 m_sourceReader->GetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), mediaType.GetAddressOf());
43 // Ensure the stream is selected.
44 m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
45
46 return mediaType;
47}
48
50{
51 if (m_sourceReader)
52 m_sourceReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, NULL, NULL, NULL, NULL);
53}
54
55//from IUnknown
56STDMETHODIMP MFDecoderSourceReader::QueryInterface(REFIID riid, LPVOID *ppvObject)
57{
58 if (!ppvObject)
59 return E_POINTER;
60 if (riid == IID_IMFSourceReaderCallback) {
61 *ppvObject = static_cast<IMFSourceReaderCallback*>(this);
62 } else if (riid == IID_IUnknown) {
63 *ppvObject = static_cast<IUnknown*>(this);
64 } else {
65 *ppvObject = NULL;
66 return E_NOINTERFACE;
67 }
68 AddRef();
69 return S_OK;
70}
71
72STDMETHODIMP_(ULONG) MFDecoderSourceReader::AddRef()
73{
74 return InterlockedIncrement(&m_cRef);
75}
76
77STDMETHODIMP_(ULONG) MFDecoderSourceReader::Release()
78{
79 LONG cRef = InterlockedDecrement(&m_cRef);
80 if (cRef == 0) {
81 this->deleteLater();
82 }
83 return cRef;
84}
85
86//from IMFSourceReaderCallback
87STDMETHODIMP MFDecoderSourceReader::OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
88 DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample)
89{
90 Q_UNUSED(hrStatus);
91 Q_UNUSED(dwStreamIndex);
92 Q_UNUSED(llTimestamp);
93 if (pSample) {
94 emit newSample(ComPtr<IMFSample>{pSample});
95 } else if ((dwStreamFlags & MF_SOURCE_READERF_ENDOFSTREAM) == MF_SOURCE_READERF_ENDOFSTREAM) {
96 emit finished();
97 }
98 return S_OK;
99}
100
102
103#include "moc_mfdecodersourcereader_p.cpp"
ComPtr< IMFMediaType > setSource(IMFMediaSource *source, QAudioFormat::SampleFormat)
STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex, DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample) override
STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override
void newSample(ComPtr< IMFSample >)
SampleFormat
Qt will always expect and use samples in the endianness of the host platform.
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
STDMETHODIMP_(ULONG) MFDecoderSourceReader
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
GLsizei GLsizei GLchar * source
#define emit
#define Q_UNUSED(x)
IUIViewSettingsInterop __RPC__in REFIID riid
long HRESULT