qtmobility/src/multimedia/audio/qaudiooutput_symbian_p.h
changeset 14 6fbed849b4f4
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
       
     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 //
       
    43 //  W A R N I N G
       
    44 //  -------------
       
    45 //
       
    46 // This file is not part of the Qt API.  It exists for the convenience
       
    47 // of other Qt classes.  This header file may change from version to
       
    48 // version without notice, or even be removed.
       
    49 //
       
    50 // We mean it.
       
    51 //
       
    52 
       
    53 #ifndef QAUDIOOUTPUT_SYMBIAN_P_H
       
    54 #define QAUDIOOUTPUT_SYMBIAN_P_H
       
    55 
       
    56 #include <qaudiosystem.h>
       
    57 #include <QTime>
       
    58 #include <QTimer>
       
    59 #include <sounddevice.h>
       
    60 #include "qaudio_symbian_p.h"
       
    61 
       
    62 QT_BEGIN_NAMESPACE
       
    63 
       
    64 class QAudioOutputPrivate;
       
    65 
       
    66 class SymbianAudioOutputPrivate : public QIODevice
       
    67 {
       
    68     friend class QAudioOutputPrivate;
       
    69     Q_OBJECT
       
    70 public:
       
    71     SymbianAudioOutputPrivate(QAudioOutputPrivate *audio);
       
    72     ~SymbianAudioOutputPrivate();
       
    73 
       
    74     qint64 readData(char *data, qint64 len);
       
    75     qint64 writeData(const char *data, qint64 len);
       
    76 
       
    77 private:
       
    78     QAudioOutputPrivate *const m_audioDevice;
       
    79 };
       
    80 
       
    81 class QAudioOutputPrivate
       
    82     :   public QAbstractAudioOutput
       
    83     ,   public MDevSoundObserver
       
    84 {
       
    85     friend class SymbianAudioOutputPrivate;
       
    86     Q_OBJECT
       
    87 public:
       
    88     QAudioOutputPrivate(const QByteArray &device);
       
    89     ~QAudioOutputPrivate();
       
    90 
       
    91     // QAbstractAudioOutput
       
    92     void start(QIODevice *device);
       
    93     QIODevice* start();
       
    94     void stop();
       
    95     void reset();
       
    96     void suspend();
       
    97     void resume();
       
    98     int bytesFree() const;
       
    99     int periodSize() const;
       
   100     void setBufferSize(int value);
       
   101     int bufferSize() const;
       
   102     void setNotifyInterval(int milliSeconds);
       
   103     int notifyInterval() const;
       
   104     qint64 processedUSecs() const;
       
   105     qint64 elapsedUSecs() const;
       
   106     QAudio::Error error() const;
       
   107     QAudio::State state() const;
       
   108     QAudioFormat format() const;
       
   109     void setFormat(const QAudioFormat& fmt);
       
   110 
       
   111     // MDevSoundObserver
       
   112     void InitializeComplete(TInt aError);
       
   113     void ToneFinished(TInt aError);
       
   114     void BufferToBeFilled(CMMFBuffer *aBuffer);
       
   115     void PlayError(TInt aError);
       
   116     void BufferToBeEmptied(CMMFBuffer *aBuffer);
       
   117     void RecordError(TInt aError);
       
   118     void ConvertError(TInt aError);
       
   119     void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg);
       
   120 
       
   121 private slots:
       
   122     void dataReady();
       
   123     void underflowTimerExpired();
       
   124 
       
   125 private:
       
   126    void open();
       
   127    void startPlayback();
       
   128    void startDevSoundL();
       
   129    void writePaddingData();
       
   130    qint64 pushData(const char *data, qint64 len);
       
   131    void pullData();
       
   132    void bufferFilled();
       
   133    void lastBufferFilled();
       
   134    Q_INVOKABLE void close();
       
   135 
       
   136    qint64 getSamplesPlayed() const;
       
   137 
       
   138    void setError(QAudio::Error error);
       
   139    void setState(SymbianAudio::State state);
       
   140 
       
   141    bool isDataReady() const;
       
   142    QAudio::State initializingState() const;
       
   143 
       
   144 private:
       
   145     const QByteArray m_device;
       
   146     QAudioFormat m_format;
       
   147 
       
   148     int m_clientBufferSize;
       
   149     int m_notifyInterval;
       
   150     QScopedPointer<QTimer> m_notifyTimer;
       
   151     QTime m_elapsed;
       
   152     QAudio::Error m_error;
       
   153 
       
   154     SymbianAudio::State m_internalState;
       
   155     QAudio::State m_externalState;
       
   156 
       
   157     bool m_pullMode;
       
   158     QIODevice *m_source;
       
   159 
       
   160     QScopedPointer<CMMFDevSound> m_devSound;
       
   161     TUint32 m_nativeFourCC;
       
   162     TMMFCapabilities m_nativeFormat;
       
   163 
       
   164     // Buffer provided by DevSound, to be filled with data.
       
   165     CMMFDataBuffer *m_devSoundBuffer;
       
   166 
       
   167     int m_devSoundBufferSize;
       
   168 
       
   169     // Number of bytes transferred from QIODevice to QAudioOutput.  It is
       
   170     // necessary to count this because data is dropped when suspend() is
       
   171     // called.  The difference between the position reported by DevSound and
       
   172     // this value allows us to calculate m_bytesPadding;
       
   173     quint32 m_bytesWritten;
       
   174 
       
   175     // True if client has provided data while the audio subsystem was not
       
   176     // ready to consume it.
       
   177     bool m_pushDataReady;
       
   178 
       
   179     // Number of zero bytes which will be written when client calls resume().
       
   180     quint32 m_bytesPadding;
       
   181 
       
   182     // True if PlayError(KErrUnderflow) has been called.
       
   183     bool m_underflow;
       
   184 
       
   185     // True if a buffer marked with the "last buffer" flag has been provided
       
   186     // to DevSound.
       
   187     bool m_lastBuffer;
       
   188 
       
   189     // Some DevSound implementations ignore all underflow errors raised by the
       
   190     // audio driver, unless the last buffer flag has been set by the client.
       
   191     // In push-mode playback, this flag will never be set, so the underflow
       
   192     // error will never be reported.  In order to work around this, a timer
       
   193     // is used, which gets reset every time the client provides more data.  If
       
   194     // the timer expires, an underflow error is raised by this object.
       
   195     QScopedPointer<QTimer> m_underflowTimer;
       
   196 
       
   197     // Result of previous call to CMMFDevSound::SamplesPlayed().  This value is
       
   198     // used to determine whether, when m_underflowTimer expires, an
       
   199     // underflow error has actually occurred.
       
   200     quint32 m_samplesPlayed;
       
   201 
       
   202     // Samples played up to the last call to suspend().  It is necessary
       
   203     // to cache this because suspend() is implemented using
       
   204     // CMMFDevSound::Stop(), which resets DevSound's SamplesPlayed() counter.
       
   205     quint32 m_totalSamplesPlayed;
       
   206 
       
   207 };
       
   208 
       
   209 QT_END_NAMESPACE
       
   210 
       
   211 #endif