qtmobility/src/multimedia/audio/qaudioinput_mac_p.h
changeset 14 6fbed849b4f4
child 15 1f895d8a5b2b
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 
       
    54 #ifndef QAUDIOINPUT_MAC_P_H
       
    55 #define QAUDIOINPUT_MAC_P_H
       
    56 
       
    57 #include <CoreServices/CoreServices.h>
       
    58 #include <CoreAudio/CoreAudio.h>
       
    59 #include <AudioUnit/AudioUnit.h>
       
    60 #include <AudioToolbox/AudioToolbox.h>
       
    61 
       
    62 #include <QtCore/qobject.h>
       
    63 #include <QtCore/qmutex.h>
       
    64 #include <QtCore/qwaitcondition.h>
       
    65 #include <QtCore/qatomic.h>
       
    66 
       
    67 #include <qaudio.h>
       
    68 #include <qaudioformat.h>
       
    69 #include <qaudiosystem.h>
       
    70 
       
    71 QT_BEGIN_HEADER
       
    72 
       
    73 QT_BEGIN_NAMESPACE
       
    74 
       
    75 class QTimer;
       
    76 class QIODevice;
       
    77 class QAbstractAudioDeviceInfo;
       
    78 
       
    79 namespace QtMultimediaInternal
       
    80 {
       
    81 class QAudioInputBuffer;
       
    82 }
       
    83 
       
    84 class QAudioInputPrivate : public QAbstractAudioInput
       
    85 {
       
    86     Q_OBJECT
       
    87 
       
    88 public:
       
    89     bool            isOpen;
       
    90     int             periodSizeBytes;
       
    91     int             internalBufferSize;
       
    92     qint64          totalFrames;
       
    93     QAudioFormat    audioFormat;
       
    94     QIODevice*      audioIO;
       
    95     AudioUnit       audioUnit;
       
    96     AudioDeviceID   audioDeviceId;
       
    97     Float64         clockFrequency;
       
    98     UInt64          startTime;
       
    99     QAudio::Error   errorCode;
       
   100     QAudio::State   stateCode;
       
   101     QtMultimediaInternal::QAudioInputBuffer*   audioBuffer;
       
   102     QMutex          mutex;
       
   103     QWaitCondition  threadFinished;
       
   104     QAtomicInt      audioThreadState;
       
   105     QTimer*         intervalTimer;
       
   106     AudioStreamBasicDescription streamFormat;
       
   107     AudioStreamBasicDescription deviceFormat;
       
   108     QAbstractAudioDeviceInfo *audioDeviceInfo;
       
   109 
       
   110     QAudioInputPrivate(const QByteArray& device);
       
   111     ~QAudioInputPrivate();
       
   112 
       
   113     bool open();
       
   114     void close();
       
   115 
       
   116     QAudioFormat format() const;
       
   117     void setFormat(const QAudioFormat& fmt);
       
   118 
       
   119     QIODevice* start();
       
   120     void start(QIODevice* device);
       
   121     void stop();
       
   122     void reset();
       
   123     void suspend();
       
   124     void resume();
       
   125     void idle();
       
   126 
       
   127     int bytesReady() const;
       
   128     int periodSize() const;
       
   129 
       
   130     void setBufferSize(int value);
       
   131     int bufferSize() const;
       
   132 
       
   133     void setNotifyInterval(int milliSeconds);
       
   134     int notifyInterval() const;
       
   135 
       
   136     qint64 processedUSecs() const;
       
   137     qint64 elapsedUSecs() const;
       
   138 
       
   139     QAudio::Error error() const;
       
   140     QAudio::State state() const;
       
   141 
       
   142     void audioThreadStart();
       
   143     void audioThreadStop();
       
   144 
       
   145     void audioDeviceStop();
       
   146     void audioDeviceFull();
       
   147     void audioDeviceError();
       
   148 
       
   149     void startTimers();
       
   150     void stopTimers();
       
   151 
       
   152 private slots:
       
   153     void deviceStopped();
       
   154 
       
   155 private:
       
   156     enum { Running, Stopped };
       
   157 
       
   158     // Input callback
       
   159     static OSStatus inputCallback(void* inRefCon,
       
   160                                     AudioUnitRenderActionFlags* ioActionFlags,
       
   161                                     const AudioTimeStamp* inTimeStamp,
       
   162                                     UInt32 inBusNumber,
       
   163                                     UInt32 inNumberFrames,
       
   164                                     AudioBufferList* ioData);
       
   165 };
       
   166 
       
   167 QT_END_NAMESPACE
       
   168 
       
   169 QT_END_HEADER
       
   170 
       
   171 #endif // QAUDIOINPUT_MAC_P_H