#ifndef OGGFILE_H
#define OGGFILE_H

//ALWrapper: OpenAL-based audio library.
//OggFile class: Inherits from AudioFile, provides Ogg streaming functionality.

#include "AudioFile.h"
#include <ogg/ogg.h>
#include <vorbis/vorbisfile.h>
#include <vorbis/codec.h>

namespace ALWrapper {

class OggFile : public AudioFile {

	protected:
		OggVorbis_File fileogg;	//An Ogg Vorbis stream pointing to file
	public:
		//Constructors. Default creates an empty OggFile.
		//Overloaded creates an OggFile and opens fname.
		OggFile() : AudioFile() {}
		OggFile(const std::string& fname) : AudioFile() {open(fname);}

		//Destructor. Closes the ogg stream.
		virtual ~OggFile();

		//Now open() can be implemented.
		//Opens both the file stream and the Ogg stream.
		//This can throw because the inherited openfile() can throw.
		virtual void open(const std::string& fname);
		virtual void close();	//Closes the currently open ogg stream.

		//Reads the specified number of bytes into a buffer.
		//Throws on error.
		virtual Buffer readData(unsigned long bufsize=defaultbufsize);

		//Seek to a particular position in the file.
		virtual void seek(unsigned long pos);	//In bytes.
		virtual void seek(double seconds);		//In seconds.

		//Get the current position in bytes.
		virtual unsigned long tell();
		virtual double tellTime();	//Or seconds.
		
		//Gets the bitrate of the current logical stream.
		//Returns 0 if the rate is unchanged or invalid.
		virtual unsigned int getCurrentBitRate();

		//Returns a reference to the Ogg Vorbis stream being used.
		inline OggVorbis_File& getVorbisFile() { return fileogg; }
};

}	//end namespace ALWrapper
#endif	//ifndef OGGFILE_H

