plugins/multimedia/qt7/mediaplayer/qt7playersession.h
changeset 5 603d3f8b6302
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 #ifndef QT7PLAYERSESSION_H
       
    43 #define QT7PLAYERSESSION_H
       
    44 
       
    45 #include <QtCore/qobject.h>
       
    46 #include <QtCore/qbytearray.h>
       
    47 #include <QtCore/qset.h>
       
    48 #include <QtCore/qresource.h>
       
    49 
       
    50 #include <qmediaplayercontrol.h>
       
    51 #include <qmediaplayer.h>
       
    52 
       
    53 #include <QtGui/qmacdefines_mac.h>
       
    54 
       
    55 
       
    56 QT_BEGIN_NAMESPACE
       
    57 
       
    58 class QT7PlayerControl;
       
    59 class QMediaPlaylist;
       
    60 class QMediaPlaylistNavigator;
       
    61 class QT7VideoOutput;
       
    62 class QT7PlayerSession;
       
    63 class QT7PlayerService;
       
    64 
       
    65 
       
    66 class QT7PlayerSession : public QObject
       
    67 {
       
    68     Q_OBJECT
       
    69 public:
       
    70     QT7PlayerSession(QObject *parent = 0);
       
    71     ~QT7PlayerSession();
       
    72 
       
    73     void *movie() const;
       
    74 
       
    75     void setControl(QT7PlayerControl *control);
       
    76 
       
    77     void setVideoOutput(QT7VideoOutput *output);
       
    78 
       
    79     QMediaPlayer::State state() const;
       
    80     QMediaPlayer::MediaStatus mediaStatus() const;
       
    81 
       
    82     QMediaContent media() const;
       
    83     const QIODevice *mediaStream() const;
       
    84     void setMedia(const QMediaContent &content, QIODevice *stream);
       
    85 
       
    86     qint64 position() const;
       
    87     qint64 duration() const;
       
    88 
       
    89     int bufferStatus() const;
       
    90 
       
    91     int volume() const;
       
    92     bool isMuted() const;
       
    93 
       
    94     bool isAudioAvailable() const;
       
    95     bool isVideoAvailable() const;
       
    96 
       
    97     bool isSeekable() const;
       
    98 
       
    99     qreal playbackRate() const;
       
   100 
       
   101 public slots:
       
   102     void setPlaybackRate(qreal rate);
       
   103 
       
   104     void setPosition(qint64 pos);
       
   105 
       
   106     void play();
       
   107     void pause();
       
   108     void stop();
       
   109 
       
   110     void setVolume(int volume);
       
   111     void setMuted(bool muted);
       
   112 
       
   113     void processEOS();
       
   114     void processLoadStateChange();
       
   115     void processVolumeChange();
       
   116     void processNaturalSizeChange();
       
   117 
       
   118 signals:
       
   119     void positionChanged(qint64 position);
       
   120     void durationChanged(qint64 duration);
       
   121     void stateChanged(QMediaPlayer::State newState);
       
   122     void mediaStatusChanged(QMediaPlayer::MediaStatus status);
       
   123     void volumeChanged(int volume);
       
   124     void mutedChanged(bool muted);
       
   125     void audioAvailableChanged(bool audioAvailable);
       
   126     void videoAvailableChanged(bool videoAvailable);
       
   127     void error(int error, const QString &errorString);
       
   128 
       
   129 private:
       
   130     class ResourceHandler {
       
   131     public:
       
   132         ResourceHandler():resource(0) {}
       
   133         ~ResourceHandler() { clear(); }
       
   134         void setResourceFile(const QString &file) {
       
   135             if (resource) {
       
   136                 if (resource->fileName() == file)
       
   137                     return;
       
   138                 delete resource;
       
   139                 rawData.clear();
       
   140             }
       
   141             resource = new QResource(file);
       
   142         }
       
   143         bool isValid() const { return resource && resource->isValid() && resource->data() != 0; }
       
   144         const uchar *data() {
       
   145             if (!isValid())
       
   146                 return 0;
       
   147             if (resource->isCompressed()) {
       
   148                 if (rawData.size() == 0)
       
   149                     rawData = qUncompress(resource->data(), resource->size());
       
   150                 return (const uchar *)rawData.constData();
       
   151             }
       
   152             return resource->data();
       
   153         }
       
   154         qint64 size() {
       
   155             if (data() == 0)
       
   156                 return 0;
       
   157             return resource->isCompressed() ? rawData.size() : resource->size();
       
   158         }
       
   159         void clear() {
       
   160             delete resource;
       
   161             rawData.clear();
       
   162         }
       
   163         QResource *resource;
       
   164         QByteArray rawData;
       
   165     };
       
   166 
       
   167     void openMovie(bool tryAsync);
       
   168 
       
   169     void *m_QTMovie;
       
   170     void *m_movieObserver;
       
   171 
       
   172     QMediaPlayer::State m_state;
       
   173     QMediaPlayer::MediaStatus m_mediaStatus;
       
   174     QIODevice *m_mediaStream;
       
   175     QMediaContent m_resources;
       
   176     ResourceHandler m_resourceHandler;
       
   177 
       
   178     QT7VideoOutput * m_videoOutput;
       
   179 
       
   180     mutable qint64 m_currentTime;
       
   181 
       
   182     bool m_muted;
       
   183     bool m_tryingAsync;
       
   184     int m_volume;
       
   185     qreal m_rate;
       
   186 
       
   187     qint64 m_duration;
       
   188     bool m_videoAvailable;
       
   189     bool m_audioAvailable;
       
   190 };
       
   191 
       
   192 QT_END_NAMESPACE
       
   193 
       
   194 #endif