23#include "statesvalidator_p.h"
25#include "mediaobject.h"
26#include "phononnamespace_p.h"
28#define P_INVALID_STATE(msg) Q_ASSERT_X(0, __FILE__, msg)
33StatesValidator::StatesValidator(MediaObject *parent)
35 , m_mediaObject(parent)
36 , m_prevState(Phonon::ErrorState)
37 , m_sourceQueued(false)
38 , m_aboutToFinishEmitted(false)
39 , m_aboutToFinishBeforeSeek(false)
40 , m_aboutToFinishPos(-1)
42 connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
43 this, SLOT(validateStateChange(Phonon::State,Phonon::State)));
45 this, SLOT(validateSourceChange()));
46 connect(m_mediaObject, SIGNAL(tick(qint64)),
this, SLOT(validateTick(qint64)));
47 connect(m_mediaObject, SIGNAL(aboutToFinish()),
this, SLOT(validateAboutToFinish()));
48 connect(m_mediaObject, SIGNAL(finished()),
this, SLOT(validateFinished()));
49 connect(m_mediaObject, SIGNAL(bufferStatus(
int)),
this, SLOT(validateBufferStatus()));
52StatesValidator::~StatesValidator()
66void StatesValidator::validateAboutToFinish()
68 if (m_aboutToFinishEmitted)
69 P_INVALID_STATE(
"aboutToFinish emitted more than once!");
70 m_aboutToFinishEmitted =
true;
71 m_aboutToFinishPos = m_pos;
74void StatesValidator::validateFinished()
76 if (m_mediaObject->state() != Phonon::PlayingState)
77 P_INVALID_STATE(
"Playback finished when we weren't playing!");
80void StatesValidator::validateSourceChange()
82 if (m_mediaObject->state() != Phonon::StoppedState
83 && m_mediaObject->state() != Phonon::PlayingState
84 && m_mediaObject->state() != Phonon::PausedState
85 && m_mediaObject->state() != Phonon::BufferingState) {
86 P_INVALID_STATE(
"Source got changed outside a valid state");
88 m_sourceQueued =
false;
89 m_aboutToFinishEmitted =
false;
90 m_aboutToFinishBeforeSeek =
false;
93void StatesValidator::validateBufferStatus()
95 if (m_mediaObject->state() != Phonon::PlayingState
96 && m_mediaObject->state() != Phonon::PausedState
97 && m_mediaObject->state() != Phonon::BufferingState) {
98 P_INVALID_STATE(
"Buffer status changed when we weren't supposed to be buffering");
102void StatesValidator::validateTick(qint64 pos)
106 if (m_mediaObject->state() != Phonon::PlayingState
107 && (m_prevState != Phonon::PlayingState
108 && m_mediaObject->state() != Phonon::BufferingState))
109 P_INVALID_STATE(
"Received tick outside of Playing state.");
114 if (m_aboutToFinishEmitted && (pos < m_aboutToFinishPos) && !m_sourceQueued)
115 m_aboutToFinishEmitted =
false;
119void StatesValidator::validateStateChange(Phonon::State newstate, Phonon::State oldstate)
121 if (!validateStateTransition(newstate, oldstate)) {
122 pDebug() <<
"Invalid state transition:" << oldstate <<
"->" << newstate;
123 P_INVALID_STATE(
"Invalid state transition");
125 pDebug() <<
"Valid state transition:" << oldstate <<
"->" << newstate;
127 m_prevState = oldstate;
130bool StatesValidator::validateStateTransition(Phonon::State newstate, Phonon::State oldstate)
134 case Phonon::StoppedState:
136 case Phonon::LoadingState:
137 case Phonon::PlayingState:
138 case Phonon::PausedState:
144 case Phonon::LoadingState:
146 case Phonon::ErrorState:
147 case Phonon::StoppedState:
153 case Phonon::ErrorState:
155 case Phonon::LoadingState:
161 case Phonon::PlayingState:
163 case Phonon::PausedState:
164 case Phonon::BufferingState:
165 case Phonon::ErrorState:
166 case Phonon::StoppedState:
172 case Phonon::PausedState:
174 case Phonon::PlayingState:
175 case Phonon::BufferingState:
176 case Phonon::ErrorState:
177 case Phonon::StoppedState:
183 case Phonon::BufferingState:
185 case Phonon::PlayingState:
186 case Phonon::PausedState:
187 case Phonon::ErrorState:
189 case Phonon::StoppedState:
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)