mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-12 08:36:43 +02:00
xxx
git-svn-id: svn://elaine/murooma/trunk@231 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
04e872e036
commit
f43e1ec18c
7 changed files with 45 additions and 63 deletions
|
@ -3,7 +3,7 @@ CC = /usr/bin/g++
|
|||
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\" -I..
|
||||
LDFLAGS = -lrt -lpthread -lboost_system -lboost_program_options -lasound -logg -lvorbis -lvorbisenc
|
||||
|
||||
OBJ = snapClient.o stream.o player.o receiver.o ../common/message.o ../common/log.o ../common/sampleFormat.o
|
||||
OBJ = snapClient.o stream.o player.o receiver.o oggDecoder.o pcmDecoder.o ../common/message.o ../common/log.o ../common/sampleFormat.o
|
||||
BIN = snapclient
|
||||
|
||||
all: client
|
||||
|
|
|
@ -7,6 +7,7 @@ class Decoder
|
|||
public:
|
||||
Decoder();
|
||||
virtual bool decode(PcmChunk* chunk) = 0;
|
||||
virtual bool setHeader(HeaderMessage* chunk) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ OggDecoder::~OggDecoder()
|
|||
}
|
||||
|
||||
|
||||
bool OggDecoder::decodePayload(PcmChunk* chunk)
|
||||
bool OggDecoder::decode(PcmChunk* chunk)
|
||||
{
|
||||
|
||||
/* grab some data at the head of the stream. We want the first page
|
||||
|
@ -116,14 +116,13 @@ bool OggDecoder::decodePayload(PcmChunk* chunk)
|
|||
}
|
||||
|
||||
|
||||
bool OggDecoder::decodeHeader(HeaderMessage* chunk)
|
||||
bool OggDecoder::setHeader(HeaderMessage* chunk)
|
||||
{
|
||||
bytes = chunk->payloadSize;
|
||||
buffer=ogg_sync_buffer(&oy, bytes);
|
||||
memcpy(buffer, chunk->payload, bytes);
|
||||
ogg_sync_wrote(&oy,bytes);
|
||||
|
||||
cout << "Decode header\n";
|
||||
if(ogg_sync_pageout(&oy,&og)!=1)
|
||||
{
|
||||
fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
|
||||
|
@ -131,7 +130,6 @@ bool OggDecoder::decodeHeader(HeaderMessage* chunk)
|
|||
}
|
||||
|
||||
ogg_stream_init(&os,ogg_page_serialno(&og));
|
||||
cout << "2" << endl;
|
||||
|
||||
vorbis_info_init(&vi);
|
||||
vorbis_comment_init(&vc);
|
||||
|
@ -152,7 +150,6 @@ cout << "2" << endl;
|
|||
fprintf(stderr,"This Ogg bitstream does not contain Vorbis audio data.\n");
|
||||
return false;
|
||||
}
|
||||
cout << "3" << endl;
|
||||
|
||||
|
||||
int i(0);
|
||||
|
@ -161,51 +158,39 @@ cout << "3" << endl;
|
|||
while(i<2)
|
||||
{
|
||||
int result=ogg_sync_pageout(&oy,&og);
|
||||
cout << result << endl;
|
||||
if(result==0)
|
||||
break; /* Need more data */
|
||||
/* Don't complain about missing or corrupt data yet. We'll
|
||||
catch it at the packet output phase */
|
||||
if(result==1)
|
||||
{
|
||||
cout << "a" << endl;
|
||||
ogg_stream_pagein(&os,&og); /* we can ignore any errors here as they'll also become apparent at packetout */
|
||||
while(i<2)
|
||||
{
|
||||
cout << "b" << endl;
|
||||
result=ogg_stream_packetout(&os,&op);
|
||||
if(result==0)
|
||||
break;
|
||||
if(result<0)
|
||||
{
|
||||
/* Uh oh; data at some point was corrupted or missing!
|
||||
We can't tolerate that in a header. Die. */
|
||||
fprintf(stderr,"Corrupt secondary header. Exiting.\n");
|
||||
return false;
|
||||
result=ogg_stream_packetout(&os,&op);
|
||||
if(result==0)
|
||||
break;
|
||||
if(result<0)
|
||||
{
|
||||
/* Uh oh; data at some point was corrupted or missing!
|
||||
We can't tolerate that in a header. Die. */
|
||||
fprintf(stderr,"Corrupt secondary header. Exiting.\n");
|
||||
return false;
|
||||
}
|
||||
result=vorbis_synthesis_headerin(&vi,&vc,&op);
|
||||
if(result<0)
|
||||
{
|
||||
fprintf(stderr,"Corrupt secondary header. Exiting.\n");
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result=vorbis_synthesis_headerin(&vi,&vc,&op);
|
||||
if(result<0)
|
||||
{
|
||||
fprintf(stderr,"Corrupt secondary header. Exiting.\n");
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* no harm in not checking before adding more */
|
||||
// buffer=ogg_sync_buffer(&oy,wireChunk->length);
|
||||
// bytes=fread(buffer,1,4096,stdin);
|
||||
// if(bytes==0 && i<2){
|
||||
// fprintf(stderr,"End of file before finding all Vorbis headers!\n");
|
||||
// exit(1);
|
||||
// }
|
||||
// ogg_sync_wrote(&oy,bytes);
|
||||
}
|
||||
|
||||
/* Throw the comments plus a few lines about the bitstream we're decoding */
|
||||
cout << "5" << endl;
|
||||
char **ptr=vc.user_comments;
|
||||
char **ptr=vc.user_comments;
|
||||
while(*ptr)
|
||||
{
|
||||
fprintf(stderr,"%s\n",*ptr);
|
||||
|
@ -213,8 +198,6 @@ cout << "5" << endl;
|
|||
}
|
||||
fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate);
|
||||
fprintf(stderr,"Encoded by: %s\n\n",vc.vendor);
|
||||
|
||||
cout << "6" << endl;
|
||||
|
||||
/* OK, got and parsed all three headers. Initialize the Vorbis
|
||||
packet->PCM decoder. */
|
||||
|
@ -228,14 +211,4 @@ cout << "6" << endl;
|
|||
}
|
||||
|
||||
|
||||
bool OggDecoder::decode(BaseMessage* chunk)
|
||||
{
|
||||
if (chunk->getType() == chunk_type::payload)
|
||||
return decodePayload(chunk);
|
||||
else if (chunk->getType() == chunk_type::header)
|
||||
return decodeHeader(chunk);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ class OggDecoder
|
|||
public:
|
||||
OggDecoder();
|
||||
virtual ~OggDecoder();
|
||||
virtual bool decode(BaseMessage* chunk);
|
||||
virtual bool decode(PcmChunk* chunk);
|
||||
virtual bool setHeader(HeaderMessage* chunk);
|
||||
|
||||
private:
|
||||
bool decodePayload(PcmChunk* chunk);
|
||||
bool decodeHeader(HeaderMessage* chunk);
|
||||
|
||||
ogg_sync_state oy; /* sync and verify incoming physical bitstream */
|
||||
ogg_stream_state os; /* take physical pages, weld into a logical
|
||||
|
|
|
@ -5,7 +5,7 @@ PcmDecoder::PcmDecoder()
|
|||
}
|
||||
|
||||
|
||||
bool PcmDecoder::decode(BaseMessage* chunk)
|
||||
bool PcmDecoder::decode(PcmChunk* chunk)
|
||||
{
|
||||
/* WireChunk* wireChunk = chunk->wireChunk;
|
||||
for (size_t n=0; n<wireChunk->length; ++n)
|
||||
|
@ -15,5 +15,11 @@ bool PcmDecoder::decode(BaseMessage* chunk)
|
|||
}
|
||||
|
||||
|
||||
bool PcmDecoder::setHeader(HeaderMessage* chunk)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ class PcmDecoder
|
|||
{
|
||||
public:
|
||||
PcmDecoder();
|
||||
virtual bool decode(BaseMessage* chunk);
|
||||
virtual bool decode(PcmChunk* chunk);
|
||||
virtual bool setHeader(HeaderMessage* chunk);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
@ -58,7 +58,7 @@ void Receiver::worker()
|
|||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
setsockopt(s.native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
|
||||
OggDecoder decoder;
|
||||
// std::clog << kLogNotice << "connected to " << ip << ":" << port << std::endl;
|
||||
while (true)
|
||||
{
|
||||
|
@ -88,17 +88,18 @@ void Receiver::worker()
|
|||
{
|
||||
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: " << chunk->payloadSize;
|
||||
if (decoder.decode(chunk))
|
||||
stream_->addChunk(chunk);
|
||||
//cout << ", decoded: " << chunk->payloadSize << ", Duration: " << chunk->getDuration() << ", sec: " << chunk->tv_sec << ", usec: " << chunk->tv_usec/1000 << ", type: " << chunk->type << "\n";
|
||||
}
|
||||
|
||||
//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))
|
||||
else if (baseMessage.type == message_type::header)
|
||||
{
|
||||
//cout << "Duration: " << chunk->getDuration() << "\n";
|
||||
stream_->addChunk(chunk);
|
||||
HeaderMessage* chunk = new HeaderMessage();
|
||||
chunk->read(is);
|
||||
decoder.setHeader(chunk);
|
||||
}
|
||||
*/ }
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue