diff options
Diffstat (limited to 'src/3rdparty/phonon/mmf/mediaobject.cpp')
-rw-r--r-- | src/3rdparty/phonon/mmf/mediaobject.cpp | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/src/3rdparty/phonon/mmf/mediaobject.cpp b/src/3rdparty/phonon/mmf/mediaobject.cpp index d264377..98326b8 100644 --- a/src/3rdparty/phonon/mmf/mediaobject.cpp +++ b/src/3rdparty/phonon/mmf/mediaobject.cpp @@ -34,6 +34,7 @@ along with this library. If not, see <http://www.gnu.org/licenses/>. #include "mediaobject.h" #include <QDir> +#include <QResource> #include <QUrl> QT_BEGIN_NAMESPACE @@ -52,6 +53,8 @@ using namespace Phonon::MMF; MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent) , m_recognizerOpened(false) , m_nextSourceSet(false) + , m_file(0) + , m_resource(0) { m_player.reset(new DummyPlayer()); @@ -68,7 +71,12 @@ MMF::MediaObject::~MediaObject() TRACE_CONTEXT(MediaObject::~MediaObject, EAudioApi); TRACE_ENTRY_0(); - m_file.Close(); + delete m_resource; + + if (m_file) + m_file->Close(); + delete m_file; + m_fileServer.Close(); m_recognizer.Close(); @@ -122,12 +130,13 @@ MMF::MediaType MMF::MediaObject::fileMediaType const QHBufC fileNameSymbian(QDir::toNativeSeparators(fileName)); - m_file.Close(); - TInt err = m_file.Open(m_fileServer, *fileNameSymbian, EFileRead | EFileShareReadersOnly); + Q_ASSERT(!m_file); + m_file = new RFile; + TInt err = m_file->Open(m_fileServer, *fileNameSymbian, EFileRead | EFileShareReadersOnly); if (KErrNone == err) { TDataRecognitionResult recognizerResult; - err = m_recognizer.RecognizeData(m_file, recognizerResult); + err = m_recognizer.RecognizeData(*m_file, recognizerResult); if (KErrNone == err) { const TPtrC mimeType = recognizerResult.iDataType.Des(); result = Utils::mimeTypeToMediaType(mimeType); @@ -142,6 +151,23 @@ MMF::MediaType MMF::MediaObject::fileMediaType return result; } +MMF::MediaType MMF::MediaObject::bufferMediaType(const uchar *data, qint64 size) +{ + TRACE_CONTEXT(MediaObject::bufferMediaType, EAudioInternal); + MediaType result = MediaTypeUnknown; + if (openRecognizer()) { + TDataRecognitionResult recognizerResult; + const TPtrC8 des(data, size); + const TInt err = m_recognizer.RecognizeData(KNullDesC, des, recognizerResult); + if (KErrNone == err) { + const TPtrC mimeType = recognizerResult.iDataType.Des(); + result = Utils::mimeTypeToMediaType(mimeType); + } else { + TRACE("RApaLsSession::RecognizeData error %d", err); + } + } + return result; +} //----------------------------------------------------------------------------- // MediaObjectInterface @@ -228,9 +254,17 @@ void MMF::MediaObject::setSource(const MediaSource &source) void MMF::MediaObject::switchToSource(const MediaSource &source) { + if (m_file) + m_file->Close(); + delete m_file; + m_file = 0; + + delete m_resource; + m_resource = 0; + createPlayer(source); m_source = source; - m_player->open(m_source, m_file); + m_player->open(); emit currentSourceChanged(m_source); } @@ -272,10 +306,29 @@ void MMF::MediaObject::createPlayer(const MediaSource &source) case MediaSource::Invalid: case MediaSource::Disc: - case MediaSource::Stream: errorMessage = tr("Error opening source: type not supported"); break; + case MediaSource::Stream: + { + const QString fileName = source.url().toLocalFile(); + if (fileName.startsWith(QLatin1String(":/")) || fileName.startsWith(QLatin1String("qrc://"))) { + Q_ASSERT(!m_resource); + m_resource = new QResource(fileName); + if (m_resource->isValid()) { + if (m_resource->isCompressed()) + errorMessage = tr("Error opening source: resource is compressed"); + else + mediaType = bufferMediaType(m_resource->data(), m_resource->size()); + } else { + errorMessage = tr("Error opening source: resource not valid"); + } + } else { + errorMessage = tr("Error opening source: type not supported"); + } + } + break; + case MediaSource::Empty: TRACE_0("Empty media source"); break; @@ -374,6 +427,16 @@ void MMF::MediaObject::volumeChanged(qreal volume) m_player->volumeChanged(volume); } +RFile* MMF::MediaObject::file() const +{ + return m_file; +} + +QResource* MMF::MediaObject::resource() const +{ + return m_resource; +} + //----------------------------------------------------------------------------- // MediaNode //----------------------------------------------------------------------------- |