src/plugins/audio/symbian/symbianaudioinput.h
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 22 79de32ba3296
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
     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 QtMultimedia module of the Qt Toolkit.
       
     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 SYMBIANAUDIOINPUT_H
       
    43 #define SYMBIANAUDIOINPUT_H
       
    44 
       
    45 #include <QtMultimedia/qaudioengine.h>
       
    46 #include <QTime>
       
    47 #include <QTimer>
       
    48 #include <sounddevice.h>
       
    49 #include "symbianaudio.h"
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 class SymbianAudioInput;
       
    54 
       
    55 class SymbianAudioInputPrivate : public QIODevice
       
    56 {
       
    57     friend class SymbianAudioInput;
       
    58     Q_OBJECT
       
    59 public:
       
    60     SymbianAudioInputPrivate(SymbianAudioInput *audio);
       
    61     ~SymbianAudioInputPrivate();
       
    62 
       
    63     qint64 readData(char *data, qint64 len);
       
    64     qint64 writeData(const char *data, qint64 len);
       
    65 
       
    66     void dataReady();
       
    67 
       
    68 private:
       
    69     SymbianAudioInput *const m_audioDevice;
       
    70 };
       
    71 
       
    72 class SymbianAudioInput
       
    73     :   public QAbstractAudioInput
       
    74     ,   public MDevSoundObserver
       
    75 {
       
    76     friend class SymbianAudioInputPrivate;
       
    77     Q_OBJECT
       
    78 public:
       
    79     SymbianAudioInput(const QByteArray &device,
       
    80                       const QAudioFormat &audioFormat);
       
    81     ~SymbianAudioInput();
       
    82 
       
    83     // QAbstractAudioInput
       
    84     QIODevice* start(QIODevice *device = 0);
       
    85     void stop();
       
    86     void reset();
       
    87     void suspend();
       
    88     void resume();
       
    89     int bytesReady() const;
       
    90     int periodSize() const;
       
    91     void setBufferSize(int value);
       
    92     int bufferSize() const;
       
    93     void setNotifyInterval(int milliSeconds);
       
    94     int notifyInterval() const;
       
    95     qint64 processedUSecs() const;
       
    96     qint64 elapsedUSecs() const;
       
    97     QAudio::Error error() const;
       
    98     QAudio::State state() const;
       
    99     QAudioFormat format() const;
       
   100 
       
   101     // MDevSoundObserver
       
   102     void InitializeComplete(TInt aError);
       
   103     void ToneFinished(TInt aError);
       
   104     void BufferToBeFilled(CMMFBuffer *aBuffer);
       
   105     void PlayError(TInt aError);
       
   106     void BufferToBeEmptied(CMMFBuffer *aBuffer);
       
   107     void RecordError(TInt aError);
       
   108     void ConvertError(TInt aError);
       
   109     void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg);
       
   110 
       
   111 private slots:
       
   112     void pullData();
       
   113 
       
   114 private:
       
   115    void open();
       
   116    void startRecording();
       
   117    void startDevSoundL();
       
   118    void startDataTransfer();
       
   119    CMMFDataBuffer* currentBuffer() const;
       
   120    void pushData();
       
   121    qint64 read(char *data, qint64 len);
       
   122    void bufferEmptied();
       
   123    Q_INVOKABLE void close();
       
   124 
       
   125    qint64 getSamplesRecorded() const;
       
   126 
       
   127    void setError(QAudio::Error error);
       
   128    void setState(SymbianAudio::State state);
       
   129 
       
   130    QAudio::State initializingState() const;
       
   131 
       
   132 private:
       
   133     const QByteArray m_device;
       
   134     const QAudioFormat m_format;
       
   135 
       
   136     int m_clientBufferSize;
       
   137     int m_notifyInterval;
       
   138     QScopedPointer<QTimer> m_notifyTimer;
       
   139     QTime m_elapsed;
       
   140     QAudio::Error m_error;
       
   141 
       
   142     SymbianAudio::State m_internalState;
       
   143     QAudio::State m_externalState;
       
   144 
       
   145     bool m_pullMode;
       
   146     QIODevice *m_sink;
       
   147 
       
   148     QScopedPointer<QTimer> m_pullTimer;
       
   149 
       
   150     QScopedPointer<CMMFDevSound> m_devSound;
       
   151     TUint32 m_nativeFourCC;
       
   152     TMMFCapabilities m_nativeFormat;
       
   153 
       
   154     // Latest buffer provided by DevSound, to be empied of data.
       
   155     CMMFDataBuffer *m_devSoundBuffer;
       
   156 
       
   157     int m_devSoundBufferSize;
       
   158 
       
   159     // Total amount of data in buffers provided by DevSound
       
   160     int m_totalBytesReady;
       
   161 
       
   162     // Queue of buffers returned after call to CMMFDevSound::Pause().
       
   163     QList<CMMFDataBuffer *> m_devSoundBufferQ;
       
   164 
       
   165     // Current read position within m_devSoundBuffer
       
   166     qint64 m_devSoundBufferPos;
       
   167 
       
   168     // Samples recorded up to the last call to suspend().  It is necessary
       
   169     // to cache this because suspend() is implemented using
       
   170     // CMMFDevSound::Stop(), which resets DevSound's SamplesRecorded() counter.
       
   171     quint32 m_totalSamplesRecorded;
       
   172 
       
   173 };
       
   174 
       
   175 QT_END_NAMESPACE
       
   176 
       
   177 #endif