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 <QtCore/private/qcomobject_p.h>
28#include <qvideoframe.h>
29#include <qcameradevice.h>
30#include <qmediarecorder.h>
31
33
34class QVideoSink;
35
37 : public QObject,
40{
42public:
43 explicit QWindowsMediaDeviceReader(QObject *parent = nullptr);
45
46 //from IMFSourceReaderCallback
47 STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
48 DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample) override;
49 STDMETHODIMP OnFlush(DWORD dwStreamIndex) override;
50 STDMETHODIMP OnEvent(DWORD dwStreamIndex, IMFMediaEvent *pEvent) override;
51
52 //from IMFSinkWriterCallback
53 STDMETHODIMP OnFinalize(HRESULT hrStatus) override;
54 STDMETHODIMP OnMarker(DWORD dwStreamIndex, LPVOID pvContext) override;
55
56 bool activate(const QString &cameraId,
57 const QCameraFormat &cameraFormat,
58 const QString &microphoneId);
59 void deactivate();
60
65 void stopRecording();
66 bool pauseRecording();
67 bool resumeRecording();
68
69 UINT32 frameWidth() const;
70 UINT32 frameHeight() const;
71 qreal frameRate() const;
72 void setInputMuted(bool muted);
73 void setInputVolume(qreal volume);
74 void setOutputMuted(bool muted);
75 void setOutputVolume(qreal volume);
76 bool setAudioOutput(const QString &audioOutputId);
77
81 void streamingError(int errorCode);
84 void recordingError(int errorCode);
85 void durationChanged(qint64 duration);
86 void videoFrameChanged(const QVideoFrame &frame);
87
88private slots:
89 void updateDuration();
90
91private:
92 HRESULT createSource(const QString &deviceId, bool video, IMFMediaSource **source);
93 HRESULT createAggregateReader(IMFMediaSource *firstSource, IMFMediaSource *secondSource,
94 IMFMediaSource **aggregateSource, IMFSourceReader **sourceReader);
95 HRESULT createVideoMediaType(const GUID &format, UINT32 bitRate, UINT32 width, UINT32 height,
96 qreal frameRate, IMFMediaType **mediaType);
97 HRESULT createAudioMediaType(const GUID &format, UINT32 bitRate, IMFMediaType **mediaType);
98 HRESULT initAudioType(IMFMediaType *mediaType, UINT32 channels, UINT32 samplesPerSec, bool flt);
99 HRESULT prepareVideoStream(DWORD mediaTypeIndex);
100 HRESULT prepareAudioStream();
101 HRESULT initSourceIndexes();
102 HRESULT updateSinkInputMediaTypes();
103 HRESULT startMonitoring();
104 void stopMonitoring();
105 void releaseResources();
106 void stopStreaming();
107 DWORD findMediaTypeIndex(const QCameraFormat &reqFormat);
108
109 QMutex m_mutex;
110 QWaitCondition m_hasFinalized;
111 IMFMediaSource *m_videoSource = nullptr;
112 IMFMediaType *m_videoMediaType = nullptr;
113 IMFMediaSource *m_audioSource = nullptr;
114 IMFMediaType *m_audioMediaType = nullptr;
115 IMFMediaSource *m_aggregateSource = nullptr;
116 IMFSourceReader *m_sourceReader = nullptr;
117 IMFSinkWriter *m_sinkWriter = nullptr;
118 IMFMediaSink *m_monitorSink = nullptr;
119 IMFSinkWriter *m_monitorWriter = nullptr;
120 QString m_audioOutputId;
121 DWORD m_sourceVideoStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
122 DWORD m_sourceAudioStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
123 DWORD m_sinkVideoStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
124 DWORD m_sinkAudioStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
125 UINT32 m_frameWidth = 0;
126 UINT32 m_frameHeight = 0;
127 qreal m_frameRate = 0.0;
128 LONG m_stride = 0;
129 bool m_active = false;
130 bool m_streaming = false;
131 bool m_recording = false;
132 bool m_firstFrame = false;
133 bool m_paused = false;
134 bool m_pauseChanging = false;
135 bool m_inputMuted = false;
136 bool m_outputMuted = false;
137 qreal m_inputVolume = 1.0;
138 qreal m_outputVolume = 1.0;
139 QVideoFrameFormat::PixelFormat m_pixelFormat = QVideoFrameFormat::Format_Invalid;
140 LONGLONG m_timeOffset = 0;
141 LONGLONG m_pauseTime = 0;
142 LONGLONG m_lastTimestamp = 0;
143 QTimer m_durationTimer;
144 qint64 m_currentDuration = -1;
145 qint64 m_lastDuration = -1;
146 QVideoFrameFormat::ColorRange m_colorRange = QVideoFrameFormat::ColorRange_Unknown;
147 QVideoFrameFormat::ColorSpace m_colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
148};
149
150QT_END_NAMESPACE
151
152#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 OnEvent(DWORD dwStreamIndex, IMFMediaEvent *pEvent) override
Combined button and popup list for selecting options.