qtmobility/src/multimedia/audio/qaudioinput_win32_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 QAUDIOINPUTWIN_H
       
    54 #define QAUDIOINPUTWIN_H
       
    55 
       
    56 #include <windows.h>
       
    57 #include <mmsystem.h>
       
    58 
       
    59 #include <QtCore/qfile.h>
       
    60 #include <QtCore/qdebug.h>
       
    61 #include <QtCore/qtimer.h>
       
    62 #include <QtCore/qstring.h>
       
    63 #include <QtCore/qstringlist.h>
       
    64 #include <QtCore/qdatetime.h>
       
    65 #include <QtCore/qmutex.h>
       
    66 
       
    67 #include <qaudio.h>
       
    68 #include <qaudiodeviceinfo.h>
       
    69 #include <qaudiosystem.h>
       
    70 
       
    71 
       
    72 QT_BEGIN_NAMESPACE
       
    73 
       
    74 // For compat with 4.6
       
    75 #if !defined(QT_WIN_CALLBACK)
       
    76 #  if defined(Q_CC_MINGW)
       
    77 #    define QT_WIN_CALLBACK CALLBACK __attribute__ ((force_align_arg_pointer))
       
    78 #  else
       
    79 #    define QT_WIN_CALLBACK CALLBACK
       
    80 #  endif
       
    81 #endif
       
    82 
       
    83 class QAudioInputPrivate : public QAbstractAudioInput
       
    84 {
       
    85     Q_OBJECT
       
    86 public:
       
    87     QAudioInputPrivate(const QByteArray &device);
       
    88     ~QAudioInputPrivate();
       
    89 
       
    90     qint64 read(char* data, qint64 len);
       
    91 
       
    92     void setFormat(const QAudioFormat& fmt);
       
    93     QAudioFormat format() const;
       
    94     QIODevice* start();
       
    95     void start(QIODevice* device);
       
    96     void stop();
       
    97     void reset();
       
    98     void suspend();
       
    99     void resume();
       
   100     int bytesReady() const;
       
   101     int periodSize() const;
       
   102     void setBufferSize(int value);
       
   103     int bufferSize() const;
       
   104     void setNotifyInterval(int milliSeconds);
       
   105     int notifyInterval() const;
       
   106     qint64 processedUSecs() const;
       
   107     qint64 elapsedUSecs() const;
       
   108     QAudio::Error error() const;
       
   109     QAudio::State state() const;
       
   110 
       
   111     QIODevice* audioSource;
       
   112     QAudioFormat settings;
       
   113     QAudio::Error errorState;
       
   114     QAudio::State deviceState;
       
   115 
       
   116 private:
       
   117     qint32 buffer_size;
       
   118     qint32 period_size;
       
   119     qint32 header;
       
   120     QByteArray m_device;
       
   121     int bytesAvailable;
       
   122     int intervalTime;
       
   123     QTime timeStamp;
       
   124     qint64 elapsedTimeOffset;
       
   125     QTime timeStampOpened;
       
   126     qint64 totalTimeValue;
       
   127     bool pullMode;
       
   128     bool resuming;
       
   129     WAVEFORMATEX wfx;
       
   130     HWAVEIN hWaveIn;
       
   131     MMRESULT result;
       
   132     WAVEHDR* waveBlocks;
       
   133     volatile bool finished;
       
   134     volatile int waveFreeBlockCount;
       
   135     int waveCurrentBlock;
       
   136 
       
   137     QMutex mutex;
       
   138     static void QT_WIN_CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg,
       
   139             DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
       
   140 
       
   141     WAVEHDR* allocateBlocks(int size, int count);
       
   142     void freeBlocks(WAVEHDR* blockArray);
       
   143     bool open();
       
   144     void close();
       
   145 
       
   146 private slots:
       
   147     void feedback();
       
   148     bool deviceReady();
       
   149 
       
   150 signals:
       
   151     void processMore();
       
   152 };
       
   153 
       
   154 class InputPrivate : public QIODevice
       
   155 {
       
   156     Q_OBJECT
       
   157 public:
       
   158     InputPrivate(QAudioInputPrivate* audio);
       
   159     ~InputPrivate();
       
   160 
       
   161     qint64 readData( char* data, qint64 len);
       
   162     qint64 writeData(const char* data, qint64 len);
       
   163 
       
   164     void trigger();
       
   165 private:
       
   166     QAudioInputPrivate *audioDevice;
       
   167 };
       
   168 
       
   169 QT_END_NAMESPACE
       
   170 
       
   171 #endif