From 00acf0ee3eebebb4f0ff8be28cd5722575445202 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Sun, 25 Mar 2018 15:15:03 +0200 Subject: [PATCH] Use timestamp of audio output --- .../openauto/autoapp/Projection/IAudioOutput.hpp | 3 ++- .../openauto/autoapp/Projection/QtAudioOutput.hpp | 2 +- .../openauto/autoapp/Projection/RtAudioOutput.hpp | 2 +- src/autoapp/Projection/AudioService.cpp | 14 +++++++------- src/autoapp/Projection/QtAudioOutput.cpp | 2 +- src/autoapp/Projection/RtAudioOutput.cpp | 9 ++++++++- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp b/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp index 383ad280..c41de312 100644 --- a/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include namespace f1x @@ -39,7 +40,7 @@ class IAudioOutput virtual ~IAudioOutput() = default; virtual bool open() = 0; - virtual void write(const aasdk::common::DataConstBuffer& buffer) = 0; + virtual void write(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer) = 0; virtual void start() = 0; virtual void stop() = 0; virtual void suspend() = 0; diff --git a/include/f1x/openauto/autoapp/Projection/QtAudioOutput.hpp b/include/f1x/openauto/autoapp/Projection/QtAudioOutput.hpp index e026a917..742dbf8c 100644 --- a/include/f1x/openauto/autoapp/Projection/QtAudioOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/QtAudioOutput.hpp @@ -39,7 +39,7 @@ class QtAudioOutput: public QObject, public IAudioOutput public: QtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate); bool open() override; - void write(const aasdk::common::DataConstBuffer& buffer) override; + void write(aasdk::messenger::Timestamp::ValueType, const aasdk::common::DataConstBuffer& buffer) override; void start() override; void stop() override; void suspend() override; diff --git a/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp b/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp index f3d69d5f..063d5b34 100644 --- a/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp @@ -36,7 +36,7 @@ class RtAudioOutput: public IAudioOutput public: RtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate); bool open() override; - void write(const aasdk::common::DataConstBuffer& buffer) override; + void write(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer) override; void start() override; void stop() override; void suspend() override; diff --git a/src/autoapp/Projection/AudioService.cpp b/src/autoapp/Projection/AudioService.cpp index d5d2da59..d09001fe 100644 --- a/src/autoapp/Projection/AudioService.cpp +++ b/src/autoapp/Projection/AudioService.cpp @@ -152,14 +152,9 @@ void AudioService::onAVChannelStopIndication(const aasdk::proto::messages::AVCha channel_->receive(this->shared_from_this()); } -void AudioService::onAVMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType, const aasdk::common::DataConstBuffer& buffer) +void AudioService::onAVMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer) { - this->onAVMediaIndication(buffer); -} - -void AudioService::onAVMediaIndication(const aasdk::common::DataConstBuffer& buffer) -{ - audioOutput_->write(buffer); + audioOutput_->write(timestamp, buffer); aasdk::proto::messages::AVMediaAckIndication indication; indication.set_session(session_); indication.set_value(1); @@ -170,6 +165,11 @@ void AudioService::onAVMediaIndication(const aasdk::common::DataConstBuffer& buf channel_->receive(this->shared_from_this()); } +void AudioService::onAVMediaIndication(const aasdk::common::DataConstBuffer& buffer) +{ + this->onAVMediaWithTimestampIndication(0, buffer); +} + void AudioService::onChannelError(const aasdk::error::Error& e) { OPENAUTO_LOG(error) << "[AudioService] channel error: " << e.what() diff --git a/src/autoapp/Projection/QtAudioOutput.cpp b/src/autoapp/Projection/QtAudioOutput.cpp index 959ca1fa..dff8049e 100644 --- a/src/autoapp/Projection/QtAudioOutput.cpp +++ b/src/autoapp/Projection/QtAudioOutput.cpp @@ -58,7 +58,7 @@ bool QtAudioOutput::open() return audioBuffer_.open(QIODevice::ReadWrite); } -void QtAudioOutput::write(const aasdk::common::DataConstBuffer& buffer) +void QtAudioOutput::write(aasdk::messenger::Timestamp::ValueType, const aasdk::common::DataConstBuffer& buffer) { audioBuffer_.write(reinterpret_cast(buffer.cdata), buffer.size); } diff --git a/src/autoapp/Projection/RtAudioOutput.cpp b/src/autoapp/Projection/RtAudioOutput.cpp index a8a43ef2..b03ef595 100644 --- a/src/autoapp/Projection/RtAudioOutput.cpp +++ b/src/autoapp/Projection/RtAudioOutput.cpp @@ -70,9 +70,16 @@ bool RtAudioOutput::open() return false; } -void RtAudioOutput::write(const aasdk::common::DataConstBuffer& buffer) +void RtAudioOutput::write(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer) { audioBuffer_.write(reinterpret_cast(buffer.cdata), buffer.size); + + std::lock_guard lock(mutex_); + + if(dac_->isStreamOpen()) + { + dac_->setStreamTime(timestamp / 1000000); + } } void RtAudioOutput::start()