src/3rdparty/phonon/ds9/videorenderer_vmr9.cpp
changeset 30 5dc02b23752f
parent 0 1918ee327afb
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    20 
    20 
    21 #ifndef QT_NO_PHONON_VIDEO
    21 #ifndef QT_NO_PHONON_VIDEO
    22 
    22 
    23 #include <QtGui/QWidget>
    23 #include <QtGui/QWidget>
    24 #include <QtGui/QPainter>
    24 #include <QtGui/QPainter>
    25 #include <QtCore/QTimerEvent>
    25 
    26 
       
    27 #ifndef Q_OS_WINCE
       
    28 #include <d3d9.h>
    26 #include <d3d9.h>
    29 #include <vmr9.h>
    27 #include <vmr9.h>
    30 #else
       
    31 #include <uuids.h>
       
    32 #endif
       
    33 
    28 
    34 QT_BEGIN_NAMESPACE
    29 QT_BEGIN_NAMESPACE
    35 
    30 
    36 
    31 
    37 namespace Phonon
    32 namespace Phonon
    46         {
    41         {
    47             return true;
    42             return true;
    48         }
    43         }
    49 
    44 
    50 
    45 
    51 #ifdef Q_OS_WINCE
       
    52         VideoRendererVMR9::VideoRendererVMR9(QWidget *target) : m_target(target)
       
    53         {
       
    54             m_target->setAttribute(Qt::WA_PaintOnScreen, true);
       
    55             m_filter = Filter(CLSID_VideoRenderer, IID_IBaseFilter);
       
    56         }
       
    57 
       
    58         QSize VideoRendererVMR9::videoSize() const
       
    59         {
       
    60             LONG w = 0,
       
    61                 h = 0;
       
    62             ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo);
       
    63             if (basic) {
       
    64                 basic->GetVideoSize( &w, &h);
       
    65             }
       
    66             return QSize(w, h);
       
    67         }
       
    68 
       
    69         void VideoRendererVMR9::repaintCurrentFrame(QWidget * /*target*/, const QRect & /*rect*/)
       
    70         {
       
    71             //nothing to do here: the renderer paints everything
       
    72         }
       
    73 
       
    74         void VideoRendererVMR9::notifyResize(const QSize &size, Phonon::VideoWidget::AspectRatio aspectRatio,
       
    75             Phonon::VideoWidget::ScaleMode scaleMode)
       
    76         {
       
    77             if (!isActive()) {
       
    78                 ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo);
       
    79                 if (basic) {
       
    80                     basic->SetDestinationPosition(0, 0, 0, 0);
       
    81                 }
       
    82                 return;
       
    83             }
       
    84 
       
    85             ComPointer<IVideoWindow> video(m_filter, IID_IVideoWindow);
       
    86 
       
    87             OAHWND owner;
       
    88             HRESULT hr = video->get_Owner(&owner);
       
    89             if (FAILED(hr)) {
       
    90                 return;
       
    91             }
       
    92 
       
    93             const OAHWND newOwner = reinterpret_cast<OAHWND>(m_target->winId());
       
    94             if (owner != newOwner) {
       
    95                 video->put_Owner(newOwner);
       
    96                 video->put_MessageDrain(newOwner);
       
    97                 video->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
       
    98             }
       
    99 
       
   100             //make sure the widget takes the whole size of the parent
       
   101             video->SetWindowPosition(0, 0, size.width(), size.height());
       
   102 
       
   103             const QSize vsize = videoSize();
       
   104             internalNotifyResize(size, vsize, aspectRatio, scaleMode);
       
   105 
       
   106             ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo);
       
   107             if (basic) {
       
   108                 basic->SetDestinationPosition(m_dstX, m_dstY, m_dstWidth, m_dstHeight);
       
   109             }
       
   110         }
       
   111 
       
   112         void VideoRendererVMR9::applyMixerSettings(qreal /*brightness*/, qreal /*contrast*/, qreal /*m_hue*/, qreal /*saturation*/)
       
   113         {
       
   114             //this can't be supported for WinCE
       
   115         }
       
   116 
       
   117         QImage VideoRendererVMR9::snapshot() const
       
   118         {
       
   119             ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo);
       
   120             if (basic) {
       
   121                 LONG bufferSize = 0;
       
   122                 //1st we get the buffer size
       
   123                 basic->GetCurrentImage(&bufferSize, 0);
       
   124 
       
   125                 QByteArray buffer;
       
   126                 buffer.resize(bufferSize);
       
   127                 HRESULT hr = basic->GetCurrentImage(&bufferSize, reinterpret_cast<long*>(buffer.data()));
       
   128 
       
   129                 if (SUCCEEDED(hr)) {
       
   130 
       
   131                     const BITMAPINFOHEADER  *bmi = reinterpret_cast<const BITMAPINFOHEADER*>(buffer.constData());
       
   132 
       
   133                     const int w = qAbs(bmi->biWidth),
       
   134                         h = qAbs(bmi->biHeight);
       
   135 
       
   136                     // Create image and copy data into image.
       
   137                     QImage ret(w, h, QImage::Format_RGB32);
       
   138 
       
   139                     if (!ret.isNull()) {
       
   140                         const char *data = buffer.constData() + bmi->biSize;
       
   141                         const int bytes_per_line = w * sizeof(QRgb);
       
   142                         for (int y = h - 1; y >= 0; --y) {
       
   143                             qMemCopy(ret.scanLine(y), //destination
       
   144                                 data,     //source
       
   145                                 bytes_per_line);
       
   146                             data += bytes_per_line;
       
   147                         }
       
   148                     }
       
   149                     return ret;
       
   150                 }
       
   151             }
       
   152             return QImage();
       
   153         }
       
   154 
       
   155 #else
       
   156         VideoRendererVMR9::VideoRendererVMR9(QWidget *target) : m_target(target)
    46         VideoRendererVMR9::VideoRendererVMR9(QWidget *target) : m_target(target)
   157         {
    47         {
   158             m_filter = Filter(CLSID_VideoMixingRenderer9, IID_IBaseFilter);
    48             m_filter = Filter(CLSID_VideoMixingRenderer9, IID_IBaseFilter);
   159             if (!m_filter) {
    49             if (!m_filter) {
   160                 qWarning("the video widget could not be initialized correctly");
       
   161                 return;
    50                 return;
   162             }
    51             }
   163 
    52 
   164             ComPointer<IVMRFilterConfig9> config(m_filter, IID_IVMRFilterConfig9);
    53             ComPointer<IVMRFilterConfig9> config(m_filter, IID_IVMRFilterConfig9);
   165             Q_ASSERT(config);
    54             Q_ASSERT(config);
   323             ctrl.Hue = ((hue < 0 ? range.MinValue : range.MaxValue) - range.DefaultValue) * qAbs(hue) + range.DefaultValue;
   212             ctrl.Hue = ((hue < 0 ? range.MinValue : range.MaxValue) - range.DefaultValue) * qAbs(hue) + range.DefaultValue;
   324 
   213 
   325             //finally set the settings
   214             //finally set the settings
   326             mixer->SetProcAmpControl(0, &ctrl);
   215             mixer->SetProcAmpControl(0, &ctrl);
   327         }
   216         }
   328 #endif
       
   329     }
   217     }
   330 }
   218 }
   331 
   219 
   332 QT_END_NAMESPACE
   220 QT_END_NAMESPACE
   333 
   221