From 0a6d409065a4c33559c36be75eb72103c2a61110 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 10 Sep 2015 21:48:18 -0400 Subject: [PATCH] tex update lock, VisualData"Re"Distributor --- src/CubicSDR.cpp | 2 +- src/CubicSDR.h | 4 ++-- src/process/VisualProcessor.h | 22 ++++++++++++++++++++++ src/visual/WaterfallCanvas.cpp | 6 +++++- src/visual/WaterfallCanvas.h | 1 + 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 56fcf70..fcb3b52 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -298,7 +298,7 @@ SpectrumVisualProcessor *CubicSDR::getDemodSpectrumProcessor() { return demodVisualThread->getProcessor(); } -VisualDataDistributor *CubicSDR::getSpectrumDistributor() { +VisualDataReDistributor *CubicSDR::getSpectrumDistributor() { return &spectrumDistributor; } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index 51640bd..fb84e99 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -60,7 +60,7 @@ public: ScopeVisualProcessor *getScopeProcessor(); SpectrumVisualProcessor *getSpectrumProcessor(); SpectrumVisualProcessor *getDemodSpectrumProcessor(); - VisualDataDistributor *getSpectrumDistributor(); + VisualDataReDistributor *getSpectrumDistributor(); DemodulatorThreadOutputQueue* getAudioVisualQueue(); DemodulatorThreadInputQueue* getIQVisualQueue(); @@ -111,7 +111,7 @@ private: ScopeVisualProcessor scopeProcessor; - VisualDataDistributor spectrumDistributor; + VisualDataReDistributor spectrumDistributor; std::thread *t_SDR; std::thread *t_PostSDR; diff --git a/src/process/VisualProcessor.h b/src/process/VisualProcessor.h index b7662bf..345224b 100644 --- a/src/process/VisualProcessor.h +++ b/src/process/VisualProcessor.h @@ -107,3 +107,25 @@ protected: } }; + +template +class VisualDataReDistributor : public VisualProcessor { +protected: + void process() { + while (!VisualProcessor::input->empty()) { + if (!VisualProcessor::isAnyOutputEmpty()) { + return; + } + OutputDataType *inp; + VisualProcessor::input->pop(inp); + + if (inp) { + OutputDataType *outp = buffers.getBuffer(); + (*outp) = (*inp); + inp->decRefCount(); + VisualProcessor::distribute(outp); + } + } + } + ReBuffer buffers; +}; diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index f4d4347..21d9e90 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -99,6 +99,7 @@ void WaterfallCanvas::processInputQueue() { if (linesPerSecond) { if (lpsIndex >= targetVis) { + tex_update.lock(); while (lpsIndex >= targetVis) { SpectrumVisualData *vData; if (!visualDataQueue.empty()) { @@ -115,6 +116,7 @@ void WaterfallCanvas::processInputQueue() { break; } } + tex_update.unlock(); } } if (processed) { @@ -235,7 +237,9 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glContext->BeginDraw(0,0,0); waterfallPanel.calcTransform(CubicVR::mat4::identity()); + tex_update.lock(); waterfallPanel.draw(); + tex_update.unlock(); std::vector &demods = wxGetApp().getDemodMgr().getDemodulators(); @@ -314,7 +318,7 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glContext->EndDraw(); - glFlush(); +// glFlush(); SwapBuffers(); } diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index 7887618..d4154a6 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -72,6 +72,7 @@ private: Timer gTimer, testTimer; double lpsIndex; bool preBuf; + std::mutex tex_update; // event table wxDECLARE_EVENT_TABLE(); };