Qt 4.8
Signals | Public Functions | Private Slots | Static Private Functions | Properties | Static Private Attributes | List of all members
QtMultimediaInternal::QAudioInputBuffer Class Reference
Inheritance diagram for QtMultimediaInternal::QAudioInputBuffer:
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
 
void flush (bool all=false)
 
 QAudioInputBuffer (int bufferSize, int maxPeriodSize, AudioStreamBasicDescription const &inputFormat, AudioStreamBasicDescription const &outputFormat, QObject *parent)
 
qint64 readBytes (char *data, qint64 len)
 
qint64 renderFromDevice (AudioUnit audioUnit, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames)
 
void reset ()
 
void setFlushDevice (QIODevice *device)
 
void startFlushTimer ()
 
void stopFlushTimer ()
 
int used () const
 
 ~QAudioInputBuffer ()
 
- 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 flushBuffer ()
 

Static Private Functions

static OSStatus converterCallback (AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
 

Properties

AudioConverterRef m_audioConverter
 
QAudioRingBufferm_buffer
 
QIODevicem_device
 
bool m_deviceError
 
QTimerm_flushTimer
 
QAudioBufferListm_inputBufferList
 
AudioStreamBasicDescription m_inputFormat
 
int m_maxPeriodSize
 
AudioStreamBasicDescription m_outputFormat
 
int m_periodTime
 

Static Private Attributes

static const OSStatus as_empty = 'qtem'
 

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 224 of file qaudioinput_mac_p.cpp.

Constructors and Destructors

◆ QAudioInputBuffer()

QtMultimediaInternal::QAudioInputBuffer::QAudioInputBuffer ( int  bufferSize,
int  maxPeriodSize,
AudioStreamBasicDescription const &  inputFormat,
AudioStreamBasicDescription const &  outputFormat,
QObject parent 
)
inline

Definition at line 229 of file qaudioinput_mac_p.cpp.

233  :
234  QObject(parent),
235  m_deviceError(false),
236  m_audioConverter(0),
237  m_inputFormat(inputFormat),
238  m_outputFormat(outputFormat)
239  {
240  m_maxPeriodSize = maxPeriodSize;
241  m_periodTime = m_maxPeriodSize / m_outputFormat.mBytesPerFrame * 1000 / m_outputFormat.mSampleRate;
242  m_buffer = new QAudioRingBuffer(bufferSize + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize)));
243  m_inputBufferList = new QAudioBufferList(m_inputFormat);
244 
245  m_flushTimer = new QTimer(this);
246  connect(m_flushTimer, SIGNAL(timeout()), SLOT(flushBuffer()));
247 
248  if (toQAudioFormat(inputFormat) != toQAudioFormat(outputFormat)) {
249  if (AudioConverterNew(&m_inputFormat, &m_outputFormat, &m_audioConverter) != noErr) {
250  qWarning() << "QAudioInput: Unable to create an Audio Converter";
251  m_audioConverter = 0;
252  }
253  }
254  }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QAudioFormat toQAudioFormat(AudioStreamBasicDescription const &sf)
Definition: qaudio_mac.cpp:63
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
Q_CORE_EXPORT void qWarning(const char *,...)
AudioStreamBasicDescription m_outputFormat
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
AudioStreamBasicDescription m_inputFormat
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56

◆ ~QAudioInputBuffer()

QtMultimediaInternal::QAudioInputBuffer::~QAudioInputBuffer ( )
inline

Definition at line 256 of file qaudioinput_mac_p.cpp.

257  {
258  delete m_buffer;
259  }

Functions

◆ available()

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

Definition at line 421 of file qaudioinput_mac_p.cpp.

422  {
423  return m_buffer->free();
424  }
int free() const
Definition: qaudio_mac.cpp:126

◆ converterCallback()

static OSStatus QtMultimediaInternal::QAudioInputBuffer::converterCallback ( AudioConverterRef  inAudioConverter,
UInt32 *  ioNumberDataPackets,
AudioBufferList *  ioData,
AudioStreamPacketDescription **  outDataPacketDescription,
void *  inUserData 
)
inlinestaticprivate

Definition at line 455 of file qaudioinput_mac_p.cpp.

460  {
461  Q_UNUSED(inAudioConverter);
462  Q_UNUSED(outDataPacketDescription);
463 
464  QAudioPacketFeeder* feeder = static_cast<QAudioPacketFeeder*>(inUserData);
465 
466  if (!feeder->feed(*ioData, *ioNumberDataPackets))
467  return as_empty;
468 
469  return noErr;
470  }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ flush()

void QtMultimediaInternal::QAudioInputBuffer::flush ( bool  all = false)
inline

Definition at line 380 of file qaudioinput_mac_p.cpp.

381  {
382  if (m_device == 0)
383  return;
384 
385  const int used = m_buffer->used();
386  const int readSize = all ? used : used - (used % m_maxPeriodSize);
387 
388  if (readSize > 0) {
389  bool wecan = true;
390  int flushed = 0;
391 
392  while (!m_deviceError && wecan && flushed < readSize) {
393  QAudioRingBuffer::Region region = m_buffer->acquireReadRegion(readSize - flushed);
394 
395  if (region.second > 0) {
396  int bytesWritten = m_device->write(region.first, region.second);
397  if (bytesWritten < 0) {
398  stopFlushTimer();
399  m_deviceError = true;
400  }
401  else {
402  region.second = bytesWritten;
403  flushed += bytesWritten;
404  wecan = bytesWritten != 0;
405  }
406  }
407  else
408  wecan = false;
409 
410  m_buffer->releaseReadRegion(region);
411  }
412  }
413  }
int used() const
Definition: qaudio_mac.cpp:121
Region acquireReadRegion(int size)
Definition: qaudio_mac_p.h:84
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
void releaseReadRegion(Region const &region)
Definition: qaudio_mac_p.h:97
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ flushBuffer

void QtMultimediaInternal::QAudioInputBuffer::flushBuffer ( )
inlineprivateslot

Definition at line 435 of file qaudioinput_mac_p.cpp.

436  {
437  flush();
438  }

◆ readBytes()

qint64 QtMultimediaInternal::QAudioInputBuffer::readBytes ( char *  data,
qint64  len 
)
inline

Definition at line 340 of file qaudioinput_mac_p.cpp.

341  {
342  bool wecan = true;
343  qint64 bytesCopied = 0;
344 
345  len -= len % m_maxPeriodSize;
346  while (wecan && bytesCopied < len) {
347  QAudioRingBuffer::Region region = m_buffer->acquireReadRegion(len - bytesCopied);
348 
349  if (region.second > 0) {
350  memcpy(data + bytesCopied, region.first, region.second);
351  bytesCopied += region.second;
352  }
353  else
354  wecan = false;
355 
356  m_buffer->releaseReadRegion(region);
357  }
358 
359  return bytesCopied;
360  }
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::QAudioInputBuffer::readyRead ( )
signal

◆ renderFromDevice()

qint64 QtMultimediaInternal::QAudioInputBuffer::renderFromDevice ( AudioUnit  audioUnit,
AudioUnitRenderActionFlags *  ioActionFlags,
const AudioTimeStamp *  inTimeStamp,
UInt32  inBusNumber,
UInt32  inNumberFrames 
)
inline

Definition at line 261 of file qaudioinput_mac_p.cpp.

266  {
267  const bool pullMode = m_device == 0;
268 
269  OSStatus err;
270  qint64 framesRendered = 0;
271 
273  err = AudioUnitRender(audioUnit,
274  ioActionFlags,
275  inTimeStamp,
276  inBusNumber,
277  inNumberFrames,
279 
280  if (m_audioConverter != 0) {
281  QAudioPacketFeeder feeder(m_inputBufferList);
282 
283  int copied = 0;
284  const int available = m_buffer->free();
285 
286  while (err == noErr && !feeder.empty()) {
288 
289  if (region.second == 0)
290  break;
291 
292  AudioBufferList output;
293  output.mNumberBuffers = 1;
294  output.mBuffers[0].mNumberChannels = 1;
295  output.mBuffers[0].mDataByteSize = region.second;
296  output.mBuffers[0].mData = region.first;
297 
298  UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket;
299  err = AudioConverterFillComplexBuffer(m_audioConverter,
301  &feeder,
302  &packetSize,
303  &output,
304  0);
305  region.second = output.mBuffers[0].mDataByteSize;
306  copied += region.second;
307 
308  m_buffer->releaseWriteRegion(region);
309  }
310 
311  framesRendered += copied / m_outputFormat.mBytesPerFrame;
312  }
313  else {
314  const int available = m_inputBufferList->bufferSize();
315  bool wecan = true;
316  int copied = 0;
317 
318  while (wecan && copied < available) {
319  QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied);
320 
321  if (region.second > 0) {
322  memcpy(region.first, m_inputBufferList->data() + copied, region.second);
323  copied += region.second;
324  }
325  else
326  wecan = false;
327 
328  m_buffer->releaseWriteRegion(region);
329  }
330 
331  framesRendered = copied / m_outputFormat.mBytesPerFrame;
332  }
333 
334  if (pullMode && framesRendered > 0)
335  emit readyRead();
336 
337  return framesRendered;
338  }
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
__int64 qint64
Definition: qglobal.h:942
signed long OSStatus
AudioStreamBasicDescription m_outputFormat
static OSStatus converterCallback(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
int free() const
Definition: qaudio_mac.cpp:126
Region acquireWriteRegion(int size)
Definition: qaudio_mac_p.h:104

◆ reset()

void QtMultimediaInternal::QAudioInputBuffer::reset ( )
inline

Definition at line 415 of file qaudioinput_mac_p.cpp.

◆ setFlushDevice()

void QtMultimediaInternal::QAudioInputBuffer::setFlushDevice ( QIODevice device)
inline

Definition at line 362 of file qaudioinput_mac_p.cpp.

363  {
364  if (m_device != device)
365  m_device = device;
366  }

◆ startFlushTimer()

void QtMultimediaInternal::QAudioInputBuffer::startFlushTimer ( )
inline

Definition at line 368 of file qaudioinput_mac_p.cpp.

369  {
370  if (m_device != 0) {
372  }
373  }
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

◆ stopFlushTimer()

void QtMultimediaInternal::QAudioInputBuffer::stopFlushTimer ( )
inline

Definition at line 375 of file qaudioinput_mac_p.cpp.

376  {
377  m_flushTimer->stop();
378  }
void stop()
Stops the timer.
Definition: qtimer.cpp:284

◆ used()

int QtMultimediaInternal::QAudioInputBuffer::used ( ) const
inline

Definition at line 426 of file qaudioinput_mac_p.cpp.

427  {
428  return m_buffer->used();
429  }
int used() const
Definition: qaudio_mac.cpp:121

Properties

◆ as_empty

const OSStatus QtMultimediaInternal::QAudioInputBuffer::as_empty = 'qtem'
staticprivate

Definition at line 452 of file qaudioinput_mac_p.cpp.

◆ m_audioConverter

AudioConverterRef QtMultimediaInternal::QAudioInputBuffer::m_audioConverter
private

Definition at line 448 of file qaudioinput_mac_p.cpp.

◆ m_buffer

QAudioRingBuffer* QtMultimediaInternal::QAudioInputBuffer::m_buffer
private

Definition at line 446 of file qaudioinput_mac_p.cpp.

◆ m_device

QIODevice* QtMultimediaInternal::QAudioInputBuffer::m_device
private

Definition at line 444 of file qaudioinput_mac_p.cpp.

◆ m_deviceError

bool QtMultimediaInternal::QAudioInputBuffer::m_deviceError
private

Definition at line 441 of file qaudioinput_mac_p.cpp.

◆ m_flushTimer

QTimer* QtMultimediaInternal::QAudioInputBuffer::m_flushTimer
private

Definition at line 445 of file qaudioinput_mac_p.cpp.

◆ m_inputBufferList

QAudioBufferList* QtMultimediaInternal::QAudioInputBuffer::m_inputBufferList
private

Definition at line 447 of file qaudioinput_mac_p.cpp.

◆ m_inputFormat

AudioStreamBasicDescription QtMultimediaInternal::QAudioInputBuffer::m_inputFormat
private

Definition at line 449 of file qaudioinput_mac_p.cpp.

◆ m_maxPeriodSize

int QtMultimediaInternal::QAudioInputBuffer::m_maxPeriodSize
private

Definition at line 442 of file qaudioinput_mac_p.cpp.

◆ m_outputFormat

AudioStreamBasicDescription QtMultimediaInternal::QAudioInputBuffer::m_outputFormat
private

Definition at line 450 of file qaudioinput_mac_p.cpp.

◆ m_periodTime

int QtMultimediaInternal::QAudioInputBuffer::m_periodTime
private

Definition at line 443 of file qaudioinput_mac_p.cpp.


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