2010-02-14 02:54:21 +01:00
|
|
|
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
|
|
|
|
// This file is part of the "cAudio Engine"
|
|
|
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
|
|
|
|
|
|
|
#ifndef CFILESOURCEFACTORY_H
|
|
|
|
#define CFILESOURCEFACTORY_H
|
|
|
|
|
|
|
|
#include "../include/IDataSourceFactory.h"
|
2010-03-05 02:52:25 +01:00
|
|
|
|
|
|
|
#ifdef CAUDIO_COMPILE_WITH_FILE_SOURCE
|
|
|
|
|
2010-02-14 02:54:21 +01:00
|
|
|
#include "../Headers/cFileSource.h"
|
|
|
|
#include "../Headers/cMemorySource.h"
|
|
|
|
#include "../Headers/cMutex.h"
|
|
|
|
|
|
|
|
namespace cAudio
|
|
|
|
{
|
|
|
|
class cFileSourceFactory : public IDataSourceFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cFileSourceFactory() { }
|
|
|
|
virtual ~cFileSourceFactory() { }
|
|
|
|
|
|
|
|
virtual IDataSource* CreateDataSource(const char* filename, bool streamingRequested)
|
|
|
|
{
|
|
|
|
cAudioMutexBasicLock lock(Mutex);
|
2010-03-08 05:56:56 +01:00
|
|
|
IDataSource* source = CAUDIO_NEW cFileSource(filename);
|
2010-02-14 02:54:21 +01:00
|
|
|
|
|
|
|
if(!streamingRequested && source && source->isValid())
|
|
|
|
{
|
|
|
|
//A bit hackish, but if the user doesn't want streaming, make this a memory source
|
|
|
|
int length = source->getSize();
|
2010-03-08 06:27:02 +01:00
|
|
|
char* tempbuf = (char*)CAUDIO_MALLOC(length);
|
2010-02-14 02:54:21 +01:00
|
|
|
if(tempbuf)
|
|
|
|
{
|
|
|
|
source->read(tempbuf, length);
|
2010-03-08 05:56:56 +01:00
|
|
|
IDataSource* memSource = CAUDIO_NEW cMemorySource(tempbuf, length, true);
|
2010-03-08 06:27:02 +01:00
|
|
|
CAUDIO_FREE(tempbuf);
|
2010-02-17 02:42:45 +01:00
|
|
|
|
2010-02-14 02:54:21 +01:00
|
|
|
if(memSource && memSource->isValid())
|
|
|
|
{
|
|
|
|
source->drop();
|
|
|
|
return memSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(memSource)
|
|
|
|
memSource->drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
cAudioMutex Mutex;
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2010-03-05 02:52:25 +01:00
|
|
|
#endif
|
|
|
|
|
2010-02-14 02:54:21 +01:00
|
|
|
#endif //! CFILESOURCEFACTORY_H
|