286 totalFrames = 0; |
286 totalFrames = 0; |
287 audioBuffer = 0; |
287 audioBuffer = 0; |
288 internalBufferSize = default_buffer_size; |
288 internalBufferSize = default_buffer_size; |
289 clockFrequency = AudioGetHostClockFrequency() / 1000; |
289 clockFrequency = AudioGetHostClockFrequency() / 1000; |
290 errorCode = QAudio::NoError; |
290 errorCode = QAudio::NoError; |
291 stateCode = QAudio::StopState; |
291 stateCode = QAudio::StoppedState; |
292 audioThreadState = Stopped; |
292 audioThreadState = Stopped; |
293 |
293 |
294 intervalTimer = new QTimer(this); |
294 intervalTimer = new QTimer(this); |
295 intervalTimer->setInterval(1000); |
295 intervalTimer->setInterval(1000); |
296 connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); |
296 connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); |
466 } |
466 } |
467 |
467 |
468 void QAudioOutputPrivate::stop() |
468 void QAudioOutputPrivate::stop() |
469 { |
469 { |
470 QMutexLocker lock(&mutex); |
470 QMutexLocker lock(&mutex); |
471 if (stateCode != QAudio::StopState) { |
471 if (stateCode != QAudio::StoppedState) { |
472 audioThreadDrain(); |
472 audioThreadDrain(); |
473 |
473 |
474 stateCode = QAudio::StopState; |
474 stateCode = QAudio::StoppedState; |
475 errorCode = QAudio::NoError; |
475 errorCode = QAudio::NoError; |
476 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
476 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
477 } |
477 } |
478 } |
478 } |
479 |
479 |
480 void QAudioOutputPrivate::reset() |
480 void QAudioOutputPrivate::reset() |
481 { |
481 { |
482 QMutexLocker lock(&mutex); |
482 QMutexLocker lock(&mutex); |
483 if (stateCode != QAudio::StopState) { |
483 if (stateCode != QAudio::StoppedState) { |
484 audioThreadStop(); |
484 audioThreadStop(); |
485 |
485 |
486 stateCode = QAudio::StopState; |
486 stateCode = QAudio::StoppedState; |
487 errorCode = QAudio::NoError; |
487 errorCode = QAudio::NoError; |
488 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
488 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
489 } |
489 } |
490 } |
490 } |
491 |
491 |
493 { |
493 { |
494 QMutexLocker lock(&mutex); |
494 QMutexLocker lock(&mutex); |
495 if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { |
495 if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { |
496 audioThreadStop(); |
496 audioThreadStop(); |
497 |
497 |
498 stateCode = QAudio::SuspendState; |
498 stateCode = QAudio::SuspendedState; |
499 errorCode = QAudio::NoError; |
499 errorCode = QAudio::NoError; |
500 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
500 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
501 } |
501 } |
502 } |
502 } |
503 |
503 |
504 void QAudioOutputPrivate::resume() |
504 void QAudioOutputPrivate::resume() |
505 { |
505 { |
506 QMutexLocker lock(&mutex); |
506 QMutexLocker lock(&mutex); |
507 if (stateCode == QAudio::SuspendState) { |
507 if (stateCode == QAudio::SuspendedState) { |
508 audioThreadStart(); |
508 audioThreadStart(); |
509 |
509 |
510 stateCode = QAudio::ActiveState; |
510 stateCode = QAudio::ActiveState; |
511 errorCode = QAudio::NoError; |
511 errorCode = QAudio::NoError; |
512 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
512 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
523 return periodSizeBytes; |
523 return periodSizeBytes; |
524 } |
524 } |
525 |
525 |
526 void QAudioOutputPrivate::setBufferSize(int bs) |
526 void QAudioOutputPrivate::setBufferSize(int bs) |
527 { |
527 { |
528 if (stateCode == QAudio::StopState) |
528 if (stateCode == QAudio::StoppedState) |
529 internalBufferSize = bs; |
529 internalBufferSize = bs; |
530 } |
530 } |
531 |
531 |
532 int QAudioOutputPrivate::bufferSize() const |
532 int QAudioOutputPrivate::bufferSize() const |
533 { |
533 { |
542 int QAudioOutputPrivate::notifyInterval() const |
542 int QAudioOutputPrivate::notifyInterval() const |
543 { |
543 { |
544 return intervalTimer->interval(); |
544 return intervalTimer->interval(); |
545 } |
545 } |
546 |
546 |
547 qint64 QAudioOutputPrivate::totalTime() const |
547 qint64 QAudioOutputPrivate::processedUSecs() const |
548 { |
548 { |
549 return totalFrames * 1000000 / audioFormat.frequency(); |
549 return totalFrames * 1000000 / audioFormat.frequency(); |
550 } |
550 } |
551 |
551 |
552 qint64 QAudioOutputPrivate::clock() const |
552 qint64 QAudioOutputPrivate::elapsedUSecs() const |
553 { |
553 { |
554 if (stateCode == QAudio::StopState) |
554 if (stateCode == QAudio::StoppedState) |
555 return 0; |
555 return 0; |
556 |
556 |
557 return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); |
557 return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); |
558 } |
558 } |
559 |
559 |
612 QMutexLocker lock(&mutex); |
612 QMutexLocker lock(&mutex); |
613 if (stateCode == QAudio::ActiveState) { |
613 if (stateCode == QAudio::ActiveState) { |
614 audioDeviceStop(); |
614 audioDeviceStop(); |
615 |
615 |
616 errorCode = QAudio::IOError; |
616 errorCode = QAudio::IOError; |
617 stateCode = QAudio::StopState; |
617 stateCode = QAudio::StoppedState; |
618 QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); |
618 QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); |
619 } |
619 } |
620 } |
620 } |
621 |
621 |
622 void QAudioOutputPrivate::startTimers() |
622 void QAudioOutputPrivate::startTimers() |