From ef312b121470ec662ff6c861d02f880026e786b0 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 26 Mar 2010 13:06:37 +1000 Subject: Support expanding aspect ratio in direct show video window control. Task-number: QTBUG-9118 Reviewed-by: Dmytro Poplavskiy --- .../mediaplayer/directshowplayerservice.cpp | 7 +++ .../mediaplayer/directshowplayerservice.h | 3 +- .../mediaplayer/vmr9videowindowcontrol.cpp | 59 +++++++++++----------- .../mediaplayer/vmr9videowindowcontrol.h | 4 ++ 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp index d54d188..a5f143f 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp @@ -191,6 +191,8 @@ void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream m_atEnd = false; m_metaDataControl->updateGraph(0, 0); + QCoreApplication::postEvent(this, new QEvent(QEvent::Type(VideoOutputChange))); + if (m_resources.isEmpty() && !stream) { m_pendingTasks = 0; m_graphStatus = NoMedia; @@ -464,6 +466,8 @@ void DirectShowPlayerService::doRender(QMutexLocker *locker) QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); } + QCoreApplication::postEvent(this, new QEvent(QEvent::Type(VideoOutputChange))); + m_executedTasks |= Render; } } @@ -1144,6 +1148,9 @@ void DirectShowPlayerService::customEvent(QEvent *event) QMutexLocker locker(&m_mutex); m_playerControl->updatePosition(m_position); + } else if (event->type() == QEvent::Type(VideoOutputChange)) { + if (m_videoWindowControl) + m_videoWindowControl->updateNativeSize(); } else { QMediaService::customEvent(event); } diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h index 23515d0..d3ef809 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h @@ -164,7 +164,8 @@ private: DurationChange, StatusChange, EndOfMedia, - PositionChange + PositionChange, + VideoOutputChange }; enum GraphStatus diff --git a/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.cpp b/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.cpp index 4b9aeb8..e25dd99 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.cpp @@ -51,6 +51,7 @@ Vmr9VideoWindowControl::Vmr9VideoWindowControl(QObject *parent) , m_filter(com_new(CLSID_VideoMixingRenderer9, IID_IBaseFilter)) , m_windowId(0) , m_dirtyValues(0) + , m_aspectRatioMode(Qt::KeepAspectRatio) , m_brightness(0) , m_contrast(0) , m_hue(0) @@ -90,33 +91,30 @@ void Vmr9VideoWindowControl::setWinId(WId id) QRect Vmr9VideoWindowControl::displayRect() const { - QRect rect; - - if (IVMRWindowlessControl9 *control = com_cast( - m_filter, IID_IVMRWindowlessControl9)) { - RECT sourceRect; - RECT displayRect; - - if (control->GetVideoPosition(&sourceRect, &displayRect) == S_OK) { - rect = QRect( - displayRect.left, - displayRect.bottom, - displayRect.right - displayRect.left, - displayRect.bottom - displayRect.top); - } - control->Release(); - } - return rect; + return m_displayRect; } void Vmr9VideoWindowControl::setDisplayRect(const QRect &rect) { + m_displayRect = rect; + if (IVMRWindowlessControl9 *control = com_cast( m_filter, IID_IVMRWindowlessControl9)) { RECT sourceRect = { 0, 0, 0, 0 }; RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() }; control->GetNativeVideoSize(&sourceRect.right, &sourceRect.bottom, 0, 0); + + if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) { + QSize clippedSize = rect.size(); + clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio); + + sourceRect.left = (sourceRect.right - clippedSize.width()) / 2; + sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2; + sourceRect.right = sourceRect.left + clippedSize.width(); + sourceRect.bottom = sourceRect.top + clippedSize.height(); + } + control->SetVideoPosition(&sourceRect, &displayRect); control->Release(); } @@ -134,7 +132,6 @@ void Vmr9VideoWindowControl::setFullScreen(bool fullScreen) void Vmr9VideoWindowControl::repaint() { - if (QWidget *widget = QWidget::find(m_windowId)) { HDC dc = widget->getDC(); if (IVMRWindowlessControl9 *control = com_cast( @@ -164,21 +161,13 @@ QSize Vmr9VideoWindowControl::nativeSize() const Qt::AspectRatioMode Vmr9VideoWindowControl::aspectRatioMode() const { - Qt::AspectRatioMode mode = Qt::KeepAspectRatio; - - if (IVMRWindowlessControl9 *control = com_cast( - m_filter, IID_IVMRWindowlessControl9)) { - DWORD arMode; - - if (control->GetAspectRatioMode(&arMode) == S_OK && arMode == VMR9ARMode_None) - mode = Qt::IgnoreAspectRatio; - control->Release(); - } - return mode; + return m_aspectRatioMode; } void Vmr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) { + m_aspectRatioMode = mode; + if (IVMRWindowlessControl9 *control = com_cast( m_filter, IID_IVMRWindowlessControl9)) { switch (mode) { @@ -188,10 +177,15 @@ void Vmr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) case Qt::KeepAspectRatio: control->SetAspectRatioMode(VMR9ARMode_LetterBox); break; + case Qt::KeepAspectRatioByExpanding: + control->SetAspectRatioMode(VMR9ARMode_LetterBox); + break; default: break; } control->Release(); + + setDisplayRect(m_displayRect); } } @@ -259,6 +253,13 @@ void Vmr9VideoWindowControl::setSaturation(int saturation) emit saturationChanged(saturation); } +void Vmr9VideoWindowControl::updateNativeSize() +{ + setDisplayRect(m_displayRect); + + emit nativeSizeChanged(); +} + void Vmr9VideoWindowControl::setProcAmpValues() { if (IVMRMixerControl9 *control = com_cast(m_filter, IID_IVMRMixerControl9)) { diff --git a/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h index bf4fb42..beac433 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h @@ -90,6 +90,8 @@ public: int saturation() const; void setSaturation(int saturation); + void updateNativeSize(); + private: void setProcAmpValues(); float scaleProcAmpValue( @@ -98,6 +100,8 @@ private: IBaseFilter *m_filter; WId m_windowId; DWORD m_dirtyValues; + Qt::AspectRatioMode m_aspectRatioMode; + QRect m_displayRect; int m_brightness; int m_contrast; int m_hue; -- cgit v0.12