Make open of sequential bufer thread safe

pull/10/head
michal.szwaj 2018-02-17 22:28:25 +01:00
parent 42bcd1892c
commit 0aa318cc97
4 changed files with 8 additions and 9 deletions

View File

@ -57,7 +57,6 @@ private:
SequentialBuffer videoBuffer_;
std::unique_ptr<QVideoWidget> videoWidget_;
std::unique_ptr<QMediaPlayer> mediaPlayer_;
std::mutex mutex_;
};
}

View File

@ -44,6 +44,7 @@ public:
bool reset() override;
bool canReadLine() const override;
qint64 bytesAvailable() const override;
bool open(OpenMode mode) override;
protected:
qint64 readData(char *data, qint64 maxlen) override;

View File

@ -49,8 +49,6 @@ void QtVideoOutput::createVideoOutput()
bool QtVideoOutput::open()
{
std::lock_guard<decltype(mutex_)> lock(mutex_);
return videoBuffer_.open(QIODevice::ReadWrite);
}
@ -67,15 +65,11 @@ void QtVideoOutput::stop()
void QtVideoOutput::write(uint64_t, const aasdk::common::DataConstBuffer& buffer)
{
std::lock_guard<decltype(mutex_)> lock(mutex_);
videoBuffer_.write(reinterpret_cast<const char*>(buffer.cdata), buffer.size);
}
void QtVideoOutput::onStartPlayback()
{
std::lock_guard<decltype(mutex_)> lock(mutex_);
videoWidget_->setAspectRatioMode(Qt::IgnoreAspectRatio);
videoWidget_->setFocus();
videoWidget_->setWindowFlags(Qt::WindowStaysOnTopHint);
@ -89,8 +83,6 @@ void QtVideoOutput::onStartPlayback()
void QtVideoOutput::onStopPlayback()
{
std::lock_guard<decltype(mutex_)> lock(mutex_);
videoWidget_->hide();
mediaPlayer_->stop();
}

View File

@ -37,6 +37,13 @@ bool SequentialBuffer::isSequential() const
return true;
}
bool SequentialBuffer::open(OpenMode mode)
{
std::lock_guard<decltype(mutex_)> lock(mutex_);
return QIODevice::open(mode);
}
qint64 SequentialBuffer::readData(char *data, qint64 maxlen)
{
std::lock_guard<decltype(mutex_)> lock(mutex_);