1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtMultimedia module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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 QAUDIOOUTPUT_MAC_P_H
|
---|
54 | #define QAUDIOOUTPUT_MAC_P_H
|
---|
55 |
|
---|
56 | #include <CoreServices/CoreServices.h>
|
---|
57 | #include <CoreAudio/CoreAudio.h>
|
---|
58 | #include <AudioUnit/AudioUnit.h>
|
---|
59 | #include <AudioToolbox/AudioToolbox.h>
|
---|
60 |
|
---|
61 | #include <QtCore/qobject.h>
|
---|
62 | #include <QtCore/qmutex.h>
|
---|
63 | #include <QtCore/qwaitcondition.h>
|
---|
64 | #include <QtCore/qtimer.h>
|
---|
65 | #include <QtCore/qatomic.h>
|
---|
66 |
|
---|
67 | #include <QtMultimedia/qaudio.h>
|
---|
68 | #include <QtMultimedia/qaudioformat.h>
|
---|
69 | #include <QtMultimedia/qaudioengine.h>
|
---|
70 |
|
---|
71 | QT_BEGIN_HEADER
|
---|
72 |
|
---|
73 | QT_BEGIN_NAMESPACE
|
---|
74 |
|
---|
75 | class QIODevice;
|
---|
76 |
|
---|
77 | namespace
|
---|
78 | {
|
---|
79 | class QAudioOutputBuffer;
|
---|
80 | }
|
---|
81 |
|
---|
82 | class QAudioOutputPrivate : public QAbstractAudioOutput
|
---|
83 | {
|
---|
84 | Q_OBJECT
|
---|
85 |
|
---|
86 | public:
|
---|
87 | bool isOpen;
|
---|
88 | int internalBufferSize;
|
---|
89 | int periodSizeBytes;
|
---|
90 | qint64 totalFrames;
|
---|
91 | QAudioFormat audioFormat;
|
---|
92 | QIODevice* audioIO;
|
---|
93 | AudioDeviceID audioDeviceId;
|
---|
94 | AudioUnit audioUnit;
|
---|
95 | Float64 clockFrequency;
|
---|
96 | UInt64 startTime;
|
---|
97 | AudioStreamBasicDescription deviceFormat;
|
---|
98 | AudioStreamBasicDescription streamFormat;
|
---|
99 | QAudioOutputBuffer* audioBuffer;
|
---|
100 | QAtomicInt audioThreadState;
|
---|
101 | QWaitCondition threadFinished;
|
---|
102 | QMutex mutex;
|
---|
103 | QTimer* intervalTimer;
|
---|
104 |
|
---|
105 | QAudio::Error errorCode;
|
---|
106 | QAudio::State stateCode;
|
---|
107 |
|
---|
108 | QAudioOutputPrivate(const QByteArray& device, const QAudioFormat& format);
|
---|
109 | ~QAudioOutputPrivate();
|
---|
110 |
|
---|
111 | bool open();
|
---|
112 | void close();
|
---|
113 |
|
---|
114 | QAudioFormat format() const;
|
---|
115 |
|
---|
116 | QIODevice* start(QIODevice* device);
|
---|
117 | void stop();
|
---|
118 | void reset();
|
---|
119 | void suspend();
|
---|
120 | void resume();
|
---|
121 |
|
---|
122 | int bytesFree() const;
|
---|
123 | int periodSize() const;
|
---|
124 |
|
---|
125 | void setBufferSize(int value);
|
---|
126 | int bufferSize() const;
|
---|
127 |
|
---|
128 | void setNotifyInterval(int milliSeconds);
|
---|
129 | int notifyInterval() const;
|
---|
130 |
|
---|
131 | qint64 processedUSecs() const;
|
---|
132 | qint64 elapsedUSecs() const;
|
---|
133 |
|
---|
134 | QAudio::Error error() const;
|
---|
135 | QAudio::State state() const;
|
---|
136 |
|
---|
137 | void audioThreadStart();
|
---|
138 | void audioThreadStop();
|
---|
139 | void audioThreadDrain();
|
---|
140 |
|
---|
141 | void audioDeviceStop();
|
---|
142 | void audioDeviceIdle();
|
---|
143 | void audioDeviceError();
|
---|
144 |
|
---|
145 | void startTimers();
|
---|
146 | void stopTimers();
|
---|
147 |
|
---|
148 | private slots:
|
---|
149 | void deviceStopped();
|
---|
150 | void inputReady();
|
---|
151 |
|
---|
152 | private:
|
---|
153 | enum { Running, Draining, Stopped };
|
---|
154 |
|
---|
155 | static OSStatus renderCallback(void* inRefCon,
|
---|
156 | AudioUnitRenderActionFlags* ioActionFlags,
|
---|
157 | const AudioTimeStamp* inTimeStamp,
|
---|
158 | UInt32 inBusNumber,
|
---|
159 | UInt32 inNumberFrames,
|
---|
160 | AudioBufferList* ioData);
|
---|
161 | };
|
---|
162 |
|
---|
163 | QT_END_NAMESPACE
|
---|
164 |
|
---|
165 | QT_END_HEADER
|
---|
166 |
|
---|
167 | #endif
|
---|