git-svn-id: svn://elaine/murooma/trunk@231 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-09-04 21:36:23 +00:00
parent 04e872e036
commit f43e1ec18c
7 changed files with 45 additions and 63 deletions

View file

@ -3,7 +3,7 @@ CC = /usr/bin/g++
CFLAGS = -std=gnu++0x -Wall -Wno-unused-function -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\" -I.. 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 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 BIN = snapclient
all: client all: client

View file

@ -7,6 +7,7 @@ class Decoder
public: public:
Decoder(); Decoder();
virtual bool decode(PcmChunk* chunk) = 0; virtual bool decode(PcmChunk* chunk) = 0;
virtual bool setHeader(HeaderMessage* chunk) = 0;
}; };

View file

@ -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 /* 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; bytes = chunk->payloadSize;
buffer=ogg_sync_buffer(&oy, bytes); buffer=ogg_sync_buffer(&oy, bytes);
memcpy(buffer, chunk->payload, bytes); memcpy(buffer, chunk->payload, bytes);
ogg_sync_wrote(&oy,bytes); ogg_sync_wrote(&oy,bytes);
cout << "Decode header\n";
if(ogg_sync_pageout(&oy,&og)!=1) if(ogg_sync_pageout(&oy,&og)!=1)
{ {
fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); 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)); ogg_stream_init(&os,ogg_page_serialno(&og));
cout << "2" << endl;
vorbis_info_init(&vi); vorbis_info_init(&vi);
vorbis_comment_init(&vc); vorbis_comment_init(&vc);
@ -152,7 +150,6 @@ cout << "2" << endl;
fprintf(stderr,"This Ogg bitstream does not contain Vorbis audio data.\n"); fprintf(stderr,"This Ogg bitstream does not contain Vorbis audio data.\n");
return false; return false;
} }
cout << "3" << endl;
int i(0); int i(0);
@ -161,18 +158,15 @@ cout << "3" << endl;
while(i<2) while(i<2)
{ {
int result=ogg_sync_pageout(&oy,&og); int result=ogg_sync_pageout(&oy,&og);
cout << result << endl;
if(result==0) if(result==0)
break; /* Need more data */ break; /* Need more data */
/* Don't complain about missing or corrupt data yet. We'll /* Don't complain about missing or corrupt data yet. We'll
catch it at the packet output phase */ catch it at the packet output phase */
if(result==1) 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 */ ogg_stream_pagein(&os,&og); /* we can ignore any errors here as they'll also become apparent at packetout */
while(i<2) while(i<2)
{ {
cout << "b" << endl;
result=ogg_stream_packetout(&os,&op); result=ogg_stream_packetout(&os,&op);
if(result==0) if(result==0)
break; break;
@ -193,18 +187,9 @@ cout << result << endl;
} }
} }
} }
/* 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 */ /* 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) while(*ptr)
{ {
@ -214,8 +199,6 @@ cout << "5" << endl;
fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate); fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate);
fprintf(stderr,"Encoded by: %s\n\n",vc.vendor); fprintf(stderr,"Encoded by: %s\n\n",vc.vendor);
cout << "6" << endl;
/* OK, got and parsed all three headers. Initialize the Vorbis /* OK, got and parsed all three headers. Initialize the Vorbis
packet->PCM decoder. */ packet->PCM decoder. */
if(vorbis_synthesis_init(&vd,&vi)==0) /* central decode state */ if(vorbis_synthesis_init(&vd,&vi)==0) /* central decode state */
@ -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;
}

View file

@ -9,11 +9,11 @@ class OggDecoder
public: public:
OggDecoder(); OggDecoder();
virtual ~OggDecoder(); virtual ~OggDecoder();
virtual bool decode(BaseMessage* chunk); virtual bool decode(PcmChunk* chunk);
virtual bool setHeader(HeaderMessage* chunk);
private: private:
bool decodePayload(PcmChunk* chunk); bool decodePayload(PcmChunk* chunk);
bool decodeHeader(HeaderMessage* chunk);
ogg_sync_state oy; /* sync and verify incoming physical bitstream */ ogg_sync_state oy; /* sync and verify incoming physical bitstream */
ogg_stream_state os; /* take physical pages, weld into a logical ogg_stream_state os; /* take physical pages, weld into a logical

View file

@ -5,7 +5,7 @@ PcmDecoder::PcmDecoder()
} }
bool PcmDecoder::decode(BaseMessage* 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)
@ -15,5 +15,11 @@ bool PcmDecoder::decode(BaseMessage* chunk)
} }
bool PcmDecoder::setHeader(HeaderMessage* chunk)
{
return true;
}

View file

@ -7,7 +7,8 @@ class PcmDecoder
{ {
public: public:
PcmDecoder(); PcmDecoder();
virtual bool decode(BaseMessage* chunk); virtual bool decode(PcmChunk* chunk);
virtual bool setHeader(HeaderMessage* chunk);
}; };

View file

@ -2,8 +2,8 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <iostream> #include <iostream>
#include "common/log.h" #include "common/log.h"
//#include "oggDecoder.h" #include "oggDecoder.h"
//#include "pcmDecoder.h" #include "pcmDecoder.h"
#define PCM_DEVICE "default" #define PCM_DEVICE "default"
@ -58,7 +58,7 @@ void Receiver::worker()
tv.tv_sec = 5; tv.tv_sec = 5;
tv.tv_usec = 0; tv.tv_usec = 0;
setsockopt(s.native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); setsockopt(s.native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
OggDecoder decoder;
// std::clog << kLogNotice << "connected to " << ip << ":" << port << std::endl; // std::clog << kLogNotice << "connected to " << ip << ":" << port << std::endl;
while (true) while (true)
{ {
@ -88,17 +88,18 @@ void Receiver::worker()
{ {
PcmChunk* chunk = new PcmChunk(stream_->format, 0); PcmChunk* chunk = new PcmChunk(stream_->format, 0);
chunk->read(is); chunk->read(is);
//cout << "WireChunk length: " << chunk->payloadSize << ", Duration: " << chunk->getDuration() << ", sec: " << chunk->tv_sec << ", usec: " << chunk->tv_usec/1000 << ", type: " << chunk->type << "\n"; //cout << "WireChunk length: " << chunk->payloadSize;
if (decoder.decode(chunk))
stream_->addChunk(chunk); stream_->addChunk(chunk);
//cout << ", decoded: " << chunk->payloadSize << ", Duration: " << chunk->getDuration() << ", sec: " << chunk->tv_sec << ", usec: " << chunk->tv_usec/1000 << ", type: " << chunk->type << "\n";
} }
else if (baseMessage.type == message_type::header)
//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))
{ {
//cout << "Duration: " << chunk->getDuration() << "\n"; HeaderMessage* chunk = new HeaderMessage();
stream_->addChunk(chunk); chunk->read(is);
decoder.setHeader(chunk);
}
} }
*/ }
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {