src/3rdparty/phonon/mmf/mediaobject.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    32 #include "videowidget.h"
    32 #include "videowidget.h"
    33 
    33 
    34 #include "mediaobject.h"
    34 #include "mediaobject.h"
    35 
    35 
    36 #include <QDir>
    36 #include <QDir>
       
    37 #include <QResource>
    37 #include <QUrl>
    38 #include <QUrl>
    38 
    39 
    39 QT_BEGIN_NAMESPACE
    40 QT_BEGIN_NAMESPACE
    40 
    41 
    41 using namespace Phonon;
    42 using namespace Phonon;
    50 //-----------------------------------------------------------------------------
    51 //-----------------------------------------------------------------------------
    51 
    52 
    52 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent)
    53 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent)
    53                                                , m_recognizerOpened(false)
    54                                                , m_recognizerOpened(false)
    54                                                , m_nextSourceSet(false)
    55                                                , m_nextSourceSet(false)
       
    56                                                , m_file(0)
       
    57                                                , m_resource(0)
    55 {
    58 {
    56     m_player.reset(new DummyPlayer());
    59     m_player.reset(new DummyPlayer());
    57 
    60 
    58     TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi);
    61     TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi);
    59     TRACE_ENTRY_0();
    62     TRACE_ENTRY_0();
    66 MMF::MediaObject::~MediaObject()
    69 MMF::MediaObject::~MediaObject()
    67 {
    70 {
    68     TRACE_CONTEXT(MediaObject::~MediaObject, EAudioApi);
    71     TRACE_CONTEXT(MediaObject::~MediaObject, EAudioApi);
    69     TRACE_ENTRY_0();
    72     TRACE_ENTRY_0();
    70 
    73 
    71     m_file.Close();
    74     delete m_resource;
       
    75 
       
    76     if (m_file)
       
    77         m_file->Close();
       
    78     delete m_file;
       
    79 
    72     m_fileServer.Close();
    80     m_fileServer.Close();
    73     m_recognizer.Close();
    81     m_recognizer.Close();
    74 
    82 
    75     TRACE_EXIT_0();
    83     TRACE_EXIT_0();
    76 }
    84 }
   120 
   128 
   121     if (openRecognizer()) {
   129     if (openRecognizer()) {
   122 
   130 
   123         const QHBufC fileNameSymbian(QDir::toNativeSeparators(fileName));
   131         const QHBufC fileNameSymbian(QDir::toNativeSeparators(fileName));
   124 
   132 
   125         m_file.Close();
   133         Q_ASSERT(!m_file);
   126         TInt err = m_file.Open(m_fileServer, *fileNameSymbian, EFileRead | EFileShareReadersOnly);
   134         m_file = new RFile;
       
   135         TInt err = m_file->Open(m_fileServer, *fileNameSymbian, EFileRead | EFileShareReadersOnly);
   127 
   136 
   128         if (KErrNone == err) {
   137         if (KErrNone == err) {
   129             TDataRecognitionResult recognizerResult;
   138             TDataRecognitionResult recognizerResult;
   130             err = m_recognizer.RecognizeData(m_file, recognizerResult);
   139             err = m_recognizer.RecognizeData(*m_file, recognizerResult);
   131             if (KErrNone == err) {
   140             if (KErrNone == err) {
   132                 const TPtrC mimeType = recognizerResult.iDataType.Des();
   141                 const TPtrC mimeType = recognizerResult.iDataType.Des();
   133                 result = Utils::mimeTypeToMediaType(mimeType);
   142                 result = Utils::mimeTypeToMediaType(mimeType);
   134             } else {
   143             } else {
   135                 TRACE("RApaLsSession::RecognizeData filename %S error %d", fileNameSymbian.data(), err);
   144                 TRACE("RApaLsSession::RecognizeData filename %S error %d", fileNameSymbian.data(), err);
   140     }
   149     }
   141 
   150 
   142     return result;
   151     return result;
   143 }
   152 }
   144 
   153 
       
   154 MMF::MediaType MMF::MediaObject::bufferMediaType(const uchar *data, qint64 size)
       
   155 {
       
   156     TRACE_CONTEXT(MediaObject::bufferMediaType, EAudioInternal);
       
   157     MediaType result = MediaTypeUnknown;
       
   158     if (openRecognizer()) {
       
   159         TDataRecognitionResult recognizerResult;
       
   160         const TPtrC8 des(data, size);
       
   161         const TInt err = m_recognizer.RecognizeData(KNullDesC, des, recognizerResult);
       
   162         if (KErrNone == err) {
       
   163             const TPtrC mimeType = recognizerResult.iDataType.Des();
       
   164             result = Utils::mimeTypeToMediaType(mimeType);
       
   165         } else {
       
   166             TRACE("RApaLsSession::RecognizeData error %d", err);
       
   167         }
       
   168     }
       
   169     return result;
       
   170 }
   145 
   171 
   146 //-----------------------------------------------------------------------------
   172 //-----------------------------------------------------------------------------
   147 // MediaObjectInterface
   173 // MediaObjectInterface
   148 //-----------------------------------------------------------------------------
   174 //-----------------------------------------------------------------------------
   149 
   175 
   226     switchToSource(source);
   252     switchToSource(source);
   227 }
   253 }
   228 
   254 
   229 void MMF::MediaObject::switchToSource(const MediaSource &source)
   255 void MMF::MediaObject::switchToSource(const MediaSource &source)
   230 {
   256 {
       
   257     if (m_file)
       
   258         m_file->Close();
       
   259     delete m_file;
       
   260     m_file = 0;
       
   261 
       
   262     delete m_resource;
       
   263     m_resource = 0;
       
   264 
   231     createPlayer(source);
   265     createPlayer(source);
   232     m_source = source;
   266     m_source = source;
   233     m_player->open(m_source, m_file);
   267     m_player->open();
   234     emit currentSourceChanged(m_source);
   268     emit currentSourceChanged(m_source);
   235 }
   269 }
   236 
   270 
   237 void MMF::MediaObject::createPlayer(const MediaSource &source)
   271 void MMF::MediaObject::createPlayer(const MediaSource &source)
   238 {
   272 {
   270         }
   304         }
   271         break;
   305         break;
   272 
   306 
   273     case MediaSource::Invalid:
   307     case MediaSource::Invalid:
   274     case MediaSource::Disc:
   308     case MediaSource::Disc:
       
   309         errorMessage = tr("Error opening source: type not supported");
       
   310         break;
       
   311 
   275     case MediaSource::Stream:
   312     case MediaSource::Stream:
   276         errorMessage = tr("Error opening source: type not supported");
   313         {
       
   314             const QString fileName = source.url().toLocalFile();
       
   315             if (fileName.startsWith(QLatin1String(":/")) || fileName.startsWith(QLatin1String("qrc://"))) {
       
   316                 Q_ASSERT(!m_resource);
       
   317                 m_resource = new QResource(fileName);
       
   318                 if (m_resource->isValid()) {
       
   319                     if (m_resource->isCompressed())
       
   320                         errorMessage = tr("Error opening source: resource is compressed");
       
   321                     else
       
   322 		        mediaType = bufferMediaType(m_resource->data(), m_resource->size());
       
   323 		} else {
       
   324                     errorMessage = tr("Error opening source: resource not valid");
       
   325                 }
       
   326             } else {
       
   327                 errorMessage = tr("Error opening source: type not supported");
       
   328             }
       
   329         }
   277         break;
   330         break;
   278 
   331 
   279     case MediaSource::Empty:
   332     case MediaSource::Empty:
   280         TRACE_0("Empty media source");
   333         TRACE_0("Empty media source");
   281         break;
   334         break;
   372 void MMF::MediaObject::volumeChanged(qreal volume)
   425 void MMF::MediaObject::volumeChanged(qreal volume)
   373 {
   426 {
   374     m_player->volumeChanged(volume);
   427     m_player->volumeChanged(volume);
   375 }
   428 }
   376 
   429 
       
   430 RFile* MMF::MediaObject::file() const
       
   431 {
       
   432     return m_file;
       
   433 }
       
   434 
       
   435 QResource* MMF::MediaObject::resource() const
       
   436 {
       
   437     return m_resource;
       
   438 }
       
   439 
   377 //-----------------------------------------------------------------------------
   440 //-----------------------------------------------------------------------------
   378 // MediaNode
   441 // MediaNode
   379 //-----------------------------------------------------------------------------
   442 //-----------------------------------------------------------------------------
   380 
   443 
   381 void MMF::MediaObject::connectMediaObject(MediaObject * /*mediaObject*/)
   444 void MMF::MediaObject::connectMediaObject(MediaObject * /*mediaObject*/)