code blocks

git-svn-id: svn://elaine/murooma/trunk@271 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-09-17 06:05:07 +00:00
parent 2cf7855261
commit 16ef1ae634
53 changed files with 2074 additions and 1759 deletions

View file

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

View file

@ -32,13 +32,47 @@
<Add option="-std=c++11" /> <Add option="-std=c++11" />
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add option="-Wno-unused-function" />
<Add directory="." /> <Add directory="." />
</Compiler> </Compiler>
<Linker> <Linker>
<Add library="pthread" />
<Add library="boost_system" /> <Add library="boost_system" />
<Add library="boost_program_options" /> <Add library="boost_program_options" />
<Add library="vorbis" />
<Add library="vorbisenc" />
<Add library="ogg" />
</Linker> </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/snapServer.cpp" />
<Unit filename="server/streamServer.cpp" />
<Unit filename="server/streamServer.h" />
<Extensions> <Extensions>
<code_completion /> <code_completion />
<debugger /> <debugger />

View file

@ -1,9 +1,154 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<ActiveTarget name="Debug" /> <ActiveTarget name="Release" />
<File name="server/snapServer.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="server/controlServer.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="4599" topLine="167" /> <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/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="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/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.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="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="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="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/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/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/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/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="server/oggEncoder.cpp" open="1" top="0" tabpos="28" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="168" />
</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="common/sampleFormat.h" open="1" top="0" tabpos="30" 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="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/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/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="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/serverSettings.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="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="82" />
</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/utils.h" open="1" top="0" tabpos="30" 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/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/snapServer.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4569" topLine="114" />
</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> </Cursor>
</File> </File>
</CodeBlocks_layout_file> </CodeBlocks_layout_file>

View file

@ -32,19 +32,55 @@
<Add option="-std=c++11" /> <Add option="-std=c++11" />
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add option="-Wno-unused-function" />
<Add directory="." /> <Add directory="." />
</Compiler> </Compiler>
<Linker> <Linker>
<Add library="pthread" /> <Add library="vorbisenc" />
<Add library="portaudio" /> <Add library="vorbis" />
<Add library="ogg" />
<Add library="asound" />
<Add library="boost_program_options" />
<Add library="boost_system" /> <Add library="boost_system" />
<Add library="pthread" />
</Linker> </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/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/snapClient.cpp" />
<Unit filename="client/stream.cpp" /> <Unit filename="client/stream.cpp" />
<Unit filename="client/stream.h" /> <Unit filename="client/stream.h" />
<Unit filename="common/chunk.cpp" /> <Unit filename="client/streamClient.cpp" />
<Unit filename="common/chunk.h" /> <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> <Extensions>
<code_completion /> <code_completion />
<debugger /> <debugger />

View file

@ -1,19 +1,64 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<ActiveTarget name="Debug" /> <ActiveTarget name="Release" />
<File name="client/stream.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <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="767" topLine="7" />
</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> <Cursor>
<Cursor1 position="0" topLine="0" /> <Cursor1 position="0" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="common/chunk.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="client/clientConnection.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="720" topLine="10" /> <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>
<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/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/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/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="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="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/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/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> </Cursor>
</File> </File>
<File name="client/doubleBuffer.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="client/doubleBuffer.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -21,9 +66,39 @@
<Cursor1 position="0" topLine="0" /> <Cursor1 position="0" topLine="0" />
</Cursor> </Cursor>
</File> </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/snapClient.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="client/snapClient.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="2862" topLine="20" /> <Cursor1 position="1647" 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/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/stream.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="767" topLine="20" />
</Cursor>
</File>
<File name="client/player.h" open="1" top="0" tabpos="18" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="11" />
</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> </Cursor>
</File> </File>
</CodeBlocks_layout_file> </CodeBlocks_layout_file>

View file

@ -32,7 +32,7 @@ void ClientConnection::worker()
{ {
{ {
// std::unique_lock<std::mutex> mlock(mutex_); // std::unique_lock<std::mutex> mlock(mutex_);
cout << "connecting\n"; cout << "connecting\n";
socket.reset(new tcp::socket(io_service)); socket.reset(new tcp::socket(io_service));
struct timeval tv; struct timeval tv;
tv.tv_sec = 5; tv.tv_sec = 5;
@ -40,12 +40,15 @@ cout << "connecting\n";
setsockopt(socket->native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); setsockopt(socket->native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
socket->connect(*iterator); socket->connect(*iterator);
connected_ = true; connected_ = true;
cout << "connected\n"; cout << "connected\n";
std::clog << kLogNotice << "connected\n";// to " << ip << ":" << port << std::endl; std::clog << kLogNotice << "connected\n";// to " << ip << ":" << port << std::endl;
} }
while(active_) while(active_)
{ {
cout << ".";
getNextMessage(); getNextMessage();
cout << "|";
cout.flush();
} }
} }
catch (const std::exception& e) catch (const std::exception& e)

View file

@ -46,7 +46,8 @@ bool OggDecoder::decode(PcmChunk* chunk)
if (result==0) if (result==0)
break; /* need more data */ break; /* need more data */
if(result<0) if(result<0)
{ /* missing or corrupt data at this page position */ {
/* missing or corrupt data at this page position */
fprintf(stderr,"Corrupt or missing data in bitstream; continuing...\n"); fprintf(stderr,"Corrupt or missing data in bitstream; continuing...\n");
continue; continue;
} }
@ -81,11 +82,11 @@ bool OggDecoder::decode(PcmChunk* chunk)
//cout << "samples: " << samples << ", convsize: " << convsize << "\n"; //cout << "samples: " << samples << ", convsize: " << convsize << "\n";
/* convert floats to 16 bit signed ints (host order) and /* convert floats to 16 bit signed ints (host order) and
interleave */ interleave */
for(int i=0;i<vi.channels;i++) for(int i=0; i<vi.channels; i++)
{ {
ogg_int16_t *ptr=convbuffer+i; ogg_int16_t *ptr=convbuffer+i;
float *mono=pcm[i]; float *mono=pcm[i];
for(int j=0;j<bout;j++) for(int j=0; j<bout; j++)
{ {
int val=floor(mono[j]*32767.f+.5f); int val=floor(mono[j]*32767.f+.5f);
/* might as well guard against clipping */ /* might as well guard against clipping */

View file

@ -7,10 +7,10 @@ PcmDecoder::PcmDecoder() : Decoder()
bool PcmDecoder::decode(PcmChunk* chunk) bool PcmDecoder::decode(PcmChunk* chunk)
{ {
/* WireChunk* wireChunk = chunk->wireChunk; /* WireChunk* wireChunk = chunk->wireChunk;
for (size_t n=0; n<wireChunk->length; ++n) for (size_t n=0; n<wireChunk->length; ++n)
wireChunk->payload[n] *= 1; wireChunk->payload[n] *= 1;
*/ */
return true; return true;
} }

View file

@ -28,11 +28,11 @@ void Player::start()
if ((pcm = snd_pcm_open(&pcm_handle, PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0)) < 0) if ((pcm = snd_pcm_open(&pcm_handle, PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
cout << "ERROR: Can't open " << PCM_DEVICE << " PCM device. " << snd_strerror(pcm) << "\n"; cout << "ERROR: Can't open " << PCM_DEVICE << " PCM device. " << snd_strerror(pcm) << "\n";
/* struct snd_pcm_playback_info_t pinfo; /* struct snd_pcm_playback_info_t pinfo;
if ( (pcm = snd_pcm_playback_info( pcm_handle, &pinfo )) < 0 ) if ( (pcm = snd_pcm_playback_info( pcm_handle, &pinfo )) < 0 )
fprintf( stderr, "Error: playback info error: %s\n", snd_strerror( err ) ); fprintf( stderr, "Error: playback info error: %s\n", snd_strerror( err ) );
printf("buffer: '%d'\n", pinfo.buffer_size); printf("buffer: '%d'\n", pinfo.buffer_size);
*/ */
/* Allocate parameters object and fill it with default values*/ /* Allocate parameters object and fill it with default values*/
snd_pcm_hw_params_alloca(&params); snd_pcm_hw_params_alloca(&params);
@ -131,10 +131,13 @@ void Player::worker()
if (stream_->getPlayerChunk(buff, (float)delay / stream_->format.msRate(), frames, 500)) if (stream_->getPlayerChunk(buff, (float)delay / stream_->format.msRate(), frames, 500))
{ {
if ((pcm = snd_pcm_writei(pcm_handle, buff, frames)) == -EPIPE) { if ((pcm = snd_pcm_writei(pcm_handle, buff, frames)) == -EPIPE)
{
printf("XRUN.\n"); printf("XRUN.\n");
snd_pcm_prepare(pcm_handle); snd_pcm_prepare(pcm_handle);
} else if (pcm < 0) { }
else if (pcm < 0)
{
printf("ERROR. Can't write to PCM device. %s\n", snd_strerror(pcm)); printf("ERROR. Can't write to PCM device. %s\n", snd_strerror(pcm));
} }
} }

View file

@ -156,7 +156,7 @@ 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"; //cout << "framesPerBuffer: " << framesPerBuffer << "\tms: " << framesPerBuffer*2 / PLAYER_CHUNK_MS_SIZE << "\t" << PLAYER_CHUNK_SIZE << "\n";
int msBuffer = framesPerBuffer / format_.msRate(); int msBuffer = framesPerBuffer / format_.msRate();
//cout << msBuffer << " ms, " << framesPerBuffer << "\t" << format_.rate/1000 << "\n"; //cout << msBuffer << " ms, " << framesPerBuffer << "\t" << format_.rate/1000 << "\n";
int ticks = 0; int ticks = 0;
long currentTick = getTickCount(); long currentTick = getTickCount();
@ -182,13 +182,13 @@ int msBuffer = framesPerBuffer / format_.msRate();
} }
else if (sleep > msBuffer/2) else if (sleep > msBuffer/2)
{ {
/* cout << "Sleep " << sleep; /* cout << "Sleep " << sleep;
time_point_ms ms(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch())); 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)); ms -= std::chrono::milliseconds((long int)(bufferMs - outputBufferDacTime));
cout << "\nms: " << Chunk::getAge(ms) << "\t chunk: " << chunk->getAge() << "\n"; cout << "\nms: " << Chunk::getAge(ms) << "\t chunk: " << chunk->getAge() << "\n";
sleep = Chunk::getAge(seekTo(ms)) - bufferMs + outputBufferDacTime; sleep = Chunk::getAge(seekTo(ms)) - bufferMs + outputBufferDacTime;
cout << " after: " << sleep << "\n"; cout << " after: " << sleep << "\n";
*/ */
if (!chunk) if (!chunk)
chunk = chunks.pop(); chunk = chunks.pop();
while (sleep > chunk->getDuration()) while (sleep > chunk->getDuration())

View file

@ -5,7 +5,7 @@
class TimeProvider class TimeProvider
{ {
public: public:
static TimeProvider& getInstance() static TimeProvider& getInstance()
{ {
static TimeProvider instance; static TimeProvider instance;
@ -16,7 +16,7 @@ class TimeProvider
long getDiffToServer(); long getDiffToServer();
long getDiffToServerMs(); long getDiffToServerMs();
private: private:
TimeProvider(); // Constructor? (the {} brackets) are needed here. TimeProvider(); // Constructor? (the {} brackets) are needed here.
// Dont forget to declare these two. You want to make sure they // Dont forget to declare these two. You want to make sure they
// are unaccessable otherwise you may accidently get copies of // are unaccessable otherwise you may accidently get copies of

View file

@ -1,6 +1,7 @@
#include "log.h" #include "log.h"
Log::Log(std::string ident, int facility) { Log::Log(std::string ident, int facility)
{
facility_ = facility; facility_ = facility;
priority_ = LOG_DEBUG; priority_ = LOG_DEBUG;
strncpy(ident_, ident.c_str(), sizeof(ident_)); strncpy(ident_, ident.c_str(), sizeof(ident_));
@ -9,8 +10,10 @@ Log::Log(std::string ident, int facility) {
openlog(ident_, LOG_PID, facility_); openlog(ident_, LOG_PID, facility_);
} }
int Log::sync() { int Log::sync()
if (buffer_.length()) { {
if (buffer_.length())
{
if (priority_ == dbg) if (priority_ == dbg)
std::cout << buffer_.c_str(); std::cout << buffer_.c_str();
else else
@ -21,16 +24,21 @@ int Log::sync() {
return 0; return 0;
} }
int Log::overflow(int c) { int Log::overflow(int c)
if (c != EOF) { {
if (c != EOF)
{
buffer_ += static_cast<char>(c); buffer_ += static_cast<char>(c);
} else { }
else
{
sync(); sync();
} }
return c; return c;
} }
std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority) { std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority)
{
static_cast<Log *>(os.rdbuf())->priority_ = (int)log_priority; static_cast<Log *>(os.rdbuf())->priority_ = (int)log_priority;
if (log_priority == dbg) if (log_priority == dbg)
os.flush(); os.flush();

View file

@ -7,7 +7,8 @@
#define logd std::clog << dbg #define logd std::clog << dbg
enum LogPriority { enum LogPriority
{
kLogEmerg = LOG_EMERG, // system is unusable kLogEmerg = LOG_EMERG, // system is unusable
kLogAlert = LOG_ALERT, // action must be taken immediately kLogAlert = LOG_ALERT, // action must be taken immediately
kLogCrit = LOG_CRIT, // critical conditions kLogCrit = LOG_CRIT, // critical conditions
@ -21,7 +22,8 @@ enum LogPriority {
std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority); std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority);
class Log : public std::basic_streambuf<char, std::char_traits<char> > { class Log : public std::basic_streambuf<char, std::char_traits<char> >
{
public: public:
explicit Log(std::string ident, int facility); explicit Log(std::string ident, int facility);

View file

@ -55,15 +55,15 @@ struct tv
int32_t sec; int32_t sec;
int32_t usec; int32_t usec;
/* /*
5.3 - 6.2 = -0.9 5.3 - 6.2 = -0.9
-1 -1
0.1 0.1
5.3 - 6.4 = -1.1 5.3 - 6.4 = -1.1
-1 -1
-0.1 -0.1
*/ */
//(timeMsg.received.sec - timeMsg.sent.sec) * 1000000 + (timeMsg.received.usec - timeMsg.sent.usec) //(timeMsg.received.sec - timeMsg.sent.sec) * 1000000 + (timeMsg.received.usec - timeMsg.sent.usec)
tv operator-(const tv& other) tv operator-(const tv& other)
{ {
@ -79,12 +79,12 @@ struct tv
{ {
result.usec *= -1; result.usec *= -1;
} }
/* else if (result.usec >= 1000000) /* else if (result.usec >= 1000000)
{ {
result.usec -= 1000000; result.usec -= 1000000;
result.sec += 1; result.sec += 1;
} }
*/ return result; */ return result;
} }
}; };

View file

@ -82,7 +82,7 @@ public:
Queue(const Queue&) = delete; // disable copying Queue(const Queue&) = delete; // disable copying
Queue& operator=(const Queue&) = delete; // disable assignment Queue& operator=(const Queue&) = delete; // disable assignment
private: private:
std::queue<T> queue_; std::queue<T> queue_;
mutable std::mutex mutex_; mutable std::mutex mutex_;
std::condition_variable cond_; std::condition_variable cond_;

View file

@ -22,7 +22,10 @@ public:
uint16_t sampleSize; uint16_t sampleSize;
uint16_t frameSize; uint16_t frameSize;
float msRate() const { return (float)rate/1000.f; } float msRate() const
{
return (float)rate/1000.f;
}
virtual void read(std::istream& stream) virtual void read(std::istream& stream)
{ {
@ -48,13 +51,13 @@ protected:
stream.write(reinterpret_cast<char *>(&frameSize), sizeof(uint16_t)); stream.write(reinterpret_cast<char *>(&frameSize), sizeof(uint16_t));
} }
/*private: /*private:
uint16_t rate_; uint16_t rate_;
uint16_t bits_; uint16_t bits_;
uint16_t channels_; uint16_t channels_;
uint16_t bytes_; uint16_t bytes_;
uint16_t frameSize_; uint16_t frameSize_;
*/ */
}; };

View file

@ -6,9 +6,11 @@
extern bool g_terminated; extern bool g_terminated;
void signal_handler(int sig) { void signal_handler(int sig)
{
switch(sig) { switch(sig)
{
case SIGHUP: case SIGHUP:
syslog(LOG_WARNING, "Received SIGHUP signal."); syslog(LOG_WARNING, "Received SIGHUP signal.");
break; break;

View file

@ -13,19 +13,22 @@
// trim from start // trim from start
static inline std::string &ltrim(std::string &s) { static inline std::string &ltrim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s; return s;
} }
// trim from end // trim from end
static inline std::string &rtrim(std::string &s) { static inline std::string &rtrim(std::string &s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s; return s;
} }
// trim from both ends // trim from both ends
static inline std::string &trim(std::string &s) { static inline std::string &trim(std::string &s)
{
return ltrim(rtrim(s)); return ltrim(rtrim(s));
} }

View file

@ -31,7 +31,7 @@ double OggEncoder::encode(PcmChunk* chunk)
float **buffer=vorbis_analysis_buffer(&vd, bytes); float **buffer=vorbis_analysis_buffer(&vd, bytes);
/* uninterleave samples */ /* uninterleave samples */
for(int i=0;i<bytes;i++) for(int i=0; i<bytes; i++)
{ {
buffer[0][i]=((chunk->payload[i*4+1]<<8)| buffer[0][i]=((chunk->payload[i*4+1]<<8)|
(0x00ff&(int)chunk->payload[i*4]))/32768.f; (0x00ff&(int)chunk->payload[i*4]))/32768.f;

View file

@ -7,10 +7,10 @@ PcmEncoder::PcmEncoder(const SampleFormat& format) : Encoder(format)
double PcmEncoder::encode(PcmChunk* chunk) double PcmEncoder::encode(PcmChunk* chunk)
{ {
/* WireChunk* wireChunk = chunk->wireChunk; /* WireChunk* wireChunk = chunk->wireChunk;
for (size_t n=0; n<wireChunk->length; ++n) for (size_t n=0; n<wireChunk->length; ++n)
wireChunk->payload[n] *= 1; wireChunk->payload[n] *= 1;
*/ */
return chunk->getDuration(); return chunk->getDuration();
} }

View file

@ -68,7 +68,7 @@ int main(int argc, char* argv[])
mkfifo(fifoName.c_str(), 0777); mkfifo(fifoName.c_str(), 0777);
SampleFormat format(sampleFormat); SampleFormat format(sampleFormat);
size_t duration = 50; size_t duration = 50;
//size_t chunkSize = duration*format.rate*format.frameSize / 1000; //size_t chunkSize = duration*format.rate*format.frameSize / 1000;
std::auto_ptr<Encoder> encoder; std::auto_ptr<Encoder> encoder;
if (codec == "ogg") if (codec == "ogg")