added: send the tcp data in bitvis from a separate thread to improve the timing
This commit is contained in:
parent
c9c082271c
commit
59573d0601
3 changed files with 53 additions and 13 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
#include "util/timeutils.h"
|
#include "util/timeutils.h"
|
||||||
|
#include "util/lock.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
|
@ -163,6 +164,8 @@ void CBitVis::Setup()
|
||||||
m_mpdclient = new CMpdClient(m_mpdaddress, m_mpdport);
|
m_mpdclient = new CMpdClient(m_mpdaddress, m_mpdport);
|
||||||
m_mpdclient->StartThread();
|
m_mpdclient->StartThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StartThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBitVis::SetupSignals()
|
void CBitVis::SetupSignals()
|
||||||
|
@ -218,7 +221,7 @@ void CBitVis::SetupSignals()
|
||||||
LogError("sigpocmask: %s", GetErrno().c_str());
|
LogError("sigpocmask: %s", GetErrno().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBitVis::Process()
|
void CBitVis::Run()
|
||||||
{
|
{
|
||||||
int64_t lastconnect = GetTimeUs() - CONNECTINTERVAL - 1;
|
int64_t lastconnect = GetTimeUs() - CONNECTINTERVAL - 1;
|
||||||
|
|
||||||
|
@ -243,6 +246,7 @@ void CBitVis::Process()
|
||||||
while ((msg = m_jackclient.GetMessage()) != MsgNone)
|
while ((msg = m_jackclient.GetMessage()) != MsgNone)
|
||||||
LogDebug("got message %s from jack client", MsgToString(msg));
|
LogDebug("got message %s from jack client", MsgToString(msg));
|
||||||
|
|
||||||
|
CLock lock(m_condition);
|
||||||
if (!m_socket.IsOpen() && m_address && GetTimeUs() - lastconnect > CONNECTINTERVAL)
|
if (!m_socket.IsOpen() && m_address && GetTimeUs() - lastconnect > CONNECTINTERVAL)
|
||||||
{
|
{
|
||||||
if (m_socket.Open(m_address, m_port, 10000000) != SUCCESS)
|
if (m_socket.Open(m_address, m_port, 10000000) != SUCCESS)
|
||||||
|
@ -256,6 +260,7 @@ void CBitVis::Process()
|
||||||
}
|
}
|
||||||
didconnect = true;
|
didconnect = true;
|
||||||
}
|
}
|
||||||
|
lock.Leave();
|
||||||
|
|
||||||
if (didconnect)
|
if (didconnect)
|
||||||
lastconnect = GetTimeUs();
|
lastconnect = GetTimeUs();
|
||||||
|
@ -278,6 +283,34 @@ void CBitVis::Process()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBitVis::Process()
|
||||||
|
{
|
||||||
|
CLock lock(m_condition);
|
||||||
|
while (!m_stop)
|
||||||
|
{
|
||||||
|
while (!m_stop && m_data.empty())
|
||||||
|
m_condition.Wait();
|
||||||
|
|
||||||
|
if (m_data.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int64_t time = m_data.front().first;
|
||||||
|
CTcpData data = m_data.front().second;
|
||||||
|
m_data.pop_front();
|
||||||
|
|
||||||
|
lock.Leave();
|
||||||
|
USleep(time - GetTimeUs());
|
||||||
|
lock.Enter();
|
||||||
|
|
||||||
|
if (m_socket.IsOpen() && m_socket.Write(data) != SUCCESS)
|
||||||
|
{
|
||||||
|
LogError("%s", m_socket.GetError().c_str());
|
||||||
|
m_socket.Close();
|
||||||
|
}
|
||||||
|
m_debugwindow.DisplayFrame(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CBitVis::ProcessSignalfd()
|
void CBitVis::ProcessSignalfd()
|
||||||
{
|
{
|
||||||
signalfd_siginfo siginfo;
|
signalfd_siginfo siginfo;
|
||||||
|
@ -366,8 +399,11 @@ void CBitVis::ProcessAudio()
|
||||||
|
|
||||||
void CBitVis::Cleanup()
|
void CBitVis::Cleanup()
|
||||||
{
|
{
|
||||||
|
AsyncStopThread();
|
||||||
|
m_condition.Signal();
|
||||||
m_jackclient.Disconnect();
|
m_jackclient.Disconnect();
|
||||||
m_debugwindow.Disable();
|
m_debugwindow.Disable();
|
||||||
|
StopThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBitVis::SendData(int64_t time)
|
void CBitVis::SendData(int64_t time)
|
||||||
|
@ -487,15 +523,10 @@ void CBitVis::SendData(int64_t time)
|
||||||
memset(end, 0, sizeof(end));
|
memset(end, 0, sizeof(end));
|
||||||
data.SetData(end, sizeof(end), true);
|
data.SetData(end, sizeof(end), true);
|
||||||
|
|
||||||
USleep(time - GetTimeUs());
|
CLock lock(m_condition);
|
||||||
|
m_data.push_back(make_pair(time + 10000, data));
|
||||||
if (m_socket.IsOpen() && m_socket.Write(data) != SUCCESS)
|
lock.Leave();
|
||||||
{
|
m_condition.Signal();
|
||||||
LogError("%s", m_socket.GetError().c_str());
|
|
||||||
m_socket.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_debugwindow.DisplayFrame(data);
|
|
||||||
|
|
||||||
if (volume != m_displayvolume)
|
if (volume != m_displayvolume)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,23 +21,29 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "jackclient.h"
|
#include "jackclient.h"
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
#include "util/tcpsocket.h"
|
#include "util/tcpsocket.h"
|
||||||
#include "util/debugwindow.h"
|
#include "util/debugwindow.h"
|
||||||
|
#include "util/thread.h"
|
||||||
|
#include "util/condition.h"
|
||||||
#include "mpdclient.h"
|
#include "mpdclient.h"
|
||||||
|
|
||||||
class CBitVis
|
class CBitVis : public CThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CBitVis(int argc, char *argv[]);
|
CBitVis(int argc, char *argv[]);
|
||||||
~CBitVis();
|
~CBitVis();
|
||||||
|
|
||||||
void Setup();
|
void Setup();
|
||||||
void Process();
|
void Run();
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
|
|
||||||
|
virtual void Process();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_stop;
|
bool m_stop;
|
||||||
char* m_address;
|
char* m_address;
|
||||||
|
@ -66,6 +72,9 @@ class CBitVis
|
||||||
int64_t m_volumetime;
|
int64_t m_volumetime;
|
||||||
int m_displayvolume;
|
int m_displayvolume;
|
||||||
|
|
||||||
|
CCondition m_condition;
|
||||||
|
std::deque< std::pair<int64_t, CTcpData> > m_data;
|
||||||
|
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
int m_debugscale;
|
int m_debugscale;
|
||||||
CDebugWindow m_debugwindow;
|
CDebugWindow m_debugwindow;
|
||||||
|
|
|
@ -23,7 +23,7 @@ int main (int argc, char *argv[])
|
||||||
CBitVis bitvis(argc, argv);
|
CBitVis bitvis(argc, argv);
|
||||||
|
|
||||||
bitvis.Setup();
|
bitvis.Setup();
|
||||||
bitvis.Process();
|
bitvis.Run();
|
||||||
bitvis.Cleanup();
|
bitvis.Cleanup();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue