Qt 4.8
qaudiooutput_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 #ifndef QAUDIOOUTPUTALSA_H
54 #define QAUDIOOUTPUTALSA_H
55 
56 #include <alsa/asoundlib.h>
57 
58 #include <QtCore/qfile.h>
59 #include <QtCore/qdebug.h>
60 #include <QtCore/qtimer.h>
61 #include <QtCore/qstring.h>
62 #include <QtCore/qstringlist.h>
63 #include <QtCore/qelapsedtimer.h>
64 #include <QtCore/qdatetime.h>
65 
66 #include <QtMultimedia/qaudio.h>
67 #include <QtMultimedia/qaudiodeviceinfo.h>
68 #include <QtMultimedia/qaudioengine.h>
69 
71 
72 class OutputPrivate;
73 
75 {
76  friend class OutputPrivate;
77  Q_OBJECT
78 public:
81 
82  qint64 write( const 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 bytesFree() 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 
105 
106 private slots:
107  void userFeed();
108  void feedback();
109  void updateAvailable();
110  bool deviceReady();
111 
112 signals:
113  void processMore();
114 
115 private:
116  bool opened;
117  bool pullMode;
118  bool resuming;
123  unsigned int buffer_time;
124  unsigned int period_time;
125  snd_pcm_uframes_t buffer_frames;
126  snd_pcm_uframes_t period_frames;
127  static void async_callback(snd_async_handler_t *ahandler);
128  int xrun_recovery(int err);
129 
130  int setFormat();
131  bool open();
132  void close();
133 
140  char* audioBuffer;
141  snd_pcm_t* handle;
142  snd_async_handler_t* ahandler;
143  snd_pcm_access_t access;
144  snd_pcm_format_t pcmformat;
145  snd_timestamp_t* timestamp;
146  snd_pcm_hw_params_t *hwparams;
147 };
148 
149 class OutputPrivate : public QIODevice
150 {
151  friend class QAudioOutputPrivate;
152  Q_OBJECT
153 public:
155  ~OutputPrivate();
156 
157  qint64 readData( char* data, qint64 len);
158  qint64 writeData(const char* data, qint64 len);
159 
160 private:
162 };
163 
165 
166 #endif
qint64 write(const char *data, qint64 len)
Error
Definition: qaudio.h:58
snd_async_handler_t * ahandler
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QAudioOutputPrivate * audioDevice
QAudio::State state() const
Returns the state of audio processing.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void resume()
Resumes processing audio data after a suspend()
The QAbstractAudioOutput class provides access for QAudioOutput to access the audio device provided b...
Definition: qaudioengine.h:73
static void async_callback(snd_async_handler_t *ahandler)
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
snd_pcm_access_t access
QAudio::Error error() const
Returns the error state.
void reset()
Drops all audio data in the buffers, resets buffers to zero.
void setBufferSize(int value)
Sets the audio buffer size to value in bytes.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAudioOutputPrivate(const QByteArray &device, const QAudioFormat &audioFormat)
int notifyInterval() const
Returns the notify interval in milliseconds.
snd_pcm_hw_params_t * hwparams
static const char * data(const QByteArray &arr)
qint64 elapsedUSecs() const
Returns the milliseconds since start() was called, including time in Idle and suspend states...
qint64 processedUSecs() const
Returns the amount of audio data processed since start() was called in milliseconds.
__int64 qint64
Definition: qglobal.h:942
void suspend()
Stops processing audio data, preserving buffered audio data.
#define Q_OBJECT
Definition: qobjectdefs.h:157
int periodSize() const
Returns the period size in bytes.
snd_timestamp_t * timestamp
QAudioFormat format() const
Returns the QAudioFormat being used.
State
Definition: qaudio.h:59
int bytesFree() const
Returns the free space available in bytes in the audio buffer.
void setNotifyInterval(int milliSeconds)
Sets the interval for notify() signal to be emitted.
snd_pcm_uframes_t period_frames
snd_pcm_format_t pcmformat
int bufferSize() const
Returns the audio buffer size in bytes.
QIODevice * start(QIODevice *device=0)
Uses the device as the QIODevice to transfer data.
void stop()
Stops the audio output.
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
#define slots
Definition: qobjectdefs.h:68
#define signals
Definition: qobjectdefs.h:69
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
snd_pcm_uframes_t buffer_frames