///////////////////////////////////////////////////////////////////////////////
/// @file deOGG.hpp
///
/// @brief Destiny Sound System OGG Bit Stream
///
/// @author paradoxnj
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Jan 2002
/// @author paradoxnj
/// @remarks Creation
///
///////////////////////////////////////////////////////////////////////////////

#ifndef DEOGG_HPP
#define DEOGG_HPP

//Destiny Includes
#include "deSound_priv.hpp"

//Vorbis SDK Includes
#include "ogg/ogg.h"
#include "vorbis/codec.h"

//Forward Class Declaration
class deOGG;
class IdeFile;
class IdeFSReal;

//Class Declaration
class deOGG : public deSoundData
{
public:
	deOGG();
	deOGG(char *filename);
	virtual ~deOGG();

private:
	WAVEFORMATEX			m_Format;			//Buffer format from OGG Bit Stream
	IdeFile					*m_pSource;			//The file to stream from
	IdeFSReal				*m_pSourceSystem;	//The file system to stream from
	
	ogg_sync_state			m_oy;				//Sync and verify incoming bitstream
	ogg_stream_state		m_os;				//Take physical pages and weld into a logical stream of packets
	ogg_page				m_og;				//One OGG Bitstream page.  Vorbis packets are inside
	ogg_packet				m_op;				//One raw packet of data for decode

	vorbis_info				m_vi;				//Struct for all the static Vorbis bitstream settings
	vorbis_comment			m_vc;				//Struct for all the bitstream user comments
	vorbis_dsp_state		m_vs;				//Central working state for the packet->PCM decoder
	vorbis_block			m_vb;				//Local working space for the packet->PCM decoder

	DWORD					m_BufferSize;		//The size of the buffer
	DWORD					m_CurrWritePos;		//The current write position of the buffer;
	DWORD					m_FillLength;		//The length of the data that fills the buffer
	DWORD					m_FillPos;			//The position to copy data to in the buffer
	DWORD					m_SecureDistance;	//A safe distance for the next data stream packet
	DWORD					m_EmptyPos;			//The end of the data stream

	int						m_InterfaceType;
	int						m_RefCount;

public:
	void					*GetInterface(int interface_id);

	deBoolean				Initialize(const char *filename);
	void					Destroy();

	int						GetDataChunk(void *ptr, long size, s32 DataOffset);
	uint8					*GetAllData();

	deBoolean				AtEndOfStream();
	void					SetPosition(long NewPos);

	void					GetFormat(WAVEFORMATEX *format);
	u32						GetLength();

	IdeResourceBase			*MakeCopy();

	int						GetType()			{	return m_InterfaceType;		}
};

#endif
