mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 11:06:16 +02:00
new messaging
git-svn-id: svn://elaine/murooma/trunk@230 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
a519d0f0dd
commit
04e872e036
15 changed files with 107 additions and 104 deletions
|
@ -2,8 +2,8 @@
|
|||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
#include "common/log.h"
|
||||
#include "oggDecoder.h"
|
||||
#include "pcmDecoder.h"
|
||||
//#include "oggDecoder.h"
|
||||
//#include "pcmDecoder.h"
|
||||
|
||||
|
||||
#define PCM_DEVICE "default"
|
||||
|
@ -47,7 +47,7 @@ void Receiver::stop()
|
|||
void Receiver::worker()
|
||||
{
|
||||
active_ = true;
|
||||
OggDecoder decoder;
|
||||
// OggDecoder decoder;
|
||||
while (active_)
|
||||
{
|
||||
try
|
||||
|
@ -62,18 +62,43 @@ void Receiver::worker()
|
|||
// std::clog << kLogNotice << "connected to " << ip << ":" << port << std::endl;
|
||||
while (true)
|
||||
{
|
||||
WireChunk* wireChunk = new WireChunk();
|
||||
socketRead(&s, wireChunk, Chunk::getHeaderSize());
|
||||
wireChunk->payload = (char*)malloc(wireChunk->length);
|
||||
socketRead(&s, wireChunk->payload, wireChunk->length);
|
||||
Chunk* chunk = new Chunk(stream_->format, wireChunk);
|
||||
BaseMessage baseMessage;
|
||||
boost::asio::streambuf b;
|
||||
// reserve 512 bytes in output sequence
|
||||
boost::asio::streambuf::mutable_buffers_type bufs = b.prepare(baseMessage.getSize());
|
||||
size_t read = s.receive(bufs);
|
||||
//cout << "read: " << read << "\n";
|
||||
// received data is "committed" from output sequence to input sequence
|
||||
b.commit(baseMessage.getSize());
|
||||
std::istream is(&b);
|
||||
baseMessage.read(is);
|
||||
// cout << "type: " << baseMessage.type << ", size: " << baseMessage.size << "\n";
|
||||
|
||||
read = 0;
|
||||
bufs = b.prepare(baseMessage.size);
|
||||
while (read < baseMessage.size)
|
||||
{
|
||||
size_t n = s.receive(bufs);
|
||||
b.commit(n);
|
||||
read += n;
|
||||
}
|
||||
// received data is "committed" from output sequence to input sequence
|
||||
// std::istream is(&b);
|
||||
if (baseMessage.type == message_type::payload)
|
||||
{
|
||||
PcmChunk* chunk = new PcmChunk(stream_->format, 0);
|
||||
chunk->read(is);
|
||||
//cout << "WireChunk length: " << chunk->payloadSize << ", Duration: " << chunk->getDuration() << ", sec: " << chunk->tv_sec << ", usec: " << chunk->tv_usec/1000 << ", type: " << chunk->type << "\n";
|
||||
stream_->addChunk(chunk);
|
||||
}
|
||||
|
||||
//cout << "WireChunk length: " << wireChunk->length << ", Duration: " << chunk->getDuration() << ", sec: " << wireChunk->tv_sec << ", usec: " << wireChunk->tv_usec/1000 << ", type: " << wireChunk->type << "\n";
|
||||
if (decoder.decode(chunk))
|
||||
/* if (decoder.decode(chunk))
|
||||
{
|
||||
//cout << "Duration: " << chunk->getDuration() << "\n";
|
||||
stream_->addChunk(chunk);
|
||||
}
|
||||
}
|
||||
*/ }
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue