mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-30 10:47:12 +02:00
123
git-svn-id: svn://elaine/murooma/trunk@38 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
59ea32bc23
commit
503f3ed83c
1 changed files with 37 additions and 16 deletions
53
server.cpp
53
server.cpp
|
@ -13,17 +13,26 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "chunk.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const int size(1024);
|
|
||||||
|
|
||||||
struct Chunk
|
void addMs(timeval& tv, int ms)
|
||||||
{
|
{
|
||||||
long tv_sec;
|
tv.tv_usec += ms*1000;
|
||||||
long tv_usec;
|
tv.tv_sec += (tv.tv_usec / 1000000);
|
||||||
char payload[size];
|
tv.tv_usec %= 1000000;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int diff_ms(const timeval& t1, const timeval& t2)
|
||||||
|
{
|
||||||
|
return (((t1.tv_sec - t2.tv_sec) * 1000000) +
|
||||||
|
(t1.tv_usec - t2.tv_usec))/1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
// Prepare our context and publisher
|
// Prepare our context and publisher
|
||||||
|
@ -34,26 +43,38 @@ int main () {
|
||||||
// Initialize random number generator
|
// Initialize random number generator
|
||||||
size_t idx(0);
|
size_t idx(0);
|
||||||
char c;//[2];
|
char c;//[2];
|
||||||
Chunk chunk;
|
Chunk chunk;
|
||||||
|
timeval ts;
|
||||||
|
ts.tv_sec = 0;
|
||||||
|
ts.tv_usec = 0;
|
||||||
|
timeval last;
|
||||||
|
gettimeofday(&last, NULL);
|
||||||
|
last.tv_sec -= 1000;
|
||||||
while (!cin.get(c).eof())
|
while (!cin.get(c).eof())
|
||||||
{
|
{
|
||||||
timeval ts;
|
|
||||||
if (idx == 0)
|
|
||||||
{
|
|
||||||
gettimeofday(&ts, NULL);
|
|
||||||
chunk.tv_sec = ts.tv_sec;
|
|
||||||
chunk.tv_usec = ts.tv_usec;
|
|
||||||
}
|
|
||||||
// read(fd, &msg[0], size);
|
// read(fd, &msg[0], size);
|
||||||
chunk.payload[idx++] = c;
|
chunk.payload[idx++] = c;
|
||||||
if (idx == size)
|
if (idx == SIZE)
|
||||||
{
|
{
|
||||||
|
timeval now;
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
if (diff_ms(now, last) > 200)
|
||||||
|
ts = now;
|
||||||
|
last = now;
|
||||||
|
|
||||||
|
// if (ts.tv_sec == 0)
|
||||||
|
// ts = now;
|
||||||
|
// else if (diff_ms(now, ts) > 1000)
|
||||||
|
// ts = now;
|
||||||
|
|
||||||
|
chunk.tv_sec = ts.tv_sec;
|
||||||
|
chunk.tv_usec = ts.tv_usec;
|
||||||
zmq::message_t message(sizeof(Chunk));
|
zmq::message_t message(sizeof(Chunk));
|
||||||
chunk.tv_usec = 3;
|
|
||||||
memcpy(message.data(), &chunk, sizeof(Chunk));
|
memcpy(message.data(), &chunk, sizeof(Chunk));
|
||||||
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c);
|
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c);
|
||||||
// message.data()[0] = c;
|
// message.data()[0] = c;
|
||||||
publisher.send(message);
|
publisher.send(message);
|
||||||
|
addMs(ts, MS);
|
||||||
idx = 0;
|
idx = 0;
|
||||||
// msg[0] = '0';
|
// msg[0] = '0';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue