git-svn-id: svn://elaine/murooma/trunk@323 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-12-28 16:49:29 +00:00
parent deca098bb4
commit b857de9f45
12 changed files with 69 additions and 449 deletions

16
Makefile Normal file
View file

@ -0,0 +1,16 @@
.PHONY: client server
all: client server
server:
$(MAKE) -C server
client:
$(MAKE) -C client
clean:
$(MAKE) clean -C client
$(MAKE) clean -C server
rm *~

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_workspace_file>
<Workspace title="Workspace">
<Project filename="SnapClient.cbp" />
<Project filename="SnapServer.cbp" />
</Workspace>
</CodeBlocks_workspace_file>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_workspace_layout_file>
<ActiveProject path="SnapServer.cbp" />
<PreferredTarget name="Release" />
</CodeBlocks_workspace_layout_file>

View file

@ -1,81 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="SnapServer" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/snapserver" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/snapserver" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add option="-Wno-unused-function" />
<Add directory="." />
</Compiler>
<Linker>
<Add library="pthread" />
<Add library="boost_system" />
<Add library="boost_program_options" />
<Add library="vorbis" />
<Add library="vorbisenc" />
<Add library="ogg" />
</Linker>
<Unit filename="common/headerMessage.h" />
<Unit filename="common/log.cpp" />
<Unit filename="common/log.h" />
<Unit filename="common/message.h" />
<Unit filename="common/pcmChunk.cpp" />
<Unit filename="common/pcmChunk.h" />
<Unit filename="common/queue.h" />
<Unit filename="common/requestMsg.h" />
<Unit filename="common/sampleFormat.cpp" />
<Unit filename="common/sampleFormat.h" />
<Unit filename="common/serverSettings.h" />
<Unit filename="common/signalHandler.h" />
<Unit filename="common/socketConnection.cpp" />
<Unit filename="common/socketConnection.h" />
<Unit filename="common/timeMsg.h" />
<Unit filename="common/timeUtils.h" />
<Unit filename="common/utils.h" />
<Unit filename="common/wireChunk.h" />
<Unit filename="server/controlServer.cpp" />
<Unit filename="server/controlServer.h" />
<Unit filename="server/encoder.h" />
<Unit filename="server/oggEncoder.cpp" />
<Unit filename="server/oggEncoder.h" />
<Unit filename="server/pcmEncoder.cpp" />
<Unit filename="server/pcmEncoder.h" />
<Unit filename="server/serverConnection.cpp" />
<Unit filename="server/serverConnection.h" />
<Unit filename="server/snapServer.cpp" />
<Unit filename="server/streamServer.cpp" />
<Unit filename="server/streamServer.h" />
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View file

@ -1,154 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Release" />
<File name="common/socketConnection.cpp" open="1" top="0" tabpos="21" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/sampleFormat.cpp" open="1" top="0" tabpos="17" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/streamServer.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/encoder.h" open="1" top="0" tabpos="19" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/headerMessage.h" open="1" top="0" tabpos="22" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/sampleFormat.h" open="1" top="1" tabpos="48" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/pcmChunk.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/serverConnection.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/requestMsg.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/wireChunk.h" open="1" top="0" tabpos="26" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/queue.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/log.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/oggEncoder.cpp" open="1" top="0" tabpos="27" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/signalHandler.h" open="1" top="0" tabpos="20" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/pcmEncoder.cpp" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/pcmEncoder.h" open="1" top="0" tabpos="23" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/pcmChunk.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/message.h" open="1" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/snapServer.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3872" topLine="138" />
</Cursor>
</File>
<File name="server/streamServer.cpp" open="1" top="0" tabpos="24" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/controlServer.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/timeUtils.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/socketConnection.h" open="1" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/log.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/serverConnection.h" open="1" top="0" tabpos="18" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/oggEncoder.h" open="1" top="0" tabpos="25" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="server/controlServer.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="215" topLine="0" />
</Cursor>
</File>
<File name="common/timeMsg.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/utils.h" open="1" top="0" tabpos="29" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/serverSettings.h" open="1" top="0" tabpos="28" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View file

@ -1,89 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="SnapClient" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/snapclient" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/snapclient" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add option="-Wno-unused-function" />
<Add directory="." />
</Compiler>
<Linker>
<Add library="vorbisenc" />
<Add library="vorbis" />
<Add library="ogg" />
<Add library="asound" />
<Add library="boost_program_options" />
<Add library="boost_system" />
<Add library="pthread" />
</Linker>
<Unit filename="client/clientConnection.cpp" />
<Unit filename="client/clientConnection.h" />
<Unit filename="client/controller.cpp" />
<Unit filename="client/controller.h" />
<Unit filename="client/decoder.h" />
<Unit filename="client/doubleBuffer.h" />
<Unit filename="client/oggDecoder.cpp" />
<Unit filename="client/oggDecoder.h" />
<Unit filename="client/pcmDecoder.cpp" />
<Unit filename="client/pcmDecoder.h" />
<Unit filename="client/player.cpp" />
<Unit filename="client/player.h" />
<Unit filename="client/snapClient.cpp" />
<Unit filename="client/stream.cpp" />
<Unit filename="client/stream.h" />
<Unit filename="client/streamClient.cpp" />
<Unit filename="client/streamClient.h" />
<Unit filename="client/timeProvider.cpp" />
<Unit filename="client/timeProvider.h" />
<Unit filename="common/headerMessage.h" />
<Unit filename="common/log.cpp" />
<Unit filename="common/log.h" />
<Unit filename="common/message.h" />
<Unit filename="common/pcmChunk.cpp" />
<Unit filename="common/pcmChunk.h" />
<Unit filename="common/queue.h" />
<Unit filename="common/requestMsg.h" />
<Unit filename="common/sampleFormat.cpp" />
<Unit filename="common/sampleFormat.h" />
<Unit filename="common/serverSettings.h" />
<Unit filename="common/signalHandler.h" />
<Unit filename="common/socketConnection.cpp" />
<Unit filename="common/socketConnection.h" />
<Unit filename="common/timeMsg.h" />
<Unit filename="common/timeUtils.h" />
<Unit filename="common/utils.h" />
<Unit filename="common/wireChunk.h" />
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View file

@ -1,104 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Release" />
<File name="client/oggDecoder.cpp" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/snapClient.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1639" topLine="49" />
</Cursor>
</File>
<File name="client/clientConnection.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/doubleBuffer.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/stream.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="767" topLine="20" />
</Cursor>
</File>
<File name="common/utils.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="707" topLine="26" />
</Cursor>
</File>
<File name="client/stream.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/clientConnection.cpp" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/timeProvider.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/streamClient.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/controller.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="common/timeUtils.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="999" topLine="39" />
</Cursor>
</File>
<File name="client/controller.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/player.h" open="1" top="1" tabpos="18" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/timeProvider.h" open="1" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/pcmDecoder.h" open="1" top="0" tabpos="17" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/decoder.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/oggDecoder.h" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/player.cpp" open="1" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="client/pcmDecoder.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View file

@ -109,6 +109,7 @@ void Player::start()
// snd_pcm_sw_params_set_stop_threshold(pcm_handle, swparams, frames);
snd_pcm_sw_params(pcm_handle, swparams);
active_ = true;
playerThread = new thread(&Player::worker, this);
}
@ -147,7 +148,7 @@ void Player::worker() {
unsigned int pcm;
snd_pcm_sframes_t framesAvail;
snd_pcm_sframes_t framesDelay;
active_ = true;
// active_ = true;
while (active_)
{
snd_pcm_avail_delay(pcm_handle, &framesAvail, &framesDelay);

View file

@ -132,6 +132,7 @@ void Controller::worker()
double latency = (reply->received.sec - reply->sent.sec) + (reply->received.usec - reply->sent.usec) / 1000000.;
TimeProvider::getInstance().setDiffToServer((reply->latency - latency) * 1000 / 2);
}
//throw std::exception();
}
}
catch (const std::exception& e)

View file

@ -98,6 +98,11 @@ int main (int argc, char *argv[])
daemonize();
std::clog << kLogNotice << "daemon started" << std::endl;
}
logS(kLogNotice) << "daemon started" << std::endl;
logD << "debug test" << std::endl;
logO << "out test" << std::endl;
logE << "error test" << std::endl;
log << "test" << std::endl;
PcmDevice pcmDevice = getPcmDevice(soundcard);
if (pcmDevice.idx == -1)

View file

@ -1,4 +1,6 @@
#include "log.h"
#include <iomanip>
#include <ctime>
Log::Log(std::string ident, int facility)
{
@ -10,20 +12,49 @@ Log::Log(std::string ident, int facility)
openlog(ident_, LOG_PID, facility_);
}
std::string Log::LogPriorityToString(const LogPriority& priority)
{
switch(priority)
{
case kLog: return "dbg";
case kOut: return "out";
case kErr: return "err";
default: return std::to_string((int)priority);
}
return std::to_string((int)priority);
}
std::string Log::Timestamp()
{
struct tm * dt;
char buffer [30];
std::time_t t = std::time(nullptr);
dt = localtime(&t);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H-%M-%S", dt);
return std::string(buffer);
}
int Log::sync()
{
if (buffer_.length())
{
if (priority_ == dbg)
std::cout << buffer_.c_str();
else
// if (priority_ == kLog)
// std::cout << Timestamp() << " [" << LogPriorityToString(priority_) << "] " << buffer_.c_str();
// else
{
std::cout << Timestamp() << " [" << LogPriorityToString((LogPriority)priority_) << "] " << buffer_.c_str();
syslog(priority_, "%s", buffer_.c_str());
}
buffer_.erase();
priority_ = LOG_DEBUG; // default to debug for each message
}
return 0;
}
int Log::overflow(int c)
{
if (c != EOF)
@ -40,8 +71,8 @@ int Log::overflow(int c)
std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority)
{
static_cast<Log *>(os.rdbuf())->priority_ = (int)log_priority;
if (log_priority == dbg)
os.flush();
// if (log_priority == dbg)
// os.flush();
return os;
}

View file

@ -5,7 +5,11 @@
#include <iostream>
#include <cstring>
#define logd std::clog << dbg
#define logD std::clog << kLog
#define logO std::clog << kOut
#define logE std::clog << kErr
#define logS(P) std::clog << P
#define log logO
enum LogPriority
{
@ -17,7 +21,7 @@ enum LogPriority
kLogNotice = LOG_NOTICE, // normal, but significant, condition
kLogInfo = LOG_INFO, // informational message
kLogDebug = LOG_DEBUG, // debug-level message
dbg
kLog, kOut, kErr
};
std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority);
@ -33,6 +37,8 @@ protected:
private:
friend std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority);
std::string Timestamp();
std::string LogPriorityToString(const LogPriority& priority);
std::string buffer_;
int facility_;
int priority_;