Qt 4.8
qaudioinput_alsa_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtMultimedia module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 QAUDIOINPUTALSA_H
55 #define QAUDIOINPUTALSA_H
56 
57 #include <alsa/asoundlib.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/qelapsedtimer.h>
65 #include <QtCore/qdatetime.h>
66 
67 #include <QtMultimedia/qaudio.h>
68 #include <QtMultimedia/qaudiodeviceinfo.h>
69 #include <QtMultimedia/qaudioengine.h>
70 
72 
73 class InputPrivate;
74 
76 {
77  Q_OBJECT
78 public:
81 
82  qint64 read(char* data, qint64 len);
83 
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  bool resuming;
101  snd_pcm_t* handle;
107 
108 private slots:
109  void userFeed();
110  bool deviceReady();
111 
112 private:
113  int checkBytesReady();
114  int xrun_recovery(int err);
115  int setFormat();
116  bool open();
117  void close();
118  void drain();
119 
125  char* audioBuffer;
128  bool pullMode;
131  unsigned int buffer_time;
132  unsigned int period_time;
133  snd_pcm_uframes_t buffer_frames;
134  snd_pcm_uframes_t period_frames;
135  snd_async_handler_t* ahandler;
136  snd_pcm_access_t access;
137  snd_pcm_format_t pcmformat;
138  snd_timestamp_t* timestamp;
139  snd_pcm_hw_params_t *hwparams;
140 };
141 
142 class InputPrivate : public QIODevice
143 {
144  Q_OBJECT
145 public:
147  ~InputPrivate();
148 
149  qint64 readData( char* data, qint64 len);
150  qint64 writeData(const char* data, qint64 len);
151 
152  void trigger();
153 private:
155 };
156 
158 
159 #endif
Error
Definition: qaudio.h:58
snd_async_handler_t * ahandler
QAudioFormat format() const
Returns the QAudioFormat being used.
void resume()
Resumes processing audio data after a suspend().
QElapsedTimer clockStamp
void suspend()
Stops processing audio data, preserving buffered audio data.
snd_pcm_hw_params_t * hwparams
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
qint64 processedUSecs() const
Returns the amount of audio data processed since start() was called in milliseconds.
int bufferSize() const
Returns the audio buffer size in milliseconds.
void stop()
Stops the audio input.
void setNotifyInterval(int milliSeconds)
Sets the interval for notify() signal to be emitted.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QIODevice * start(QIODevice *device=0)
Uses the device as the QIODevice to transfer data.
QAudioFormat audioFormat
snd_pcm_access_t access
int bytesReady() const
Returns the amount of audio data available to read in bytes.
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
void setBufferSize(int value)
Sets the audio buffer size to value in milliseconds.
QAudio::State state() const
Returns the state of audio processing.
qint64 read(char *data, qint64 len)
int notifyInterval() const
Returns the notify interval in milliseconds.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAudio::Error errorState
qint64 elapsedUSecs() const
Returns the milliseconds since start() was called, including time in Idle and suspend states...
static const char * data(const QByteArray &arr)
void reset()
Drops all audio data in the buffers, resets buffers to zero.
__int64 qint64
Definition: qglobal.h:942
The QAbstractAudioInput class provides access for QAudioInput to access the audio device provided by ...
Definition: qaudioengine.h:100
#define Q_OBJECT
Definition: qobjectdefs.h:157
snd_pcm_format_t pcmformat
snd_pcm_uframes_t buffer_frames
State
Definition: qaudio.h:59
snd_timestamp_t * timestamp
QAudioInputPrivate * audioDevice
int periodSize() const
Returns the period size in bytes.
QAudio::Error error() const
Returns the error state.
snd_pcm_uframes_t period_frames
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
QAudio::State deviceState
#define slots
Definition: qobjectdefs.h:68
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
QAudioInputPrivate(const QByteArray &device, const QAudioFormat &audioFormat)