summaryrefslogtreecommitdiff
path: root/src/3rdparty/phonon/mmf/videoplayer_surface.cpp
blob: f380e69ff5d8eb1796a1c0df071b489f4af36d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*  This file is part of the KDE project.

Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <videoplayer2.h>

#include <QtCore/private/qcore_symbian_p.h> // for qt_QRect2TRect

#include "utils.h"
#include "videooutput_surface.h"
#include "videoplayer_surface.h"

QT_BEGIN_NAMESPACE

using namespace Phonon;
using namespace Phonon::MMF;

// Two-phase constructor idiom is used because construct() calls virtual
// functions and therefore cannot be called from the AbstractVideoPlayer
// C++ constructor.
SurfaceVideoPlayer* SurfaceVideoPlayer::create(MediaObject *parent,
                                       const AbstractPlayer *player)
{
    QScopedPointer<SurfaceVideoPlayer> self(new SurfaceVideoPlayer(parent, player));
    self->construct();
    return self.take();
}

SurfaceVideoPlayer::SurfaceVideoPlayer(MediaObject *parent, const AbstractPlayer *player)
    :   AbstractVideoPlayer(parent, player)
    ,   m_displayWindow(0)
{

}

SurfaceVideoPlayer::~SurfaceVideoPlayer()
{

}


//-----------------------------------------------------------------------------
// Public functions
//-----------------------------------------------------------------------------

void MMF::SurfaceVideoPlayer::videoWindowSizeChanged()
{
    if (m_videoOutput)
        updateScaleFactors(m_videoOutput->videoWindowSize());
}


//-----------------------------------------------------------------------------
// Private functions
//-----------------------------------------------------------------------------

void MMF::SurfaceVideoPlayer::createPlayer()
{
    const TInt priority = 0;
    const TMdaPriorityPreference preference = EMdaPriorityPreferenceNone;

    CVideoPlayerUtility2 *player = 0;
    QT_TRAP_THROWING(player = CVideoPlayerUtility2::NewL(*this,
                                         priority, preference));
    m_player.reset(player);
}

void MMF::SurfaceVideoPlayer::initVideoOutput()
{
    Q_ASSERT(m_videoOutput);

    bool connected = connect(
        m_videoOutput, SIGNAL(videoWindowSizeChanged()),
        this, SLOT(videoWindowSizeChanged())
    );
    Q_ASSERT(connected);

    // Suppress warnings in release builds
    Q_UNUSED(connected);

    AbstractVideoPlayer::initVideoOutput();
}

void MMF::SurfaceVideoPlayer::prepareCompleted()
{
    videoWindowSizeChanged();
}

void MMF::SurfaceVideoPlayer::handleVideoWindowChanged()
{
    parametersChanged(WindowHandle);
}

void MMF::SurfaceVideoPlayer::handleParametersChanged(VideoParameters parameters)
{
    TRACE_CONTEXT(SurfaceVideoPlayer::handleParametersChanged, EVideoApi);
    TRACE_ENTRY("parameters 0x%x", parameters.operator int());

    TRect rect;
    if (m_videoOutput) {
        m_videoOutput->dump();
        const QSize size = m_videoOutput->videoWindowSize();
        rect.SetSize(TSize(size.width(), size.height()));
    }

    CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data());
    if (player) {
        int err = KErrNone;
        if (parameters & WindowHandle) {
            removeDisplayWindow();
            addDisplayWindow(rect);
        }

        if (KErrNone == err) {
            if (parameters & ScaleFactors) {
                if (!m_displayWindow)
                    addDisplayWindow(rect);
                Q_ASSERT(m_displayWindow);
                TRAP(err, player->SetVideoExtentL(*m_displayWindow, rect));
                if (KErrNone == err)
                    TRAP(err, player->SetWindowClipRectL(*m_displayWindow, rect));
                if (KErrNone == err)
                    TRAP(err, player->SetScaleFactorL(*m_displayWindow, m_scaleWidth, m_scaleHeight));
                if (KErrNone != err)
                    setError(tr("Video display error"), err);
            }
        }
    }

    TRACE_EXIT_0();
}

void MMF::SurfaceVideoPlayer::addDisplayWindow(const TRect &rect)
{
    TRACE_CONTEXT(SurfaceVideoPlayer::addDisplayWindow, EVideoApi);
    TRACE_ENTRY("rect %d %d - %d %d", rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);

    Q_ASSERT(!m_displayWindow);
    RWindow *window = static_cast<RWindow *>(m_window);

    TRACE("window 0x%08x", window);

    if (window) {
        window->SetBackgroundColor(TRgb(0, 0, 0, 255));
        CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data());
        Q_ASSERT(player);
        TRAPD(err, player->AddDisplayWindowL(m_wsSession, m_screenDevice, *window, rect, rect));
        if (KErrNone == err)
            m_displayWindow = window;
        else
            setError(tr("Video display error"), err);
	TRACE("err %d", err);
    }

    TRACE_EXIT_0();
}

void MMF::SurfaceVideoPlayer::removeDisplayWindow()
{
    TRACE_CONTEXT(SurfaceVideoPlayer::removeDisplayWindow, EVideoApi);
    TRACE("player 0x%08x window 0x%08x", m_player.data(), m_displayWindow);

    CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data());
    if (player && m_displayWindow) {
        player->RemoveDisplayWindow(*m_displayWindow);
        m_displayWindow = 0;
    }
}

QT_END_NAMESPACE