DirectShow: use the EVR in the window control.

Reuse existing code from the WMF plugin, which already uses the EVR.
This enables HW-accelerated video decoding when using QMediaPlayer
with a QVideoWidget.

Task-number: QTBUG-45593
Change-Id: I757e4d53cd2c648aee6ba33a4851a8c6adc62843
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
Yoann Lopes
2015-09-10 18:25:37 +02:00
parent b2e9ae8856
commit 95bd9d58d8
24 changed files with 554 additions and 196 deletions

View File

@@ -6,9 +6,9 @@ win32 {
qtCompileTest(directshow) {
qtCompileTest(wshellitem)
}
qtCompileTest(evr)
qtCompileTest(wmsdk)
contains(QT_CONFIG, wmf-backend): qtCompileTest(wmf)
qtCompileTest(evr)
} else:mac {
qtCompileTest(avfoundation)
} else:qnx {

View File

@@ -0,0 +1,8 @@
INCLUDEPATH += $$PWD/evr
qtHaveModule(widgets): QT += widgets
HEADERS += $$PWD/evr/evrvideowindowcontrol.h \
$$PWD/evr/evrdefs.h
SOURCES += $$PWD/evr/evrvideowindowcontrol.cpp

View File

@@ -0,0 +1,127 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef EVRDEFS_H
#define EVRDEFS_H
#include <d3d9.h>
#include <Evr9.h>
#include <dxva2api.h>
// The following is required to compile with MinGW
#ifdef __GNUC__
typedef struct MFVideoNormalizedRect {
float left;
float top;
float right;
float bottom;
} MFVideoNormalizedRect;
#endif
#ifndef __IMFGetService_INTERFACE_DEFINED__
#define __IMFGetService_INTERFACE_DEFINED__
DEFINE_GUID(IID_IMFGetService, 0xfa993888, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7);
MIDL_INTERFACE("fa993888-4383-415a-a930-dd472a8cf6f7")
IMFGetService : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE GetService(REFGUID, REFIID, LPVOID *) = 0;
};
#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL(IMFGetService, 0xfa993888, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7)
#endif
#endif // __IMFGetService_INTERFACE_DEFINED__
#ifndef __IMFVideoDisplayControl_INTERFACE_DEFINED__
#define __IMFVideoDisplayControl_INTERFACE_DEFINED__
typedef enum MFVideoAspectRatioMode
{
MFVideoARMode_None = 0,
MFVideoARMode_PreservePicture = 0x1,
MFVideoARMode_PreservePixel = 0x2,
MFVideoARMode_NonLinearStretch = 0x4,
MFVideoARMode_Mask = 0x7
} MFVideoAspectRatioMode;
DEFINE_GUID(IID_IMFVideoDisplayControl, 0xa490b1e4, 0xab84, 0x4d31, 0xa1,0xb2, 0x18,0x1e,0x03,0xb1,0x07,0x7a);
MIDL_INTERFACE("a490b1e4-ab84-4d31-a1b2-181e03b1077a")
IMFVideoDisplayControl : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE GetNativeVideoSize(SIZE *, SIZE *) = 0;
virtual HRESULT STDMETHODCALLTYPE GetIdealVideoSize(SIZE *, SIZE *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetVideoPosition(const MFVideoNormalizedRect *, const LPRECT) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVideoPosition(MFVideoNormalizedRect *, LPRECT) = 0;
virtual HRESULT STDMETHODCALLTYPE SetAspectRatioMode(DWORD) = 0;
virtual HRESULT STDMETHODCALLTYPE GetAspectRatioMode(DWORD *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetVideoWindow(HWND) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVideoWindow(HWND *) = 0;
virtual HRESULT STDMETHODCALLTYPE RepaintVideo(void) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentImage(BITMAPINFOHEADER *, BYTE **, DWORD *, LONGLONG *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetBorderColor(COLORREF) = 0;
virtual HRESULT STDMETHODCALLTYPE GetBorderColor(COLORREF *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetRenderingPrefs(DWORD) = 0;
virtual HRESULT STDMETHODCALLTYPE GetRenderingPrefs(DWORD *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetFullscreen(BOOL) = 0;
virtual HRESULT STDMETHODCALLTYPE GetFullscreen(BOOL *) = 0;
};
#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL(IMFVideoDisplayControl, 0xa490b1e4, 0xab84, 0x4d31, 0xa1,0xb2, 0x18,0x1e,0x03,0xb1,0x07,0x7a)
#endif
#endif // __IMFVideoDisplayControl_INTERFACE_DEFINED__
#ifndef __IMFVideoProcessor_INTERFACE_DEFINED__
#define __IMFVideoProcessor_INTERFACE_DEFINED__
DEFINE_GUID(IID_IMFVideoProcessor, 0x6AB0000C, 0xFECE, 0x4d1f, 0xA2,0xAC, 0xA9,0x57,0x35,0x30,0x65,0x6E);
MIDL_INTERFACE("6AB0000C-FECE-4d1f-A2AC-A9573530656E")
IMFVideoProcessor : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE GetAvailableVideoProcessorModes(UINT *, GUID **) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVideoProcessorCaps(LPGUID, DXVA2_VideoProcessorCaps *) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVideoProcessorMode(LPGUID) = 0;
virtual HRESULT STDMETHODCALLTYPE SetVideoProcessorMode(LPGUID) = 0;
virtual HRESULT STDMETHODCALLTYPE GetProcAmpRange(DWORD, DXVA2_ValueRange *) = 0;
virtual HRESULT STDMETHODCALLTYPE GetProcAmpValues(DWORD, DXVA2_ProcAmpValues *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetProcAmpValues(DWORD, DXVA2_ProcAmpValues *) = 0;
virtual HRESULT STDMETHODCALLTYPE GetFilteringRange(DWORD, DXVA2_ValueRange *) = 0;
virtual HRESULT STDMETHODCALLTYPE GetFilteringValue(DWORD, DXVA2_Fixed32 *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetFilteringValue(DWORD, DXVA2_Fixed32 *) = 0;
virtual HRESULT STDMETHODCALLTYPE GetBackgroundColor(COLORREF *) = 0;
virtual HRESULT STDMETHODCALLTYPE SetBackgroundColor(COLORREF) = 0;
};
#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL(IMFVideoProcessor, 0x6AB0000C, 0xFECE, 0x4d1f, 0xA2,0xAC, 0xA9,0x57,0x35,0x30,0x65,0x6E)
#endif
#endif // __IMFVideoProcessor_INTERFACE_DEFINED__
#endif // EVRDEFS_H

View File

@@ -3,7 +3,7 @@
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Mobility Components.
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
@@ -31,14 +31,16 @@
**
****************************************************************************/
#include "evr9videowindowcontrol.h"
#include <QtWidgets/qwidget.h>
#include <QtCore/qdebug.h>
#include <QtCore/qglobal.h>
#include "evrvideowindowcontrol.h"
Evr9VideoWindowControl::Evr9VideoWindowControl(QObject *parent)
#ifndef QT_NO_WIDGETS
#include <qwidget.h>
#endif
EvrVideoWindowControl::EvrVideoWindowControl(QObject *parent)
: QVideoWindowControl(parent)
, m_windowId(0)
, m_windowColor(RGB(0, 0, 0))
, m_dirtyValues(0)
, m_aspectRatioMode(Qt::KeepAspectRatio)
, m_brightness(0)
@@ -46,68 +48,83 @@ Evr9VideoWindowControl::Evr9VideoWindowControl(QObject *parent)
, m_hue(0)
, m_saturation(0)
, m_fullScreen(false)
, m_currentActivate(0)
, m_evrSink(0)
, m_displayControl(0)
, m_processor(0)
{
}
Evr9VideoWindowControl::~Evr9VideoWindowControl()
EvrVideoWindowControl::~EvrVideoWindowControl()
{
clear();
}
void Evr9VideoWindowControl::clear()
{
if (m_processor)
m_processor->Release();
if (m_displayControl)
m_displayControl->Release();
if (m_evrSink)
m_evrSink->Release();
if (m_currentActivate) {
m_currentActivate->ShutdownObject();
m_currentActivate->Release();
}
m_processor = NULL;
m_displayControl = NULL;
m_evrSink = NULL;
m_currentActivate = NULL;
}
void Evr9VideoWindowControl::releaseActivate()
bool EvrVideoWindowControl::setEvr(IUnknown *evr)
{
clear();
if (!evr)
return true;
static const GUID mr_VIDEO_RENDER_SERVICE = { 0x1092a86c, 0xab1a, 0x459a, {0xa3, 0x36, 0x83, 0x1f, 0xbc, 0x4d, 0x11, 0xff} };
static const GUID mr_VIDEO_MIXER_SERVICE = { 0x73cd2fc, 0x6cf4, 0x40b7, {0x88, 0x59, 0xe8, 0x95, 0x52, 0xc8, 0x41, 0xf8} };
IMFGetService *service = NULL;
if (SUCCEEDED(evr->QueryInterface(IID_PPV_ARGS(&service)))
&& SUCCEEDED(service->GetService(mr_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_displayControl)))) {
service->GetService(mr_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_processor));
setWinId(m_windowId);
setDisplayRect(m_displayRect);
setAspectRatioMode(m_aspectRatioMode);
m_dirtyValues = DXVA2_ProcAmp_Brightness | DXVA2_ProcAmp_Contrast | DXVA2_ProcAmp_Hue | DXVA2_ProcAmp_Saturation;
applyImageControls();
}
if (service)
service->Release();
return m_displayControl != NULL;
}
WId Evr9VideoWindowControl::winId() const
void EvrVideoWindowControl::clear()
{
if (m_displayControl)
m_displayControl->Release();
m_displayControl = NULL;
if (m_processor)
m_processor->Release();
m_processor = NULL;
}
WId EvrVideoWindowControl::winId() const
{
return m_windowId;
}
void Evr9VideoWindowControl::setWinId(WId id)
void EvrVideoWindowControl::setWinId(WId id)
{
m_windowId = id;
#ifndef QT_NO_WIDGETS
if (QWidget *widget = QWidget::find(m_windowId)) {
const QColor color = widget->palette().color(QPalette::Window);
m_windowColor = RGB(color.red(), color.green(), color.blue());
}
#endif
if (m_displayControl) {
if (m_displayControl)
m_displayControl->SetVideoWindow(HWND(m_windowId));
}
}
QRect Evr9VideoWindowControl::displayRect() const
QRect EvrVideoWindowControl::displayRect() const
{
return m_displayRect;
}
void Evr9VideoWindowControl::setDisplayRect(const QRect &rect)
void EvrVideoWindowControl::setDisplayRect(const QRect &rect)
{
m_displayRect = rect;
@@ -140,19 +157,19 @@ void Evr9VideoWindowControl::setDisplayRect(const QRect &rect)
}
}
bool Evr9VideoWindowControl::isFullScreen() const
bool EvrVideoWindowControl::isFullScreen() const
{
return m_fullScreen;
}
void Evr9VideoWindowControl::setFullScreen(bool fullScreen)
void EvrVideoWindowControl::setFullScreen(bool fullScreen)
{
if (m_fullScreen == fullScreen)
return;
emit fullScreenChanged(m_fullScreen = fullScreen);
}
void Evr9VideoWindowControl::repaint()
void EvrVideoWindowControl::repaint()
{
QSize size = nativeSize();
if (size.width() > 0 && size.height() > 0
@@ -181,7 +198,7 @@ void Evr9VideoWindowControl::repaint()
}
}
QSize Evr9VideoWindowControl::nativeSize() const
QSize EvrVideoWindowControl::nativeSize() const
{
QSize size;
if (m_displayControl) {
@@ -192,12 +209,12 @@ QSize Evr9VideoWindowControl::nativeSize() const
return size;
}
Qt::AspectRatioMode Evr9VideoWindowControl::aspectRatioMode() const
Qt::AspectRatioMode EvrVideoWindowControl::aspectRatioMode() const
{
return m_aspectRatioMode;
}
void Evr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
void EvrVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
{
m_aspectRatioMode = mode;
@@ -222,12 +239,12 @@ void Evr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
}
}
int Evr9VideoWindowControl::brightness() const
int EvrVideoWindowControl::brightness() const
{
return m_brightness;
}
void Evr9VideoWindowControl::setBrightness(int brightness)
void EvrVideoWindowControl::setBrightness(int brightness)
{
if (m_brightness == brightness)
return;
@@ -236,17 +253,17 @@ void Evr9VideoWindowControl::setBrightness(int brightness)
m_dirtyValues |= DXVA2_ProcAmp_Brightness;
setProcAmpValues();
applyImageControls();
emit brightnessChanged(brightness);
}
int Evr9VideoWindowControl::contrast() const
int EvrVideoWindowControl::contrast() const
{
return m_contrast;
}
void Evr9VideoWindowControl::setContrast(int contrast)
void EvrVideoWindowControl::setContrast(int contrast)
{
if (m_contrast == contrast)
return;
@@ -255,17 +272,17 @@ void Evr9VideoWindowControl::setContrast(int contrast)
m_dirtyValues |= DXVA2_ProcAmp_Contrast;
setProcAmpValues();
applyImageControls();
emit contrastChanged(contrast);
}
int Evr9VideoWindowControl::hue() const
int EvrVideoWindowControl::hue() const
{
return m_hue;
}
void Evr9VideoWindowControl::setHue(int hue)
void EvrVideoWindowControl::setHue(int hue)
{
if (m_hue == hue)
return;
@@ -274,17 +291,17 @@ void Evr9VideoWindowControl::setHue(int hue)
m_dirtyValues |= DXVA2_ProcAmp_Hue;
setProcAmpValues();
applyImageControls();
emit hueChanged(hue);
}
int Evr9VideoWindowControl::saturation() const
int EvrVideoWindowControl::saturation() const
{
return m_saturation;
}
void Evr9VideoWindowControl::setSaturation(int saturation)
void EvrVideoWindowControl::setSaturation(int saturation)
{
if (m_saturation == saturation)
return;
@@ -293,41 +310,12 @@ void Evr9VideoWindowControl::setSaturation(int saturation)
m_dirtyValues |= DXVA2_ProcAmp_Saturation;
setProcAmpValues();
applyImageControls();
emit saturationChanged(saturation);
}
IMFActivate* Evr9VideoWindowControl::createActivate()
{
clear();
if (FAILED(MFCreateVideoRendererActivate(0, &m_currentActivate))) {
qWarning() << "Failed to create evr video renderer activate!";
return 0;
}
if (FAILED(m_currentActivate->ActivateObject(IID_IMFMediaSink, (LPVOID*)(&m_evrSink)))) {
qWarning() << "Failed to activate evr media sink!";
return 0;
}
if (FAILED(MFGetService(m_evrSink, MR_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_displayControl)))) {
qWarning() << "Failed to get display control from evr media sink!";
return 0;
}
if (FAILED(MFGetService(m_evrSink, MR_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_processor)))) {
qWarning() << "Failed to get video processor from evr media sink!";
return 0;
}
setWinId(m_windowId);
setDisplayRect(m_displayRect);
setAspectRatioMode(m_aspectRatioMode);
m_dirtyValues = DXVA2_ProcAmp_Brightness | DXVA2_ProcAmp_Contrast | DXVA2_ProcAmp_Hue | DXVA2_ProcAmp_Saturation;
return m_currentActivate;
}
void Evr9VideoWindowControl::setProcAmpValues()
void EvrVideoWindowControl::applyImageControls()
{
if (m_processor) {
DXVA2_ProcAmpValues values;
@@ -350,7 +338,7 @@ void Evr9VideoWindowControl::setProcAmpValues()
}
}
DXVA2_Fixed32 Evr9VideoWindowControl::scaleProcAmpValue(DWORD prop, int value) const
DXVA2_Fixed32 EvrVideoWindowControl::scaleProcAmpValue(DWORD prop, int value) const
{
float scaledValue = 0.0;

View File

@@ -31,23 +31,23 @@
**
****************************************************************************/
#ifndef EVR9VIDEOWINDOWCONTROL_H
#define EVR9VIDEOWINDOWCONTROL_H
#ifndef EVRVIDEOWINDOWCONTROL_H
#define EVRVIDEOWINDOWCONTROL_H
#include "qvideowindowcontrol.h"
#include <Mfidl.h>
#include <d3d9.h>
#include <Evr9.h>
#include "evrdefs.h"
QT_USE_NAMESPACE
class Evr9VideoWindowControl : public QVideoWindowControl
class EvrVideoWindowControl : public QVideoWindowControl
{
Q_OBJECT
public:
Evr9VideoWindowControl(QObject *parent = 0);
~Evr9VideoWindowControl();
EvrVideoWindowControl(QObject *parent = 0);
~EvrVideoWindowControl();
bool setEvr(IUnknown *evr);
WId winId() const;
void setWinId(WId id);
@@ -77,10 +77,7 @@ public:
int saturation() const;
void setSaturation(int saturation);
IMFActivate* createActivate();
void releaseActivate();
void setProcAmpValues();
void applyImageControls();
private:
void clear();
@@ -97,8 +94,6 @@ private:
int m_saturation;
bool m_fullScreen;
IMFActivate *m_currentActivate;
IMFMediaSink *m_evrSink;
IMFVideoDisplayControl *m_displayControl;
IMFVideoProcessor *m_processor;
};

View File

@@ -13,11 +13,6 @@ SOURCES += dsserviceplugin.cpp
!config_wmsdk: DEFINES += QT_NO_WMSDK
qtHaveModule(widgets) {
QT += multimediawidgets
DEFINES += HAVE_WIDGETS
}
mingw: DEFINES += NO_DSHOW_STRSAFE
!config_wmf: include(player/player.pri)

View File

@@ -44,7 +44,7 @@ DirectShowAudioEndpointControl::DirectShowAudioEndpointControl(
, m_deviceEnumerator(0)
{
if (CreateBindCtx(0, &m_bindContext) == S_OK) {
m_deviceEnumerator = com_new<ICreateDevEnum>(CLSID_SystemDeviceEnum, IID_ICreateDevEnum);
m_deviceEnumerator = com_new<ICreateDevEnum>(CLSID_SystemDeviceEnum);
updateEndpoints();

View File

@@ -0,0 +1,63 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "directshowevrvideowindowcontrol.h"
#include "directshowglobal.h"
DirectShowEvrVideoWindowControl::DirectShowEvrVideoWindowControl(QObject *parent)
: EvrVideoWindowControl(parent)
, m_evrFilter(NULL)
{
}
DirectShowEvrVideoWindowControl::~DirectShowEvrVideoWindowControl()
{
if (m_evrFilter)
m_evrFilter->Release();
}
IBaseFilter *DirectShowEvrVideoWindowControl::filter()
{
static const GUID clsid_EnhancendVideoRenderer = { 0xfa10746c, 0x9b63, 0x4b6c, {0xbc, 0x49, 0xfc, 0x30, 0xe, 0xa5, 0xf2, 0x56} };
if (!m_evrFilter) {
m_evrFilter = com_new<IBaseFilter>(clsid_EnhancendVideoRenderer);
if (!setEvr(m_evrFilter)) {
m_evrFilter->Release();
m_evrFilter = NULL;
}
}
return m_evrFilter;
}

View File

@@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef DIRECTSHOWEVRVIDEOWINDOWCONTROL_H
#define DIRECTSHOWEVRVIDEOWINDOWCONTROL_H
#include "evrvideowindowcontrol.h"
struct IBaseFilter;
QT_USE_NAMESPACE
class DirectShowEvrVideoWindowControl : public EvrVideoWindowControl
{
public:
DirectShowEvrVideoWindowControl(QObject *parent = 0);
~DirectShowEvrVideoWindowControl();
IBaseFilter *filter();
private:
IBaseFilter *m_evrFilter;
};
#endif // DIRECTSHOWEVRVIDEOWINDOWCONTROL_H

View File

@@ -46,6 +46,18 @@ template <typename T> T *com_cast(IUnknown *unknown, const IID &iid)
: 0;
}
template <typename T> T *com_new(const IID &clsid)
{
T *object = 0;
return CoCreateInstance(
clsid,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&object)) == S_OK
? object
: 0;
}
template <typename T> T *com_new(const IID &clsid, const IID &iid)
{
T *object = 0;

View File

@@ -132,7 +132,7 @@ HRESULT DirectShowIOReader::RequestAllocator(
return S_OK;
} else {
*ppActual = com_new<IMemAllocator>(CLSID_MemoryAllocator, IID_IMemAllocator);
*ppActual = com_new<IMemAllocator>(CLSID_MemoryAllocator);
if (*ppActual) {
if ((*ppActual)->SetProperties(pProps, &actualProperties) != S_OK) {

View File

@@ -413,7 +413,7 @@ HRESULT DirectShowIOSource::tryConnect(IPin *pin, const AM_MEDIA_TYPE *type)
hr = VFW_E_NO_TRANSPORT;
if (IMemInputPin *memPin = com_cast<IMemInputPin>(pin, IID_IMemInputPin)) {
if ((m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator, IID_IMemAllocator))) {
if ((m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator))) {
ALLOCATOR_PROPERTIES properties;
if (memPin->GetAllocatorRequirements(&properties) == S_OK
|| m_allocator->GetProperties(&properties) == S_OK) {

View File

@@ -38,8 +38,10 @@
#include "directshowmetadatacontrol.h"
#include "directshowplayercontrol.h"
#include "directshowvideorenderercontrol.h"
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
#include "vmr9videowindowcontrol.h"
#ifdef HAVE_EVR
#include "directshowevrvideowindowcontrol.h"
#endif
#ifndef QT_NO_WMSDK
@@ -79,9 +81,7 @@ DirectShowPlayerService::DirectShowPlayerService(QObject *parent)
, m_playerControl(0)
, m_metaDataControl(0)
, m_videoRendererControl(0)
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
, m_videoWindowControl(0)
#endif
, m_audioEndpointControl(0)
, m_taskThread(0)
, m_loop(qt_directShowEventLoop())
@@ -140,9 +140,7 @@ DirectShowPlayerService::~DirectShowPlayerService()
delete m_audioEndpointControl;
delete m_metaDataControl;
delete m_videoRendererControl;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
delete m_videoWindowControl;
#endif
::CloseHandle(m_taskHandle);
}
@@ -156,11 +154,7 @@ QMediaControl *DirectShowPlayerService::requestControl(const char *name)
} else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
return m_metaDataControl;
} else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
if (!m_videoRendererControl && !m_videoWindowControl) {
#else
if (!m_videoRendererControl) {
#endif
m_videoRendererControl = new DirectShowVideoRendererControl(m_loop);
connect(m_videoRendererControl, SIGNAL(filterChanged()),
@@ -168,16 +162,28 @@ QMediaControl *DirectShowPlayerService::requestControl(const char *name)
return m_videoRendererControl;
}
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
} else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
if (!m_videoRendererControl && !m_videoWindowControl) {
m_videoWindowControl = new Vmr9VideoWindowControl;
IBaseFilter *filter;
setVideoOutput(m_videoWindowControl->filter());
#ifdef HAVE_EVR
DirectShowEvrVideoWindowControl *evrControl = new DirectShowEvrVideoWindowControl;
if ((filter = evrControl->filter()))
m_videoWindowControl = evrControl;
else
delete evrControl;
#endif
// Fall back to the VMR9 if the EVR is not available
if (!m_videoWindowControl) {
Vmr9VideoWindowControl *vmr9Control = new Vmr9VideoWindowControl;
filter = vmr9Control->filter();
m_videoWindowControl = vmr9Control;
}
setVideoOutput(filter);
return m_videoWindowControl;
}
#endif
}
return 0;
}
@@ -193,14 +199,12 @@ void DirectShowPlayerService::releaseControl(QMediaControl *control)
delete m_videoRendererControl;
m_videoRendererControl = 0;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
} else if (control == m_videoWindowControl) {
setVideoOutput(0);
delete m_videoWindowControl;
m_videoWindowControl = 0;
#endif
}
}
@@ -275,8 +279,7 @@ void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker)
static const GUID iid_IFileSourceFilter = {
0x56a868a6, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} };
if (IFileSourceFilter *fileSource = com_new<IFileSourceFilter>(
clsid_WMAsfReader, iid_IFileSourceFilter)) {
if (IFileSourceFilter *fileSource = com_new<IFileSourceFilter>(clsid_WMAsfReader, iid_IFileSourceFilter)) {
locker->unlock();
hr = fileSource->Load(reinterpret_cast<const OLECHAR *>(m_url.toString().utf16()), 0);

View File

@@ -51,12 +51,10 @@ class DirectShowAudioEndpointControl;
class DirectShowMetaDataControl;
class DirectShowPlayerControl;
class DirectShowVideoRendererControl;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
class Vmr9VideoWindowControl;
#endif
QT_BEGIN_NAMESPACE
class QMediaContent;
class QVideoWindowControl;
QT_END_NAMESPACE
QT_USE_NAMESPACE
@@ -172,9 +170,7 @@ private:
DirectShowPlayerControl *m_playerControl;
DirectShowMetaDataControl *m_metaDataControl;
DirectShowVideoRendererControl *m_videoRendererControl;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
Vmr9VideoWindowControl *m_videoWindowControl;
#endif
QVideoWindowControl *m_videoWindowControl;
DirectShowAudioEndpointControl *m_audioEndpointControl;
QThread *m_taskThread;

View File

@@ -1,5 +1,9 @@
INCLUDEPATH += $$PWD
LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 -lgdi32
qtHaveModule(widgets): QT += widgets
DEFINES += QMEDIA_DIRECTSHOW_PLAYER
HEADERS += \
@@ -17,7 +21,8 @@ HEADERS += \
$$PWD/directshowsamplescheduler.h \
$$PWD/directshowvideorenderercontrol.h \
$$PWD/mediasamplevideobuffer.h \
$$PWD/videosurfacefilter.h
$$PWD/videosurfacefilter.h \
$$PWD/vmr9videowindowcontrol.h
SOURCES += \
$$PWD/directshowaudioendpointcontrol.cpp \
@@ -33,14 +38,16 @@ SOURCES += \
$$PWD/directshowsamplescheduler.cpp \
$$PWD/directshowvideorenderercontrol.cpp \
$$PWD/mediasamplevideobuffer.cpp \
$$PWD/videosurfacefilter.cpp
qtHaveModule(widgets):!simulator {
HEADERS += \
$$PWD/vmr9videowindowcontrol.h
SOURCES += \
$$PWD/videosurfacefilter.cpp \
$$PWD/vmr9videowindowcontrol.cpp
config_evr {
DEFINES += HAVE_EVR
include($$PWD/../../common/evr.pri)
HEADERS += $$PWD/directshowevrvideowindowcontrol.h
SOURCES += $$PWD/directshowevrvideowindowcontrol.cpp
}
config_wshellitem {
@@ -48,6 +55,3 @@ config_wshellitem {
} else {
DEFINES += QT_NO_SHELLITEM
}
LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 -lgdi32

View File

@@ -35,13 +35,16 @@
#include "directshowglobal.h"
#ifndef QT_NO_WIDGETS
#include <QtGui/QPalette>
#include <QtWidgets/QWidget>
#endif
Vmr9VideoWindowControl::Vmr9VideoWindowControl(QObject *parent)
: QVideoWindowControl(parent)
, m_filter(com_new<IBaseFilter>(CLSID_VideoMixingRenderer9, IID_IBaseFilter))
, m_filter(com_new<IBaseFilter>(CLSID_VideoMixingRenderer9))
, m_windowId(0)
, m_windowColor(RGB(0, 0, 0))
, m_dirtyValues(0)
, m_aspectRatioMode(Qt::KeepAspectRatio)
, m_brightness(0)
@@ -74,11 +77,13 @@ void Vmr9VideoWindowControl::setWinId(WId id)
{
m_windowId = id;
#ifndef QT_NO_WIDGETS
if (QWidget *widget = QWidget::find(m_windowId)) {
const QColor color = widget->palette().color(QPalette::Window);
m_windowColor = RGB(color.red(), color.green(), color.blue());
}
#endif
if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(
m_filter, IID_IVMRWindowlessControl9)) {

View File

@@ -0,0 +1,85 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "mfevrvideowindowcontrol.h"
#include <qdebug.h>
MFEvrVideoWindowControl::MFEvrVideoWindowControl(QObject *parent)
: EvrVideoWindowControl(parent)
, m_currentActivate(NULL)
, m_evrSink(NULL)
{
}
MFEvrVideoWindowControl::~MFEvrVideoWindowControl()
{
clear();
}
void MFEvrVideoWindowControl::clear()
{
setEvr(NULL);
if (m_evrSink)
m_evrSink->Release();
if (m_currentActivate) {
m_currentActivate->ShutdownObject();
m_currentActivate->Release();
}
m_evrSink = NULL;
m_currentActivate = NULL;
}
IMFActivate* MFEvrVideoWindowControl::createActivate()
{
clear();
if (FAILED(MFCreateVideoRendererActivate(0, &m_currentActivate))) {
qWarning() << "Failed to create evr video renderer activate!";
return NULL;
}
if (FAILED(m_currentActivate->ActivateObject(IID_IMFMediaSink, (LPVOID*)(&m_evrSink)))) {
qWarning() << "Failed to activate evr media sink!";
return NULL;
}
if (!setEvr(m_evrSink))
return NULL;
return m_currentActivate;
}
void MFEvrVideoWindowControl::releaseActivate()
{
clear();
}

View File

@@ -0,0 +1,57 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MFEVRVIDEOWINDOWCONTROL_H
#define MFEVRVIDEOWINDOWCONTROL_H
#include "evrvideowindowcontrol.h"
QT_USE_NAMESPACE
class MFEvrVideoWindowControl : public EvrVideoWindowControl
{
public:
MFEvrVideoWindowControl(QObject *parent = 0);
~MFEvrVideoWindowControl();
IMFActivate* createActivate();
void releaseActivate();
private:
void clear();
IMFActivate *m_currentActivate;
IMFMediaSink *m_evrSink;
};
#endif // MFEVRVIDEOWINDOWCONTROL_H

View File

@@ -36,9 +36,7 @@
#include <QtCore/qdebug.h>
#include "mfplayercontrol.h"
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
#include "evr9videowindowcontrol.h"
#endif
#include "mfevrvideowindowcontrol.h"
#include "mfvideorenderercontrol.h"
#include "mfaudioendpointcontrol.h"
#include "mfaudioprobecontrol.h"
@@ -50,9 +48,7 @@
MFPlayerService::MFPlayerService(QObject *parent)
: QMediaService(parent)
, m_session(0)
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
, m_videoWindowControl(0)
#endif
, m_videoRendererControl(0)
{
m_audioEndpointControl = new MFAudioEndpointControl(this);
@@ -65,10 +61,8 @@ MFPlayerService::~MFPlayerService()
{
m_session->close();
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
if (m_videoWindowControl)
delete m_videoWindowControl;
#endif
if (m_videoRendererControl)
delete m_videoRendererControl;
@@ -85,21 +79,15 @@ QMediaControl* MFPlayerService::requestControl(const char *name)
} else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
return m_metaDataControl;
} else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
if (!m_videoRendererControl && !m_videoWindowControl) {
#else
if (!m_videoRendererControl) {
#endif
m_videoRendererControl = new MFVideoRendererControl;
return m_videoRendererControl;
}
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
} else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
if (!m_videoRendererControl && !m_videoWindowControl) {
m_videoWindowControl = new Evr9VideoWindowControl;
m_videoWindowControl = new MFEvrVideoWindowControl;
return m_videoWindowControl;
}
#endif
} else if (qstrcmp(name,QMediaAudioProbeControl_iid) == 0) {
if (m_session) {
MFAudioProbeControl *probe = new MFAudioProbeControl(this);
@@ -129,12 +117,10 @@ void MFPlayerService::releaseControl(QMediaControl *control)
delete m_videoRendererControl;
m_videoRendererControl = 0;
return;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
} else if (control == m_videoWindowControl) {
delete m_videoWindowControl;
m_videoWindowControl = 0;
return;
#endif
}
MFAudioProbeControl* audioProbe = qobject_cast<MFAudioProbeControl*>(control);
@@ -164,12 +150,10 @@ MFVideoRendererControl* MFPlayerService::videoRendererControl() const
return m_videoRendererControl;
}
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
Evr9VideoWindowControl* MFPlayerService::videoWindowControl() const
MFEvrVideoWindowControl* MFPlayerService::videoWindowControl() const
{
return m_videoWindowControl;
}
#endif
MFMetaDataControl* MFPlayerService::metaDataControl() const
{

View File

@@ -48,9 +48,7 @@ QT_END_NAMESPACE
QT_USE_NAMESPACE
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
class Evr9VideoWindowControl;
#endif
class MFEvrVideoWindowControl;
class MFAudioEndpointControl;
class MFVideoRendererControl;
class MFPlayerControl;
@@ -69,18 +67,14 @@ public:
MFAudioEndpointControl* audioEndpointControl() const;
MFVideoRendererControl* videoRendererControl() const;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
Evr9VideoWindowControl* videoWindowControl() const;
#endif
MFEvrVideoWindowControl* videoWindowControl() const;
MFMetaDataControl* metaDataControl() const;
private:
MFPlayerSession *m_session;
MFVideoRendererControl *m_videoRendererControl;
MFAudioEndpointControl *m_audioEndpointControl;
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
Evr9VideoWindowControl *m_videoWindowControl;
#endif
MFEvrVideoWindowControl *m_videoWindowControl;
MFPlayerControl *m_player;
MFMetaDataControl *m_metaDataControl;
};

View File

@@ -43,9 +43,7 @@
#include <QtCore/qbuffer.h>
#include "mfplayercontrol.h"
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
#include "evr9videowindowcontrol.h"
#endif
#include "mfevrvideowindowcontrol.h"
#include "mfvideorenderercontrol.h"
#include "mfaudioendpointcontrol.h"
@@ -140,10 +138,8 @@ void MFPlayerSession::close()
if (m_playerService->videoRendererControl()) {
m_playerService->videoRendererControl()->releaseActivate();
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
} else if (m_playerService->videoWindowControl()) {
m_playerService->videoWindowControl()->releaseActivate();
#endif
}
if (m_session)
@@ -404,10 +400,8 @@ IMFTopologyNode* MFPlayerSession::addOutputNode(IMFStreamDescriptor *streamDesc,
mediaType = Video;
if (m_playerService->videoRendererControl()) {
activate = m_playerService->videoRendererControl()->createActivate();
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
} else if (m_playerService->videoWindowControl()) {
activate = m_playerService->videoWindowControl()->createActivate();
#endif
} else {
qWarning() << "no videoWindowControl or videoRendererControl, unable to add output node for video data";
}
@@ -1580,13 +1574,11 @@ void MFPlayerSession::handleSessionEvent(IMFMediaEvent *sessionEvent)
}
updatePendingCommands(CmdStart);
#if defined(HAVE_WIDGETS) && !defined(Q_WS_SIMULATOR)
// playback started, we can now set again the procAmpValues if they have been
// changed previously (these are lost when loading a new media)
if (m_playerService->videoWindowControl()) {
m_playerService->videoWindowControl()->setProcAmpValues();
m_playerService->videoWindowControl()->applyImageControls();
}
#endif
break;
case MESessionStopped:
if (m_status != QMediaPlayer::EndOfMedia) {

View File

@@ -57,7 +57,7 @@ QT_USE_NAMESPACE
class SourceResolver;
#ifndef Q_WS_SIMULATOR
class Evr9VideoWindowControl;
class EvrVideoWindowControl;
#endif
class MFAudioEndpointControl;
class MFVideoRendererControl;

View File

@@ -12,7 +12,8 @@ HEADERS += \
$$PWD/mfaudioendpointcontrol.h \
$$PWD/mfmetadatacontrol.h \
$$PWD/mfaudioprobecontrol.h \
$$PWD/mfvideoprobecontrol.h
$$PWD/mfvideoprobecontrol.h \
$$PWD/mfevrvideowindowcontrol.h
SOURCES += \
$$PWD/mfplayerservice.cpp \
@@ -22,9 +23,7 @@ SOURCES += \
$$PWD/mfaudioendpointcontrol.cpp \
$$PWD/mfmetadatacontrol.cpp \
$$PWD/mfaudioprobecontrol.cpp \
$$PWD/mfvideoprobecontrol.cpp
$$PWD/mfvideoprobecontrol.cpp \
$$PWD/mfevrvideowindowcontrol.cpp
qtHaveModule(widgets):!simulator {
HEADERS += $$PWD/evr9videowindowcontrol.h
SOURCES += $$PWD/evr9videowindowcontrol.cpp
}
include($$PWD/../../common/evr.pri)

View File

@@ -1,9 +1,6 @@
TARGET = wmfengine
QT += multimedia-private network
qtHaveModule(widgets) {
QT += multimediawidgets-private
DEFINES += HAVE_WIDGETS
}
win32:!qtHaveModule(opengl) {
LIBS_PRIVATE += -lgdi32 -luser32
}
@@ -37,15 +34,14 @@ contains(QT_CONFIG, angle)|contains(QT_CONFIG, dynamicgl) {
QT += gui-private
HEADERS += \
evrcustompresenter.h \
evrd3dpresentengine.h
$$PWD/evrcustompresenter.h \
$$PWD/evrd3dpresentengine.h
SOURCES += \
evrcustompresenter.cpp \
evrd3dpresentengine.cpp
$$PWD/evrcustompresenter.cpp \
$$PWD/evrd3dpresentengine.cpp
}
include (player/player.pri)
include (decoder/decoder.pri)