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:
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user