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
qwindowsmediadevicereader_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#ifndef QWINDOWSMEDIADEVICEREADER_H
5#define QWINDOWSMEDIADEVICEREADER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <mfapi.h>
19#include <mfidl.h>
20#include <mferror.h>
21#include <mfreadwrite.h>
22
23#include <QtCore/qobject.h>
24#include <QtCore/qmutex.h>
25#include <QtCore/qwaitcondition.h>
26#include <QtCore/qtimer.h>
27#include <qvideoframe.h>
28#include <qcameradevice.h>
29#include <qmediarecorder.h>
30
32
33class QVideoSink;
34
38{
40public:
41 explicit QWindowsMediaDeviceReader(QObject *parent = nullptr);
43
44 //from IUnknown
45 STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
48
49 //from IMFSourceReaderCallback
50 STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
51 DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample) override;
52 STDMETHODIMP OnFlush(DWORD dwStreamIndex) override;
53 STDMETHODIMP OnEvent(DWORD dwStreamIndex, IMFMediaEvent *pEvent) override;
54
55 //from IMFSinkWriterCallback
56 STDMETHODIMP OnFinalize(HRESULT hrStatus) override;
57 STDMETHODIMP OnMarker(DWORD dwStreamIndex, LPVOID pvContext) override;
58
59 bool activate(const QString &cameraId,
60 const QCameraFormat &cameraFormat,
61 const QString &microphoneId);
62 void deactivate();
63
68 void stopRecording();
69 bool pauseRecording();
70 bool resumeRecording();
71
72 UINT32 frameWidth() const;
73 UINT32 frameHeight() const;
74 qreal frameRate() const;
75 void setInputMuted(bool muted);
76 void setInputVolume(qreal volume);
77 void setOutputMuted(bool muted);
78 void setOutputVolume(qreal volume);
79 bool setAudioOutput(const QString &audioOutputId);
80
84 void streamingError(int errorCode);
87 void recordingError(int errorCode);
88 void durationChanged(qint64 duration);
89 void videoFrameChanged(const QVideoFrame &frame);
90
91private slots:
92 void updateDuration();
93
94private:
95 HRESULT createSource(const QString &deviceId, bool video, IMFMediaSource **source);
96 HRESULT createAggregateReader(IMFMediaSource *firstSource, IMFMediaSource *secondSource,
97 IMFMediaSource **aggregateSource, IMFSourceReader **sourceReader);
98 HRESULT createVideoMediaType(const GUID &format, UINT32 bitRate, UINT32 width, UINT32 height,
99 qreal frameRate, IMFMediaType **mediaType);
100 HRESULT createAudioMediaType(const GUID &format, UINT32 bitRate, IMFMediaType **mediaType);
101 HRESULT initAudioType(IMFMediaType *mediaType, UINT32 channels, UINT32 samplesPerSec, bool flt);
102 HRESULT prepareVideoStream(DWORD mediaTypeIndex);
103 HRESULT prepareAudioStream();
104 HRESULT initSourceIndexes();
105 HRESULT updateSinkInputMediaTypes();
106 HRESULT startMonitoring();
107 void stopMonitoring();
108 void releaseResources();
109 void stopStreaming();
110 DWORD findMediaTypeIndex(const QCameraFormat &reqFormat);
111
112 long m_cRef = 1;
113 QMutex m_mutex;
114 QWaitCondition m_hasFinalized;
115 IMFMediaSource *m_videoSource = nullptr;
116 IMFMediaType *m_videoMediaType = nullptr;
117 IMFMediaSource *m_audioSource = nullptr;
118 IMFMediaType *m_audioMediaType = nullptr;
119 IMFMediaSource *m_aggregateSource = nullptr;
120 IMFSourceReader *m_sourceReader = nullptr;
121 IMFSinkWriter *m_sinkWriter = nullptr;
122 IMFMediaSink *m_monitorSink = nullptr;
123 IMFSinkWriter *m_monitorWriter = nullptr;
124 QString m_audioOutputId;
125 DWORD m_sourceVideoStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
126 DWORD m_sourceAudioStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
127 DWORD m_sinkVideoStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
128 DWORD m_sinkAudioStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
129 UINT32 m_frameWidth = 0;
130 UINT32 m_frameHeight = 0;
131 qreal m_frameRate = 0.0;
132 LONG m_stride = 0;
133 bool m_active = false;
134 bool m_streaming = false;
135 bool m_recording = false;
136 bool m_firstFrame = false;
137 bool m_paused = false;
138 bool m_pauseChanging = false;
139 bool m_inputMuted = false;
140 bool m_outputMuted = false;
141 qreal m_inputVolume = 1.0;
142 qreal m_outputVolume = 1.0;
143 QVideoFrameFormat::PixelFormat m_pixelFormat = QVideoFrameFormat::Format_Invalid;
144 LONGLONG m_timeOffset = 0;
145 LONGLONG m_pauseTime = 0;
146 LONGLONG m_lastTimestamp = 0;
147 QTimer m_durationTimer;
148 qint64 m_currentDuration = -1;
149 qint64 m_lastDuration = -1;
150};
151
152QT_END_NAMESPACE
153
154#endif // QWINDOWSMEDIADEVICEREADER_H
void durationChanged(qint64 duration)
bool activate(const QString &cameraId, const QCameraFormat &cameraFormat, const QString &microphoneId)
void videoFrameChanged(const QVideoFrame &frame)
bool setAudioOutput(const QString &audioOutputId)
STDMETHODIMP OnFlush(DWORD dwStreamIndex) override
STDMETHODIMP OnFinalize(HRESULT hrStatus) override
STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex, DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample) override
void streamingError(int errorCode)
STDMETHODIMP OnMarker(DWORD dwStreamIndex, LPVOID pvContext) override
void recordingError(int errorCode)
STDMETHODIMP_(ULONG) AddRef(void) override
STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override
STDMETHODIMP OnEvent(DWORD dwStreamIndex, IMFMediaEvent *pEvent) override
STDMETHODIMP_(ULONG) QWindowsMediaDeviceReader