1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef MFTRANSFORM_H
41 #define MFTRANSFORM_H
42 
43 #include <mfapi.h>
44 #include <mfidl.h>
45 #include <QtCore/qlist.h>
46 #include <QtCore/qmutex.h>
47 #include <QtMultimedia/qvideosurfaceformat.h>
48 
49 QT_USE_NAMESPACE
50 
51 class MFVideoProbeControl;
52 
53 class MFTransform: public IMFTransform
54 {
55 public:
56     MFTransform();
57     ~MFTransform();
58 
59     void addProbe(MFVideoProbeControl* probe);
60     void removeProbe(MFVideoProbeControl* probe);
61 
62     void setVideoSink(IUnknown *videoSink);
63 
64     // IUnknown methods
65     STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
66     STDMETHODIMP_(ULONG) AddRef();
67     STDMETHODIMP_(ULONG) Release();
68 
69     // IMFTransform methods
70     STDMETHODIMP GetStreamLimits(DWORD *pdwInputMinimum, DWORD *pdwInputMaximum, DWORD *pdwOutputMinimum, DWORD *pdwOutputMaximum);
71     STDMETHODIMP GetStreamCount(DWORD *pcInputStreams, DWORD *pcOutputStreams);
72     STDMETHODIMP GetStreamIDs(DWORD dwInputIDArraySize, DWORD *pdwInputIDs, DWORD dwOutputIDArraySize, DWORD *pdwOutputIDs);
73     STDMETHODIMP GetInputStreamInfo(DWORD dwInputStreamID, MFT_INPUT_STREAM_INFO *pStreamInfo);
74     STDMETHODIMP GetOutputStreamInfo(DWORD dwOutputStreamID, MFT_OUTPUT_STREAM_INFO *pStreamInfo);
75     STDMETHODIMP GetAttributes(IMFAttributes **pAttributes);
76     STDMETHODIMP GetInputStreamAttributes(DWORD dwInputStreamID, IMFAttributes **pAttributes);
77     STDMETHODIMP GetOutputStreamAttributes(DWORD dwOutputStreamID, IMFAttributes **pAttributes);
78     STDMETHODIMP DeleteInputStream(DWORD dwStreamID);
79     STDMETHODIMP AddInputStreams(DWORD cStreams, DWORD *adwStreamIDs);
80     STDMETHODIMP GetInputAvailableType(DWORD dwInputStreamID, DWORD dwTypeIndex, IMFMediaType **ppType);
81     STDMETHODIMP GetOutputAvailableType(DWORD dwOutputStreamID,DWORD dwTypeIndex, IMFMediaType **ppType);
82     STDMETHODIMP SetInputType(DWORD dwInputStreamID, IMFMediaType *pType, DWORD dwFlags);
83     STDMETHODIMP SetOutputType(DWORD dwOutputStreamID, IMFMediaType *pType, DWORD dwFlags);
84     STDMETHODIMP GetInputCurrentType(DWORD dwInputStreamID, IMFMediaType **ppType);
85     STDMETHODIMP GetOutputCurrentType(DWORD dwOutputStreamID, IMFMediaType **ppType);
86     STDMETHODIMP GetInputStatus(DWORD dwInputStreamID, DWORD *pdwFlags);
87     STDMETHODIMP GetOutputStatus(DWORD *pdwFlags);
88     STDMETHODIMP SetOutputBounds(LONGLONG hnsLowerBound, LONGLONG hnsUpperBound);
89     STDMETHODIMP ProcessEvent(DWORD dwInputStreamID, IMFMediaEvent *pEvent);
90     STDMETHODIMP ProcessMessage(MFT_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
91     STDMETHODIMP ProcessInput(DWORD dwInputStreamID, IMFSample *pSample, DWORD dwFlags);
92     STDMETHODIMP ProcessOutput(DWORD dwFlags, DWORD cOutputBufferCount, MFT_OUTPUT_DATA_BUFFER *pOutputSamples, DWORD *pdwStatus);
93 
94 private:
95     HRESULT OnFlush();
96     static QVideoFrame::PixelFormat formatFromSubtype(const GUID& subtype);
97     static QVideoSurfaceFormat videoFormatForMFMediaType(IMFMediaType *mediaType, int *bytesPerLine);
98     QVideoFrame makeVideoFrame();
99     QByteArray dataFromBuffer(IMFMediaBuffer *buffer, int height, int *bytesPerLine);
100     bool isMediaTypeSupported(IMFMediaType *type);
101 
102     long m_cRef;
103     IMFMediaType *m_inputType;
104     IMFMediaType *m_outputType;
105     IMFSample *m_sample;
106     QMutex m_mutex;
107 
108     IMFMediaTypeHandler *m_videoSinkTypeHandler;
109 
110     QList<MFVideoProbeControl*> m_videoProbes;
111     QMutex m_videoProbeMutex;
112 
113     QVideoSurfaceFormat m_format;
114     int m_bytesPerLine;
115 };
116 
117 #endif
118