qtmobility/plugins/multimedia/wmp/qevrvideooverlay.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "qevrvideooverlay.h"
    42 #include "qevrvideooverlay.h"
    43 
    43 
    44 #include <d3d9.h>
    44 #include <d3d9.h>
       
    45 #include <wmp.h>
    45 
    46 
    46 QEvrVideoOverlay::QEvrVideoOverlay(HINSTANCE evrHwnd)
    47 QEvrVideoOverlay::QEvrVideoOverlay(HINSTANCE evrHwnd)
    47     : m_ref(1)
    48     : m_ref(1)
    48     , m_evrHwnd(evrHwnd)
    49     , m_evrHwnd(evrHwnd)
    49     , ptrMFCreateVideoPresenter(0)
    50     , ptrMFCreateVideoPresenter(0)
    50     , m_presenter(0)
    51     , m_presenter(0)
    51     , m_displayControl(0)
    52     , m_displayControl(0)
    52     , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
    53     , m_aspectRatioMode(Qt::KeepAspectRatio)
    53     , m_winId(0)
    54     , m_winId(0)
    54     , m_fullScreen(0)
    55     , m_fullScreen(0)
    55 {
    56 {
    56     ptrMFCreateVideoPresenter = reinterpret_cast<PtrMFCreateVideoPresenter>(
    57     ptrMFCreateVideoPresenter = reinterpret_cast<PtrMFCreateVideoPresenter>(
    57             GetProcAddress(m_evrHwnd, "MFCreateVideoPresenter"));
    58             GetProcAddress(m_evrHwnd, "MFCreateVideoPresenter"));
    67     return m_winId;
    68     return m_winId;
    68 }
    69 }
    69 
    70 
    70 void QEvrVideoOverlay::setWinId(WId id)
    71 void QEvrVideoOverlay::setWinId(WId id)
    71 {
    72 {
       
    73     m_winId = id;
       
    74 
    72     if (m_displayControl) {
    75     if (m_displayControl) {
    73         m_displayControl->SetVideoWindow(id);
    76         m_displayControl->SetVideoWindow(id);
    74 
    77         m_displayControl->SetAspectRatioMode(m_aspectRatioMode == Qt::KeepAspectRatio
    75         QRect rect = m_displayRect;
    78                 ? MFVideoARMode_PreservePicture
    76 
    79                 : MFVideoARMode_None);
    77         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
    80 
    78 
    81         setDisplayRect(m_displayRect);
    79         m_displayControl->SetVideoPosition(0, &displayRect);
    82     }
    80     }
       
    81 
       
    82     m_winId = id;
       
    83 }
    83 }
    84 
    84 
    85 QRect QEvrVideoOverlay::displayRect() const
    85 QRect QEvrVideoOverlay::displayRect() const
    86 {
    86 {
    87     return m_displayRect;
    87     return m_displayRect;
    90 void QEvrVideoOverlay::setDisplayRect(const QRect &rect)
    90 void QEvrVideoOverlay::setDisplayRect(const QRect &rect)
    91 {
    91 {
    92     if (m_displayControl) {
    92     if (m_displayControl) {
    93         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
    93         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
    94 
    94 
    95         m_displayControl->SetVideoPosition(0, &displayRect);
    95         if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
       
    96             SIZE size;
       
    97             m_displayControl->GetNativeVideoSize(&size, 0);
       
    98 
       
    99             QSize clippedSize = rect.size();
       
   100             clippedSize.scale(size.cx, size.cy, Qt::KeepAspectRatio);
       
   101 
       
   102             long x = (size.cx - clippedSize.width()) / 2;
       
   103             long y = (size.cy - clippedSize.height()) / 2;
       
   104 
       
   105             MFVideoNormalizedRect sourceRect =
       
   106             { 
       
   107                 float(x) / size.cx,
       
   108                 float(y) / size.cy, 
       
   109                 float(x + clippedSize.width()) / size.cx,
       
   110                 float(y + clippedSize.height()) / size.cy
       
   111             }; 
       
   112             m_displayControl->SetVideoPosition(&sourceRect, &displayRect);
       
   113         } else {
       
   114             m_displayControl->SetVideoPosition(0, &displayRect);
       
   115         }
    96     }
   116     }
    97 
   117 
    98     m_displayRect = rect;
   118     m_displayRect = rect;
    99 }
   119 }
   100 
   120 
   117     } else {
   137     } else {
   118         return QSize();
   138         return QSize();
   119     }
   139     }
   120 }
   140 }
   121 
   141 
   122 QVideoWidget::AspectRatioMode QEvrVideoOverlay::aspectRatioMode() const
   142 Qt::AspectRatioMode QEvrVideoOverlay::aspectRatioMode() const
   123 {
   143 {
   124     return m_aspectRatioMode;
   144     return m_aspectRatioMode;
   125 }
   145 }
   126 
   146 
   127 void QEvrVideoOverlay::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
   147 void QEvrVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode)
   128 {
   148 {
   129     switch (mode) {
   149     m_aspectRatioMode = mode;
   130     case QVideoWidget::KeepAspectRatio:
   150 
   131         if (m_displayControl)
   151     if (m_displayControl) {
   132                 m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
   152         m_displayControl->SetAspectRatioMode(mode == Qt::KeepAspectRatio
   133 
   153                 ? MFVideoARMode_PreservePicture
   134         m_aspectRatioMode = mode;
   154                 : MFVideoARMode_None);
   135         break;
   155         setDisplayRect(m_displayRect);
   136     case QVideoWidget::IgnoreAspectRatio:
   156     } 
   137         if (m_displayControl)
       
   138                 m_displayControl->SetAspectRatioMode(MFVideoARMode_None);
       
   139 
       
   140         m_aspectRatioMode = mode;
       
   141         break;
       
   142     default:
       
   143         break;
       
   144     }
       
   145 }
   157 }
   146 
   158 
   147 void QEvrVideoOverlay::repaint()
   159 void QEvrVideoOverlay::repaint()
   148 {
   160 {
   149     if (m_displayControl)
   161     if (m_displayControl)
   192         m_displayControl->Release();
   204         m_displayControl->Release();
   193 
   205 
   194     m_displayControl = control;
   206     m_displayControl = control;
   195 
   207 
   196     if (m_displayControl) {
   208     if (m_displayControl) {
   197         QRect rect = displayRect();
       
   198         RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() };
       
   199 
       
   200         m_displayControl->AddRef();
   209         m_displayControl->AddRef();
   201         m_displayControl->SetVideoWindow(winId());
   210         m_displayControl->SetVideoWindow(m_winId);
   202         m_displayControl->SetVideoPosition(0, &displayRect);
   211         m_displayControl->SetAspectRatioMode(m_aspectRatioMode == Qt::KeepAspectRatio
   203     }
   212                 ? MFVideoARMode_PreservePicture
   204 }
   213                 : MFVideoARMode_None);
       
   214 
       
   215         setDisplayRect(m_displayRect);
       
   216     }
       
   217 }
       
   218 
       
   219 void QEvrVideoOverlay::openStateChanged(long state)
       
   220 {
       
   221     if (state == wmposMediaOpen) {
       
   222         setDisplayRect(m_displayRect);
       
   223 
       
   224         emit nativeSizeChanged();
       
   225     }
       
   226 };
   205 
   227 
   206 // IUnknown
   228 // IUnknown
   207 HRESULT QEvrVideoOverlay::QueryInterface(REFIID riid, void **object)
   229 HRESULT QEvrVideoOverlay::QueryInterface(REFIID riid, void **object)
   208 {
   230 {
   209     if (!object) {
   231     if (!object) {