qtmobility/plugins/multimedia/symbian/mediaplayer/s60mediaplayerservice.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtCore/qvariant.h>
       
    43 #include <QtCore/qdebug.h>
       
    44 #include <QtGui/qwidget.h>
       
    45 
       
    46 #include "s60mediaplayerservice.h"
       
    47 #include "s60mediaplayercontrol.h"
       
    48 #include "s60videoplayersession.h"
       
    49 #include "s60audioplayersession.h"
       
    50 #include "s60mediametadataprovider.h"
       
    51 #include "s60videowidget.h"
       
    52 #include "s60mediarecognizer.h"
       
    53 //#include <qmediatimerange.h>
       
    54 #include "s60videooverlay.h"
       
    55 #include "s60videorenderer.h"
       
    56 
       
    57 #include <QMediaPlaylistNavigator>
       
    58 #include <QMediaPlaylist>
       
    59 
       
    60 S60MediaPlayerService::S60MediaPlayerService(QObject *parent)
       
    61     : QMediaService(parent)
       
    62     , m_control(NULL)
       
    63     , m_mediaRecognizer(NULL)
       
    64     , m_videoOutput(NULL)
       
    65     , m_videoPlayerSession(NULL)
       
    66     , m_audioPlayerSession(NULL)
       
    67     , m_metaData(NULL)
       
    68     , m_videoWidget(NULL) 
       
    69     , m_videoWindow(NULL)
       
    70     , m_videoRenderer(NULL)
       
    71 { 
       
    72     m_control = new S60MediaPlayerControl(*this, this);
       
    73     m_mediaRecognizer = new S60MediaRecognizer(this);  
       
    74     m_metaData = new S60MediaMetaDataProvider(*this);
       
    75 }
       
    76 
       
    77 S60MediaPlayerService::~S60MediaPlayerService()
       
    78 {
       
    79     delete m_videoWidget;
       
    80     delete m_videoRenderer;
       
    81     delete m_videoWindow;
       
    82     delete m_videoOutput;
       
    83     delete m_metaData;
       
    84 }
       
    85 
       
    86 QMediaControl *S60MediaPlayerService::control(const char *name) const
       
    87 {
       
    88     if (qstrcmp(name, QMediaPlayerControl_iid) == 0)
       
    89         return m_control;
       
    90 
       
    91     if (qstrcmp(name, QMetaDataControl_iid) == 0) {
       
    92         return m_metaData;
       
    93     }
       
    94 
       
    95     if (qstrcmp(name, QVideoOutputControl_iid) == 0) {
       
    96         if (!m_videoOutput) {
       
    97             m_videoOutput = new S60VideoOutputControl;
       
    98             connect(m_videoOutput, SIGNAL(outputChanged(QVideoOutputControl::Output)),
       
    99                     this, SLOT(videoOutputChanged(QVideoOutputControl::Output)));
       
   100             m_videoOutput->setAvailableOutputs(QList<QVideoOutputControl::Output>() 
       
   101 //                        << QVideoOutputControl::RendererOutput
       
   102 //                        << QVideoOutputControl::WindowOutput
       
   103                         << QVideoOutputControl::WidgetOutput);
       
   104             
       
   105         }
       
   106         return m_videoOutput;
       
   107     }
       
   108 
       
   109     if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
       
   110         if (!m_videoWidget)
       
   111             m_videoWidget = new S60VideoWidgetControl;
       
   112         return m_videoWidget;
       
   113     }
       
   114     
       
   115     if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
       
   116         if (m_videoRenderer)
       
   117             m_videoRenderer = new S60VideoRenderer;
       
   118         return m_videoRenderer;
       
   119     }
       
   120     
       
   121     if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
       
   122         if (!m_videoWindow)
       
   123             m_videoWindow = new S60VideoOverlay;
       
   124         return m_videoWindow;
       
   125     }
       
   126 
       
   127     return 0;
       
   128 
       
   129 }
       
   130 
       
   131 void S60MediaPlayerService::videoOutputChanged(QVideoOutputControl::Output output)
       
   132 {
       
   133     switch (output) {
       
   134     case QVideoOutputControl::NoOutput:
       
   135         m_control->setVideoOutput(0);
       
   136         break;
       
   137 
       
   138     case QVideoOutputControl::RendererOutput:
       
   139         m_control->setVideoOutput(m_videoRenderer);
       
   140         break;
       
   141     case QVideoOutputControl::WindowOutput:
       
   142         m_control->setVideoOutput(m_videoWindow);
       
   143         break;
       
   144 
       
   145     case QVideoOutputControl::WidgetOutput:
       
   146         m_control->setVideoOutput(m_videoWidget);
       
   147         break;
       
   148     default:
       
   149         qWarning("Invalid video output selection");
       
   150         break;
       
   151     }
       
   152 }
       
   153 
       
   154 S60MediaPlayerSession* S60MediaPlayerService::PlayerSession()
       
   155 {
       
   156     QUrl url = m_control->media().canonicalUrl();
       
   157   
       
   158     if (url.isEmpty() == true) {
       
   159         return NULL;
       
   160     }
       
   161     
       
   162     S60MediaRecognizer::MediaType mediaType = m_mediaRecognizer->IdentifyMediaType(url);
       
   163     
       
   164     switch (mediaType) {
       
   165     	case S60MediaRecognizer::Video:
       
   166             return VideoPlayerSession(true);
       
   167     	case S60MediaRecognizer::Audio:
       
   168             return AudioPlayerSession();
       
   169     	case S60MediaRecognizer::Url:
       
   170             return VideoPlayerSession(false);
       
   171     	default:	
       
   172     		break;
       
   173     }
       
   174     
       
   175     return NULL;
       
   176 }
       
   177 
       
   178 S60MediaPlayerSession* S60MediaPlayerService::VideoPlayerSession(bool isLocal)
       
   179 {
       
   180     if (!m_videoPlayerSession) {
       
   181         m_videoPlayerSession = new S60VideoPlayerSession(this);
       
   182         
       
   183         connect(m_videoPlayerSession, SIGNAL(positionChanged(qint64)),
       
   184                 m_control, SIGNAL(positionChanged(qint64)));
       
   185         connect(m_videoPlayerSession, SIGNAL(durationChanged(qint64)),
       
   186                 m_control, SIGNAL(durationChanged(qint64)));
       
   187         connect(m_videoPlayerSession, SIGNAL(stateChanged(QMediaPlayer::State)),
       
   188                 m_control, SIGNAL(stateChanged(QMediaPlayer::State)));
       
   189         connect(m_videoPlayerSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
       
   190                 m_control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)));
       
   191         connect(m_videoPlayerSession,SIGNAL(bufferStatusChanged(int)),
       
   192                 m_control, SIGNAL(bufferStatusChanged(int)));
       
   193         connect(m_videoPlayerSession, SIGNAL(videoAvailableChanged(bool)),
       
   194                 m_control, SIGNAL(videoAvailableChanged(bool)));
       
   195         connect(m_videoPlayerSession, SIGNAL(seekableChanged(bool)),
       
   196                 m_control, SIGNAL(seekableChanged(bool)));
       
   197         connect(m_videoPlayerSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)),
       
   198                 m_control, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)));
       
   199         connect(m_videoPlayerSession, SIGNAL(error(int, const QString &)),
       
   200                 m_control, SIGNAL(error(int, const QString &)));
       
   201         connect(m_videoPlayerSession, SIGNAL(metaDataChanged()), 
       
   202                 m_metaData, SIGNAL(metaDataChanged()));
       
   203     }
       
   204     
       
   205     m_videoPlayerSession->setVolume(m_control->mediaControlSettings().volume());
       
   206     m_videoPlayerSession->setMuted(m_control->mediaControlSettings().isMuted());
       
   207     m_videoPlayerSession->setMediaFileLocal(isLocal);
       
   208     return m_videoPlayerSession;
       
   209 }
       
   210 
       
   211 S60MediaPlayerSession* S60MediaPlayerService::AudioPlayerSession(bool isLocal)
       
   212 {
       
   213     if (!m_audioPlayerSession) {
       
   214         m_audioPlayerSession = new S60AudioPlayerSession(this);
       
   215         
       
   216         connect(m_audioPlayerSession, SIGNAL(positionChanged(qint64)),
       
   217                 m_control, SIGNAL(positionChanged(qint64)));
       
   218         connect(m_audioPlayerSession, SIGNAL(durationChanged(qint64)),
       
   219                 m_control, SIGNAL(durationChanged(qint64)));
       
   220         connect(m_audioPlayerSession, SIGNAL(stateChanged(QMediaPlayer::State)),
       
   221                 m_control, SIGNAL(stateChanged(QMediaPlayer::State)));
       
   222         connect(m_audioPlayerSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
       
   223                 m_control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)));
       
   224         connect(m_audioPlayerSession,SIGNAL(bufferStatusChanged(int)),
       
   225                 m_control, SIGNAL(bufferStatusChanged(int)));
       
   226         connect(m_audioPlayerSession, SIGNAL(videoAvailableChanged(bool)),
       
   227                 m_control, SIGNAL(videoAvailableChanged(bool)));
       
   228         connect(m_audioPlayerSession, SIGNAL(seekableChanged(bool)),
       
   229                 m_control, SIGNAL(seekableChanged(bool)));
       
   230         connect(m_audioPlayerSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)),    
       
   231                 m_control, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)));
       
   232         connect(m_audioPlayerSession, SIGNAL(error(int, const QString &)),
       
   233                 m_control, SIGNAL(error(int, const QString &)));
       
   234         connect(m_audioPlayerSession, SIGNAL(metaDataChanged()), 
       
   235                 m_metaData, SIGNAL(metaDataChanged()));
       
   236     }
       
   237     
       
   238     m_audioPlayerSession->setVolume(m_control->mediaControlSettings().volume());
       
   239     m_audioPlayerSession->setMuted(m_control->mediaControlSettings().isMuted());
       
   240     m_audioPlayerSession->setMediaFileLocal(isLocal);
       
   241     return m_audioPlayerSession;
       
   242 }
       
   243