mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 19:16:14 +02:00
message sub directory
git-svn-id: svn://elaine/murooma/trunk@287 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
e0a6ac9467
commit
983ded3d29
24 changed files with 137 additions and 137 deletions
|
@ -3,7 +3,7 @@ CC = /usr/bin/g++
|
||||||
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -g -D_REENTRANT -DVERSION=\"$(VERSION)\" -I..
|
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -g -D_REENTRANT -DVERSION=\"$(VERSION)\" -I..
|
||||||
LDFLAGS = -lrt -lpthread -lboost_system -lboost_program_options -lasound -logg -lvorbis -lvorbisenc
|
LDFLAGS = -lrt -lpthread -lboost_system -lboost_program_options -lasound -logg -lvorbis -lvorbisenc
|
||||||
|
|
||||||
OBJ = snapClient.o stream.o player.o clientConnection.o timeProvider.o oggDecoder.o pcmDecoder.o controller.o ../common/pcmChunk.o ../common/log.o ../common/sampleFormat.o
|
OBJ = snapClient.o stream.o player.o clientConnection.o timeProvider.o oggDecoder.o pcmDecoder.o controller.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o
|
||||||
BIN = snapclient
|
BIN = snapclient
|
||||||
|
|
||||||
all: client
|
all: client
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "common/message.h"
|
#include "message/message.h"
|
||||||
|
|
||||||
|
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
#include "pcmDecoder.h"
|
#include "pcmDecoder.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "timeProvider.h"
|
#include "timeProvider.h"
|
||||||
#include "common/serverSettings.h"
|
#include "message/serverSettings.h"
|
||||||
#include "common/timeMsg.h"
|
#include "message/timeMsg.h"
|
||||||
#include "common/requestMsg.h"
|
#include "message/requestMsg.h"
|
||||||
#include "common/ackMsg.h"
|
#include "message/ackMsg.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include "common/message.h"
|
#include "message/message.h"
|
||||||
#include "clientConnection.h"
|
#include "clientConnection.h"
|
||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef DECODER_H
|
#ifndef DECODER_H
|
||||||
#define DECODER_H
|
#define DECODER_H
|
||||||
#include "common/pcmChunk.h"
|
#include "message/pcmChunk.h"
|
||||||
#include "common/headerMessage.h"
|
#include "message/headerMessage.h"
|
||||||
|
|
||||||
class Decoder
|
class Decoder
|
||||||
{
|
{
|
||||||
|
|
|
@ -155,121 +155,121 @@ void Stream::resetBuffers()
|
||||||
|
|
||||||
bool Stream::getPlayerChunk(void* outputBuffer, double outputBufferDacTime, unsigned long framesPerBuffer, size_t timeout)
|
bool Stream::getPlayerChunk(void* outputBuffer, double outputBufferDacTime, unsigned long framesPerBuffer, size_t timeout)
|
||||||
{
|
{
|
||||||
//cout << "framesPerBuffer: " << framesPerBuffer << "\tms: " << framesPerBuffer*2 / PLAYER_CHUNK_MS_SIZE << "\t" << PLAYER_CHUNK_SIZE << "\n";
|
|
||||||
int msBuffer = framesPerBuffer / format_.msRate();
|
|
||||||
//cout << msBuffer << " ms, " << framesPerBuffer << "\t" << format_.rate/1000 << "\n";
|
|
||||||
int ticks = 0;
|
|
||||||
long currentTick = getTickCount();
|
|
||||||
if (lastTick == 0)
|
|
||||||
lastTick = currentTick;
|
|
||||||
ticks = currentTick - lastTick;
|
|
||||||
lastTick = currentTick;
|
|
||||||
|
|
||||||
int correction = 0;
|
|
||||||
if (sleep != 0)
|
|
||||||
{
|
|
||||||
resetBuffers();
|
|
||||||
if (sleep < -msBuffer/2)
|
|
||||||
{
|
|
||||||
cout << "Sleep " << sleep;
|
|
||||||
sleep = PcmChunk::getAge(getSilentPlayerChunk(outputBuffer, framesPerBuffer)) - bufferMs + outputBufferDacTime + TimeProvider::getInstance().getDiffToServerMs();
|
|
||||||
std::cerr << " after: " << sleep << ", chunks: " << chunks.size() << "\n";
|
|
||||||
// std::clog << kLogNotice << "sleep: " << sleep << std::endl;
|
|
||||||
// if (sleep > -msBuffer/2)
|
|
||||||
// sleep = 0;
|
|
||||||
if (sleep < -msBuffer/2)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (sleep > msBuffer/2)
|
|
||||||
{
|
|
||||||
/* cout << "Sleep " << sleep;
|
|
||||||
time_point_ms ms(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()));
|
|
||||||
ms -= std::chrono::milliseconds((long int)(bufferMs - outputBufferDacTime));
|
|
||||||
cout << "\nms: " << Chunk::getAge(ms) << "\t chunk: " << chunk->getAge() << "\n";
|
|
||||||
sleep = Chunk::getAge(seekTo(ms)) - bufferMs + outputBufferDacTime;
|
|
||||||
cout << " after: " << sleep << "\n";
|
|
||||||
*/
|
|
||||||
if (!chunk)
|
|
||||||
chunk = chunks.pop();
|
|
||||||
while (sleep > chunk->getDuration())
|
|
||||||
{
|
|
||||||
chunk = chunks.pop();
|
|
||||||
sleep = chunk->getAge() - bufferMs + outputBufferDacTime + TimeProvider::getInstance().getDiffToServerMs();
|
|
||||||
// cout << "chunk->getAge() > chunk->getDuration(): " << chunk->getAge() - bufferMs + outputBufferDacTime << " > " << chunk->getDuration() << ", chunks: " << chunks.size() << ", out: " << outputBufferDacTime << ", needed: " << msBuffer << ", sleep: " << sleep << "\n";
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
cout << "seek: " << PcmChunk::getAge(seek(sleep)) - bufferMs + outputBufferDacTime << "\n";
|
|
||||||
sleep = 0;
|
|
||||||
}
|
|
||||||
else if (sleep < 0)
|
|
||||||
{
|
|
||||||
++sleep;
|
|
||||||
correction = -1;
|
|
||||||
}
|
|
||||||
else if (sleep > 0)
|
|
||||||
{
|
|
||||||
--sleep;
|
|
||||||
correction = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long age(0);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//cout << "framesPerBuffer: " << framesPerBuffer << "\tms: " << framesPerBuffer*2 / PLAYER_CHUNK_MS_SIZE << "\t" << PLAYER_CHUNK_SIZE << "\n";
|
||||||
|
int msBuffer = framesPerBuffer / format_.msRate();
|
||||||
|
//cout << msBuffer << " ms, " << framesPerBuffer << "\t" << format_.rate/1000 << "\n";
|
||||||
|
int ticks = 0;
|
||||||
|
long currentTick = getTickCount();
|
||||||
|
if (lastTick == 0)
|
||||||
|
lastTick = currentTick;
|
||||||
|
ticks = currentTick - lastTick;
|
||||||
|
lastTick = currentTick;
|
||||||
|
|
||||||
|
int correction = 0;
|
||||||
|
if (sleep != 0)
|
||||||
|
{
|
||||||
|
resetBuffers();
|
||||||
|
if (sleep < -msBuffer/2)
|
||||||
|
{
|
||||||
|
cout << "Sleep " << sleep;
|
||||||
|
sleep = PcmChunk::getAge(getSilentPlayerChunk(outputBuffer, framesPerBuffer)) - bufferMs + outputBufferDacTime + TimeProvider::getInstance().getDiffToServerMs();
|
||||||
|
std::cerr << " after: " << sleep << ", chunks: " << chunks.size() << "\n";
|
||||||
|
// std::clog << kLogNotice << "sleep: " << sleep << std::endl;
|
||||||
|
// if (sleep > -msBuffer/2)
|
||||||
|
// sleep = 0;
|
||||||
|
if (sleep < -msBuffer/2)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (sleep > msBuffer/2)
|
||||||
|
{
|
||||||
|
/* cout << "Sleep " << sleep;
|
||||||
|
time_point_ms ms(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()));
|
||||||
|
ms -= std::chrono::milliseconds((long int)(bufferMs - outputBufferDacTime));
|
||||||
|
cout << "\nms: " << Chunk::getAge(ms) << "\t chunk: " << chunk->getAge() << "\n";
|
||||||
|
sleep = Chunk::getAge(seekTo(ms)) - bufferMs + outputBufferDacTime;
|
||||||
|
cout << " after: " << sleep << "\n";
|
||||||
|
*/
|
||||||
|
if (!chunk)
|
||||||
|
if (!chunks.try_pop(chunk, std::chrono::milliseconds(timeout)))
|
||||||
|
throw 0;
|
||||||
|
while (sleep > chunk->getDuration())
|
||||||
|
{
|
||||||
|
if (!chunks.try_pop(chunk, std::chrono::milliseconds(timeout)))
|
||||||
|
throw 0;
|
||||||
|
sleep = chunk->getAge() - bufferMs + outputBufferDacTime + TimeProvider::getInstance().getDiffToServerMs();
|
||||||
|
// cout << "chunk->getAge() > chunk->getDuration(): " << chunk->getAge() - bufferMs + outputBufferDacTime << " > " << chunk->getDuration() << ", chunks: " << chunks.size() << ", out: " << outputBufferDacTime << ", needed: " << msBuffer << ", sleep: " << sleep << "\n";
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
cout << "seek: " << PcmChunk::getAge(seek(sleep)) - bufferMs + outputBufferDacTime << "\n";
|
||||||
|
sleep = 0;
|
||||||
|
}
|
||||||
|
else if (sleep < 0)
|
||||||
|
{
|
||||||
|
++sleep;
|
||||||
|
correction = -1;
|
||||||
|
}
|
||||||
|
else if (sleep > 0)
|
||||||
|
{
|
||||||
|
--sleep;
|
||||||
|
correction = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long age(0);
|
||||||
age = PcmChunk::getAge(getNextPlayerChunk(outputBuffer, framesPerBuffer, timeout, correction)) - bufferMs + outputBufferDacTime + TimeProvider::getInstance().getDiffToServerMs();
|
age = PcmChunk::getAge(getNextPlayerChunk(outputBuffer, framesPerBuffer, timeout, correction)) - bufferMs + outputBufferDacTime + TimeProvider::getInstance().getDiffToServerMs();
|
||||||
|
|
||||||
|
|
||||||
|
if (sleep == 0)
|
||||||
|
{
|
||||||
|
if (buffer.full() && (abs(median) > 1))
|
||||||
|
{
|
||||||
|
cout << "pBuffer->full() && (abs(median) > 1): " << median << "\n";
|
||||||
|
sleep = median;
|
||||||
|
}
|
||||||
|
else if (shortBuffer.full() && (abs(shortMedian) > 5))
|
||||||
|
{
|
||||||
|
cout << "pShortBuffer->full() && (abs(shortMedian) > 5): " << shortMedian << "\n";
|
||||||
|
sleep = shortMedian;
|
||||||
|
}
|
||||||
|
else if (miniBuffer.full() && (abs(miniBuffer.median()) > 50))
|
||||||
|
{
|
||||||
|
cout << "pMiniBuffer->full() && (abs(pMiniBuffer->mean()) > 50): " << miniBuffer.median() << "\n";
|
||||||
|
sleep = miniBuffer.mean();
|
||||||
|
}
|
||||||
|
else if (abs(age) > 200)
|
||||||
|
{
|
||||||
|
cout << "age > 50: " << age << "\n";
|
||||||
|
sleep = age;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sleep != 0)
|
||||||
|
std::cerr << "Sleep: " << sleep << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
// std::cerr << "Chunk: " << age << "\t" << outputBufferDacTime*1000 << "\n";
|
||||||
|
if (ticks > 2)
|
||||||
|
{
|
||||||
|
// cout << age << "\n";
|
||||||
|
updateBuffers(age);
|
||||||
|
}
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (now != lastUpdate)
|
||||||
|
{
|
||||||
|
lastUpdate = now;
|
||||||
|
median = buffer.median();
|
||||||
|
shortMedian = shortBuffer.median();
|
||||||
|
std::cerr << "Chunk: " << age << "\t" << miniBuffer.median() << "\t" << shortMedian << "\t" << median << "\t" << buffer.size() << "\t" << /*cardBuffer << "\t" <<*/ outputBufferDacTime << "\n";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch(int e)
|
catch(int e)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (sleep == 0)
|
|
||||||
{
|
|
||||||
if (buffer.full() && (abs(median) > 1))
|
|
||||||
{
|
|
||||||
cout << "pBuffer->full() && (abs(median) > 1): " << median << "\n";
|
|
||||||
sleep = median;
|
|
||||||
}
|
|
||||||
else if (shortBuffer.full() && (abs(shortMedian) > 5))
|
|
||||||
{
|
|
||||||
cout << "pShortBuffer->full() && (abs(shortMedian) > 5): " << shortMedian << "\n";
|
|
||||||
sleep = shortMedian;
|
|
||||||
}
|
|
||||||
else if (miniBuffer.full() && (abs(miniBuffer.median()) > 50))
|
|
||||||
{
|
|
||||||
cout << "pMiniBuffer->full() && (abs(pMiniBuffer->mean()) > 50): " << miniBuffer.median() << "\n";
|
|
||||||
sleep = miniBuffer.mean();
|
|
||||||
}
|
|
||||||
else if (abs(age) > 200)
|
|
||||||
{
|
|
||||||
cout << "age > 50: " << age << "\n";
|
|
||||||
sleep = age;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sleep != 0)
|
|
||||||
std::cerr << "Sleep: " << sleep << "\n";
|
|
||||||
|
|
||||||
|
|
||||||
// std::cerr << "Chunk: " << age << "\t" << outputBufferDacTime*1000 << "\n";
|
|
||||||
if (ticks > 2)
|
|
||||||
{
|
|
||||||
// cout << age << "\n";
|
|
||||||
updateBuffers(age);
|
|
||||||
}
|
|
||||||
time_t now = time(NULL);
|
|
||||||
if (now != lastUpdate)
|
|
||||||
{
|
|
||||||
lastUpdate = now;
|
|
||||||
median = buffer.median();
|
|
||||||
shortMedian = shortBuffer.median();
|
|
||||||
std::cerr << "Chunk: " << age << "\t" << miniBuffer.median() << "\t" << shortMedian << "\t" << median << "\t" << buffer.size() << "\t" << /*cardBuffer << "\t" <<*/ outputBufferDacTime << "\n";
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "doubleBuffer.h"
|
#include "doubleBuffer.h"
|
||||||
#include "common/message.h"
|
#include "message/message.h"
|
||||||
#include "common/pcmChunk.h"
|
#include "message/pcmChunk.h"
|
||||||
|
#include "message/sampleFormat.h"
|
||||||
#include "common/timeUtils.h"
|
#include "common/timeUtils.h"
|
||||||
#include "common/queue.h"
|
#include "common/queue.h"
|
||||||
#include "common/sampleFormat.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Stream
|
class Stream
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef HEADER_MESSAGE_H
|
#ifndef HEADER_MESSAGE_H
|
||||||
#define HEADER_MESSAGE_H
|
#define HEADER_MESSAGE_H
|
||||||
|
|
||||||
#include "common/message.h"
|
#include "message.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef SERVER_SETTINGS_H
|
#ifndef SERVER_SETTINGS_H
|
||||||
#define SERVER_SETTINGS_H
|
#define SERVER_SETTINGS_H
|
||||||
|
|
||||||
#include "message.h"
|
#include "message/message.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ CC = /usr/bin/g++
|
||||||
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -D_REENTRANT -DVERSION=\"$(VERSION)\" -I..
|
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -D_REENTRANT -DVERSION=\"$(VERSION)\" -I..
|
||||||
LDFLAGS = -lrt -lpthread -lboost_system -lboost_program_options -lvorbis -lvorbisenc -logg
|
LDFLAGS = -lrt -lpthread -lboost_system -lboost_program_options -lvorbis -lvorbisenc -logg
|
||||||
|
|
||||||
OBJ = snapServer.o controlServer.o pcmEncoder.o oggEncoder.o serverSession.o ../common/log.o ../common/pcmChunk.o ../common/sampleFormat.o
|
OBJ = snapServer.o controlServer.o pcmEncoder.o oggEncoder.o serverSession.o ../common/log.o ../message/pcmChunk.o ../message/sampleFormat.o
|
||||||
BIN = snapserver
|
BIN = snapserver
|
||||||
|
|
||||||
all: server
|
all: server
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "controlServer.h"
|
#include "controlServer.h"
|
||||||
#include "common/timeMsg.h"
|
#include "message/timeMsg.h"
|
||||||
#include "common/ackMsg.h"
|
#include "message/ackMsg.h"
|
||||||
#include "common/requestMsg.h"
|
#include "message/requestMsg.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
#include "serverSession.h"
|
#include "serverSession.h"
|
||||||
#include "common/timeUtils.h"
|
#include "common/timeUtils.h"
|
||||||
#include "common/queue.h"
|
#include "common/queue.h"
|
||||||
#include "common/message.h"
|
#include "message/message.h"
|
||||||
#include "common/headerMessage.h"
|
#include "message/headerMessage.h"
|
||||||
#include "common/sampleFormat.h"
|
#include "message/sampleFormat.h"
|
||||||
#include "common/serverSettings.h"
|
#include "message/serverSettings.h"
|
||||||
|
|
||||||
|
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef ENCODER_H
|
#ifndef ENCODER_H
|
||||||
#define ENCODER_H
|
#define ENCODER_H
|
||||||
#include "common/pcmChunk.h"
|
#include "message/pcmChunk.h"
|
||||||
#include "common/headerMessage.h"
|
#include "message/headerMessage.h"
|
||||||
#include "common/sampleFormat.h"
|
#include "message/sampleFormat.h"
|
||||||
|
|
||||||
|
|
||||||
class Encoder
|
class Encoder
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "common/message.h"
|
#include "message/message.h"
|
||||||
#include "common/queue.h"
|
#include "common/queue.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
#include "common/timeUtils.h"
|
#include "common/timeUtils.h"
|
||||||
#include "common/signalHandler.h"
|
#include "common/signalHandler.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "common/sampleFormat.h"
|
#include "message/sampleFormat.h"
|
||||||
#include "../server/pcmEncoder.h"
|
#include "message/message.h"
|
||||||
#include "../server/oggEncoder.h"
|
#include "pcmEncoder.h"
|
||||||
#include "common/message.h"
|
#include "oggEncoder.h"
|
||||||
#include "controlServer.h"
|
#include "controlServer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue