From 1ef8ddc53d3d2512bbe5afbd2e6fb26cae206944 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Fri, 14 Aug 2009 15:23:24 +0200 Subject: Pushing compile fix from Gareth, modified by me. Seems this code path was broken. --- src/3rdparty/phonon/phonon/factory.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/3rdparty/phonon/phonon/factory.cpp b/src/3rdparty/phonon/phonon/factory.cpp index e0b245e..b14c2b9 100644 --- a/src/3rdparty/phonon/phonon/factory.cpp +++ b/src/3rdparty/phonon/phonon/factory.cpp @@ -133,6 +133,8 @@ bool FactoryPrivate::createBackend() continue; } + QStringList plugins(dir.entryList(QDir::Files)); + #ifdef Q_OS_SYMBIAN /* On Symbian OS we might have two plugins, one which uses Symbian * MMF framework("phonon_mmf"), and one which uses Real Networks's @@ -140,6 +142,7 @@ bool FactoryPrivate::createBackend() * sophisticated, so we make sure the Helix backend is attempted * to be loaded first, and the MMF backend is used for backup. */ { + const int hxphonon = plugins.indexOf(QLatin1String("hxphonon")); if (hxphonon != -1) plugins.move(hxphonon, 0); @@ -152,9 +155,8 @@ bool FactoryPrivate::createBackend() } #endif - const QStringList files = dir.entryList(QDir::Files); - for (int i = 0; i < files.count(); ++i) { - QPluginLoader pluginLoader(libPath + files.at(i)); + for (int i = 0; i < plugins.count(); ++i) { + QPluginLoader pluginLoader(libPath + plugins.at(i)); if (!pluginLoader.load()) { pDebug() << Q_FUNC_INFO << " load failed:" << pluginLoader.errorString(); -- cgit v0.12 From d10291404e189e3a57cda7fac6f69aa5f9629cae Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Mon, 17 Aug 2009 15:40:04 +0200 Subject: Refactor the media object such that we can do both video and sound. As per discussions with Gareth. --- src/3rdparty/phonon/mmf/abstractplayer.h | 53 +++ src/3rdparty/phonon/mmf/audiooutput.cpp | 2 + src/3rdparty/phonon/mmf/audioplayer.cpp | 631 ++++++++++++++++++++++++++++ src/3rdparty/phonon/mmf/audioplayer.h | 173 ++++++++ src/3rdparty/phonon/mmf/mediaobject.cpp | 499 +--------------------- src/3rdparty/phonon/mmf/mediaobject.h | 102 +---- src/3rdparty/phonon/mmf/mmf_videoplayer.cpp | 577 +++++++++++++++++++++++++ src/3rdparty/phonon/mmf/mmf_videoplayer.h | 163 +++++++ src/plugins/phonon/mmf/mmf.pro | 27 +- 9 files changed, 1618 insertions(+), 609 deletions(-) create mode 100644 src/3rdparty/phonon/mmf/abstractplayer.h create mode 100644 src/3rdparty/phonon/mmf/audioplayer.cpp create mode 100644 src/3rdparty/phonon/mmf/audioplayer.h create mode 100644 src/3rdparty/phonon/mmf/mmf_videoplayer.cpp create mode 100644 src/3rdparty/phonon/mmf/mmf_videoplayer.h diff --git a/src/3rdparty/phonon/mmf/abstractplayer.h b/src/3rdparty/phonon/mmf/abstractplayer.h new file mode 100644 index 0000000..6452090 --- /dev/null +++ b/src/3rdparty/phonon/mmf/abstractplayer.h @@ -0,0 +1,53 @@ +/* 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 . + +*/ + +#ifndef PHONON_MMF_ABSTRACTPLAYER_H +#define PHONON_MMF_ABSTRACTPLAYER_H + +#include +#include +#include + +namespace Phonon +{ + namespace MMF + { + class AbstractPlayer : public QObject + { + public: + virtual void play() = 0; + virtual void pause() = 0; + virtual void stop() = 0; + virtual void seek(qint64 milliseconds) = 0; + virtual qint32 tickInterval() const = 0; + virtual void setTickInterval() const = 0; + virtual bool hasVideo() const = 0; + virtual bool isSeekable() const = 0; + virtual qint64 currentTime() const = 0; + virtual Phonon::State state() const = 0; + virtual QString errorString() const = 0; + virtual Phonon::ErrorType errorType() const = 0; + virtual Phonon::MediaSource source() const = 0; + virtual void setSource(const Phonon::MediaSource &) = 0; + virtual void setNextSource(const Phonon::MediaSource &) = 0; + }; + } +} + +#endif + diff --git a/src/3rdparty/phonon/mmf/audiooutput.cpp b/src/3rdparty/phonon/mmf/audiooutput.cpp index 9c8cb6b..d8758fd 100644 --- a/src/3rdparty/phonon/mmf/audiooutput.cpp +++ b/src/3rdparty/phonon/mmf/audiooutput.cpp @@ -16,6 +16,8 @@ along with this library. If not, see . */ +#include + #include "mediaobject.h" #include "audiooutput.h" #include "utils.h" diff --git a/src/3rdparty/phonon/mmf/audioplayer.cpp b/src/3rdparty/phonon/mmf/audioplayer.cpp new file mode 100644 index 0000000..4dd2eb8 --- /dev/null +++ b/src/3rdparty/phonon/mmf/audioplayer.cpp @@ -0,0 +1,631 @@ +/* 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 . + +*/ + +#include +#include +#include + +#include "audioplayer.h" +#include "audiooutput.h" +#include "utils.h" + +using namespace Phonon; +using namespace Phonon::MMF; + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const qint32 DefaultTickInterval = 20; +const int NullMaxVolume = -1; + + +//----------------------------------------------------------------------------- +// Constructor / destructor +//----------------------------------------------------------------------------- + +MMF::AudioPlayer::AudioPlayer(QObject *parent) : m_player(NULL) + , m_audioOutput(NULL) + , m_error(NoError) + , m_state(GroundState) + , m_tickInterval(DefaultTickInterval) + , m_tickTimer(NULL) + , m_volume(0.0) + , m_maxVolume(NullMaxVolume) +{ + TRACE_CONTEXT(AudioPlayer::AudioPlayer, EAudioApi); + TRACE_ENTRY_0(); + + Q_UNUSED(parent); + + // TODO: should leaves be trapped in the constructor? + m_player = CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone); + + m_tickTimer = new QTimer(this); + connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); + + TRACE_EXIT_0(); +} + +MMF::AudioPlayer::~AudioPlayer() +{ + TRACE_CONTEXT(AudioPlayer::~AudioPlayer, EAudioApi); + TRACE_ENTRY_0(); + + delete m_tickTimer; + delete m_player; + + TRACE_EXIT_0(); +} + +//----------------------------------------------------------------------------- +// AudioPlayerInterface +//----------------------------------------------------------------------------- + +void MMF::AudioPlayer::play() +{ + TRACE_CONTEXT(AudioPlayer::play, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + // Is this the correct error? Really we want 'NotReadyError' + m_error = NormalError; + changeState(ErrorState); + break; + + case StoppedState: + case PausedState: + m_player->Play(); + m_tickTimer->start(m_tickInterval); + changeState(PlayingState); + break; + + case PlayingState: + case BufferingState: + case ErrorState: + // Do nothing + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +} + +void MMF::AudioPlayer::pause() +{ + TRACE_CONTEXT(AudioPlayer::pause, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + case StoppedState: + case PausedState: + case ErrorState: + // Do nothing + break; + + case PlayingState: + case BufferingState: + m_player->Pause(); + m_tickTimer->stop(); + changeState(PausedState); + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +} + +void MMF::AudioPlayer::stop() +{ + TRACE_CONTEXT(AudioPlayer::stop, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + case StoppedState: + case ErrorState: + // Do nothing + break; + + case PlayingState: + case BufferingState: + case PausedState: + m_player->Stop(); + m_tickTimer->stop(); + changeState(StoppedState); + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +} + +void MMF::AudioPlayer::seek(qint64 ms) +{ + TRACE_CONTEXT(AudioPlayer::seek, EAudioApi); + TRACE_ENTRY("state %d pos %Ld", m_state, ms); + + m_player->SetPosition(TTimeIntervalMicroSeconds(ms)); + + TRACE_EXIT_0(); +} + +qint32 MMF::AudioPlayer::tickInterval() const +{ + TRACE_CONTEXT(AudioPlayer::tickInterval, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_RETURN("%d", m_tickInterval); +} + +void MMF::AudioPlayer::setTickInterval(qint32 interval) +{ + TRACE_CONTEXT(AudioPlayer::setTickInterval, EAudioApi); + TRACE_ENTRY("state %d m_interval %d interval %d", m_state, m_tickInterval, interval); + + m_tickInterval = interval; + m_tickTimer->setInterval(interval); + + TRACE_EXIT_0(); +} + +bool MMF::AudioPlayer::hasVideo() const +{ + TRACE_CONTEXT(AudioPlayer::hasVideo, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: re-factor this class so that audio playback and video playback are + // delegated to separate classes, which internally hoat a + // CMdaAudioPlayerUtility / CVideoPlayerUtility instance as appropriate. + + TRACE_RETURN("%d", false); +} + +bool MMF::AudioPlayer::isSeekable() const +{ + TRACE_CONTEXT(AudioPlayer::isSeekable, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_RETURN("%d", true); +} + +Phonon::State MMF::AudioPlayer::state() const +{ + TRACE_CONTEXT(AudioPlayer::state, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const Phonon::State result = phononState(m_state); + + TRACE_RETURN("%d", result); +} + +qint64 MMF::AudioPlayer::currentTime() const +{ + TRACE_CONTEXT(AudioPlayer::currentTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TTimeIntervalMicroSeconds us; + const TInt err = m_player->GetPosition(us); + + qint64 result = -1; + + if(KErrNone == err) { + result = toMilliSeconds(us); + } + + TRACE_RETURN("%Ld", result); +} + +QString MMF::AudioPlayer::errorString() const +{ + TRACE_CONTEXT(AudioPlayer::errorString, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_EXIT_0(); + // TODO: put in proper error strings + QString result; + return result; +} + +Phonon::ErrorType MMF::AudioPlayer::errorType() const +{ + TRACE_CONTEXT(AudioPlayer::errorType, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const Phonon::ErrorType result = (ErrorState == m_state) + ? m_error : NoError; + + TRACE_RETURN("%d", result); +} + +qint64 MMF::AudioPlayer::totalTime() const +{ + TRACE_CONTEXT(AudioPlayer::totalTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const qint64 result = toMilliSeconds(m_player->Duration()); + + TRACE_RETURN("%Ld", result); +} + +MediaSource MMF::AudioPlayer::source() const +{ + TRACE_CONTEXT(AudioPlayer::source, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_EXIT_0(); + return m_mediaSource; +} + +void MMF::AudioPlayer::setSource(const MediaSource &source) +{ + TRACE_CONTEXT(AudioPlayer::setSource, EAudioApi); + TRACE_ENTRY("state %d source.type %d", m_state, source.type()); + + m_player->Close(); + changeState(GroundState); + + // TODO: is it correct to assign even if the media type is not supported in + // the switch statement below? + m_mediaSource = source; + + TInt symbianErr = KErrNone; + + switch(m_mediaSource.type()) + { + case MediaSource::LocalFile: + { + // TODO: work out whose responsibility it is to ensure that paths + // are Symbian-style, i.e. have backslashes for path delimiters. + // Until then, use this utility function... + const QHBufC filename = Utils::symbianFilename(m_mediaSource.fileName()); + TRAP(symbianErr, m_player->OpenFileL(*filename)); + break; + } + + case MediaSource::Url: + { + const QHBufC filename(m_mediaSource.url().toString()); + TRAP(symbianErr, m_player->OpenUrlL(*filename)); + break; + } + + case MediaSource::Invalid: + case MediaSource::Disc: + case MediaSource::Stream: + symbianErr = KErrNotSupported; + break; + + case MediaSource::Empty: + TRACE_EXIT_0(); + return; + + // Protection against adding new media types and forgetting to update this switch + default: + TRACE_PANIC(InvalidMediaTypePanic); + } + + if(KErrNone == symbianErr) + { +#ifdef QT_PHONON_MMF_AUDIO_DRM + // There appears to be a bug in the CDrmPlayerUtility implementation (at least + // in S60 5.x) whereby the player does not check whether the loading observer + // pointer is null before dereferencing it. Therefore we must register for + // loading notification, even though we do nothing in the callback functions. + m_player->RegisterForAudioLoadingNotification(*this); +#endif + changeState(LoadingState); + } + else + { + // TODO: do something with the value of symbianErr? + m_error = NormalError; + changeState(ErrorState); + } + + TRACE_EXIT_0(); +} + +void MMF::AudioPlayer::setNextSource(const MediaSource &source) +{ + TRACE_CONTEXT(AudioPlayer::setNextSource, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: handle 'next source' + + m_nextSource = source; + Q_UNUSED(source); + + TRACE_EXIT_0(); +} + +qint32 MMF::AudioPlayer::prefinishMark() const +{ + TRACE_CONTEXT(AudioPlayer::prefinishMark, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: implement prefinish mark + const qint32 result = 0; + TRACE_RETURN("%d", result); +} + +void MMF::AudioPlayer::setPrefinishMark(qint32 mark) +{ + TRACE_CONTEXT(AudioPlayer::setPrefinishMark, EAudioApi); + TRACE_ENTRY("state %d mark %d", m_state, mark); + Q_UNUSED(mark); // to silence warnings in release builds + + // TODO: implement prefinish mark + + TRACE_EXIT_0(); +} + +qint32 MMF::AudioPlayer::transitionTime() const +{ + TRACE_CONTEXT(AudioPlayer::transitionTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: implement transition time + const qint32 result = 0; + TRACE_RETURN("%d", result); +} + +void MMF::AudioPlayer::setTransitionTime(qint32 time) +{ + TRACE_CONTEXT(AudioPlayer::setTransitionTime, EAudioApi); + TRACE_ENTRY("state %d time %d", m_state, time); + Q_UNUSED(time); // to silence warnings in release builds + + // TODO: implement transition time + + TRACE_EXIT_0(); +} + + +//----------------------------------------------------------------------------- +// Symbian multimedia client observer callbacks +//----------------------------------------------------------------------------- + +#ifdef QT_PHONON_MMF_AUDIO_DRM +void MMF::AudioPlayer::MdapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &) +#else +void MMF::AudioPlayer::MapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &) +#endif +{ + TRACE_CONTEXT(AudioPlayer::MapcInitComplete, EAudioInternal); + TRACE_ENTRY("state %d error %d", m_state, aError); + + __ASSERT_ALWAYS(LoadingState == m_state, Utils::panic(InvalidStatePanic)); + + if(KErrNone == aError) + { + TInt volume = 0; + aError = m_player->GetVolume(volume); + if(KErrNone == aError) + { + m_maxVolume = m_player->MaxVolume(); + m_volume = static_cast(volume) / m_maxVolume; + + if(m_audioOutput) + { + // Trigger AudioOutput signal + m_audioOutput->triggerVolumeChanged(m_volume); + } + + emit totalTimeChanged(); + changeState(StoppedState); + } + } + else + { + // TODO: set different error states according to value of aError? + m_error = NormalError; + changeState(ErrorState); + } + + TRACE_EXIT_0(); +} + +#ifdef QT_PHONON_MMF_AUDIO_DRM +void MMF::AudioPlayer::MdapcPlayComplete(TInt aError) +#else +void MMF::AudioPlayer::MapcPlayComplete(TInt aError) +#endif +{ + TRACE_CONTEXT(AudioPlayer::MapcPlayComplete, EAudioInternal); + TRACE_ENTRY("state %d error %d", m_state, aError); + + m_tickTimer->stop(); + + if(KErrNone == aError) + { + changeState(StoppedState); + // TODO: move on to m_nextSource + } + else + { + // TODO: do something with aError? + m_error = NormalError; + changeState(ErrorState); + } + +/* + if(aError == KErrNone) { + if(m_nextSource.type() == MediaSource::Empty) { + emit finished(); + } else { + setSource(m_nextSource); + m_nextSource = MediaSource(); + } + + changeState(StoppedState); + } + else { + m_error = NormalError; + changeState(ErrorState); + } +*/ + + TRACE_EXIT_0(); +} + +#ifdef QT_PHONON_MMF_AUDIO_DRM +void MMF::AudioPlayer::MaloLoadingStarted() +{ + +} + +void MMF::AudioPlayer::MaloLoadingComplete() +{ + +} +#endif // QT_PHONON_MMF_AUDIO_DRM + + +//----------------------------------------------------------------------------- +// Volume +//----------------------------------------------------------------------------- + +qreal MMF::AudioPlayer::volume() const +{ + return m_volume; +} + +bool MMF::AudioPlayer::setVolume(qreal volume) +{ + TRACE_CONTEXT(AudioPlayer::setVolume, EAudioInternal); + TRACE_ENTRY("state %d", m_state); + + bool volumeChanged = false; + + switch(m_state) + { + case GroundState: + case LoadingState: + case ErrorState: + // Do nothing + break; + + case StoppedState: + case PausedState: + case PlayingState: + case BufferingState: + { + if(volume != m_volume) + { + const int err = m_player->SetVolume(volume * m_maxVolume); + if(KErrNone == err) + { + m_volume = volume; + volumeChanged = true; + } + else + { + m_error = NormalError; + changeState(ErrorState); + } + } + break; + } + + // Protection against adding new states and forgetting to update this + // switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_RETURN("%d", volumeChanged); +} + +void MMF::AudioPlayer::setAudioOutput(AudioOutput* audioOutput) +{ + m_audioOutput = audioOutput; +} + + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +qint64 MMF::AudioPlayer::toMilliSeconds(const TTimeIntervalMicroSeconds &in) +{ + return in.Int64() / 1000; +} + +Phonon::State MMF::AudioPlayer::phononState(PrivateState state) +{ + const Phonon::State phononState = + GroundState == state + ? Phonon::StoppedState + : static_cast(state); + + return phononState; +} + +void MMF::AudioPlayer::changeState(PrivateState newState) +{ + TRACE_CONTEXT(AudioPlayer::changeState, EAudioInternal); + TRACE_ENTRY("state %d newState %d", m_state, newState); + + // TODO: add some invariants to check that the transition is valid + + const Phonon::State currentPhononState = phononState(m_state); + const Phonon::State newPhononState = phononState(newState); + if(currentPhononState != newPhononState) + { + TRACE("emit stateChanged(%d, %d)", newPhononState, currentPhononState); + emit stateChanged(newPhononState, currentPhononState); + } + + m_state = newState; + + TRACE_EXIT_0(); +} + +void MMF::AudioPlayer::tick() +{ + TRACE_CONTEXT(AudioPlayer::tick, EAudioInternal); + TRACE_ENTRY("state %d", m_state); + + emit tick(currentTime()); + + TRACE_EXIT_0(); +} + + + + diff --git a/src/3rdparty/phonon/mmf/audioplayer.h b/src/3rdparty/phonon/mmf/audioplayer.h new file mode 100644 index 0000000..d9a64e1 --- /dev/null +++ b/src/3rdparty/phonon/mmf/audioplayer.h @@ -0,0 +1,173 @@ +/* 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 . + +*/ + +#ifndef PHONON_MMF_AUDIOPLAYER_H +#define PHONON_MMF_AUDIOPLAYER_H + +#include "abstractplayer.h" + +class CDrmPlayerUtility; +class TTimeIntervalMicroSeconds; +class QTimer; + +#ifdef QT_PHONON_MMF_AUDIO_DRM +#include +typedef CDrmPlayerUtility CPlayerType; +typedef MDrmAudioPlayerCallback MPlayerObserverType; +#else +#include +typedef CMdaAudioPlayerUtility CPlayerType; +typedef MMdaAudioPlayerCallback MPlayerObserverType; +#endif + +namespace Phonon +{ + namespace MMF + { + class AudioOutput; + + /** + * + * See + * How to + * play a video file using CVideoPlayerUtility + */ + class AudioPlayer : public AbstractPlayer + , public MPlayerObserverType // typedef +#ifdef QT_PHONON_MMF_AUDIO_DRM + , public MAudioLoadingObserver +#endif + { + Q_OBJECT + + public: + AudioPlayer(QObject *parent); + virtual ~AudioPlayer(); + + // AbstractPlayer + virtual void play(); + virtual void pause(); + virtual void stop(); + virtual void seek(qint64 milliseconds); + virtual qint32 tickInterval() const; + virtual void setTickInterval(qint32 interval); + virtual bool hasVideo() const; + virtual bool isSeekable() const; + virtual qint64 currentTime() const; + virtual Phonon::State state() const; + virtual QString errorString() const; + virtual Phonon::ErrorType errorType() const; + virtual qint64 totalTime() const; + virtual MediaSource source() const; + virtual void setSource(const MediaSource &); + virtual void setNextSource(const MediaSource &source); + virtual qint32 prefinishMark() const; + virtual void setPrefinishMark(qint32); + virtual qint32 transitionTime() const; + virtual void setTransitionTime(qint32); + +#ifdef QT_PHONON_MMF_AUDIO_DRM + // MDrmAudioPlayerCallback + virtual void MdapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &aDuration); + virtual void MdapcPlayComplete(TInt aError); + + // MAudioLoadingObserver + virtual void MaloLoadingStarted(); + virtual void MaloLoadingComplete(); +#else + // MMdaAudioPlayerCallback + virtual void MapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &aDuration); + virtual void MapcPlayComplete(TInt aError); +#endif + + qreal volume() const; + bool setVolume(qreal volume); + + void setAudioOutput(AudioOutput* audioOutput); + + Q_SIGNALS: + void totalTimeChanged(); + void stateChanged(Phonon::State oldState, + Phonon::State newState); + void finished(); + void tick(qint64 time); + + private Q_SLOTS: + /** + * Receives signal from m_tickTimer + */ + void tick(); + + private: + static qint64 toMilliSeconds(const TTimeIntervalMicroSeconds &); + + /** + * Defined private state enumeration in order to add GroundState + */ + enum PrivateState + { + LoadingState = Phonon::LoadingState, + StoppedState = Phonon::StoppedState, + PlayingState = Phonon::PlayingState, + BufferingState = Phonon::BufferingState, + PausedState = Phonon::PausedState, + ErrorState = Phonon::ErrorState, + GroundState + }; + + /** + * Converts PrivateState into the corresponding Phonon::State + */ + static Phonon::State phononState(PrivateState state); + + /** + * Changes state and emits stateChanged() + */ + void changeState(PrivateState newState); + + /** + * Using CPlayerType typedef in order to be able to easily switch between + * CMdaAudioPlayerUtility and CDrmPlayerUtility + */ + CPlayerType* m_player; + + AudioOutput* m_audioOutput; + + ErrorType m_error; + + /** + * Do not set this directly - call changeState() instead. + */ + PrivateState m_state; + + qint32 m_tickInterval; + + QTimer* m_tickTimer; + + MediaSource m_mediaSource; + MediaSource m_nextSource; + + qreal m_volume; + int m_maxVolume; + }; + } +} + +#endif diff --git a/src/3rdparty/phonon/mmf/mediaobject.cpp b/src/3rdparty/phonon/mmf/mediaobject.cpp index 8a4b76e..fb079f0 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.cpp +++ b/src/3rdparty/phonon/mmf/mediaobject.cpp @@ -16,61 +16,21 @@ along with this library. If not, see . */ -#include -#include -#include - #include "mediaobject.h" -#include "audiooutput.h" -#include "utils.h" using namespace Phonon; using namespace Phonon::MMF; //----------------------------------------------------------------------------- -// Constants -//----------------------------------------------------------------------------- - -const qint32 DefaultTickInterval = 20; -const int NullMaxVolume = -1; - - -//----------------------------------------------------------------------------- // Constructor / destructor //----------------------------------------------------------------------------- -MMF::MediaObject::MediaObject(QObject *parent) : m_player(NULL) - , m_audioOutput(NULL) - , m_error(NoError) - , m_state(GroundState) - , m_tickInterval(DefaultTickInterval) - , m_tickTimer(NULL) - , m_volume(0.0) - , m_maxVolume(NullMaxVolume) +MMF::MediaObject::MediaObject(QObject *parent) : QObject::QObject(parent) { - TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi); - TRACE_ENTRY_0(); - - Q_UNUSED(parent); - - // TODO: should leaves be trapped in the constructor? - m_player = CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone); - - m_tickTimer = new QTimer(this); - connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); - - TRACE_EXIT_0(); } MMF::MediaObject::~MediaObject() { - TRACE_CONTEXT(MediaObject::~MediaObject, EAudioApi); - TRACE_ENTRY_0(); - - delete m_tickTimer; - delete m_player; - - TRACE_EXIT_0(); } //----------------------------------------------------------------------------- @@ -79,442 +39,84 @@ MMF::MediaObject::~MediaObject() void MMF::MediaObject::play() { - TRACE_CONTEXT(MediaObject::play, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - switch(m_state) - { - case GroundState: - case LoadingState: - // Is this the correct error? Really we want 'NotReadyError' - m_error = NormalError; - changeState(ErrorState); - break; - - case StoppedState: - case PausedState: - m_player->Play(); - m_tickTimer->start(m_tickInterval); - changeState(PlayingState); - break; - - case PlayingState: - case BufferingState: - case ErrorState: - // Do nothing - break; - - // Protection against adding new states and forgetting to update this switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_EXIT("state %d", m_state); } void MMF::MediaObject::pause() { - TRACE_CONTEXT(MediaObject::pause, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - switch(m_state) - { - case GroundState: - case LoadingState: - case StoppedState: - case PausedState: - case ErrorState: - // Do nothing - break; - - case PlayingState: - case BufferingState: - m_player->Pause(); - m_tickTimer->stop(); - changeState(PausedState); - break; - - // Protection against adding new states and forgetting to update this switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_EXIT("state %d", m_state); } void MMF::MediaObject::stop() { - TRACE_CONTEXT(MediaObject::stop, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - switch(m_state) - { - case GroundState: - case LoadingState: - case StoppedState: - case ErrorState: - // Do nothing - break; - - case PlayingState: - case BufferingState: - case PausedState: - m_player->Stop(); - m_tickTimer->stop(); - changeState(StoppedState); - break; - - // Protection against adding new states and forgetting to update this switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_EXIT("state %d", m_state); } void MMF::MediaObject::seek(qint64 ms) { - TRACE_CONTEXT(MediaObject::seek, EAudioApi); - TRACE_ENTRY("state %d pos %Ld", m_state, ms); - - m_player->SetPosition(TTimeIntervalMicroSeconds(ms)); - - TRACE_EXIT_0(); + Q_UNUSED(ms); } qint32 MMF::MediaObject::tickInterval() const { - TRACE_CONTEXT(MediaObject::tickInterval, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_RETURN("%d", m_tickInterval); } void MMF::MediaObject::setTickInterval(qint32 interval) { - TRACE_CONTEXT(MediaObject::setTickInterval, EAudioApi); - TRACE_ENTRY("state %d m_interval %d interval %d", m_state, m_tickInterval, interval); - - m_tickInterval = interval; - m_tickTimer->setInterval(interval); - - TRACE_EXIT_0(); } bool MMF::MediaObject::hasVideo() const { - TRACE_CONTEXT(MediaObject::hasVideo, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: re-factor this class so that audio playback and video playback are - // delegated to separate classes, which internally hoat a - // CMdaAudioPlayerUtility / CVideoPlayerUtility instance as appropriate. - - TRACE_RETURN("%d", false); } bool MMF::MediaObject::isSeekable() const { - TRACE_CONTEXT(MediaObject::isSeekable, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_RETURN("%d", true); } Phonon::State MMF::MediaObject::state() const { - TRACE_CONTEXT(MediaObject::state, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - const Phonon::State result = phononState(m_state); - - TRACE_RETURN("%d", result); } qint64 MMF::MediaObject::currentTime() const { - TRACE_CONTEXT(MediaObject::currentTime, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TTimeIntervalMicroSeconds us; - const TInt err = m_player->GetPosition(us); - - qint64 result = -1; - - if(KErrNone == err) { - result = toMilliSeconds(us); - } - - TRACE_RETURN("%Ld", result); } QString MMF::MediaObject::errorString() const { - TRACE_CONTEXT(MediaObject::errorString, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_EXIT_0(); - // TODO: put in proper error strings - QString result; - return result; } Phonon::ErrorType MMF::MediaObject::errorType() const { - TRACE_CONTEXT(MediaObject::errorType, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - const Phonon::ErrorType result = (ErrorState == m_state) - ? m_error : NoError; - - TRACE_RETURN("%d", result); } qint64 MMF::MediaObject::totalTime() const { - TRACE_CONTEXT(MediaObject::totalTime, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - const qint64 result = toMilliSeconds(m_player->Duration()); - - TRACE_RETURN("%Ld", result); } MediaSource MMF::MediaObject::source() const { - TRACE_CONTEXT(MediaObject::source, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_EXIT_0(); - return m_mediaSource; } void MMF::MediaObject::setSource(const MediaSource &source) { - TRACE_CONTEXT(MediaObject::setSource, EAudioApi); - TRACE_ENTRY("state %d source.type %d", m_state, source.type()); - - m_player->Close(); - changeState(GroundState); - - // TODO: is it correct to assign even if the media type is not supported in - // the switch statement below? - m_mediaSource = source; - - TInt symbianErr = KErrNone; - - switch(m_mediaSource.type()) - { - case MediaSource::LocalFile: - { - // TODO: work out whose responsibility it is to ensure that paths - // are Symbian-style, i.e. have backslashes for path delimiters. - // Until then, use this utility function... - const QHBufC filename = Utils::symbianFilename(m_mediaSource.fileName()); - TRAP(symbianErr, m_player->OpenFileL(*filename)); - break; - } - - case MediaSource::Url: - { - const QHBufC filename(m_mediaSource.url().toString()); - TRAP(symbianErr, m_player->OpenUrlL(*filename)); - break; - } - - case MediaSource::Invalid: - case MediaSource::Disc: - case MediaSource::Stream: - symbianErr = KErrNotSupported; - break; - - case MediaSource::Empty: - TRACE_EXIT_0(); - return; - - // Protection against adding new media types and forgetting to update this switch - default: - TRACE_PANIC(InvalidMediaTypePanic); - } - - if(KErrNone == symbianErr) - { -#ifdef QT_PHONON_MMF_AUDIO_DRM - // There appears to be a bug in the CDrmPlayerUtility implementation (at least - // in S60 5.x) whereby the player does not check whether the loading observer - // pointer is null before dereferencing it. Therefore we must register for - // loading notification, even though we do nothing in the callback functions. - m_player->RegisterForAudioLoadingNotification(*this); -#endif - changeState(LoadingState); - } - else - { - // TODO: do something with the value of symbianErr? - m_error = NormalError; - changeState(ErrorState); - } - - TRACE_EXIT_0(); } void MMF::MediaObject::setNextSource(const MediaSource &source) { - TRACE_CONTEXT(MediaObject::setNextSource, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: handle 'next source' - - m_nextSource = source; - Q_UNUSED(source); - - TRACE_EXIT_0(); } qint32 MMF::MediaObject::prefinishMark() const { - TRACE_CONTEXT(MediaObject::prefinishMark, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: implement prefinish mark - const qint32 result = 0; - TRACE_RETURN("%d", result); } void MMF::MediaObject::setPrefinishMark(qint32 mark) { - TRACE_CONTEXT(MediaObject::setPrefinishMark, EAudioApi); - TRACE_ENTRY("state %d mark %d", m_state, mark); - Q_UNUSED(mark); // to silence warnings in release builds - - // TODO: implement prefinish mark - - TRACE_EXIT_0(); } qint32 MMF::MediaObject::transitionTime() const { - TRACE_CONTEXT(MediaObject::transitionTime, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: implement transition time - const qint32 result = 0; - TRACE_RETURN("%d", result); } void MMF::MediaObject::setTransitionTime(qint32 time) { - TRACE_CONTEXT(MediaObject::setTransitionTime, EAudioApi); - TRACE_ENTRY("state %d time %d", m_state, time); - Q_UNUSED(time); // to silence warnings in release builds - - // TODO: implement transition time - - TRACE_EXIT_0(); -} - - -//----------------------------------------------------------------------------- -// Symbian multimedia client observer callbacks -//----------------------------------------------------------------------------- - -#ifdef QT_PHONON_MMF_AUDIO_DRM -void MMF::MediaObject::MdapcInitComplete(TInt aError, - const TTimeIntervalMicroSeconds &) -#else -void MMF::MediaObject::MapcInitComplete(TInt aError, - const TTimeIntervalMicroSeconds &) -#endif -{ - TRACE_CONTEXT(MediaObject::MapcInitComplete, EAudioInternal); - TRACE_ENTRY("state %d error %d", m_state, aError); - - __ASSERT_ALWAYS(LoadingState == m_state, Utils::panic(InvalidStatePanic)); - - if(KErrNone == aError) - { - TInt volume = 0; - aError = m_player->GetVolume(volume); - if(KErrNone == aError) - { - m_maxVolume = m_player->MaxVolume(); - m_volume = static_cast(volume) / m_maxVolume; - - if(m_audioOutput) - { - // Trigger AudioOutput signal - m_audioOutput->triggerVolumeChanged(m_volume); - } - - emit totalTimeChanged(); - changeState(StoppedState); - } - } - else - { - // TODO: set different error states according to value of aError? - m_error = NormalError; - changeState(ErrorState); - } - - TRACE_EXIT_0(); -} - -#ifdef QT_PHONON_MMF_AUDIO_DRM -void MMF::MediaObject::MdapcPlayComplete(TInt aError) -#else -void MMF::MediaObject::MapcPlayComplete(TInt aError) -#endif -{ - TRACE_CONTEXT(MediaObject::MapcPlayComplete, EAudioInternal); - TRACE_ENTRY("state %d error %d", m_state, aError); - - m_tickTimer->stop(); - - if(KErrNone == aError) - { - changeState(StoppedState); - // TODO: move on to m_nextSource - } - else - { - // TODO: do something with aError? - m_error = NormalError; - changeState(ErrorState); - } - -/* - if(aError == KErrNone) { - if(m_nextSource.type() == MediaSource::Empty) { - emit finished(); - } else { - setSource(m_nextSource); - m_nextSource = MediaSource(); - } - - changeState(StoppedState); - } - else { - m_error = NormalError; - changeState(ErrorState); - } -*/ - - TRACE_EXIT_0(); -} - -#ifdef QT_PHONON_MMF_AUDIO_DRM -void MMF::MediaObject::MaloLoadingStarted() -{ - -} - -void MMF::MediaObject::MaloLoadingComplete() -{ - } -#endif // QT_PHONON_MMF_AUDIO_DRM - //----------------------------------------------------------------------------- // Volume @@ -522,110 +124,13 @@ void MMF::MediaObject::MaloLoadingComplete() qreal MMF::MediaObject::volume() const { - return m_volume; } bool MMF::MediaObject::setVolume(qreal volume) { - TRACE_CONTEXT(MediaObject::setVolume, EAudioInternal); - TRACE_ENTRY("state %d", m_state); - - bool volumeChanged = false; - - switch(m_state) - { - case GroundState: - case LoadingState: - case ErrorState: - // Do nothing - break; - - case StoppedState: - case PausedState: - case PlayingState: - case BufferingState: - { - if(volume != m_volume) - { - const int err = m_player->SetVolume(volume * m_maxVolume); - if(KErrNone == err) - { - m_volume = volume; - volumeChanged = true; - } - else - { - m_error = NormalError; - changeState(ErrorState); - } - } - break; - } - - // Protection against adding new states and forgetting to update this - // switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_RETURN("%d", volumeChanged); } void MMF::MediaObject::setAudioOutput(AudioOutput* audioOutput) { - m_audioOutput = audioOutput; -} - - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -qint64 MMF::MediaObject::toMilliSeconds(const TTimeIntervalMicroSeconds &in) -{ - return in.Int64() / 1000; -} - -Phonon::State MMF::MediaObject::phononState(PrivateState state) -{ - const Phonon::State phononState = - GroundState == state - ? Phonon::StoppedState - : static_cast(state); - - return phononState; -} - -void MMF::MediaObject::changeState(PrivateState newState) -{ - TRACE_CONTEXT(MediaObject::changeState, EAudioInternal); - TRACE_ENTRY("state %d newState %d", m_state, newState); - - // TODO: add some invariants to check that the transition is valid - - const Phonon::State currentPhononState = phononState(m_state); - const Phonon::State newPhononState = phononState(newState); - if(currentPhononState != newPhononState) - { - TRACE("emit stateChanged(%d, %d)", newPhononState, currentPhononState); - emit stateChanged(newPhononState, currentPhononState); - } - - m_state = newState; - - TRACE_EXIT_0(); -} - -void MMF::MediaObject::tick() -{ - TRACE_CONTEXT(MediaObject::tick, EAudioInternal); - TRACE_ENTRY("state %d", m_state); - - emit tick(currentTime()); - - TRACE_EXIT_0(); } - - - diff --git a/src/3rdparty/phonon/mmf/mediaobject.h b/src/3rdparty/phonon/mmf/mediaobject.h index f17580e..d162455 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.h +++ b/src/3rdparty/phonon/mmf/mediaobject.h @@ -19,26 +19,8 @@ along with this library. If not, see . #ifndef PHONON_MMF_MEDIAOBJECT_H #define PHONON_MMF_MEDIAOBJECT_H -/* We use the extra qualification include/ to avoid picking up the include - * Phonon has. */ -#include - #include -#include - -class CDrmPlayerUtility; -class TTimeIntervalMicroSeconds; -class QTimer; - -#ifdef QT_PHONON_MMF_AUDIO_DRM -#include -typedef CDrmPlayerUtility CPlayerType; -typedef MDrmAudioPlayerCallback MPlayerObserverType; -#else -#include -typedef CMdaAudioPlayerUtility CPlayerType; -typedef MMdaAudioPlayerCallback MPlayerObserverType; -#endif +#include namespace Phonon { @@ -47,17 +29,9 @@ namespace Phonon class AudioOutput; /** - * - * See - * How to - * play a video file using CVideoPlayerUtility */ class MediaObject : public QObject , public MediaObjectInterface - , public MPlayerObserverType // typedef -#ifdef QT_PHONON_MMF_AUDIO_DRM - , public MAudioLoadingObserver -#endif { Q_OBJECT Q_INTERFACES(Phonon::MediaObjectInterface) @@ -88,22 +62,6 @@ namespace Phonon virtual qint32 transitionTime() const; virtual void setTransitionTime(qint32); -#ifdef QT_PHONON_MMF_AUDIO_DRM - // MDrmAudioPlayerCallback - virtual void MdapcInitComplete(TInt aError, - const TTimeIntervalMicroSeconds &aDuration); - virtual void MdapcPlayComplete(TInt aError); - - // MAudioLoadingObserver - virtual void MaloLoadingStarted(); - virtual void MaloLoadingComplete(); -#else - // MMdaAudioPlayerCallback - virtual void MapcInitComplete(TInt aError, - const TTimeIntervalMicroSeconds &aDuration); - virtual void MapcPlayComplete(TInt aError); -#endif - qreal volume() const; bool setVolume(qreal volume); @@ -115,64 +73,6 @@ namespace Phonon Phonon::State newState); void finished(); void tick(qint64 time); - - private Q_SLOTS: - /** - * Receives signal from m_tickTimer - */ - void tick(); - - private: - static qint64 toMilliSeconds(const TTimeIntervalMicroSeconds &); - - /** - * Defined private state enumeration in order to add GroundState - */ - enum PrivateState - { - LoadingState = Phonon::LoadingState, - StoppedState = Phonon::StoppedState, - PlayingState = Phonon::PlayingState, - BufferingState = Phonon::BufferingState, - PausedState = Phonon::PausedState, - ErrorState = Phonon::ErrorState, - GroundState - }; - - /** - * Converts PrivateState into the corresponding Phonon::State - */ - static Phonon::State phononState(PrivateState state); - - /** - * Changes state and emits stateChanged() - */ - void changeState(PrivateState newState); - - /** - * Using CPlayerType typedef in order to be able to easily switch between - * CMdaAudioPlayerUtility and CDrmPlayerUtility - */ - CPlayerType* m_player; - - AudioOutput* m_audioOutput; - - ErrorType m_error; - - /** - * Do not set this directly - call changeState() instead. - */ - PrivateState m_state; - - qint32 m_tickInterval; - - QTimer* m_tickTimer; - - MediaSource m_mediaSource; - MediaSource m_nextSource; - - qreal m_volume; - int m_maxVolume; }; } } diff --git a/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp b/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp new file mode 100644 index 0000000..3a51070 --- /dev/null +++ b/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp @@ -0,0 +1,577 @@ +/* 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 . + +*/ + +#include +#include +#include + +#include "mmf_videoplayer.h" +#include "audiooutput.h" +#include "utils.h" + +using namespace Phonon; +using namespace Phonon::MMF; + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const qint32 DefaultTickInterval = 20; +const int NullMaxVolume = -1; + + +//----------------------------------------------------------------------------- +// Constructor / destructor +//----------------------------------------------------------------------------- + +MMF::VideoPlayer::VideoPlayer(QObject *parent) : m_audioOutput(NULL) + , m_error(NoError) + , m_state(GroundState) + , m_tickInterval(DefaultTickInterval) + , m_tickTimer(NULL) + , m_volume(0.0) + , m_maxVolume(NullMaxVolume) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::VideoPlayer, EAudioApi); + TRACE_ENTRY_0(); + + Q_UNUSED(parent); + + // TODO: should leaves be trapped in the constructor? + m_player = CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone); + + m_tickTimer = new QTimer(this); + connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); + + TRACE_EXIT_0(); +#endif +} + +MMF::VideoPlayer::~VideoPlayer() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::~VideoPlayer, EAudioApi); + TRACE_ENTRY_0(); + + delete m_tickTimer; + delete m_player; + + TRACE_EXIT_0(); +#endif +} + +//----------------------------------------------------------------------------- +// VideoPlayerInterface +//----------------------------------------------------------------------------- + +void MMF::VideoPlayer::play() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::play, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + // Is this the correct error? Really we want 'NotReadyError' + m_error = NormalError; + changeState(ErrorState); + break; + + case StoppedState: + case PausedState: + m_player->Play(); + m_tickTimer->start(m_tickInterval); + changeState(PlayingState); + break; + + case PlayingState: + case BufferingState: + case ErrorState: + // Do nothing + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +#endif +} + +void MMF::VideoPlayer::pause() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::pause, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + case StoppedState: + case PausedState: + case ErrorState: + // Do nothing + break; + + case PlayingState: + case BufferingState: + m_player->Pause(); + m_tickTimer->stop(); + changeState(PausedState); + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +#endif +} + +void MMF::VideoPlayer::stop() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::stop, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + case StoppedState: + case ErrorState: + // Do nothing + break; + + case PlayingState: + case BufferingState: + case PausedState: + m_player->Stop(); + m_tickTimer->stop(); + changeState(StoppedState); + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +#endif +} + +void MMF::VideoPlayer::seek(qint64 ms) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::seek, EAudioApi); + TRACE_ENTRY("state %d pos %Ld", m_state, ms); + + m_player->SetPosition(TTimeIntervalMicroSeconds(ms)); + + TRACE_EXIT_0(); +#endif +} + +qint32 MMF::VideoPlayer::tickInterval() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::tickInterval, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_RETURN("%d", m_tickInterval); +#endif +} + +void MMF::VideoPlayer::setTickInterval(qint32 interval) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setTickInterval, EAudioApi); + TRACE_ENTRY("state %d m_interval %d interval %d", m_state, m_tickInterval, interval); + + m_tickInterval = interval; + m_tickTimer->setInterval(interval); + + TRACE_EXIT_0(); +#endif +} + +bool MMF::VideoPlayer::hasVideo() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::hasVideo, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: re-factor this class so that audio playback and video playback are + // delegated to separate classes, which internally hoat a + // CMdaVideoPlayerUtility / CVideoPlayerUtility instance as appropriate. + + TRACE_RETURN("%d", false); +#endif +} + +bool MMF::VideoPlayer::isSeekable() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::isSeekable, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_RETURN("%d", true); +#endif +} + +Phonon::State MMF::VideoPlayer::state() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::state, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const Phonon::State result = phononState(m_state); + + TRACE_RETURN("%d", result); +#endif +} + +qint64 MMF::VideoPlayer::currentTime() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::currentTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TTimeIntervalMicroSeconds us; + const TInt err = m_player->GetPosition(us); + + qint64 result = -1; + + if(KErrNone == err) { + result = toMilliSeconds(us); + } + + TRACE_RETURN("%Ld", result); +#endif +} + +QString MMF::VideoPlayer::errorString() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::errorString, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_EXIT_0(); + // TODO: put in proper error strings + QString result; + return result; +#endif +} + +Phonon::ErrorType MMF::VideoPlayer::errorType() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::errorType, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const Phonon::ErrorType result = (ErrorState == m_state) + ? m_error : NoError; + + TRACE_RETURN("%d", result); +#endif +} + +qint64 MMF::VideoPlayer::totalTime() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::totalTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const qint64 result = toMilliSeconds(m_player->Duration()); + + TRACE_RETURN("%Ld", result); +#endif +} + +MediaSource MMF::VideoPlayer::source() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::source, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_EXIT_0(); + return m_mediaSource; +#endif +} + +void MMF::VideoPlayer::setSource(const MediaSource &source) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setSource, EAudioApi); + TRACE_ENTRY("state %d source.type %d", m_state, source.type()); + + m_player->Close(); + changeState(GroundState); + + // TODO: is it correct to assign even if the media type is not supported in + // the switch statement below? + m_mediaSource = source; + + TInt symbianErr = KErrNone; + + switch(m_mediaSource.type()) + { + case MediaSource::LocalFile: + { + // TODO: work out whose responsibility it is to ensure that paths + // are Symbian-style, i.e. have backslashes for path delimiters. + // Until then, use this utility function... + const QHBufC filename = Utils::symbianFilename(m_mediaSource.fileName()); + TRAP(symbianErr, m_player->OpenFileL(*filename)); + break; + } + + case MediaSource::Url: + { + const QHBufC filename(m_mediaSource.url().toString()); + TRAP(symbianErr, m_player->OpenUrlL(*filename)); + break; + } + + case MediaSource::Invalid: + case MediaSource::Disc: + case MediaSource::Stream: + symbianErr = KErrNotSupported; + break; + + case MediaSource::Empty: + TRACE_EXIT_0(); + return; + + // Protection against adding new media types and forgetting to update this switch + default: + TRACE_PANIC(InvalidMediaTypePanic); + } + + if(KErrNone == symbianErr) + { +#ifdef QT_PHONON_MMF_AUDIO_DRM + // There appears to be a bug in the CDrmPlayerUtility implementation (at least + // in S60 5.x) whereby the player does not check whether the loading observer + // pointer is null before dereferencing it. Therefore we must register for + // loading notification, even though we do nothing in the callback functions. + m_player->RegisterForAudioLoadingNotification(*this); +#endif + changeState(LoadingState); + } + else + { + // TODO: do something with the value of symbianErr? + m_error = NormalError; + changeState(ErrorState); + } + + TRACE_EXIT_0(); +#endif +} + +void MMF::VideoPlayer::setNextSource(const MediaSource &source) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setNextSource, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: handle 'next source' + + m_nextSource = source; + Q_UNUSED(source); + + TRACE_EXIT_0(); +#endif +} + +qint32 MMF::VideoPlayer::prefinishMark() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::prefinishMark, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: implement prefinish mark + const qint32 result = 0; + TRACE_RETURN("%d", result); +#endif +} + +void MMF::VideoPlayer::setPrefinishMark(qint32 mark) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setPrefinishMark, EAudioApi); + TRACE_ENTRY("state %d mark %d", m_state, mark); + Q_UNUSED(mark); // to silence warnings in release builds + + // TODO: implement prefinish mark + + TRACE_EXIT_0(); +#endif +} + +qint32 MMF::VideoPlayer::transitionTime() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::transitionTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: implement transition time + const qint32 result = 0; + TRACE_RETURN("%d", result); +#endif +} + +void MMF::VideoPlayer::setTransitionTime(qint32 time) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setTransitionTime, EAudioApi); + TRACE_ENTRY("state %d time %d", m_state, time); + Q_UNUSED(time); // to silence warnings in release builds + + // TODO: implement transition time + + TRACE_EXIT_0(); +#endif +} + + +//----------------------------------------------------------------------------- +// Volume +//----------------------------------------------------------------------------- + +qreal MMF::VideoPlayer::volume() const +{ + //return m_volume; +} + +bool MMF::VideoPlayer::setVolume(qreal volume) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setVolume, EAudioInternal); + TRACE_ENTRY("state %d", m_state); + + bool volumeChanged = false; + + switch(m_state) + { + case GroundState: + case LoadingState: + case ErrorState: + // Do nothing + break; + + case StoppedState: + case PausedState: + case PlayingState: + case BufferingState: + { + if(volume != m_volume) + { + const int err = m_player->SetVolume(volume * m_maxVolume); + if(KErrNone == err) + { + m_volume = volume; + volumeChanged = true; + } + else + { + m_error = NormalError; + changeState(ErrorState); + } + } + break; + } + + // Protection against adding new states and forgetting to update this + // switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_RETURN("%d", volumeChanged); +#endif +} + +void MMF::VideoPlayer::setAudioOutput(AudioOutput* audioOutput) +{ + //m_audioOutput = audioOutput; +} + + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +qint64 MMF::VideoPlayer::toMilliSeconds(const TTimeIntervalMicroSeconds &in) +{ + //return in.Int64() / 1000; +} + +Phonon::State MMF::VideoPlayer::phononState(PrivateState state) +{ +#if 0 + const Phonon::State phononState = + GroundState == state + ? Phonon::StoppedState + : static_cast(state); + + return phononState; +#endif +} + +void MMF::VideoPlayer::changeState(PrivateState newState) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::changeState, EAudioInternal); + TRACE_ENTRY("state %d newState %d", m_state, newState); + + // TODO: add some invariants to check that the transition is valid + + const Phonon::State currentPhononState = phononState(m_state); + const Phonon::State newPhononState = phononState(newState); + if(currentPhononState != newPhononState) + { + TRACE("emit stateChanged(%d, %d)", newPhononState, currentPhononState); + emit stateChanged(newPhononState, currentPhononState); + } + + m_state = newState; + + TRACE_EXIT_0(); +#endif +} + +void MMF::VideoPlayer::tick() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::tick, EAudioInternal); + TRACE_ENTRY("state %d", m_state); + + emit tick(currentTime()); + + TRACE_EXIT_0(); +#endif +} + diff --git a/src/3rdparty/phonon/mmf/mmf_videoplayer.h b/src/3rdparty/phonon/mmf/mmf_videoplayer.h new file mode 100644 index 0000000..3b0cd98 --- /dev/null +++ b/src/3rdparty/phonon/mmf/mmf_videoplayer.h @@ -0,0 +1,163 @@ +/* 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 . + +*/ + +#ifndef PHONON_MMF_VIDEOPLAYER_H +#define PHONON_MMF_VIDEOPLAYER_H + +/* We use the extra qualification include/ to avoid picking up the include + * Phonon has. */ +#include +#include "abstractplayer.h" + +#include + +class CDrmPlayerUtility; +class TTimeIntervalMicroSeconds; +class QTimer; + +namespace Phonon +{ + namespace MMF + { + class AudioOutput; + + /** + * + * See + * How to + * play a video file using CVideoPlayerUtility + */ + class VideoPlayer : public AbstractPlayer + { + Q_OBJECT + public: + VideoPlayer(QObject *parent); + virtual ~VideoPlayer(); + + // AbstractPlayer + virtual void play(); + virtual void pause(); + virtual void stop(); + virtual void seek(qint64 milliseconds); + virtual qint32 tickInterval() const; + virtual void setTickInterval(qint32 interval); + virtual bool hasVideo() const; + virtual bool isSeekable() const; + virtual qint64 currentTime() const; + virtual Phonon::State state() const; + virtual QString errorString() const; + virtual Phonon::ErrorType errorType() const; + virtual qint64 totalTime() const; + virtual MediaSource source() const; + virtual void setSource(const MediaSource &); + virtual void setNextSource(const MediaSource &source); + virtual qint32 prefinishMark() const; + virtual void setPrefinishMark(qint32); + virtual qint32 transitionTime() const; + virtual void setTransitionTime(qint32); + +#ifdef QT_PHONON_MMF_AUDIO_DRM + // MDrmVideoPlayerCallback + virtual void MdapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &aDuration); + virtual void MdapcPlayComplete(TInt aError); + + // MAudioLoadingObserver + virtual void MaloLoadingStarted(); + virtual void MaloLoadingComplete(); +#else + // MMdaVideoPlayerCallback + virtual void MapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &aDuration); + virtual void MapcPlayComplete(TInt aError); +#endif + + qreal volume() const; + bool setVolume(qreal volume); + + void setAudioOutput(AudioOutput* audioOutput); + + Q_SIGNALS: + void totalTimeChanged(); + void stateChanged(Phonon::State oldState, + Phonon::State newState); + void finished(); + void tick(qint64 time); + + private Q_SLOTS: + /** + * Receives signal from m_tickTimer + */ + void tick(); + + private: + static qint64 toMilliSeconds(const TTimeIntervalMicroSeconds &); + + /** + * Defined private state enumeration in order to add GroundState + */ + enum PrivateState + { + LoadingState = Phonon::LoadingState, + StoppedState = Phonon::StoppedState, + PlayingState = Phonon::PlayingState, + BufferingState = Phonon::BufferingState, + PausedState = Phonon::PausedState, + ErrorState = Phonon::ErrorState, + GroundState + }; + + /** + * Converts PrivateState into the corresponding Phonon::State + */ + static Phonon::State phononState(PrivateState state); + + /** + * Changes state and emits stateChanged() + */ + void changeState(PrivateState newState); + + /** + * Using CPlayerType typedef in order to be able to easily switch between + * CMdaVideoPlayerUtility and CDrmPlayerUtility + */ + // CPlayerType* m_player; TODO + + AudioOutput* m_audioOutput; + + ErrorType m_error; + + /** + * Do not set this directly - call changeState() instead. + */ + PrivateState m_state; + + qint32 m_tickInterval; + + QTimer* m_tickTimer; + + MediaSource m_mediaSource; + MediaSource m_nextSource; + + qreal m_volume; + int m_maxVolume; + }; + } +} + +#endif diff --git a/src/plugins/phonon/mmf/mmf.pro b/src/plugins/phonon/mmf/mmf.pro index ee2d3f9..266c3db 100644 --- a/src/plugins/phonon/mmf/mmf.pro +++ b/src/plugins/phonon/mmf/mmf.pro @@ -21,17 +21,22 @@ phonon_mmf_audio_drm { LIBS += -lmediaclientaudio.lib } -HEADERS += \ - $$PHONON_MMF_DIR/audiooutput.h \ - $$PHONON_MMF_DIR/backend.h \ - $$PHONON_MMF_DIR/mediaobject.h \ - $$PHONON_MMF_DIR/utils.h - -SOURCES += \ - $$PHONON_MMF_DIR/audiooutput.cpp \ - $$PHONON_MMF_DIR/backend.cpp \ - $$PHONON_MMF_DIR/mediaobject.cpp \ - $$PHONON_MMF_DIR/utils.cpp +HEADERS += \ + $$PHONON_MMF_DIR/abstractplayer.h \ + $$PHONON_MMF_DIR/audiooutput.h \ + $$PHONON_MMF_DIR/audioplayer.h \ + $$PHONON_MMF_DIR/backend.h \ + $$PHONON_MMF_DIR/mediaobject.h \ + $$PHONON_MMF_DIR/utils.h \ + $$PHONON_MMF_DIR/mmf_videoplayer.h + +SOURCES += \ + $$PHONON_MMF_DIR/audiooutput.cpp \ + $$PHONON_MMF_DIR/audioplayer.cpp \ + $$PHONON_MMF_DIR/backend.cpp \ + $$PHONON_MMF_DIR/mediaobject.cpp \ + $$PHONON_MMF_DIR/utils.cpp \ + $$PHONON_MMF_DIR/mmf_videoplayer.cpp # This is needed for having the .qtplugin file properly created on Symbian. QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/phonon_backend -- cgit v0.12 From a7b1ad0b2ecdedd5f2a9d52fe09c4497078bc669 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Mon, 17 Aug 2009 16:58:44 +0200 Subject: Delegate from MediaObject. --- src/3rdparty/phonon/mmf/abstractplayer.h | 13 +++++++++++++ src/3rdparty/phonon/mmf/mediaobject.cpp | 25 ++++++++++++++++++++++++- src/3rdparty/phonon/mmf/mediaobject.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/3rdparty/phonon/mmf/abstractplayer.h b/src/3rdparty/phonon/mmf/abstractplayer.h index 6452090..0188068 100644 --- a/src/3rdparty/phonon/mmf/abstractplayer.h +++ b/src/3rdparty/phonon/mmf/abstractplayer.h @@ -27,6 +27,8 @@ namespace Phonon { namespace MMF { + class AudioOutput; + class AbstractPlayer : public QObject { public: @@ -42,9 +44,20 @@ namespace Phonon virtual Phonon::State state() const = 0; virtual QString errorString() const = 0; virtual Phonon::ErrorType errorType() const = 0; + virtual qint64 totalTime() const = 0; virtual Phonon::MediaSource source() const = 0; virtual void setSource(const Phonon::MediaSource &) = 0; virtual void setNextSource(const Phonon::MediaSource &) = 0; + + virtual void setTransitionTime(qint32) = 0; + virtual qint32 transitionTime() const = 0; + virtual qint32 prefinishMark() const = 0; + virtual void setPrefinishMark(qint32) = 0; + + virtual bool setVolume(qreal) = 0; + virtual qreal volume() const = 0; + + virtual void setAudioOutput(AudioOutput *) = 0; }; } } diff --git a/src/3rdparty/phonon/mmf/mediaobject.cpp b/src/3rdparty/phonon/mmf/mediaobject.cpp index fb079f0..4769249 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.cpp +++ b/src/3rdparty/phonon/mmf/mediaobject.cpp @@ -16,6 +16,7 @@ along with this library. If not, see . */ +#include "abstractplayer.h" #include "mediaobject.h" using namespace Phonon; @@ -39,83 +40,102 @@ MMF::MediaObject::~MediaObject() void MMF::MediaObject::play() { + m_player->play(); } void MMF::MediaObject::pause() { + m_player->pause(); } void MMF::MediaObject::stop() { + m_player->stop(); } void MMF::MediaObject::seek(qint64 ms) { - Q_UNUSED(ms); + m_player->seek(ms); } qint32 MMF::MediaObject::tickInterval() const { + return m_player->tickInterval(); } void MMF::MediaObject::setTickInterval(qint32 interval) { + m_player->setTransitionTime(interval); } bool MMF::MediaObject::hasVideo() const { + return m_player->hasVideo(); } bool MMF::MediaObject::isSeekable() const { + return m_player->isSeekable(); } Phonon::State MMF::MediaObject::state() const { + return m_player->state(); } qint64 MMF::MediaObject::currentTime() const { + return m_player->currentTime(); } QString MMF::MediaObject::errorString() const { + return m_player->errorString(); } Phonon::ErrorType MMF::MediaObject::errorType() const { + return m_player->errorType(); } qint64 MMF::MediaObject::totalTime() const { + return m_player->totalTime(); } MediaSource MMF::MediaObject::source() const { + return m_player->source(); } void MMF::MediaObject::setSource(const MediaSource &source) { + return m_player->setSource(source); } void MMF::MediaObject::setNextSource(const MediaSource &source) { + return m_player->setNextSource(source); } qint32 MMF::MediaObject::prefinishMark() const { + return m_player->prefinishMark(); } void MMF::MediaObject::setPrefinishMark(qint32 mark) { + m_player->setPrefinishMark(mark); } qint32 MMF::MediaObject::transitionTime() const { + return m_player->transitionTime(); } void MMF::MediaObject::setTransitionTime(qint32 time) { + m_player->setTransitionTime(time); } //----------------------------------------------------------------------------- @@ -124,13 +144,16 @@ void MMF::MediaObject::setTransitionTime(qint32 time) qreal MMF::MediaObject::volume() const { + return m_player->volume(); } bool MMF::MediaObject::setVolume(qreal volume) { + return m_player->setVolume(volume); } void MMF::MediaObject::setAudioOutput(AudioOutput* audioOutput) { + m_player->setAudioOutput(audioOutput); } diff --git a/src/3rdparty/phonon/mmf/mediaobject.h b/src/3rdparty/phonon/mmf/mediaobject.h index d162455..9b1e914 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.h +++ b/src/3rdparty/phonon/mmf/mediaobject.h @@ -26,6 +26,7 @@ namespace Phonon { namespace MMF { + class AbstractPlayer; class AudioOutput; /** @@ -73,6 +74,9 @@ namespace Phonon Phonon::State newState); void finished(); void tick(qint64 time); + + private: + AbstractPlayer *m_player; }; } } -- cgit v0.12 From 257984d8b8cf31394c4f20070ea045f5ae7fa170 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Mon, 17 Aug 2009 17:24:34 +0200 Subject: More delegation, basic plumbing. --- src/3rdparty/phonon/mmf/abstractplayer.h | 4 +--- src/3rdparty/phonon/mmf/audioplayer.cpp | 16 ++++++++-------- src/3rdparty/phonon/mmf/audioplayer.h | 2 +- src/3rdparty/phonon/mmf/mediaobject.cpp | 19 ++++++++++++++++++- src/3rdparty/phonon/mmf/mediaobject.h | 6 +++++- src/3rdparty/phonon/mmf/mmf_videoplayer.cpp | 14 +++++++------- src/3rdparty/phonon/mmf/mmf_videoplayer.h | 2 +- 7 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/3rdparty/phonon/mmf/abstractplayer.h b/src/3rdparty/phonon/mmf/abstractplayer.h index 0188068..613831a 100644 --- a/src/3rdparty/phonon/mmf/abstractplayer.h +++ b/src/3rdparty/phonon/mmf/abstractplayer.h @@ -37,7 +37,7 @@ namespace Phonon virtual void stop() = 0; virtual void seek(qint64 milliseconds) = 0; virtual qint32 tickInterval() const = 0; - virtual void setTickInterval() const = 0; + virtual void setTickInterval(qint32) = 0; virtual bool hasVideo() const = 0; virtual bool isSeekable() const = 0; virtual qint64 currentTime() const = 0; @@ -53,10 +53,8 @@ namespace Phonon virtual qint32 transitionTime() const = 0; virtual qint32 prefinishMark() const = 0; virtual void setPrefinishMark(qint32) = 0; - virtual bool setVolume(qreal) = 0; virtual qreal volume() const = 0; - virtual void setAudioOutput(AudioOutput *) = 0; }; } diff --git a/src/3rdparty/phonon/mmf/audioplayer.cpp b/src/3rdparty/phonon/mmf/audioplayer.cpp index 4dd2eb8..106b71b 100644 --- a/src/3rdparty/phonon/mmf/audioplayer.cpp +++ b/src/3rdparty/phonon/mmf/audioplayer.cpp @@ -39,14 +39,14 @@ const int NullMaxVolume = -1; // Constructor / destructor //----------------------------------------------------------------------------- -MMF::AudioPlayer::AudioPlayer(QObject *parent) : m_player(NULL) - , m_audioOutput(NULL) - , m_error(NoError) - , m_state(GroundState) - , m_tickInterval(DefaultTickInterval) - , m_tickTimer(NULL) - , m_volume(0.0) - , m_maxVolume(NullMaxVolume) +MMF::AudioPlayer::AudioPlayer() : m_player(NULL) + , m_audioOutput(NULL) + , m_error(NoError) + , m_state(GroundState) + , m_tickInterval(DefaultTickInterval) + , m_tickTimer(NULL) + , m_volume(0.0) + , m_maxVolume(NullMaxVolume) { TRACE_CONTEXT(AudioPlayer::AudioPlayer, EAudioApi); TRACE_ENTRY_0(); diff --git a/src/3rdparty/phonon/mmf/audioplayer.h b/src/3rdparty/phonon/mmf/audioplayer.h index d9a64e1..338c6fa 100644 --- a/src/3rdparty/phonon/mmf/audioplayer.h +++ b/src/3rdparty/phonon/mmf/audioplayer.h @@ -56,7 +56,7 @@ namespace Phonon Q_OBJECT public: - AudioPlayer(QObject *parent); + AudioPlayer(); virtual ~AudioPlayer(); // AbstractPlayer diff --git a/src/3rdparty/phonon/mmf/mediaobject.cpp b/src/3rdparty/phonon/mmf/mediaobject.cpp index 4769249..e9e4b5b 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.cpp +++ b/src/3rdparty/phonon/mmf/mediaobject.cpp @@ -17,6 +17,8 @@ along with this library. If not, see . */ #include "abstractplayer.h" +#include "audioplayer.h" +#include "mmf_videoplayer.h" #include "mediaobject.h" using namespace Phonon; @@ -65,7 +67,7 @@ qint32 MMF::MediaObject::tickInterval() const void MMF::MediaObject::setTickInterval(qint32 interval) { - m_player->setTransitionTime(interval); + m_player->setTickInterval(interval); } bool MMF::MediaObject::hasVideo() const @@ -110,9 +112,24 @@ MediaSource MMF::MediaObject::source() const void MMF::MediaObject::setSource(const MediaSource &source) { + loadPlayer(source); + return m_player->setSource(source); } +void MMF::MediaObject::loadPlayer(const MediaSource &source) +{ + disconnect(m_player.data(), 0, this, 0); + + // TODO determine media type + m_player.reset(new AudioPlayer()); + + connect(m_player.data(), SIGNAL(totalTimeChanged()), SIGNAL(totalTimeChanged())); + connect(m_player.data(), SIGNAL(stateChanged(Phonon::State, Phonon::State)), SIGNAL(stateChanged(Phonon::State, Phonon::State))); + connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished())); + connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64))); +} + void MMF::MediaObject::setNextSource(const MediaSource &source) { return m_player->setNextSource(source); diff --git a/src/3rdparty/phonon/mmf/mediaobject.h b/src/3rdparty/phonon/mmf/mediaobject.h index 9b1e914..a55b6e6 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.h +++ b/src/3rdparty/phonon/mmf/mediaobject.h @@ -21,6 +21,7 @@ along with this library. If not, see . #include #include +#include namespace Phonon { @@ -76,7 +77,10 @@ namespace Phonon void tick(qint64 time); private: - AbstractPlayer *m_player; + void loadPlayer(const MediaSource &source); + + QScopedPointer m_player; + }; } } diff --git a/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp b/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp index 3a51070..c226835 100644 --- a/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp +++ b/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp @@ -39,13 +39,13 @@ const int NullMaxVolume = -1; // Constructor / destructor //----------------------------------------------------------------------------- -MMF::VideoPlayer::VideoPlayer(QObject *parent) : m_audioOutput(NULL) - , m_error(NoError) - , m_state(GroundState) - , m_tickInterval(DefaultTickInterval) - , m_tickTimer(NULL) - , m_volume(0.0) - , m_maxVolume(NullMaxVolume) +MMF::VideoPlayer::VideoPlayer() : m_audioOutput(NULL) + , m_error(NoError) + , m_state(GroundState) + , m_tickInterval(DefaultTickInterval) + , m_tickTimer(NULL) + , m_volume(0.0) + , m_maxVolume(NullMaxVolume) { #if 0 TRACE_CONTEXT(VideoPlayer::VideoPlayer, EAudioApi); diff --git a/src/3rdparty/phonon/mmf/mmf_videoplayer.h b/src/3rdparty/phonon/mmf/mmf_videoplayer.h index 3b0cd98..3ea9c1a 100644 --- a/src/3rdparty/phonon/mmf/mmf_videoplayer.h +++ b/src/3rdparty/phonon/mmf/mmf_videoplayer.h @@ -46,7 +46,7 @@ namespace Phonon { Q_OBJECT public: - VideoPlayer(QObject *parent); + VideoPlayer(); virtual ~VideoPlayer(); // AbstractPlayer -- cgit v0.12 From 6b7603a0a2fed844b1264d8deb0ce78b110858c4 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Mon, 17 Aug 2009 17:31:02 +0200 Subject: Rename mmf_videoplayer back to videoplayer, apparently the includes can be resolved anyway. --- src/3rdparty/phonon/mmf/mediaobject.cpp | 2 +- src/3rdparty/phonon/mmf/mmf_videoplayer.cpp | 577 ---------------------------- src/3rdparty/phonon/mmf/mmf_videoplayer.h | 163 -------- src/3rdparty/phonon/mmf/videoplayer.cpp | 577 ++++++++++++++++++++++++++++ src/3rdparty/phonon/mmf/videoplayer.h | 163 ++++++++ src/plugins/phonon/mmf/mmf.pro | 4 +- 6 files changed, 743 insertions(+), 743 deletions(-) delete mode 100644 src/3rdparty/phonon/mmf/mmf_videoplayer.cpp delete mode 100644 src/3rdparty/phonon/mmf/mmf_videoplayer.h create mode 100644 src/3rdparty/phonon/mmf/videoplayer.cpp create mode 100644 src/3rdparty/phonon/mmf/videoplayer.h diff --git a/src/3rdparty/phonon/mmf/mediaobject.cpp b/src/3rdparty/phonon/mmf/mediaobject.cpp index e9e4b5b..877e463 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.cpp +++ b/src/3rdparty/phonon/mmf/mediaobject.cpp @@ -18,7 +18,7 @@ along with this library. If not, see . #include "abstractplayer.h" #include "audioplayer.h" -#include "mmf_videoplayer.h" +#include "videoplayer.h" #include "mediaobject.h" using namespace Phonon; diff --git a/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp b/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp deleted file mode 100644 index c226835..0000000 --- a/src/3rdparty/phonon/mmf/mmf_videoplayer.cpp +++ /dev/null @@ -1,577 +0,0 @@ -/* 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 . - -*/ - -#include -#include -#include - -#include "mmf_videoplayer.h" -#include "audiooutput.h" -#include "utils.h" - -using namespace Phonon; -using namespace Phonon::MMF; - -//----------------------------------------------------------------------------- -// Constants -//----------------------------------------------------------------------------- - -const qint32 DefaultTickInterval = 20; -const int NullMaxVolume = -1; - - -//----------------------------------------------------------------------------- -// Constructor / destructor -//----------------------------------------------------------------------------- - -MMF::VideoPlayer::VideoPlayer() : m_audioOutput(NULL) - , m_error(NoError) - , m_state(GroundState) - , m_tickInterval(DefaultTickInterval) - , m_tickTimer(NULL) - , m_volume(0.0) - , m_maxVolume(NullMaxVolume) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::VideoPlayer, EAudioApi); - TRACE_ENTRY_0(); - - Q_UNUSED(parent); - - // TODO: should leaves be trapped in the constructor? - m_player = CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone); - - m_tickTimer = new QTimer(this); - connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); - - TRACE_EXIT_0(); -#endif -} - -MMF::VideoPlayer::~VideoPlayer() -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::~VideoPlayer, EAudioApi); - TRACE_ENTRY_0(); - - delete m_tickTimer; - delete m_player; - - TRACE_EXIT_0(); -#endif -} - -//----------------------------------------------------------------------------- -// VideoPlayerInterface -//----------------------------------------------------------------------------- - -void MMF::VideoPlayer::play() -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::play, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - switch(m_state) - { - case GroundState: - case LoadingState: - // Is this the correct error? Really we want 'NotReadyError' - m_error = NormalError; - changeState(ErrorState); - break; - - case StoppedState: - case PausedState: - m_player->Play(); - m_tickTimer->start(m_tickInterval); - changeState(PlayingState); - break; - - case PlayingState: - case BufferingState: - case ErrorState: - // Do nothing - break; - - // Protection against adding new states and forgetting to update this switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_EXIT("state %d", m_state); -#endif -} - -void MMF::VideoPlayer::pause() -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::pause, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - switch(m_state) - { - case GroundState: - case LoadingState: - case StoppedState: - case PausedState: - case ErrorState: - // Do nothing - break; - - case PlayingState: - case BufferingState: - m_player->Pause(); - m_tickTimer->stop(); - changeState(PausedState); - break; - - // Protection against adding new states and forgetting to update this switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_EXIT("state %d", m_state); -#endif -} - -void MMF::VideoPlayer::stop() -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::stop, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - switch(m_state) - { - case GroundState: - case LoadingState: - case StoppedState: - case ErrorState: - // Do nothing - break; - - case PlayingState: - case BufferingState: - case PausedState: - m_player->Stop(); - m_tickTimer->stop(); - changeState(StoppedState); - break; - - // Protection against adding new states and forgetting to update this switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_EXIT("state %d", m_state); -#endif -} - -void MMF::VideoPlayer::seek(qint64 ms) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::seek, EAudioApi); - TRACE_ENTRY("state %d pos %Ld", m_state, ms); - - m_player->SetPosition(TTimeIntervalMicroSeconds(ms)); - - TRACE_EXIT_0(); -#endif -} - -qint32 MMF::VideoPlayer::tickInterval() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::tickInterval, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_RETURN("%d", m_tickInterval); -#endif -} - -void MMF::VideoPlayer::setTickInterval(qint32 interval) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::setTickInterval, EAudioApi); - TRACE_ENTRY("state %d m_interval %d interval %d", m_state, m_tickInterval, interval); - - m_tickInterval = interval; - m_tickTimer->setInterval(interval); - - TRACE_EXIT_0(); -#endif -} - -bool MMF::VideoPlayer::hasVideo() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::hasVideo, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: re-factor this class so that audio playback and video playback are - // delegated to separate classes, which internally hoat a - // CMdaVideoPlayerUtility / CVideoPlayerUtility instance as appropriate. - - TRACE_RETURN("%d", false); -#endif -} - -bool MMF::VideoPlayer::isSeekable() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::isSeekable, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_RETURN("%d", true); -#endif -} - -Phonon::State MMF::VideoPlayer::state() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::state, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - const Phonon::State result = phononState(m_state); - - TRACE_RETURN("%d", result); -#endif -} - -qint64 MMF::VideoPlayer::currentTime() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::currentTime, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TTimeIntervalMicroSeconds us; - const TInt err = m_player->GetPosition(us); - - qint64 result = -1; - - if(KErrNone == err) { - result = toMilliSeconds(us); - } - - TRACE_RETURN("%Ld", result); -#endif -} - -QString MMF::VideoPlayer::errorString() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::errorString, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_EXIT_0(); - // TODO: put in proper error strings - QString result; - return result; -#endif -} - -Phonon::ErrorType MMF::VideoPlayer::errorType() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::errorType, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - const Phonon::ErrorType result = (ErrorState == m_state) - ? m_error : NoError; - - TRACE_RETURN("%d", result); -#endif -} - -qint64 MMF::VideoPlayer::totalTime() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::totalTime, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - const qint64 result = toMilliSeconds(m_player->Duration()); - - TRACE_RETURN("%Ld", result); -#endif -} - -MediaSource MMF::VideoPlayer::source() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::source, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - TRACE_EXIT_0(); - return m_mediaSource; -#endif -} - -void MMF::VideoPlayer::setSource(const MediaSource &source) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::setSource, EAudioApi); - TRACE_ENTRY("state %d source.type %d", m_state, source.type()); - - m_player->Close(); - changeState(GroundState); - - // TODO: is it correct to assign even if the media type is not supported in - // the switch statement below? - m_mediaSource = source; - - TInt symbianErr = KErrNone; - - switch(m_mediaSource.type()) - { - case MediaSource::LocalFile: - { - // TODO: work out whose responsibility it is to ensure that paths - // are Symbian-style, i.e. have backslashes for path delimiters. - // Until then, use this utility function... - const QHBufC filename = Utils::symbianFilename(m_mediaSource.fileName()); - TRAP(symbianErr, m_player->OpenFileL(*filename)); - break; - } - - case MediaSource::Url: - { - const QHBufC filename(m_mediaSource.url().toString()); - TRAP(symbianErr, m_player->OpenUrlL(*filename)); - break; - } - - case MediaSource::Invalid: - case MediaSource::Disc: - case MediaSource::Stream: - symbianErr = KErrNotSupported; - break; - - case MediaSource::Empty: - TRACE_EXIT_0(); - return; - - // Protection against adding new media types and forgetting to update this switch - default: - TRACE_PANIC(InvalidMediaTypePanic); - } - - if(KErrNone == symbianErr) - { -#ifdef QT_PHONON_MMF_AUDIO_DRM - // There appears to be a bug in the CDrmPlayerUtility implementation (at least - // in S60 5.x) whereby the player does not check whether the loading observer - // pointer is null before dereferencing it. Therefore we must register for - // loading notification, even though we do nothing in the callback functions. - m_player->RegisterForAudioLoadingNotification(*this); -#endif - changeState(LoadingState); - } - else - { - // TODO: do something with the value of symbianErr? - m_error = NormalError; - changeState(ErrorState); - } - - TRACE_EXIT_0(); -#endif -} - -void MMF::VideoPlayer::setNextSource(const MediaSource &source) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::setNextSource, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: handle 'next source' - - m_nextSource = source; - Q_UNUSED(source); - - TRACE_EXIT_0(); -#endif -} - -qint32 MMF::VideoPlayer::prefinishMark() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::prefinishMark, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: implement prefinish mark - const qint32 result = 0; - TRACE_RETURN("%d", result); -#endif -} - -void MMF::VideoPlayer::setPrefinishMark(qint32 mark) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::setPrefinishMark, EAudioApi); - TRACE_ENTRY("state %d mark %d", m_state, mark); - Q_UNUSED(mark); // to silence warnings in release builds - - // TODO: implement prefinish mark - - TRACE_EXIT_0(); -#endif -} - -qint32 MMF::VideoPlayer::transitionTime() const -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::transitionTime, EAudioApi); - TRACE_ENTRY("state %d", m_state); - - // TODO: implement transition time - const qint32 result = 0; - TRACE_RETURN("%d", result); -#endif -} - -void MMF::VideoPlayer::setTransitionTime(qint32 time) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::setTransitionTime, EAudioApi); - TRACE_ENTRY("state %d time %d", m_state, time); - Q_UNUSED(time); // to silence warnings in release builds - - // TODO: implement transition time - - TRACE_EXIT_0(); -#endif -} - - -//----------------------------------------------------------------------------- -// Volume -//----------------------------------------------------------------------------- - -qreal MMF::VideoPlayer::volume() const -{ - //return m_volume; -} - -bool MMF::VideoPlayer::setVolume(qreal volume) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::setVolume, EAudioInternal); - TRACE_ENTRY("state %d", m_state); - - bool volumeChanged = false; - - switch(m_state) - { - case GroundState: - case LoadingState: - case ErrorState: - // Do nothing - break; - - case StoppedState: - case PausedState: - case PlayingState: - case BufferingState: - { - if(volume != m_volume) - { - const int err = m_player->SetVolume(volume * m_maxVolume); - if(KErrNone == err) - { - m_volume = volume; - volumeChanged = true; - } - else - { - m_error = NormalError; - changeState(ErrorState); - } - } - break; - } - - // Protection against adding new states and forgetting to update this - // switch - default: - TRACE_PANIC(InvalidStatePanic); - } - - TRACE_RETURN("%d", volumeChanged); -#endif -} - -void MMF::VideoPlayer::setAudioOutput(AudioOutput* audioOutput) -{ - //m_audioOutput = audioOutput; -} - - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -qint64 MMF::VideoPlayer::toMilliSeconds(const TTimeIntervalMicroSeconds &in) -{ - //return in.Int64() / 1000; -} - -Phonon::State MMF::VideoPlayer::phononState(PrivateState state) -{ -#if 0 - const Phonon::State phononState = - GroundState == state - ? Phonon::StoppedState - : static_cast(state); - - return phononState; -#endif -} - -void MMF::VideoPlayer::changeState(PrivateState newState) -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::changeState, EAudioInternal); - TRACE_ENTRY("state %d newState %d", m_state, newState); - - // TODO: add some invariants to check that the transition is valid - - const Phonon::State currentPhononState = phononState(m_state); - const Phonon::State newPhononState = phononState(newState); - if(currentPhononState != newPhononState) - { - TRACE("emit stateChanged(%d, %d)", newPhononState, currentPhononState); - emit stateChanged(newPhononState, currentPhononState); - } - - m_state = newState; - - TRACE_EXIT_0(); -#endif -} - -void MMF::VideoPlayer::tick() -{ -#if 0 - TRACE_CONTEXT(VideoPlayer::tick, EAudioInternal); - TRACE_ENTRY("state %d", m_state); - - emit tick(currentTime()); - - TRACE_EXIT_0(); -#endif -} - diff --git a/src/3rdparty/phonon/mmf/mmf_videoplayer.h b/src/3rdparty/phonon/mmf/mmf_videoplayer.h deleted file mode 100644 index 3ea9c1a..0000000 --- a/src/3rdparty/phonon/mmf/mmf_videoplayer.h +++ /dev/null @@ -1,163 +0,0 @@ -/* 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 . - -*/ - -#ifndef PHONON_MMF_VIDEOPLAYER_H -#define PHONON_MMF_VIDEOPLAYER_H - -/* We use the extra qualification include/ to avoid picking up the include - * Phonon has. */ -#include -#include "abstractplayer.h" - -#include - -class CDrmPlayerUtility; -class TTimeIntervalMicroSeconds; -class QTimer; - -namespace Phonon -{ - namespace MMF - { - class AudioOutput; - - /** - * - * See - * How to - * play a video file using CVideoPlayerUtility - */ - class VideoPlayer : public AbstractPlayer - { - Q_OBJECT - public: - VideoPlayer(); - virtual ~VideoPlayer(); - - // AbstractPlayer - virtual void play(); - virtual void pause(); - virtual void stop(); - virtual void seek(qint64 milliseconds); - virtual qint32 tickInterval() const; - virtual void setTickInterval(qint32 interval); - virtual bool hasVideo() const; - virtual bool isSeekable() const; - virtual qint64 currentTime() const; - virtual Phonon::State state() const; - virtual QString errorString() const; - virtual Phonon::ErrorType errorType() const; - virtual qint64 totalTime() const; - virtual MediaSource source() const; - virtual void setSource(const MediaSource &); - virtual void setNextSource(const MediaSource &source); - virtual qint32 prefinishMark() const; - virtual void setPrefinishMark(qint32); - virtual qint32 transitionTime() const; - virtual void setTransitionTime(qint32); - -#ifdef QT_PHONON_MMF_AUDIO_DRM - // MDrmVideoPlayerCallback - virtual void MdapcInitComplete(TInt aError, - const TTimeIntervalMicroSeconds &aDuration); - virtual void MdapcPlayComplete(TInt aError); - - // MAudioLoadingObserver - virtual void MaloLoadingStarted(); - virtual void MaloLoadingComplete(); -#else - // MMdaVideoPlayerCallback - virtual void MapcInitComplete(TInt aError, - const TTimeIntervalMicroSeconds &aDuration); - virtual void MapcPlayComplete(TInt aError); -#endif - - qreal volume() const; - bool setVolume(qreal volume); - - void setAudioOutput(AudioOutput* audioOutput); - - Q_SIGNALS: - void totalTimeChanged(); - void stateChanged(Phonon::State oldState, - Phonon::State newState); - void finished(); - void tick(qint64 time); - - private Q_SLOTS: - /** - * Receives signal from m_tickTimer - */ - void tick(); - - private: - static qint64 toMilliSeconds(const TTimeIntervalMicroSeconds &); - - /** - * Defined private state enumeration in order to add GroundState - */ - enum PrivateState - { - LoadingState = Phonon::LoadingState, - StoppedState = Phonon::StoppedState, - PlayingState = Phonon::PlayingState, - BufferingState = Phonon::BufferingState, - PausedState = Phonon::PausedState, - ErrorState = Phonon::ErrorState, - GroundState - }; - - /** - * Converts PrivateState into the corresponding Phonon::State - */ - static Phonon::State phononState(PrivateState state); - - /** - * Changes state and emits stateChanged() - */ - void changeState(PrivateState newState); - - /** - * Using CPlayerType typedef in order to be able to easily switch between - * CMdaVideoPlayerUtility and CDrmPlayerUtility - */ - // CPlayerType* m_player; TODO - - AudioOutput* m_audioOutput; - - ErrorType m_error; - - /** - * Do not set this directly - call changeState() instead. - */ - PrivateState m_state; - - qint32 m_tickInterval; - - QTimer* m_tickTimer; - - MediaSource m_mediaSource; - MediaSource m_nextSource; - - qreal m_volume; - int m_maxVolume; - }; - } -} - -#endif diff --git a/src/3rdparty/phonon/mmf/videoplayer.cpp b/src/3rdparty/phonon/mmf/videoplayer.cpp new file mode 100644 index 0000000..f465c96 --- /dev/null +++ b/src/3rdparty/phonon/mmf/videoplayer.cpp @@ -0,0 +1,577 @@ +/* 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 . + +*/ + +#include +#include +#include + +#include "videoplayer.h" +#include "audiooutput.h" +#include "utils.h" + +using namespace Phonon; +using namespace Phonon::MMF; + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const qint32 DefaultTickInterval = 20; +const int NullMaxVolume = -1; + + +//----------------------------------------------------------------------------- +// Constructor / destructor +//----------------------------------------------------------------------------- + +MMF::VideoPlayer::VideoPlayer() : m_audioOutput(NULL) + , m_error(NoError) + , m_state(GroundState) + , m_tickInterval(DefaultTickInterval) + , m_tickTimer(NULL) + , m_volume(0.0) + , m_maxVolume(NullMaxVolume) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::VideoPlayer, EAudioApi); + TRACE_ENTRY_0(); + + Q_UNUSED(parent); + + // TODO: should leaves be trapped in the constructor? + m_player = CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone); + + m_tickTimer = new QTimer(this); + connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); + + TRACE_EXIT_0(); +#endif +} + +MMF::VideoPlayer::~VideoPlayer() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::~VideoPlayer, EAudioApi); + TRACE_ENTRY_0(); + + delete m_tickTimer; + delete m_player; + + TRACE_EXIT_0(); +#endif +} + +//----------------------------------------------------------------------------- +// VideoPlayerInterface +//----------------------------------------------------------------------------- + +void MMF::VideoPlayer::play() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::play, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + // Is this the correct error? Really we want 'NotReadyError' + m_error = NormalError; + changeState(ErrorState); + break; + + case StoppedState: + case PausedState: + m_player->Play(); + m_tickTimer->start(m_tickInterval); + changeState(PlayingState); + break; + + case PlayingState: + case BufferingState: + case ErrorState: + // Do nothing + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +#endif +} + +void MMF::VideoPlayer::pause() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::pause, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + case StoppedState: + case PausedState: + case ErrorState: + // Do nothing + break; + + case PlayingState: + case BufferingState: + m_player->Pause(); + m_tickTimer->stop(); + changeState(PausedState); + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +#endif +} + +void MMF::VideoPlayer::stop() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::stop, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + switch(m_state) + { + case GroundState: + case LoadingState: + case StoppedState: + case ErrorState: + // Do nothing + break; + + case PlayingState: + case BufferingState: + case PausedState: + m_player->Stop(); + m_tickTimer->stop(); + changeState(StoppedState); + break; + + // Protection against adding new states and forgetting to update this switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_EXIT("state %d", m_state); +#endif +} + +void MMF::VideoPlayer::seek(qint64 ms) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::seek, EAudioApi); + TRACE_ENTRY("state %d pos %Ld", m_state, ms); + + m_player->SetPosition(TTimeIntervalMicroSeconds(ms)); + + TRACE_EXIT_0(); +#endif +} + +qint32 MMF::VideoPlayer::tickInterval() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::tickInterval, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_RETURN("%d", m_tickInterval); +#endif +} + +void MMF::VideoPlayer::setTickInterval(qint32 interval) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setTickInterval, EAudioApi); + TRACE_ENTRY("state %d m_interval %d interval %d", m_state, m_tickInterval, interval); + + m_tickInterval = interval; + m_tickTimer->setInterval(interval); + + TRACE_EXIT_0(); +#endif +} + +bool MMF::VideoPlayer::hasVideo() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::hasVideo, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: re-factor this class so that audio playback and video playback are + // delegated to separate classes, which internally hoat a + // CMdaVideoPlayerUtility / CVideoPlayerUtility instance as appropriate. + + TRACE_RETURN("%d", false); +#endif +} + +bool MMF::VideoPlayer::isSeekable() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::isSeekable, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_RETURN("%d", true); +#endif +} + +Phonon::State MMF::VideoPlayer::state() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::state, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const Phonon::State result = phononState(m_state); + + TRACE_RETURN("%d", result); +#endif +} + +qint64 MMF::VideoPlayer::currentTime() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::currentTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TTimeIntervalMicroSeconds us; + const TInt err = m_player->GetPosition(us); + + qint64 result = -1; + + if(KErrNone == err) { + result = toMilliSeconds(us); + } + + TRACE_RETURN("%Ld", result); +#endif +} + +QString MMF::VideoPlayer::errorString() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::errorString, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_EXIT_0(); + // TODO: put in proper error strings + QString result; + return result; +#endif +} + +Phonon::ErrorType MMF::VideoPlayer::errorType() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::errorType, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const Phonon::ErrorType result = (ErrorState == m_state) + ? m_error : NoError; + + TRACE_RETURN("%d", result); +#endif +} + +qint64 MMF::VideoPlayer::totalTime() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::totalTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + const qint64 result = toMilliSeconds(m_player->Duration()); + + TRACE_RETURN("%Ld", result); +#endif +} + +MediaSource MMF::VideoPlayer::source() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::source, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + TRACE_EXIT_0(); + return m_mediaSource; +#endif +} + +void MMF::VideoPlayer::setSource(const MediaSource &source) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setSource, EAudioApi); + TRACE_ENTRY("state %d source.type %d", m_state, source.type()); + + m_player->Close(); + changeState(GroundState); + + // TODO: is it correct to assign even if the media type is not supported in + // the switch statement below? + m_mediaSource = source; + + TInt symbianErr = KErrNone; + + switch(m_mediaSource.type()) + { + case MediaSource::LocalFile: + { + // TODO: work out whose responsibility it is to ensure that paths + // are Symbian-style, i.e. have backslashes for path delimiters. + // Until then, use this utility function... + const QHBufC filename = Utils::symbianFilename(m_mediaSource.fileName()); + TRAP(symbianErr, m_player->OpenFileL(*filename)); + break; + } + + case MediaSource::Url: + { + const QHBufC filename(m_mediaSource.url().toString()); + TRAP(symbianErr, m_player->OpenUrlL(*filename)); + break; + } + + case MediaSource::Invalid: + case MediaSource::Disc: + case MediaSource::Stream: + symbianErr = KErrNotSupported; + break; + + case MediaSource::Empty: + TRACE_EXIT_0(); + return; + + // Protection against adding new media types and forgetting to update this switch + default: + TRACE_PANIC(InvalidMediaTypePanic); + } + + if(KErrNone == symbianErr) + { +#ifdef QT_PHONON_MMF_AUDIO_DRM + // There appears to be a bug in the CDrmPlayerUtility implementation (at least + // in S60 5.x) whereby the player does not check whether the loading observer + // pointer is null before dereferencing it. Therefore we must register for + // loading notification, even though we do nothing in the callback functions. + m_player->RegisterForAudioLoadingNotification(*this); +#endif + changeState(LoadingState); + } + else + { + // TODO: do something with the value of symbianErr? + m_error = NormalError; + changeState(ErrorState); + } + + TRACE_EXIT_0(); +#endif +} + +void MMF::VideoPlayer::setNextSource(const MediaSource &source) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setNextSource, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: handle 'next source' + + m_nextSource = source; + Q_UNUSED(source); + + TRACE_EXIT_0(); +#endif +} + +qint32 MMF::VideoPlayer::prefinishMark() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::prefinishMark, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: implement prefinish mark + const qint32 result = 0; + TRACE_RETURN("%d", result); +#endif +} + +void MMF::VideoPlayer::setPrefinishMark(qint32 mark) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setPrefinishMark, EAudioApi); + TRACE_ENTRY("state %d mark %d", m_state, mark); + Q_UNUSED(mark); // to silence warnings in release builds + + // TODO: implement prefinish mark + + TRACE_EXIT_0(); +#endif +} + +qint32 MMF::VideoPlayer::transitionTime() const +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::transitionTime, EAudioApi); + TRACE_ENTRY("state %d", m_state); + + // TODO: implement transition time + const qint32 result = 0; + TRACE_RETURN("%d", result); +#endif +} + +void MMF::VideoPlayer::setTransitionTime(qint32 time) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setTransitionTime, EAudioApi); + TRACE_ENTRY("state %d time %d", m_state, time); + Q_UNUSED(time); // to silence warnings in release builds + + // TODO: implement transition time + + TRACE_EXIT_0(); +#endif +} + + +//----------------------------------------------------------------------------- +// Volume +//----------------------------------------------------------------------------- + +qreal MMF::VideoPlayer::volume() const +{ + //return m_volume; +} + +bool MMF::VideoPlayer::setVolume(qreal volume) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::setVolume, EAudioInternal); + TRACE_ENTRY("state %d", m_state); + + bool volumeChanged = false; + + switch(m_state) + { + case GroundState: + case LoadingState: + case ErrorState: + // Do nothing + break; + + case StoppedState: + case PausedState: + case PlayingState: + case BufferingState: + { + if(volume != m_volume) + { + const int err = m_player->SetVolume(volume * m_maxVolume); + if(KErrNone == err) + { + m_volume = volume; + volumeChanged = true; + } + else + { + m_error = NormalError; + changeState(ErrorState); + } + } + break; + } + + // Protection against adding new states and forgetting to update this + // switch + default: + TRACE_PANIC(InvalidStatePanic); + } + + TRACE_RETURN("%d", volumeChanged); +#endif +} + +void MMF::VideoPlayer::setAudioOutput(AudioOutput* audioOutput) +{ + //m_audioOutput = audioOutput; +} + + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +qint64 MMF::VideoPlayer::toMilliSeconds(const TTimeIntervalMicroSeconds &in) +{ + //return in.Int64() / 1000; +} + +Phonon::State MMF::VideoPlayer::phononState(PrivateState state) +{ +#if 0 + const Phonon::State phononState = + GroundState == state + ? Phonon::StoppedState + : static_cast(state); + + return phononState; +#endif +} + +void MMF::VideoPlayer::changeState(PrivateState newState) +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::changeState, EAudioInternal); + TRACE_ENTRY("state %d newState %d", m_state, newState); + + // TODO: add some invariants to check that the transition is valid + + const Phonon::State currentPhononState = phononState(m_state); + const Phonon::State newPhononState = phononState(newState); + if(currentPhononState != newPhononState) + { + TRACE("emit stateChanged(%d, %d)", newPhononState, currentPhononState); + emit stateChanged(newPhononState, currentPhononState); + } + + m_state = newState; + + TRACE_EXIT_0(); +#endif +} + +void MMF::VideoPlayer::tick() +{ +#if 0 + TRACE_CONTEXT(VideoPlayer::tick, EAudioInternal); + TRACE_ENTRY("state %d", m_state); + + emit tick(currentTime()); + + TRACE_EXIT_0(); +#endif +} + diff --git a/src/3rdparty/phonon/mmf/videoplayer.h b/src/3rdparty/phonon/mmf/videoplayer.h new file mode 100644 index 0000000..3ea9c1a --- /dev/null +++ b/src/3rdparty/phonon/mmf/videoplayer.h @@ -0,0 +1,163 @@ +/* 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 . + +*/ + +#ifndef PHONON_MMF_VIDEOPLAYER_H +#define PHONON_MMF_VIDEOPLAYER_H + +/* We use the extra qualification include/ to avoid picking up the include + * Phonon has. */ +#include +#include "abstractplayer.h" + +#include + +class CDrmPlayerUtility; +class TTimeIntervalMicroSeconds; +class QTimer; + +namespace Phonon +{ + namespace MMF + { + class AudioOutput; + + /** + * + * See + * How to + * play a video file using CVideoPlayerUtility + */ + class VideoPlayer : public AbstractPlayer + { + Q_OBJECT + public: + VideoPlayer(); + virtual ~VideoPlayer(); + + // AbstractPlayer + virtual void play(); + virtual void pause(); + virtual void stop(); + virtual void seek(qint64 milliseconds); + virtual qint32 tickInterval() const; + virtual void setTickInterval(qint32 interval); + virtual bool hasVideo() const; + virtual bool isSeekable() const; + virtual qint64 currentTime() const; + virtual Phonon::State state() const; + virtual QString errorString() const; + virtual Phonon::ErrorType errorType() const; + virtual qint64 totalTime() const; + virtual MediaSource source() const; + virtual void setSource(const MediaSource &); + virtual void setNextSource(const MediaSource &source); + virtual qint32 prefinishMark() const; + virtual void setPrefinishMark(qint32); + virtual qint32 transitionTime() const; + virtual void setTransitionTime(qint32); + +#ifdef QT_PHONON_MMF_AUDIO_DRM + // MDrmVideoPlayerCallback + virtual void MdapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &aDuration); + virtual void MdapcPlayComplete(TInt aError); + + // MAudioLoadingObserver + virtual void MaloLoadingStarted(); + virtual void MaloLoadingComplete(); +#else + // MMdaVideoPlayerCallback + virtual void MapcInitComplete(TInt aError, + const TTimeIntervalMicroSeconds &aDuration); + virtual void MapcPlayComplete(TInt aError); +#endif + + qreal volume() const; + bool setVolume(qreal volume); + + void setAudioOutput(AudioOutput* audioOutput); + + Q_SIGNALS: + void totalTimeChanged(); + void stateChanged(Phonon::State oldState, + Phonon::State newState); + void finished(); + void tick(qint64 time); + + private Q_SLOTS: + /** + * Receives signal from m_tickTimer + */ + void tick(); + + private: + static qint64 toMilliSeconds(const TTimeIntervalMicroSeconds &); + + /** + * Defined private state enumeration in order to add GroundState + */ + enum PrivateState + { + LoadingState = Phonon::LoadingState, + StoppedState = Phonon::StoppedState, + PlayingState = Phonon::PlayingState, + BufferingState = Phonon::BufferingState, + PausedState = Phonon::PausedState, + ErrorState = Phonon::ErrorState, + GroundState + }; + + /** + * Converts PrivateState into the corresponding Phonon::State + */ + static Phonon::State phononState(PrivateState state); + + /** + * Changes state and emits stateChanged() + */ + void changeState(PrivateState newState); + + /** + * Using CPlayerType typedef in order to be able to easily switch between + * CMdaVideoPlayerUtility and CDrmPlayerUtility + */ + // CPlayerType* m_player; TODO + + AudioOutput* m_audioOutput; + + ErrorType m_error; + + /** + * Do not set this directly - call changeState() instead. + */ + PrivateState m_state; + + qint32 m_tickInterval; + + QTimer* m_tickTimer; + + MediaSource m_mediaSource; + MediaSource m_nextSource; + + qreal m_volume; + int m_maxVolume; + }; + } +} + +#endif diff --git a/src/plugins/phonon/mmf/mmf.pro b/src/plugins/phonon/mmf/mmf.pro index 266c3db..5ac62ad 100644 --- a/src/plugins/phonon/mmf/mmf.pro +++ b/src/plugins/phonon/mmf/mmf.pro @@ -28,7 +28,7 @@ HEADERS += \ $$PHONON_MMF_DIR/backend.h \ $$PHONON_MMF_DIR/mediaobject.h \ $$PHONON_MMF_DIR/utils.h \ - $$PHONON_MMF_DIR/mmf_videoplayer.h + $$PHONON_MMF_DIR/videoplayer.h SOURCES += \ $$PHONON_MMF_DIR/audiooutput.cpp \ @@ -36,7 +36,7 @@ SOURCES += \ $$PHONON_MMF_DIR/backend.cpp \ $$PHONON_MMF_DIR/mediaobject.cpp \ $$PHONON_MMF_DIR/utils.cpp \ - $$PHONON_MMF_DIR/mmf_videoplayer.cpp + $$PHONON_MMF_DIR/videoplayer.cpp # This is needed for having the .qtplugin file properly created on Symbian. QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/phonon_backend -- cgit v0.12