Qt 4.8
qaudio_mac_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 QAUDIO_MAC_P_H
55 #define QAUDIO_MAC_P_H
56 
57 #include <CoreAudio/CoreAudio.h>
58 
59 #include <QtCore/qdebug.h>
60 #include <QtCore/qatomic.h>
61 
62 #include <QtMultimedia/qaudioformat.h>
63 
65 
67 
68 QT_MODULE(Multimedia)
69 
70 
71 extern QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat);
72 
73 extern QAudioFormat toQAudioFormat(const AudioStreamBasicDescription& streamFormat);
74 extern AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat);
75 
77 {
78 public:
80 
81  QAudioRingBuffer(int bufferSize);
83 
84  Region acquireReadRegion(int size)
85  {
86  const int used = m_bufferUsed.fetchAndAddAcquire(0);
87 
88  if (used > 0) {
89  const int readSize = qMin(size, qMin(m_bufferSize - m_readPos, used));
90 
91  return readSize > 0 ? Region(m_buffer + m_readPos, readSize) : Region(0, 0);
92  }
93 
94  return Region(0, 0);
95  }
96 
97  void releaseReadRegion(Region const& region)
98  {
99  m_readPos = (m_readPos + region.second) % m_bufferSize;
100 
102  }
103 
105  {
107 
108  if (free > 0) {
109  const int writeSize = qMin(size, qMin(m_bufferSize - m_writePos, free));
110 
111  return writeSize > 0 ? Region(m_buffer + m_writePos, writeSize) : Region(0, 0);
112  }
113 
114  return Region(0, 0);
115  }
116 
117  void releaseWriteRegion(Region const& region)
118  {
119  m_writePos = (m_writePos + region.second) % m_bufferSize;
120 
122  }
123 
124  int used() const;
125  int free() const;
126  int size() const;
127 
128  void reset();
129 
130 private:
134  char* m_buffer;
136 };
137 
139 
141 
142 #endif // QAUDIO_MAC_P_H
143 
144 
int used() const
Definition: qaudio_mac.cpp:121
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
Region acquireReadRegion(int size)
Definition: qaudio_mac_p.h:84
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
T2 second
Definition: qpair.h:66
void releaseWriteRegion(Region const &region)
Definition: qaudio_mac_p.h:117
QAudioFormat toQAudioFormat(const AudioStreamBasicDescription &streamFormat)
Definition: qaudio_mac.cpp:63
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int fetchAndAddAcquire(int valueToAdd)
Atomic fetch-and-add.
QPair< char *, int > Region
Definition: qaudio_mac_p.h:79
int free() const
Definition: qaudio_mac.cpp:126
Region acquireWriteRegion(int size)
Definition: qaudio_mac_p.h:104
AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const &audioFormat)
Definition: qaudio_mac.cpp:82
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
void releaseReadRegion(Region const &region)
Definition: qaudio_mac_p.h:97
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135
#define QT_END_HEADER
Definition: qglobal.h:137
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
int size() const
Definition: qaudio_mac.cpp:131
QAudioRingBuffer(int bufferSize)
Definition: qaudio_mac.cpp:109
int fetchAndAddRelease(int valueToAdd)
Atomic fetch-and-add.