16 #include <vorbis/vorbisfile.h>
19 #ifndef OGG_BUFFER_SIZE
20 #define OGG_BUFFER_SIZE 4096*2*2
30 throw FileOpenException(
"Error opening file \"" + path +
"\"");
31 oggData =
new __impl::OggData(
file, getFormatInternal(), 0);
34 duration = ov_time_total( &oggData->vorbisFile, oggData->streamIndex );
37 readBufferSize = OGG_BUFFER_SIZE;
39 readBuffer = malloc(readBufferSize);
42 OggStream::~OggStream()
48 double OggStream::getLengthImpl()
const throw(
Exception)
53 double OggStream::getPositionImpl()
const throw()
55 return ov_time_tell( &oggData->vorbisFile );
58 void OggStream::seekImpl(
double position)
throw(
Exception)
60 if (position >= duration)
61 throw EndOfStreamException();
65 switch (ov_time_seek(&oggData->vorbisFile, position)) {
67 case OV_ENOSEEK:
throw Exception(
"Stream not seekable");
68 case OV_EINVAL:
throw Exception(
"Invalid argument or state");
69 case OV_EREAD:
throw Exception(
"Read error");
70 case OV_EFAULT:
throw Exception(
"Internal logic fault, bug or heap/stack corruption");
71 case OV_EBADLINK:
throw CorruptStreamException(
false);
72 default:
throw Exception(
"Unidentified error code");
76 void OggStream::getBufferImpl(
void *&
buffer,
unsigned int &bufferSize)
throw(
Exception)
78 if (readBufferAvail == 0)
79 throw NoBufferException();
82 bufferSize = readBufferAvail;
85 void OggStream::nextBufferImpl() throw(
Exception)
87 int curStream = oggData->streamIndex;
89 switch( ovr = ov_read(&oggData->vorbisFile,
90 (
char*)readBuffer, readBufferSize,
91 0, 2, 1, &curStream) )
93 case OV_HOLE:
throw CorruptStreamException(
false);
94 case OV_EBADLINK:
throw CorruptStreamException(
false);
95 case 0:
throw EndOfStreamException();
96 default: readBufferSize = ovr;