author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 14 | c0432d11811c |
parent 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 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 "abstractplayer.h" |
|
20 |
#include "defs.h" |
|
21 |
#include "utils.h" |
|
22 |
||
23 |
QT_BEGIN_NAMESPACE |
|
24 |
||
25 |
using namespace Phonon; |
|
26 |
using namespace Phonon::MMF; |
|
27 |
||
28 |
/*! \class MMF::AbstractPlayer |
|
29 |
\internal |
|
30 |
*/ |
|
31 |
||
32 |
//----------------------------------------------------------------------------- |
|
33 |
// Constructor / destructor |
|
34 |
//----------------------------------------------------------------------------- |
|
35 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
36 |
MMF::AbstractPlayer::AbstractPlayer(const AbstractPlayer *player) |
0 | 37 |
: m_videoOutput(0) |
38 |
, m_volume(InitialVolume) |
|
39 |
, m_state(GroundState) |
|
40 |
, m_error(NoError) |
|
41 |
, m_tickInterval(DefaultTickInterval) |
|
42 |
, m_transitionTime(0) |
|
43 |
, m_prefinishMark(0) |
|
44 |
{ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
45 |
if(player) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
46 |
m_videoOutput = player->m_videoOutput; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
47 |
m_volume = player->m_volume; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
48 |
m_tickInterval = player->m_tickInterval; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
49 |
m_transitionTime = player->m_transitionTime; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
50 |
m_prefinishMark = player->m_prefinishMark; |
14
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
8
diff
changeset
|
51 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
8
diff
changeset
|
52 |
// This is to prevent unwanted state transitions occurring as a result |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
8
diff
changeset
|
53 |
// of MediaObject::switchToNextSource() during playlist playback. |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
8
diff
changeset
|
54 |
if (StoppedState == player->m_state) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
8
diff
changeset
|
55 |
m_state = player->m_state; |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
56 |
} |
0 | 57 |
} |
58 |
||
59 |
//----------------------------------------------------------------------------- |
|
60 |
// MediaObjectInterface |
|
61 |
//----------------------------------------------------------------------------- |
|
62 |
||
63 |
qint32 MMF::AbstractPlayer::tickInterval() const |
|
64 |
{ |
|
65 |
return m_tickInterval; |
|
66 |
} |
|
67 |
||
68 |
void MMF::AbstractPlayer::setTickInterval(qint32 interval) |
|
69 |
{ |
|
70 |
m_tickInterval = interval; |
|
71 |
doSetTickInterval(interval); |
|
72 |
} |
|
73 |
||
74 |
qint32 MMF::AbstractPlayer::prefinishMark() const |
|
75 |
{ |
|
76 |
return m_prefinishMark; |
|
77 |
} |
|
78 |
||
79 |
void MMF::AbstractPlayer::setPrefinishMark(qint32 mark) |
|
80 |
{ |
|
81 |
m_prefinishMark = mark; |
|
82 |
} |
|
83 |
||
84 |
qint32 MMF::AbstractPlayer::transitionTime() const |
|
85 |
{ |
|
86 |
return m_transitionTime; |
|
87 |
} |
|
88 |
||
89 |
void MMF::AbstractPlayer::setTransitionTime(qint32 time) |
|
90 |
{ |
|
91 |
m_transitionTime = time; |
|
92 |
} |
|
93 |
||
94 |
void MMF::AbstractPlayer::volumeChanged(qreal volume) |
|
95 |
{ |
|
96 |
m_volume = volume; |
|
97 |
} |
|
98 |
||
99 |
||
100 |
//----------------------------------------------------------------------------- |
|
101 |
// Video output |
|
102 |
//----------------------------------------------------------------------------- |
|
103 |
||
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
104 |
void MMF::AbstractPlayer::setVideoOutput(AbstractVideoOutput* videoOutput) |
0 | 105 |
{ |
106 |
m_videoOutput = videoOutput; |
|
107 |
videoOutputChanged(); |
|
108 |
} |
|
109 |
||
110 |
void MMF::AbstractPlayer::videoOutputChanged() |
|
111 |
{ |
|
112 |
// Default behaviour is empty - overridden by VideoPlayer |
|
113 |
} |
|
114 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
115 |
void MMF::AbstractPlayer::setError(const QString &errorMessage) |
0 | 116 |
{ |
117 |
TRACE_CONTEXT(AbstractPlayer::setError, EAudioInternal); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
118 |
TRACE_ENTRY("state %d", m_state); |
0 | 119 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
120 |
m_error = Phonon::NormalError; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
m_errorString = errorMessage; |
0 | 122 |
changeState(ErrorState); |
123 |
||
124 |
TRACE_EXIT_0(); |
|
125 |
} |
|
126 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
127 |
void MMF::AbstractPlayer::setError(const QString &errorMessage, int symbianError) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
128 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
129 |
setError(errorMessage + ": " + Utils::symbianErrorToString(symbianError)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
130 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
131 |
|
0 | 132 |
Phonon::ErrorType MMF::AbstractPlayer::errorType() const |
133 |
{ |
|
134 |
const Phonon::ErrorType result = (ErrorState == m_state) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
? m_error : NoError; |
0 | 136 |
return result; |
137 |
} |
|
138 |
||
139 |
QString MMF::AbstractPlayer::errorString() const |
|
140 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
return m_errorString; |
0 | 142 |
} |
143 |
||
144 |
Phonon::State MMF::AbstractPlayer::phononState() const |
|
145 |
{ |
|
146 |
return phononState(m_state); |
|
147 |
} |
|
148 |
||
14
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
8
diff
changeset
|
149 |
Phonon::State MMF::AbstractPlayer::phononState(PrivateState state) const |
0 | 150 |
{ |
151 |
const Phonon::State phononState = |
|
152 |
GroundState == state |
|
153 |
? Phonon::LoadingState |
|
154 |
: static_cast<Phonon::State>(state); |
|
155 |
||
156 |
return phononState; |
|
157 |
} |
|
158 |
||
159 |
AbstractPlayer::PrivateState AbstractPlayer::privateState() const |
|
160 |
{ |
|
161 |
return m_state; |
|
162 |
} |
|
163 |
||
164 |
Phonon::State MMF::AbstractPlayer::state() const |
|
165 |
{ |
|
166 |
return phononState(m_state); |
|
167 |
} |
|
168 |
||
169 |
void MMF::AbstractPlayer::setState(PrivateState newState) |
|
170 |
{ |
|
171 |
m_state = newState; |
|
172 |
} |
|
173 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
void MMF::AbstractPlayer::changeState(PrivateState newState) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
TRACE_CONTEXT(AbstractPlayer::changeState, EAudioInternal); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
TRACE_ENTRY("state %d newState %d", privateState(), newState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
// TODO: add some invariants to check that the transition is valid |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
const Phonon::State oldPhononState = phononState(privateState()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
// We need to change the state before we emit stateChanged(), because |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
// some user code, for instance the mediaplayer, switch on MediaObject's |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
// state. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
setState(newState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
const Phonon::State newPhononState = phononState(newState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
if (oldPhononState != newPhononState) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
TRACE("emit stateChanged(%d, %d)", newPhononState, oldPhononState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
emit stateChanged(newPhononState, oldPhononState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
TRACE_EXIT_0(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
|
0 | 198 |
QT_END_NAMESPACE |
199 |