mirror of https://github.com/f1xpl/openauto.git
Use resume/suspend from audio output to preserve audio resources
parent
640c0c6dc9
commit
88aeb591b4
|
@ -42,23 +42,27 @@ public:
|
|||
void write(const aasdk::common::DataConstBuffer& buffer) override;
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void suspend() override;
|
||||
uint32_t getSampleSize() const override;
|
||||
uint32_t getChannelCount() const override;
|
||||
uint32_t getSampleRate() const override;
|
||||
|
||||
signals:
|
||||
void startPlayback();
|
||||
void suspendPlayback();
|
||||
void stopPlayback();
|
||||
|
||||
protected slots:
|
||||
void createAudioOutput();
|
||||
void onStartPlayback();
|
||||
void onSuspendPlayback();
|
||||
void onStopPlayback();
|
||||
|
||||
private:
|
||||
QAudioFormat audioFormat_;
|
||||
SequentialBuffer audioBuffer_;
|
||||
std::unique_ptr<QAudioOutput> audioOutput_;
|
||||
bool playbackStarted_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
virtual void write(const aasdk::common::DataConstBuffer& buffer) = 0;
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void suspend() = 0;
|
||||
virtual uint32_t getSampleSize() const = 0;
|
||||
virtual uint32_t getChannelCount() const = 0;
|
||||
virtual uint32_t getSampleRate() const = 0;
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace projection
|
|||
{
|
||||
|
||||
AudioOutput::AudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate)
|
||||
: playbackStarted_(false)
|
||||
{
|
||||
audioFormat_.setChannelCount(channelCount);
|
||||
audioFormat_.setSampleRate(sampleRate);
|
||||
|
@ -40,6 +41,7 @@ AudioOutput::AudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sa
|
|||
|
||||
this->moveToThread(QApplication::instance()->thread());
|
||||
connect(this, &AudioOutput::startPlayback, this, &AudioOutput::onStartPlayback);
|
||||
connect(this, &AudioOutput::suspendPlayback, this, &AudioOutput::onSuspendPlayback);
|
||||
connect(this, &AudioOutput::stopPlayback, this, &AudioOutput::onStopPlayback);
|
||||
|
||||
QMetaObject::invokeMethod(this, "createAudioOutput", Qt::BlockingQueuedConnection);
|
||||
|
@ -74,6 +76,11 @@ void AudioOutput::stop()
|
|||
emit stopPlayback();
|
||||
}
|
||||
|
||||
void AudioOutput::suspend()
|
||||
{
|
||||
emit suspendPlayback();
|
||||
}
|
||||
|
||||
uint32_t AudioOutput::getSampleSize() const
|
||||
{
|
||||
return audioFormat_.sampleSize();
|
||||
|
@ -91,14 +98,31 @@ uint32_t AudioOutput::getSampleRate() const
|
|||
|
||||
void AudioOutput::onStartPlayback()
|
||||
{
|
||||
audioOutput_->start(&audioBuffer_);
|
||||
if(!playbackStarted_)
|
||||
{
|
||||
audioOutput_->start(&audioBuffer_);
|
||||
playbackStarted_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
audioOutput_->resume();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioOutput::onStopPlayback()
|
||||
void AudioOutput::onSuspendPlayback()
|
||||
{
|
||||
audioOutput_->suspend();
|
||||
}
|
||||
|
||||
void AudioOutput::onStopPlayback()
|
||||
{
|
||||
if(playbackStarted_)
|
||||
{
|
||||
audioOutput_->stop();
|
||||
playbackStarted_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ void AudioService::onAVChannelStopIndication(const aasdk::proto::messages::AVCha
|
|||
<< ", channel: " << aasdk::messenger::channelIdToString(channel_->getId())
|
||||
<< ", session: " << session_;
|
||||
session_ = -1;
|
||||
audioOutput_->stop();
|
||||
audioOutput_->suspend();
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue