Blender  V2.59
AUD_FileFactory.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: AUD_FileFactory.cpp 35141 2011-02-25 10:21:56Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * Copyright 2009-2011 Jörg Hermann Müller
00007  *
00008  * This file is part of AudaSpace.
00009  *
00010  * Audaspace is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * AudaSpace is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with Audaspace; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #ifdef WITH_FFMPEG
00033 // needed for INT64_C
00034 #ifndef __STDC_CONSTANT_MACROS
00035 #define __STDC_CONSTANT_MACROS
00036 #endif
00037 #include "AUD_FFMPEGReader.h"
00038 #endif
00039 
00040 #include "AUD_FileFactory.h"
00041 #include "AUD_Buffer.h"
00042 
00043 #include <cstring>
00044 
00045 #ifdef WITH_SNDFILE
00046 #include "AUD_SndFileReader.h"
00047 #endif
00048 
00049 AUD_FileFactory::AUD_FileFactory(std::string filename) :
00050         m_filename(filename)
00051 {
00052 }
00053 
00054 AUD_FileFactory::AUD_FileFactory(const data_t* buffer, int size) :
00055         m_buffer(new AUD_Buffer(size))
00056 {
00057         memcpy(m_buffer.get()->getBuffer(), buffer, size);
00058 }
00059 
00060 static const char* read_error = "AUD_FileFactory: File couldn't be read.";
00061 
00062 AUD_IReader* AUD_FileFactory::createReader() const
00063 {
00064 #ifdef WITH_SNDFILE
00065         try
00066         {
00067                 if(m_buffer.get())
00068                         return new AUD_SndFileReader(m_buffer);
00069                 else
00070                         return new AUD_SndFileReader(m_filename);
00071         }
00072         catch(AUD_Exception&) {}
00073 #endif
00074 
00075 #ifdef WITH_FFMPEG
00076         try
00077         {
00078                 if(m_buffer.get())
00079                         return new AUD_FFMPEGReader(m_buffer);
00080                 else
00081                         return new AUD_FFMPEGReader(m_filename);
00082         }
00083         catch(AUD_Exception&) {}
00084 #endif
00085 
00086         AUD_THROW(AUD_ERROR_FILE, read_error);
00087 }