Qt 4.8
Public Types | Public Functions | Properties | List of all members
QAudioRingBuffer Class Reference

#include <qaudio_mac_p.h>

Public Types

typedef QPair< char *, int > Region
 

Public Functions

Region acquireReadRegion (int size)
 
Region acquireWriteRegion (int size)
 
int free () const
 
 QAudioRingBuffer (int bufferSize)
 
void releaseReadRegion (Region const &region)
 
void releaseWriteRegion (Region const &region)
 
void reset ()
 
int size () const
 
int used () const
 
 ~QAudioRingBuffer ()
 

Properties

char * m_buffer
 
int m_bufferSize
 
QAtomicInt m_bufferUsed
 
int m_readPos
 
int m_writePos
 

Detailed Description

Definition at line 76 of file qaudio_mac_p.h.

Typedefs

◆ Region

typedef QPair<char*, int> QAudioRingBuffer::Region

Definition at line 79 of file qaudio_mac_p.h.

Constructors and Destructors

◆ QAudioRingBuffer()

QAudioRingBuffer::QAudioRingBuffer ( int  bufferSize)

Definition at line 109 of file qaudio_mac.cpp.

109  :
110  m_bufferSize(bufferSize)
111 {
112  m_buffer = new char[m_bufferSize];
113  reset();
114 }

◆ ~QAudioRingBuffer()

QAudioRingBuffer::~QAudioRingBuffer ( )

Definition at line 116 of file qaudio_mac.cpp.

117 {
118  delete m_buffer;
119 }

Functions

◆ acquireReadRegion()

Region QAudioRingBuffer::acquireReadRegion ( int  size)
inline

Definition at line 84 of file qaudio_mac_p.h.

Referenced by QtMultimediaInternal::QAudioOutputBuffer::readFrames().

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  }
int used() const
Definition: qaudio_mac.cpp:121
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int fetchAndAddAcquire(int valueToAdd)
Atomic fetch-and-add.
QPair< char *, int > Region
Definition: qaudio_mac_p.h:79
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135
int size() const
Definition: qaudio_mac.cpp:131

◆ acquireWriteRegion()

Region QAudioRingBuffer::acquireWriteRegion ( int  size)
inline

Definition at line 104 of file qaudio_mac_p.h.

Referenced by QtMultimediaInternal::QAudioOutputBuffer::fillBuffer(), and QtMultimediaInternal::QAudioOutputBuffer::writeBytes().

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  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
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
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135
int size() const
Definition: qaudio_mac.cpp:131

◆ free()

int QAudioRingBuffer::free ( ) const

◆ releaseReadRegion()

void QAudioRingBuffer::releaseReadRegion ( Region const &  region)
inline

Definition at line 97 of file qaudio_mac_p.h.

Referenced by QtMultimediaInternal::QAudioOutputBuffer::readFrames().

98  {
99  m_readPos = (m_readPos + region.second) % m_bufferSize;
100 
101  m_bufferUsed.fetchAndAddRelease(-region.second);
102  }
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135
int fetchAndAddRelease(int valueToAdd)
Atomic fetch-and-add.

◆ releaseWriteRegion()

void QAudioRingBuffer::releaseWriteRegion ( Region const &  region)
inline

Definition at line 117 of file qaudio_mac_p.h.

Referenced by QtMultimediaInternal::QAudioOutputBuffer::fillBuffer(), and QtMultimediaInternal::QAudioOutputBuffer::writeBytes().

118  {
119  m_writePos = (m_writePos + region.second) % m_bufferSize;
120 
121  m_bufferUsed.fetchAndAddRelease(region.second);
122  }
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135
int fetchAndAddRelease(int valueToAdd)
Atomic fetch-and-add.

◆ reset()

void QAudioRingBuffer::reset ( )

Definition at line 136 of file qaudio_mac.cpp.

Referenced by QAudioRingBuffer(), releaseWriteRegion(), and QtMultimediaInternal::QAudioOutputBuffer::reset().

137 {
138  m_readPos = 0;
139  m_writePos = 0;
140  m_bufferUsed = 0;
141 }
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135

◆ size()

int QAudioRingBuffer::size ( ) const

Definition at line 131 of file qaudio_mac.cpp.

Referenced by releaseWriteRegion(), and QtMultimediaInternal::QAudioOutputBuffer::startFillTimer().

132 {
133  return m_bufferSize;
134 }

◆ used()

int QAudioRingBuffer::used ( ) const

Definition at line 121 of file qaudio_mac.cpp.

Referenced by acquireReadRegion(), and releaseWriteRegion().

122 {
123  return m_bufferUsed;
124 }
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135

Properties

◆ m_buffer

char* QAudioRingBuffer::m_buffer
private

◆ m_bufferSize

int QAudioRingBuffer::m_bufferSize
private

◆ m_bufferUsed

QAtomicInt QAudioRingBuffer::m_bufferUsed
private

◆ m_readPos

int QAudioRingBuffer::m_readPos
private

Definition at line 132 of file qaudio_mac_p.h.

Referenced by acquireReadRegion(), releaseReadRegion(), and reset().

◆ m_writePos

int QAudioRingBuffer::m_writePos
private

Definition at line 133 of file qaudio_mac_p.h.

Referenced by acquireWriteRegion(), releaseWriteRegion(), and reset().


The documentation for this class was generated from the following files: