diff options
author | APTX <APTX@321@gmail.com> | 2009-09-25 00:45:20 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-16 10:59:03 (GMT) |
commit | 4c34411151516badbf0e286c9a477845cb02b1cc (patch) | |
tree | 334e10ab771adf37e84361eeb3e8080b44560195 /src | |
parent | b4790f30d62b00bd1a91ca9de78b3c5738de5fd1 (diff) | |
download | Qt-4c34411151516badbf0e286c9a477845cb02b1cc.zip Qt-4c34411151516badbf0e286c9a477845cb02b1cc.tar.gz Qt-4c34411151516badbf0e286c9a477845cb02b1cc.tar.bz2 |
Add EVR to the Phonon DirectShow9 (ds9) backend as the default.
EVR stands for Enhanced Video Renderer and uses DXVA2. It was
introduced in Windows Vista.
Merge-Request: 1606
Reviewed-By: Thierry
Diffstat (limited to 'src')
-rw-r--r-- | src/3rdparty/phonon/ds9/videorenderer_evr.cpp | 197 | ||||
-rw-r--r-- | src/3rdparty/phonon/ds9/videorenderer_evr.h | 70 | ||||
-rw-r--r-- | src/3rdparty/phonon/ds9/videowidget.cpp | 16 | ||||
-rw-r--r-- | src/plugins/phonon/ds9/ds9.pro | 4 |
4 files changed, 282 insertions, 5 deletions
diff --git a/src/3rdparty/phonon/ds9/videorenderer_evr.cpp b/src/3rdparty/phonon/ds9/videorenderer_evr.cpp new file mode 100644 index 0000000..3c6ee0d --- /dev/null +++ b/src/3rdparty/phonon/ds9/videorenderer_evr.cpp @@ -0,0 +1,197 @@ +/* This file is part of the KDE project.
+
+Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+
+This library is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 2.1 or 3 of the License.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include "videorenderer_evr.h"
+
+#ifndef QT_NO_PHONON_VIDEO
+
+#include <QtGui/QWidget>
+#include <QtGui/QPainter>
+#include <QtCore/QTimerEvent>
+
+#include <d3d9.h>
+#include <Evr9.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Phonon
+{
+ namespace DS9
+ {
+ VideoRendererEVR::~VideoRendererEVR()
+ {
+ }
+
+ bool VideoRendererEVR::isNative() const
+ {
+ return true;
+ }
+
+ VideoRendererEVR::VideoRendererEVR(QWidget *target) : m_target(target)
+ {
+ m_filter = Filter(CLSID_EnhancedVideoRenderer, IID_IBaseFilter);
+ if (!m_filter) {
+ qWarning("the video widget could not be initialized correctly");
+ return;
+ }
+
+ ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
+
+ filterControl->SetVideoWindow(reinterpret_cast<HWND>(target->winId()));
+ filterControl->SetAspectRatioMode(MFVideoARMode_None); // We're in control of the size
+ }
+
+ QImage VideoRendererEVR::snapshot() const
+ {
+ // TODO test
+ // This will always capture black areas where no video is drawn, if any are present.
+ // Due to the hack in notifyResize()
+ ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
+ if (filterControl) {
+ BITMAPINFOHEADER bmi;
+ BYTE *buffer = 0;
+ DWORD bufferSize;
+ LONGLONG timeStamp;
+
+ bmi.biSize = sizeof(BITMAPINFOHEADER);
+
+ HRESULT hr = filterControl->GetCurrentImage(&bmi, &buffer, &bufferSize, &timeStamp);
+ if (SUCCEEDED(hr)) {
+
+ const int w = qAbs(bmi.biWidth),
+ h = qAbs(bmi.biHeight);
+
+ // Create image and copy data into image.
+ QImage ret(w, h, QImage::Format_RGB32);
+
+ if (!ret.isNull()) {
+ uchar *data = buffer;
+ const int bytes_per_line = w * sizeof(QRgb);
+ for (int y = h - 1; y >= 0; --y) {
+ qMemCopy(ret.scanLine(y), //destination
+ data, //source
+ bytes_per_line);
+ data += bytes_per_line;
+ }
+ }
+ ::CoTaskMemFree(buffer);
+ return ret;
+ }
+ }
+ return QImage();
+ }
+
+ QSize VideoRendererEVR::videoSize() const
+ {
+ SIZE nativeSize;
+ SIZE aspectRatioSize;
+
+ ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
+
+ filterControl->GetNativeVideoSize(&nativeSize, &aspectRatioSize);
+
+ return QSize(nativeSize.cx, nativeSize.cy);
+ }
+
+ void VideoRendererEVR::repaintCurrentFrame(QWidget *target, const QRect &rect)
+ {
+ // repaint the video
+ ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
+ // All failed results can be safely ignored
+ filterControl->RepaintVideo();
+ }
+
+ void VideoRendererEVR::notifyResize(const QSize &size, Phonon::VideoWidget::AspectRatio aspectRatio,
+ Phonon::VideoWidget::ScaleMode scaleMode)
+ {
+ if (!isActive()) {
+ RECT dummyRect = { 0, 0, 0, 0};
+ ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
+ filterControl->SetVideoPosition(0, &dummyRect);
+ return;
+ }
+
+ const QSize vsize = videoSize();
+ internalNotifyResize(size, vsize, aspectRatio, scaleMode);
+
+ RECT dstRectWin = { 0, 0, size.width(), size.height()};
+
+ // Resize the Stream output rect instead of the destination rect.
+ // Hacky workaround for flicker in the areas outside of the destination rect
+ // This way these areas don't exist
+ MFVideoNormalizedRect streamOutputRect = { float(m_dstX) / float(size.width()), float(m_dstY) / float(size.height()),
+ float(m_dstWidth + m_dstX) / float(size.width()), float(m_dstHeight + m_dstY) / float(size.height())};
+
+ ComPointer<IMFVideoMixerControl> filterMixer = getService<IMFVideoMixerControl>(MR_VIDEO_MIXER_SERVICE, IID_IMFVideoMixerControl);
+ ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
+
+ filterMixer->SetStreamOutputRect(0, &streamOutputRect);
+ filterControl->SetVideoPosition(0, &dstRectWin);
+ }
+
+ void VideoRendererEVR::applyMixerSettings(qreal brightness, qreal contrast, qreal hue, qreal saturation)
+ {
+ InputPin sink = BackendNode::pins(m_filter, PINDIR_INPUT).first();
+ OutputPin source;
+ if (FAILED(sink->ConnectedTo(source.pparam()))) {
+ return; //it must be connected to work
+ }
+
+ // Get the "Video Processor" (used for brightness/contrast/saturation/hue)
+ ComPointer<IMFVideoProcessor> processor = getService<IMFVideoProcessor>(MR_VIDEO_MIXER_SERVICE, IID_IMFVideoProcessor);
+ Q_ASSERT(processor);
+
+ DXVA2_ValueRange contrastRange;
+ DXVA2_ValueRange brightnessRange;
+ DXVA2_ValueRange saturationRange;
+ DXVA2_ValueRange hueRange;
+
+ if (FAILED(processor->GetProcAmpRange(DXVA2_ProcAmp_Contrast, &contrastRange)))
+ return;
+ if (FAILED(processor->GetProcAmpRange(DXVA2_ProcAmp_Brightness, &brightnessRange)))
+ return;
+ if (FAILED(processor->GetProcAmpRange(DXVA2_ProcAmp_Saturation, &saturationRange)))
+ return;
+ if (FAILED(processor->GetProcAmpRange(DXVA2_ProcAmp_Hue, &hueRange)))
+ return;
+
+ DXVA2_ProcAmpValues values;
+
+ values.Contrast = DXVA2FloatToFixed(((contrast < 0
+ ? DXVA2FixedToFloat(contrastRange.MinValue) : DXVA2FixedToFloat(contrastRange.MaxValue))
+ - DXVA2FixedToFloat(contrastRange.DefaultValue)) * qAbs(contrast) + DXVA2FixedToFloat(contrastRange.DefaultValue));
+ values.Brightness = DXVA2FloatToFixed(((brightness < 0
+ ? DXVA2FixedToFloat(brightnessRange.MinValue) : DXVA2FixedToFloat(brightnessRange.MaxValue))
+ - DXVA2FixedToFloat(brightnessRange.DefaultValue)) * qAbs(brightness) + DXVA2FixedToFloat(brightnessRange.DefaultValue));
+ values.Saturation = DXVA2FloatToFixed(((saturation < 0
+ ? DXVA2FixedToFloat(saturationRange.MinValue) : DXVA2FixedToFloat(saturationRange.MaxValue))
+ - DXVA2FixedToFloat(saturationRange.DefaultValue)) * qAbs(saturation) + DXVA2FixedToFloat(saturationRange.DefaultValue));
+ values.Hue = DXVA2FloatToFixed(((hue < 0
+ ? DXVA2FixedToFloat(hueRange.MinValue) : DXVA2FixedToFloat(hueRange.MaxValue))
+ - DXVA2FixedToFloat(hueRange.DefaultValue)) * qAbs(hue) + DXVA2FixedToFloat(hueRange.DefaultValue));
+
+ //finally set the settings
+ processor->SetProcAmpValues(DXVA2_ProcAmp_Contrast | DXVA2_ProcAmp_Brightness | DXVA2_ProcAmp_Saturation | DXVA2_ProcAmp_Hue, &values);
+
+ }
+ }
+}
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_PHONON_VIDEO
diff --git a/src/3rdparty/phonon/ds9/videorenderer_evr.h b/src/3rdparty/phonon/ds9/videorenderer_evr.h new file mode 100644 index 0000000..055e618 --- /dev/null +++ b/src/3rdparty/phonon/ds9/videorenderer_evr.h @@ -0,0 +1,70 @@ +/* This file is part of the KDE project.
+
+Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+
+This library is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 2.1 or 3 of the License.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef PHONON_VIDEORENDERER_EVR_H
+#define PHONON_VIDEORENDERER_EVR_H
+
+#include "abstractvideorenderer.h"
+#include "compointer.h"
+
+#include <Mfidl.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PHONON_VIDEO
+
+namespace Phonon
+{
+ namespace DS9
+ {
+ class VideoRendererEVR : public AbstractVideoRenderer
+ {
+ public:
+ VideoRendererEVR(QWidget *target);
+ ~VideoRendererEVR();
+
+ //Implementation from AbstractVideoRenderer
+ void repaintCurrentFrame(QWidget *target, const QRect &rect);
+ void notifyResize(const QSize&, Phonon::VideoWidget::AspectRatio, Phonon::VideoWidget::ScaleMode);
+ QSize videoSize() const;
+ QImage snapshot() const;
+ void applyMixerSettings(qreal brightness, qreal contrast, qreal m_hue, qreal saturation);
+ bool isNative() const;
+ private:
+ QWidget *m_target;
+
+ template <typename T> ComPointer<T> getService(REFGUID guidService, REFIID riid) const
+ {
+ ComPointer<IMFGetService> getService(m_filter, IID_IMFGetService);
+ Q_ASSERT(getService);
+ T *ptr = 0;
+ HRESULT hr = getService->GetService(guidService, riid, (void **) &ptr);
+ if (!SUCCEEDED(hr) || ptr == 0)
+ Q_ASSERT(!SUCCEEDED(hr) && ptr != 0);
+ ComPointer<T> service(ptr);
+ return service;
+ }
+ };
+ }
+}
+
+#endif //QT_NO_PHONON_VIDEO
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/3rdparty/phonon/ds9/videowidget.cpp b/src/3rdparty/phonon/ds9/videowidget.cpp index 091be16..f71eb6f 100644 --- a/src/3rdparty/phonon/ds9/videowidget.cpp +++ b/src/3rdparty/phonon/ds9/videowidget.cpp @@ -24,6 +24,7 @@ along with this library. If not, see <http://www.gnu.org/licenses/>. #include "mediaobject.h" +#include "videorenderer_evr.h" #include "videorenderer_vmr9.h" #include "videorenderer_soft.h" @@ -349,14 +350,21 @@ namespace Phonon int index = graphIndex * 2 + type; if (m_renderers[index] == 0 && autoCreate) { AbstractVideoRenderer *renderer = 0; - if (type == Native) { - renderer = new VideoRendererVMR9(m_widget); + if (type == Native) { + renderer = new VideoRendererEVR(m_widget); if (renderer->getFilter() == 0) { - //instanciating the renderer might fail with error VFW_E_DDRAW_CAPS_NOT_SUITABLE (0x80040273) - m_noNativeRendererSupported = true; delete renderer; renderer = 0; } + if (renderer == 0) { + renderer = new VideoRendererVMR9(m_widget); + if (renderer->getFilter() == 0) { + //instanciating the renderer might fail with error VFW_E_DDRAW_CAPS_NOT_SUITABLE (0x80040273) + m_noNativeRendererSupported = true; + delete renderer; + renderer = 0; + } + } } if (renderer == 0) { diff --git a/src/plugins/phonon/ds9/ds9.pro b/src/plugins/phonon/ds9/ds9.pro index 786338a..440f2c5 100644 --- a/src/plugins/phonon/ds9/ds9.pro +++ b/src/plugins/phonon/ds9/ds9.pro @@ -3,7 +3,7 @@ QT += phonon win32:!wince*:contains(QT_CONFIG,opengl):LIBS += -lopengl32 win32:!wince*:LIBS += -lgdi32 win32-msvc2005:DEFINES += _CRT_SECURE_NO_WARNINGS -LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 +LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 -lMfuuid -lStrmiids TARGET = phonon_ds9 DEFINES += PHONON_MAKE_QT_ONLY_BACKEND @@ -23,6 +23,7 @@ HEADERS += \ $$PHONON_DS9_DIR/videowidget.h \ $$PHONON_DS9_DIR/videorenderer_soft.h \ $$PHONON_DS9_DIR/videorenderer_vmr9.h \ + $$PHONON_DS9_DIR/videorenderer_evr.h \ $$PHONON_DS9_DIR/volumeeffect.h \ $$PHONON_DS9_DIR/qbasefilter.h \ $$PHONON_DS9_DIR/qpin.h \ @@ -46,6 +47,7 @@ SOURCES += \ $$PHONON_DS9_DIR/videowidget.cpp \ $$PHONON_DS9_DIR/videorenderer_soft.cpp \ $$PHONON_DS9_DIR/videorenderer_vmr9.cpp \ + $$PHONON_DS9_DIR/videorenderer_evr.cpp \ $$PHONON_DS9_DIR/volumeeffect.cpp \ $$PHONON_DS9_DIR/qbasefilter.cpp \ $$PHONON_DS9_DIR/qpin.cpp \ |