/*  $Id: soundprovider_vorbis.cpp,v 1.3 2004/04/06 21:57:43 mbn Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
**
*/

#include "Sound/precomp.h"
#include "API/Vorbis/soundprovider_vorbis.h"
#include "API/Core/IOData/inputsource.h"
#include "API/Core/IOData/inputsource_provider.h"
#include "API/Core/System/clanstring.h"
#include "soundprovider_vorbis_generic.h"
#include "soundprovider_vorbis_session.h"

/////////////////////////////////////////////////////////////////////////////
// CL_SoundProvider_Vorbis construction:

CL_SoundProvider_Vorbis::CL_SoundProvider_Vorbis(
	const std::string &filename,
	CL_InputSourceProvider *provider,
	bool stream) : impl(new CL_SoundProvider_Vorbis_Generic)
{
	if (provider == 0) provider = CL_InputSourceProvider::create_file_provider(".");
	else provider = provider->clone();

	try
	{
		impl->provider = provider;
		impl->filename = filename;
		impl->stream = stream;

		CL_InputSource *input = provider->open_source(filename);
		int size = input->size();
		impl->buffer = new unsigned char[size];
		impl->buffer_size = input->read(impl->buffer, size);
		delete input;
	}
	catch (...)
	{
		delete impl->provider;
		throw;
	}
}

CL_SoundProvider_Vorbis::~CL_SoundProvider_Vorbis()
{
	delete[] impl->buffer;
	delete impl->provider;
	delete impl;
}

/////////////////////////////////////////////////////////////////////////////
// CL_SoundProvider_Vorbis operations:

CL_SoundProvider_Session *CL_SoundProvider_Vorbis::begin_session()
{
	return new CL_SoundProvider_Vorbis_Session(impl);
}

void CL_SoundProvider_Vorbis::end_session(CL_SoundProvider_Session *session)
{
	delete session;
}

/////////////////////////////////////////////////////////////////////////////
// CL_SoundProvider_Vorbis implementation:
