cFileSourceFactory.h

00001 // Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
00002 // This file is part of the "cAudio Engine"
00003 // For conditions of distribution and use, see copyright notice in cAudio.h
00004 
00005 #ifndef CFILESOURCEFACTORY_H
00006 #define CFILESOURCEFACTORY_H
00007 
00008 #include "../include/IDataSourceFactory.h"
00009 #include "../Headers/cFileSource.h"
00010 #include "../Headers/cMemorySource.h"
00011 #include "../Headers/cMutex.h"
00012 
00013 namespace cAudio
00014 {
00015         class cFileSourceFactory : public IDataSourceFactory
00016         {
00017                 public:
00018                         cFileSourceFactory() { }
00019                         virtual ~cFileSourceFactory() { }
00020 
00021                         virtual IDataSource* CreateDataSource(const char* filename, bool streamingRequested)
00022                         {
00023                                 cAudioMutexBasicLock lock(Mutex);
00024                                 IDataSource* source = new cFileSource(filename);
00025 
00026                                 if(!streamingRequested && source && source->isValid())
00027                                 {
00028                                         //A bit hackish, but if the user doesn't want streaming, make this a memory source
00029                                         int length = source->getSize();
00030                                         char* tempbuf = new char[length];
00031                                         if(tempbuf)
00032                                         {
00033                                                 source->read(tempbuf, length);
00034                                                 IDataSource* memSource = new cMemorySource(tempbuf, length, true);
00035                                                 delete[] tempbuf;
00036 
00037                                                 if(memSource && memSource->isValid())
00038                                                 {
00039                                                         source->drop();
00040                                                         return memSource;
00041                                                 }
00042 
00043                                                 if(memSource)
00044                                                         memSource->drop();
00045                                         }
00046                                 }
00047                                 return source;
00048                         }
00049                 protected:
00050                         cAudioMutex Mutex;
00051                 private:
00052         };
00053 };
00054 
00055 #endif 
 All Classes Namespaces Functions Variables Enumerations

Generated on Sat Feb 20 22:55:07 2010 for cAudio by  doxygen 1.6.2