Qt 4.8
Signals | Public Functions | Private Slots | Properties | List of all members
QtMultimediaInternal::QAudioOutputBuffer Class Reference
Inheritance diagram for QtMultimediaInternal::QAudioOutputBuffer:
QObject

Signals

void readyRead ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

int available () const
 
 QAudioOutputBuffer (int bufferSize, int maxPeriodSize, QAudioFormat const &audioFormat)
 
qint64 readFrames (char *data, qint64 maxFrames)
 
void reset ()
 
void setPrefetchDevice (QIODevice *device)
 
void startFillTimer ()
 
void stopFillTimer ()
 
qint64 writeBytes (const char *data, qint64 maxSize)
 
 ~QAudioOutputBuffer ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void fillBuffer ()
 

Properties

QAudioRingBufferm_buffer
 
int m_bytesPerFrame
 
QIODevicem_device
 
bool m_deviceError
 
QTimerm_fillTimer
 
int m_maxPeriodSize
 
int m_periodTime
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 79 of file qaudiooutput_mac_p.cpp.

Constructors and Destructors

◆ QAudioOutputBuffer()

QtMultimediaInternal::QAudioOutputBuffer::QAudioOutputBuffer ( int  bufferSize,
int  maxPeriodSize,
QAudioFormat const &  audioFormat 
)
inline

Definition at line 84 of file qaudiooutput_mac_p.cpp.

84  :
85  m_deviceError(false),
86  m_maxPeriodSize(maxPeriodSize),
87  m_device(0)
88  {
89  m_buffer = new QAudioRingBuffer(bufferSize + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize)));
90  m_bytesPerFrame = (audioFormat.sampleSize() / 8) * audioFormat.channels();
91  m_periodTime = m_maxPeriodSize / m_bytesPerFrame * 1000 / audioFormat.frequency();
92 
93  m_fillTimer = new QTimer(this);
94  connect(m_fillTimer, SIGNAL(timeout()), SLOT(fillBuffer()));
95  }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56

◆ ~QAudioOutputBuffer()

QtMultimediaInternal::QAudioOutputBuffer::~QAudioOutputBuffer ( )
inline

Definition at line 97 of file qaudiooutput_mac_p.cpp.

98  {
99  delete m_buffer;
100  }

Functions

◆ available()

int QtMultimediaInternal::QAudioOutputBuffer::available ( ) const
inline

Definition at line 152 of file qaudiooutput_mac_p.cpp.

153  {
154  return m_buffer->free();
155  }
int free() const
Definition: qaudio_mac.cpp:126

◆ fillBuffer

void QtMultimediaInternal::QAudioOutputBuffer::fillBuffer ( )
inlineprivateslot

Definition at line 187 of file qaudiooutput_mac_p.cpp.

Referenced by QAudioOutputBuffer(), and setPrefetchDevice().

188  {
189  const int free = m_buffer->free();
190  const int writeSize = free - (free % m_maxPeriodSize);
191 
192  if (writeSize > 0) {
193  bool wecan = true;
194  int filled = 0;
195 
196  while (!m_deviceError && wecan && filled < writeSize) {
197  QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(writeSize - filled);
198 
199  if (region.second > 0) {
200  region.second = m_device->read(region.first, region.second);
201  if (region.second > 0)
202  filled += region.second;
203  else if (region.second == 0)
204  wecan = false;
205  else if (region.second < 0) {
206  m_fillTimer->stop();
207  region.second = 0;
208  m_deviceError = true;
209  }
210  }
211  else
212  wecan = false;
213 
214  m_buffer->releaseWriteRegion(region);
215  }
216 
217  if (filled > 0)
218  emit readyRead();
219  }
220  }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
void releaseWriteRegion(Region const &region)
Definition: qaudio_mac_p.h:117
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
#define emit
Definition: qobjectdefs.h:76
int free() const
Definition: qaudio_mac.cpp:126
Region acquireWriteRegion(int size)
Definition: qaudio_mac_p.h:104
void stop()
Stops the timer.
Definition: qtimer.cpp:284

◆ readFrames()

qint64 QtMultimediaInternal::QAudioOutputBuffer::readFrames ( char *  data,
qint64  maxFrames 
)
inline

Definition at line 102 of file qaudiooutput_mac_p.cpp.

103  {
104  bool wecan = true;
105  qint64 framesRead = 0;
106 
107  while (wecan && framesRead < maxFrames) {
108  QAudioRingBuffer::Region region = m_buffer->acquireReadRegion((maxFrames - framesRead) * m_bytesPerFrame);
109 
110  if (region.second > 0) {
111  region.second -= region.second % m_bytesPerFrame;
112  memcpy(data + (framesRead * m_bytesPerFrame), region.first, region.second);
113  framesRead += region.second / m_bytesPerFrame;
114  }
115  else
116  wecan = false;
117 
118  m_buffer->releaseReadRegion(region);
119  }
120 
121  if (framesRead == 0 && m_deviceError)
122  framesRead = -1;
123 
124  return framesRead;
125  }
Region acquireReadRegion(int size)
Definition: qaudio_mac_p.h:84
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
void releaseReadRegion(Region const &region)
Definition: qaudio_mac_p.h:97

◆ readyRead

void QtMultimediaInternal::QAudioOutputBuffer::readyRead ( )
signal

◆ reset()

void QtMultimediaInternal::QAudioOutputBuffer::reset ( )
inline

Definition at line 157 of file qaudiooutput_mac_p.cpp.

◆ setPrefetchDevice()

void QtMultimediaInternal::QAudioOutputBuffer::setPrefetchDevice ( QIODevice device)
inline

Definition at line 163 of file qaudiooutput_mac_p.cpp.

164  {
165  if (m_device != device) {
166  m_device = device;
167  if (m_device != 0)
168  fillBuffer();
169  }
170  }

◆ startFillTimer()

void QtMultimediaInternal::QAudioOutputBuffer::startFillTimer ( )
inline

Definition at line 172 of file qaudiooutput_mac_p.cpp.

173  {
174  if (m_device != 0)
176  }
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249
int size() const
Definition: qaudio_mac.cpp:131

◆ stopFillTimer()

void QtMultimediaInternal::QAudioOutputBuffer::stopFillTimer ( )
inline

Definition at line 178 of file qaudiooutput_mac_p.cpp.

179  {
180  m_fillTimer->stop();
181  }
void stop()
Stops the timer.
Definition: qtimer.cpp:284

◆ writeBytes()

qint64 QtMultimediaInternal::QAudioOutputBuffer::writeBytes ( const char *  data,
qint64  maxSize 
)
inline

Definition at line 127 of file qaudiooutput_mac_p.cpp.

128  {
129  bool wecan = true;
130  qint64 bytesWritten = 0;
131 
132  maxSize -= maxSize % m_bytesPerFrame;
133  while (wecan && bytesWritten < maxSize) {
134  QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(maxSize - bytesWritten);
135 
136  if (region.second > 0) {
137  memcpy(region.first, data + bytesWritten, region.second);
138  bytesWritten += region.second;
139  }
140  else
141  wecan = false;
142 
143  m_buffer->releaseWriteRegion(region);
144  }
145 
146  if (bytesWritten > 0)
147  emit readyRead();
148 
149  return bytesWritten;
150  }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
void releaseWriteRegion(Region const &region)
Definition: qaudio_mac_p.h:117
#define emit
Definition: qobjectdefs.h:76
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
Region acquireWriteRegion(int size)
Definition: qaudio_mac_p.h:104

Properties

◆ m_buffer

QAudioRingBuffer* QtMultimediaInternal::QAudioOutputBuffer::m_buffer
private

◆ m_bytesPerFrame

int QtMultimediaInternal::QAudioOutputBuffer::m_bytesPerFrame
private

Definition at line 225 of file qaudiooutput_mac_p.cpp.

Referenced by QAudioOutputBuffer(), readFrames(), and writeBytes().

◆ m_device

QIODevice* QtMultimediaInternal::QAudioOutputBuffer::m_device
private

Definition at line 227 of file qaudiooutput_mac_p.cpp.

Referenced by fillBuffer(), setPrefetchDevice(), and startFillTimer().

◆ m_deviceError

bool QtMultimediaInternal::QAudioOutputBuffer::m_deviceError
private

Definition at line 223 of file qaudiooutput_mac_p.cpp.

Referenced by fillBuffer(), readFrames(), and reset().

◆ m_fillTimer

QTimer* QtMultimediaInternal::QAudioOutputBuffer::m_fillTimer
private

◆ m_maxPeriodSize

int QtMultimediaInternal::QAudioOutputBuffer::m_maxPeriodSize
private

Definition at line 224 of file qaudiooutput_mac_p.cpp.

Referenced by fillBuffer(), QAudioOutputBuffer(), and startFillTimer().

◆ m_periodTime

int QtMultimediaInternal::QAudioOutputBuffer::m_periodTime
private

Definition at line 226 of file qaudiooutput_mac_p.cpp.

Referenced by QAudioOutputBuffer(), and startFillTimer().


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