source: trunk/src/3rdparty/phonon/mmf/abstractplayer.cpp

Last change on this file was 769, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/* This file is part of the KDE project.
2
3Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5This library is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 2.1 or 3 of the License.
8
9This library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU Lesser General Public License for more details.
13
14You should have received a copy of the GNU Lesser General Public License
15along 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
23QT_BEGIN_NAMESPACE
24
25using namespace Phonon;
26using namespace Phonon::MMF;
27
28/*! \class MMF::AbstractPlayer
29 \internal
30*/
31
32//-----------------------------------------------------------------------------
33// Constructor / destructor
34//-----------------------------------------------------------------------------
35
36MMF::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
63qint32 MMF::AbstractPlayer::tickInterval() const
64{
65 return m_tickInterval;
66}
67
68void MMF::AbstractPlayer::setTickInterval(qint32 interval)
69{
70 m_tickInterval = interval;
71 doSetTickInterval(interval);
72}
73
74qint32 MMF::AbstractPlayer::prefinishMark() const
75{
76 return m_prefinishMark;
77}
78
79void MMF::AbstractPlayer::setPrefinishMark(qint32 mark)
80{
81 m_prefinishMark = mark;
82}
83
84qint32 MMF::AbstractPlayer::transitionTime() const
85{
86 return m_transitionTime;
87}
88
89void MMF::AbstractPlayer::setTransitionTime(qint32 time)
90{
91 m_transitionTime = time;
92}
93
94void MMF::AbstractPlayer::volumeChanged(qreal volume)
95{
96 m_volume = volume;
97}
98
99
100//-----------------------------------------------------------------------------
101// Video output
102//-----------------------------------------------------------------------------
103
104void MMF::AbstractPlayer::setVideoOutput(AbstractVideoOutput* videoOutput)
105{
106 m_videoOutput = videoOutput;
107 videoOutputChanged();
108}
109
110void MMF::AbstractPlayer::videoOutputChanged()
111{
112 // Default behaviour is empty - overridden by VideoPlayer
113}
114
115void 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
127void MMF::AbstractPlayer::setError(const QString &errorMessage, int symbianError)
128{
129 setError(errorMessage + ": " + Utils::symbianErrorToString(symbianError));
130}
131
132Phonon::ErrorType MMF::AbstractPlayer::errorType() const
133{
134 const Phonon::ErrorType result = (ErrorState == m_state)
135 ? m_error : NoError;
136 return result;
137}
138
139QString MMF::AbstractPlayer::errorString() const
140{
141 return m_errorString;
142}
143
144Phonon::State MMF::AbstractPlayer::phononState() const
145{
146 return phononState(m_state);
147}
148
149Phonon::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
159AbstractPlayer::PrivateState AbstractPlayer::privateState() const
160{
161 return m_state;
162}
163
164Phonon::State MMF::AbstractPlayer::state() const
165{
166 return phononState(m_state);
167}
168
169void MMF::AbstractPlayer::setState(PrivateState newState)
170{
171 m_state = newState;
172}
173
174void 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
198QT_END_NAMESPACE
199
Note: See TracBrowser for help on using the repository browser.