diff options
Diffstat (limited to 'src/3rdparty/phonon/mmf/mediaobject.cpp')
-rw-r--r-- | src/3rdparty/phonon/mmf/mediaobject.cpp | 316 |
1 files changed, 281 insertions, 35 deletions
diff --git a/src/3rdparty/phonon/mmf/mediaobject.cpp b/src/3rdparty/phonon/mmf/mediaobject.cpp index 877e463..62dc903 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.cpp +++ b/src/3rdparty/phonon/mmf/mediaobject.cpp @@ -16,10 +16,11 @@ along with this library. If not, see <http://www.gnu.org/licenses/>. */ -#include "abstractplayer.h" #include "audioplayer.h" -#include "videoplayer.h" #include "mediaobject.h" +#include "utils.h" +#include "videoplayer.h" + using namespace Phonon; using namespace Phonon::MMF; @@ -30,129 +31,361 @@ using namespace Phonon::MMF; MMF::MediaObject::MediaObject(QObject *parent) : QObject::QObject(parent) { + TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi); + TRACE_ENTRY_0(); + + Q_UNUSED(parent); + + TInt err = m_recognizer.Connect(); + err = m_fileServer.Connect(); + // TODO: handle this error + + // This must be called in order to be able to share file handles with + // the recognizer server (see fileMediaType function). + err = m_fileServer.ShareProtected(); + // TODO: handle this error + + 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; + + m_file.Close(); + m_fileServer.Close(); + m_recognizer.Close(); + + TRACE_EXIT_0(); +} + + +//----------------------------------------------------------------------------- +// Recognizer +//----------------------------------------------------------------------------- + +const TInt KMimePrefixLength = 6; // either "audio/" or "video/" +_LIT(KMimePrefixAudio, "audio/"); +_LIT(KMimePrefixVideo, "video/"); + +MMF::MediaObject::MediaType MMF::MediaObject::mimeTypeToMediaType(const TDesC& mimeType) +{ + MediaType result = MediaTypeUnknown; + + if(mimeType.Left(KMimePrefixLength).Compare(KMimePrefixAudio) == 0) + { + result = MediaTypeAudio; + } + else if(mimeType.Left(KMimePrefixLength).Compare(KMimePrefixVideo) == 0) + { + result = MediaTypeVideo; + } + + return result; } + +MMF::MediaObject::MediaType MMF::MediaObject::fileMediaType + (const QString& fileName) +{ + MediaType result = MediaTypeUnknown; + + QHBufC fileNameSymbian = Utils::symbianFilename(fileName); + + m_file.Close(); + TInt err = m_file.Open(m_fileServer, *fileNameSymbian, EFileRead|EFileShareReadersOnly); + + if(KErrNone == err) + { + TDataRecognitionResult recognizerResult; + err = m_recognizer.RecognizeData(m_file, recognizerResult); + if(KErrNone == err) + { + const TPtrC mimeType = recognizerResult.iDataType.Des(); + result = mimeTypeToMediaType(mimeType); + } + } + return result; +} + + //----------------------------------------------------------------------------- // MediaObjectInterface //----------------------------------------------------------------------------- void MMF::MediaObject::play() { - m_player->play(); + if(!m_player.isNull()) + { + m_player->play(); + } } void MMF::MediaObject::pause() { - m_player->pause(); + if(!m_player.isNull()) + { + m_player->pause(); + } } void MMF::MediaObject::stop() { - m_player->stop(); + if(!m_player.isNull()) + { + m_player->stop(); + } } void MMF::MediaObject::seek(qint64 ms) { - m_player->seek(ms); + if(!m_player.isNull()) + { + m_player->seek(ms); + } } qint32 MMF::MediaObject::tickInterval() const { - return m_player->tickInterval(); + qint32 result = 0; + if(!m_player.isNull()) + { + result = m_player->tickInterval(); + } + return result; } void MMF::MediaObject::setTickInterval(qint32 interval) { - m_player->setTickInterval(interval); + if(!m_player.isNull()) + { + m_player->setTickInterval(interval); + } } bool MMF::MediaObject::hasVideo() const { - return m_player->hasVideo(); + bool result = false; + if(!m_player.isNull()) + { + result = m_player->hasVideo(); + } + return result; } bool MMF::MediaObject::isSeekable() const { - return m_player->isSeekable(); + bool result = false; + if(!m_player.isNull()) + { + result = m_player->isSeekable(); + } + return result; } Phonon::State MMF::MediaObject::state() const { - return m_player->state(); + Phonon::State result = Phonon::StoppedState; + if(!m_player.isNull()) + { + result = m_player->state(); + } + return result; } qint64 MMF::MediaObject::currentTime() const { - return m_player->currentTime(); + qint64 result = 0; + if(!m_player.isNull()) + { + result = m_player->currentTime(); + } + return result; } QString MMF::MediaObject::errorString() const { - return m_player->errorString(); + QString result; + if(!m_player.isNull()) + { + result = m_player->errorString(); + } + return result; } Phonon::ErrorType MMF::MediaObject::errorType() const { - return m_player->errorType(); + Phonon::ErrorType result = Phonon::NoError; + if(!m_player.isNull()) + { + result = m_player->errorType(); + } + return result; } qint64 MMF::MediaObject::totalTime() const { - return m_player->totalTime(); + qint64 result = 0; + if(!m_player.isNull()) + { + result = m_player->totalTime(); + } + return result; } MediaSource MMF::MediaObject::source() const { - return m_player->source(); + MediaSource result; + if(!m_player.isNull()) + { + result = m_player->source(); + } + return result; } void MMF::MediaObject::setSource(const MediaSource &source) { loadPlayer(source); - - return m_player->setSource(source); + if(!m_player.isNull()) + { + //m_player->setSource(source); + + // This is a hack to work around KErrInUse from MMF client utility + // OpenFileL calls + m_player->setFileSource(source, m_file); + } } 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))); + TRACE_CONTEXT(AudioPlayer::loadPlayer, EAudioApi); + //TRACE_ENTRY("state %d source.type %d", m_state, source.type()); + // TODO: log state + TRACE_ENTRY("source.type %d", source.type()); + + // Destroy old player object + if(!m_player.isNull()) + { + disconnect(m_player.data(), 0, this, 0); + m_player.reset(NULL); + } + + MediaType mediaType = MediaTypeUnknown; + + // Determine media type + switch(source.type()) + { + case MediaSource::LocalFile: + mediaType = fileMediaType(source.fileName()); + break; + + case MediaSource::Url: + // TODO: support detection of media type from HTTP streams + TRACE_0("Network streaming not supported yet"); + + /* + * TODO: handle error + * + m_error = NormalError; + changeState(ErrorState); + break; + */ + + case MediaSource::Invalid: + case MediaSource::Disc: + case MediaSource::Stream: + TRACE_0("Unsupported media type"); + /* + * TODO: handle error + * + m_error = NormalError; + changeState(ErrorState); + */ + break; + + case MediaSource::Empty: + TRACE_EXIT_0(); + return; + } + + switch(mediaType) + { + case MediaTypeUnknown: + TRACE_0("Media type could not be determined"); + /* + * TODO: handle error + * + m_error = NormalError; + changeState(ErrorState); + */ + break; + + case MediaTypeAudio: + m_player.reset(new AudioPlayer()); + break; + + case MediaTypeVideo: + m_player.reset(new VideoPlayer()); + break; + } + + if(!m_player.isNull()) + { + 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); + if(!m_player.isNull()) + { + m_player->setNextSource(source); + } } qint32 MMF::MediaObject::prefinishMark() const { - return m_player->prefinishMark(); + qint32 result = 0; + if(!m_player.isNull()) + { + result = m_player->prefinishMark(); + } + return result; } void MMF::MediaObject::setPrefinishMark(qint32 mark) { - m_player->setPrefinishMark(mark); + if(!m_player.isNull()) + { + m_player->setPrefinishMark(mark); + } } qint32 MMF::MediaObject::transitionTime() const { - return m_player->transitionTime(); + qint32 result = 0; + if(!m_player.isNull()) + { + result = m_player->transitionTime(); + } + return result; } void MMF::MediaObject::setTransitionTime(qint32 time) { - m_player->setTransitionTime(time); + if(!m_player.isNull()) + { + m_player->setTransitionTime(time); + } } //----------------------------------------------------------------------------- @@ -161,16 +394,29 @@ void MMF::MediaObject::setTransitionTime(qint32 time) qreal MMF::MediaObject::volume() const { - return m_player->volume(); + qreal result = 0.0; + if(!m_player.isNull()) + { + m_player->volume(); + } + return result; } bool MMF::MediaObject::setVolume(qreal volume) { - return m_player->setVolume(volume); + bool result = false; + if(!m_player.isNull()) + { + result = m_player->setVolume(volume); + } + return result; } void MMF::MediaObject::setAudioOutput(AudioOutput* audioOutput) { - m_player->setAudioOutput(audioOutput); + if(!m_player.isNull()) + { + m_player->setAudioOutput(audioOutput); + } } |