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
AbstractPlayer(const AbstractPlayer * player)36 MMF::AbstractPlayer::AbstractPlayer(const AbstractPlayer *player)
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 {
45 if(player) {
46 m_videoOutput = player->m_videoOutput;
47 m_volume = player->m_volume;
48 m_tickInterval = player->m_tickInterval;
49 m_transitionTime = player->m_transitionTime;
50 m_prefinishMark = player->m_prefinishMark;
51
52 // This is to prevent unwanted state transitions occurring as a result
53 // of MediaObject::switchToNextSource() during playlist playback.
54 if (StoppedState == player->m_state)
55 m_state = player->m_state;
56 }
57 }
58
59 //-----------------------------------------------------------------------------
60 // MediaObjectInterface
61 //-----------------------------------------------------------------------------
62
tickInterval() const63 qint32 MMF::AbstractPlayer::tickInterval() const
64 {
65 return m_tickInterval;
66 }
67
setTickInterval(qint32 interval)68 void MMF::AbstractPlayer::setTickInterval(qint32 interval)
69 {
70 m_tickInterval = interval;
71 doSetTickInterval(interval);
72 }
73
prefinishMark() const74 qint32 MMF::AbstractPlayer::prefinishMark() const
75 {
76 return m_prefinishMark;
77 }
78
setPrefinishMark(qint32 mark)79 void MMF::AbstractPlayer::setPrefinishMark(qint32 mark)
80 {
81 m_prefinishMark = mark;
82 }
83
transitionTime() const84 qint32 MMF::AbstractPlayer::transitionTime() const
85 {
86 return m_transitionTime;
87 }
88
setTransitionTime(qint32 time)89 void MMF::AbstractPlayer::setTransitionTime(qint32 time)
90 {
91 m_transitionTime = time;
92 }
93
volumeChanged(qreal volume)94 void MMF::AbstractPlayer::volumeChanged(qreal volume)
95 {
96 m_volume = volume;
97 }
98
99
100 //-----------------------------------------------------------------------------
101 // Video output
102 //-----------------------------------------------------------------------------
103
setVideoOutput(AbstractVideoOutput * videoOutput)104 void MMF::AbstractPlayer::setVideoOutput(AbstractVideoOutput* videoOutput)
105 {
106 m_videoOutput = videoOutput;
107 videoOutputChanged();
108 }
109
videoOutputChanged()110 void MMF::AbstractPlayer::videoOutputChanged()
111 {
112 // Default behaviour is empty - overridden by VideoPlayer
113 }
114
setError(const QString & errorMessage)115 void MMF::AbstractPlayer::setError(const QString &errorMessage)
116 {
117 TRACE_CONTEXT(AbstractPlayer::setError, EAudioInternal);
118 TRACE_ENTRY("state %d", m_state);
119
120 m_error = Phonon::NormalError;
121 m_errorString = errorMessage;
122 changeState(ErrorState);
123
124 TRACE_EXIT_0();
125 }
126
setError(const QString & errorMessage,int symbianError)127 void MMF::AbstractPlayer::setError(const QString &errorMessage, int symbianError)
128 {
129 setError(errorMessage + ": " + Utils::symbianErrorToString(symbianError));
130 }
131
errorType() const132 Phonon::ErrorType MMF::AbstractPlayer::errorType() const
133 {
134 const Phonon::ErrorType result = (ErrorState == m_state)
135 ? m_error : NoError;
136 return result;
137 }
138
errorString() const139 QString MMF::AbstractPlayer::errorString() const
140 {
141 return m_errorString;
142 }
143
phononState() const144 Phonon::State MMF::AbstractPlayer::phononState() const
145 {
146 return phononState(m_state);
147 }
148
phononState(PrivateState state) const149 Phonon::State MMF::AbstractPlayer::phononState(PrivateState state) const
150 {
151 const Phonon::State phononState =
152 GroundState == state
153 ? Phonon::LoadingState
154 : static_cast<Phonon::State>(state);
155
156 return phononState;
157 }
158
privateState() const159 AbstractPlayer::PrivateState AbstractPlayer::privateState() const
160 {
161 return m_state;
162 }
163
state() const164 Phonon::State MMF::AbstractPlayer::state() const
165 {
166 return phononState(m_state);
167 }
168
setState(PrivateState newState)169 void MMF::AbstractPlayer::setState(PrivateState newState)
170 {
171 m_state = newState;
172 }
173
changeState(PrivateState newState)174 void MMF::AbstractPlayer::changeState(PrivateState newState)
175 {
176 TRACE_CONTEXT(AbstractPlayer::changeState, EAudioInternal);
177 TRACE_ENTRY("state %d newState %d", privateState(), newState);
178
179 // TODO: add some invariants to check that the transition is valid
180
181 const Phonon::State oldPhononState = phononState(privateState());
182
183 // We need to change the state before we emit stateChanged(), because
184 // some user code, for instance the mediaplayer, switch on MediaObject's
185 // state.
186 setState(newState);
187
188 const Phonon::State newPhononState = phononState(newState);
189
190 if (oldPhononState != newPhononState) {
191 TRACE("emit stateChanged(%d, %d)", newPhononState, oldPhononState);
192 emit stateChanged(newPhononState, oldPhononState);
193 }
194
195 TRACE_EXIT_0();
196 }
197
198 QT_END_NAMESPACE
199
200