| 1 |
/* This file is part of the KDE project. |
| 2 |
|
| 3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
|
| 5 |
This library is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU Lesser General Public License as published by |
| 7 |
the Free Software Foundation, either version 2.1 or 3 of the License. |
| 8 |
|
| 9 |
This library is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
|
| 19 |
#include "videorenderer_default.h" |
| 20 |
|
| 21 |
#ifndef QT_NO_PHONON_VIDEO |
| 22 |
|
| 23 |
#include <QtGui/QWidget> |
| 24 |
#include <QtGui/QPainter> |
| 25 |
|
| 26 |
#include <uuids.h> |
| 27 |
|
| 28 |
QT_BEGIN_NAMESPACE |
| 29 |
|
| 30 |
|
| 31 |
namespace Phonon |
| 32 |
{ |
| 33 |
namespace DS9 |
| 34 |
{ |
| 35 |
VideoRendererDefault::~VideoRendererDefault() |
| 36 |
{ |
| 37 |
} |
| 38 |
|
| 39 |
bool VideoRendererDefault::isNative() const |
| 40 |
{ |
| 41 |
return true; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
VideoRendererDefault::VideoRendererDefault(QWidget *target) : m_target(target) |
| 46 |
{ |
| 47 |
m_target->setAttribute(Qt::WA_PaintOnScreen, true); |
| 48 |
m_filter = Filter(CLSID_VideoRenderer, IID_IBaseFilter); |
| 49 |
} |
| 50 |
|
| 51 |
QSize VideoRendererDefault::videoSize() const |
| 52 |
{ |
| 53 |
LONG w = 0, |
| 54 |
h = 0; |
| 55 |
ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo); |
| 56 |
if (basic) { |
| 57 |
basic->GetVideoSize( &w, &h); |
| 58 |
} |
| 59 |
return QSize(w, h); |
| 60 |
} |
| 61 |
|
| 62 |
void VideoRendererDefault::repaintCurrentFrame(QWidget * /*target*/, const QRect & /*rect*/) |
| 63 |
{ |
| 64 |
//nothing to do here: the renderer paints everything |
| 65 |
} |
| 66 |
|
| 67 |
void VideoRendererDefault::notifyResize(const QSize &size, Phonon::VideoWidget::AspectRatio aspectRatio, |
| 68 |
Phonon::VideoWidget::ScaleMode scaleMode) |
| 69 |
{ |
| 70 |
if (!isActive()) { |
| 71 |
ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo); |
| 72 |
if (basic) { |
| 73 |
basic->SetDestinationPosition(0, 0, 0, 0); |
| 74 |
} |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
ComPointer<IVideoWindow> video(m_filter, IID_IVideoWindow); |
| 79 |
|
| 80 |
OAHWND owner; |
| 81 |
HRESULT hr = video->get_Owner(&owner); |
| 82 |
if (FAILED(hr)) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
const OAHWND newOwner = reinterpret_cast<OAHWND>(m_target->winId()); |
| 87 |
if (owner != newOwner) { |
| 88 |
video->put_Owner(newOwner); |
| 89 |
video->put_MessageDrain(newOwner); |
| 90 |
video->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); |
| 91 |
} |
| 92 |
|
| 93 |
//make sure the widget takes the whole size of the parent |
| 94 |
video->SetWindowPosition(0, 0, size.width(), size.height()); |
| 95 |
|
| 96 |
const QSize vsize = videoSize(); |
| 97 |
internalNotifyResize(size, vsize, aspectRatio, scaleMode); |
| 98 |
|
| 99 |
ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo); |
| 100 |
if (basic) { |
| 101 |
basic->SetDestinationPosition(m_dstX, m_dstY, m_dstWidth, m_dstHeight); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
void VideoRendererDefault::applyMixerSettings(qreal /*brightness*/, qreal /*contrast*/, qreal /*m_hue*/, qreal /*saturation*/) |
| 106 |
{ |
| 107 |
//this can't be supported for the default renderer |
| 108 |
} |
| 109 |
|
| 110 |
QImage VideoRendererDefault::snapshot() const |
| 111 |
{ |
| 112 |
ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo); |
| 113 |
if (basic) { |
| 114 |
LONG bufferSize = 0; |
| 115 |
//1st we get the buffer size |
| 116 |
basic->GetCurrentImage(&bufferSize, 0); |
| 117 |
|
| 118 |
QByteArray buffer; |
| 119 |
buffer.resize(bufferSize); |
| 120 |
HRESULT hr = basic->GetCurrentImage(&bufferSize, reinterpret_cast<long*>(buffer.data())); |
| 121 |
|
| 122 |
if (SUCCEEDED(hr)) { |
| 123 |
|
| 124 |
const BITMAPINFOHEADER *bmi = reinterpret_cast<const BITMAPINFOHEADER*>(buffer.constData()); |
| 125 |
|
| 126 |
const int w = qAbs(bmi->biWidth), |
| 127 |
h = qAbs(bmi->biHeight); |
| 128 |
|
| 129 |
// Create image and copy data into image. |
| 130 |
QImage ret(w, h, QImage::Format_RGB32); |
| 131 |
|
| 132 |
if (!ret.isNull()) { |
| 133 |
const char *data = buffer.constData() + bmi->biSize; |
| 134 |
const int bytes_per_line = w * sizeof(QRgb); |
| 135 |
for (int y = h - 1; y >= 0; --y) { |
| 136 |
qMemCopy(ret.scanLine(y), //destination |
| 137 |
data, //source |
| 138 |
bytes_per_line); |
| 139 |
data += bytes_per_line; |
| 140 |
} |
| 141 |
} |
| 142 |
return ret; |
| 143 |
} |
| 144 |
} |
| 145 |
return QImage(); |
| 146 |
} |
| 147 |
|
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
QT_END_NAMESPACE |
| 152 |
|
| 153 |
#endif //QT_NO_PHONON_VIDEO |