qtmobility/plugins/multimedia/wmp/qevrvideooverlay.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qevrvideooverlay.h"
       
    43 
       
    44 #include <d3d9.h>
       
    45 
       
    46 QEvrVideoOverlay::QEvrVideoOverlay(HINSTANCE evrHwnd)
       
    47     : m_ref(1)
       
    48     , m_evrHwnd(evrHwnd)
       
    49     , ptrMFCreateVideoPresenter(0)
       
    50     , m_presenter(0)
       
    51     , m_displayControl(0)
       
    52     , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
       
    53     , m_winId(0)
       
    54     , m_fullScreen(0)
       
    55 {
       
    56     ptrMFCreateVideoPresenter = reinterpret_cast<PtrMFCreateVideoPresenter>(
       
    57             GetProcAddress(m_evrHwnd, "MFCreateVideoPresenter"));
       
    58 }
       
    59 
       
    60 QEvrVideoOverlay::~QEvrVideoOverlay()
       
    61 {
       
    62     FreeLibrary(m_evrHwnd);
       
    63 }
       
    64 
       
    65 WId QEvrVideoOverlay::winId() const
       
    66 {
       
    67     return m_winId;
       
    68 }
       
    69 
       
    70 void QEvrVideoOverlay::setWinId(WId id)
       
    71 {
       
    72     if (m_displayControl) {
       
    73         m_displayControl->SetVideoWindow(id);
       
    74 
       
    75         QRect rect = m_displayRect;
       
    76 
       
    77         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
       
    78 
       
    79         m_displayControl->SetVideoPosition(0, &displayRect);
       
    80     }
       
    81 
       
    82     m_winId = id;
       
    83 }
       
    84 
       
    85 QRect QEvrVideoOverlay::displayRect() const
       
    86 {
       
    87     return m_displayRect;
       
    88 }
       
    89 
       
    90 void QEvrVideoOverlay::setDisplayRect(const QRect &rect)
       
    91 {
       
    92     if (m_displayControl) {
       
    93         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
       
    94 
       
    95         m_displayControl->SetVideoPosition(0, &displayRect);
       
    96     }
       
    97 
       
    98     m_displayRect = rect;
       
    99 }
       
   100 
       
   101 bool QEvrVideoOverlay::isFullScreen() const
       
   102 {
       
   103     return m_fullScreen;
       
   104 }
       
   105 
       
   106 void QEvrVideoOverlay::setFullScreen(bool fullScreen)
       
   107 {
       
   108     emit fullScreenChanged(m_fullScreen = fullScreen);
       
   109 }
       
   110 
       
   111 QSize QEvrVideoOverlay::nativeSize() const
       
   112 {
       
   113     SIZE size;
       
   114 
       
   115     if (m_displayControl && m_displayControl->GetNativeVideoSize(&size, 0) == S_OK) {
       
   116         return QSize(size.cx, size.cy);
       
   117     } else {
       
   118         return QSize();
       
   119     }
       
   120 }
       
   121 
       
   122 QVideoWidget::AspectRatioMode QEvrVideoOverlay::aspectRatioMode() const
       
   123 {
       
   124     return m_aspectRatioMode;
       
   125 }
       
   126 
       
   127 void QEvrVideoOverlay::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
       
   128 {
       
   129     switch (mode) {
       
   130     case QVideoWidget::KeepAspectRatio:
       
   131         if (m_displayControl)
       
   132                 m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
       
   133 
       
   134         m_aspectRatioMode = mode;
       
   135         break;
       
   136     case QVideoWidget::IgnoreAspectRatio:
       
   137         if (m_displayControl)
       
   138                 m_displayControl->SetAspectRatioMode(MFVideoARMode_None);
       
   139 
       
   140         m_aspectRatioMode = mode;
       
   141         break;
       
   142     default:
       
   143         break;
       
   144     }
       
   145 }
       
   146 
       
   147 void QEvrVideoOverlay::repaint()
       
   148 {
       
   149     if (m_displayControl)
       
   150         m_displayControl->RepaintVideo();
       
   151 }
       
   152 
       
   153 int QEvrVideoOverlay::brightness() const
       
   154 {
       
   155     return 0;
       
   156 }
       
   157 
       
   158 void QEvrVideoOverlay::setBrightness(int)
       
   159 {
       
   160 }
       
   161 
       
   162 int QEvrVideoOverlay::contrast() const
       
   163 {
       
   164     return 0;
       
   165 }
       
   166 
       
   167 void QEvrVideoOverlay::setContrast(int)
       
   168 {
       
   169 }
       
   170 
       
   171 int QEvrVideoOverlay::hue() const
       
   172 {
       
   173     return 0;
       
   174 }
       
   175 
       
   176 void QEvrVideoOverlay::setHue(int)
       
   177 {
       
   178 }
       
   179 
       
   180 int QEvrVideoOverlay::saturation() const
       
   181 {
       
   182     return 0;
       
   183 }
       
   184 
       
   185 void QEvrVideoOverlay::setSaturation(int)
       
   186 {
       
   187 }
       
   188 
       
   189 void QEvrVideoOverlay::setDisplayControl(IMFVideoDisplayControl *control)
       
   190 {
       
   191     if (m_displayControl)
       
   192         m_displayControl->Release();
       
   193 
       
   194     m_displayControl = control;
       
   195 
       
   196     if (m_displayControl) {
       
   197         QRect rect = displayRect();
       
   198         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
       
   199 
       
   200         m_displayControl->AddRef();
       
   201         m_displayControl->SetVideoWindow(winId());
       
   202         m_displayControl->SetVideoPosition(0, &displayRect);
       
   203     }
       
   204 }
       
   205 
       
   206 // IUnknown
       
   207 HRESULT QEvrVideoOverlay::QueryInterface(REFIID riid, void **object)
       
   208 {
       
   209     if (!object) {
       
   210         return E_POINTER;
       
   211     } else if (riid == __uuidof(IUnknown)
       
   212             || riid == __uuidof(IMFAttributes)
       
   213             || riid == __uuidof(IMFActivate)) {
       
   214         *object = static_cast<IMFActivate *>(this);
       
   215     } else {
       
   216         return E_NOINTERFACE;
       
   217     }
       
   218 
       
   219     AddRef();
       
   220 
       
   221     return S_OK;
       
   222 }
       
   223 
       
   224 ULONG QEvrVideoOverlay::AddRef()
       
   225 {
       
   226     return InterlockedIncrement(&m_ref);
       
   227 }
       
   228 
       
   229 ULONG QEvrVideoOverlay::Release()
       
   230 {
       
   231     ULONG ref = InterlockedDecrement(&m_ref);
       
   232 
       
   233     Q_ASSERT(ref != 0);
       
   234 
       
   235     return ref;
       
   236 }
       
   237 
       
   238 // IMFActivate
       
   239 HRESULT QEvrVideoOverlay::ActivateObject(REFIID riid, void **ppv)
       
   240 {
       
   241     if (riid != __uuidof(IMFVideoPresenter)) {
       
   242         return E_NOINTERFACE;
       
   243     } else if (!ptrMFCreateVideoPresenter) {
       
   244         return E_NOINTERFACE;
       
   245     } else if (m_presenter) {
       
   246         *ppv = m_presenter;
       
   247 
       
   248         return S_OK;
       
   249     } else {
       
   250         IMFVideoDisplayControl *displayControl = 0;
       
   251 
       
   252         IMFGetService *service;
       
   253         HRESULT hr;
       
   254         if ((hr = (*ptrMFCreateVideoPresenter)(
       
   255                 0,
       
   256                 __uuidof(IDirect3DDevice9),
       
   257                 __uuidof(IMFVideoPresenter),
       
   258                 reinterpret_cast<void **>(&m_presenter))) != S_OK) {
       
   259             qWarning("failed to create video presenter");
       
   260         } else if ((hr = m_presenter->QueryInterface(
       
   261                 __uuidof(IMFGetService), reinterpret_cast<void **>(&service))) != S_OK) {
       
   262             qWarning("failed to query IMFGetService interface");
       
   263         } else {
       
   264             if ((hr = service->GetService(
       
   265                     MR_VIDEO_RENDER_SERVICE,
       
   266                     __uuidof(IMFVideoDisplayControl),
       
   267                     reinterpret_cast<void **>(&displayControl))) != S_OK) {
       
   268                 qWarning("failed to get IMFVideoDisplayControl service");
       
   269             }
       
   270             service->Release();
       
   271         }
       
   272 
       
   273         setDisplayControl(displayControl);
       
   274 
       
   275         if (m_presenter && hr != S_OK) {
       
   276             m_presenter->Release();
       
   277             m_presenter = 0;
       
   278         }
       
   279 
       
   280         *ppv = m_presenter;
       
   281 
       
   282         return hr;
       
   283     }
       
   284 }
       
   285 
       
   286 HRESULT QEvrVideoOverlay::ShutdownObject()
       
   287 {
       
   288     setDisplayControl(0);
       
   289 
       
   290     if (m_presenter) {
       
   291         m_presenter->Release();
       
   292         m_presenter = 0;
       
   293     }
       
   294     return S_OK;
       
   295 }
       
   296 
       
   297 HRESULT QEvrVideoOverlay::DetachObject()
       
   298 {
       
   299     if (m_presenter) {
       
   300         m_presenter->Release();
       
   301         m_presenter = 0;
       
   302     }
       
   303 
       
   304     return S_OK;
       
   305 }