Skip to content

Commit

Permalink
Use timestamp of audio output
Browse files Browse the repository at this point in the history
  • Loading branch information
f1xpl committed Mar 25, 2018
1 parent b550104 commit 00acf0e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <memory>
#include <f1x/aasdk/Messenger/Timestamp.hpp>
#include <f1x/aasdk/Common/Data.hpp>

namespace f1x
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/f1x/openauto/autoapp/Projection/QtAudioOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/autoapp/Projection/AudioService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/autoapp/Projection/QtAudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>(buffer.cdata), buffer.size);
}
Expand Down
9 changes: 8 additions & 1 deletion src/autoapp/Projection/RtAudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>(buffer.cdata), buffer.size);

std::lock_guard<decltype(mutex_)> lock(mutex_);

if(dac_->isStreamOpen())
{
dac_->setStreamTime(timestamp / 1000000);
}
}

void RtAudioOutput::start()
Expand Down

0 comments on commit 00acf0e

Please sign in to comment.