SVN maintenance.
[blender.git] / intern / audaspace / intern / AUD_FileFactory.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN LGPL LICENSE BLOCK *****
5  *
6  * Copyright 2009 Jörg Hermann Müller
7  *
8  * This file is part of AudaSpace.
9  *
10  * AudaSpace is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * AudaSpace is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * ***** END LGPL LICENSE BLOCK *****
24  */
25
26 #include "AUD_FileFactory.h"
27 #include "AUD_Buffer.h"
28
29 #include <cstring>
30
31 #ifdef WITH_FFMPEG
32 #include "AUD_FFMPEGReader.h"
33 #endif
34 #ifdef WITH_SNDFILE
35 #include "AUD_SndFileReader.h"
36 #endif
37
38 AUD_FileFactory::AUD_FileFactory(const char* filename)
39 {
40         if(filename != NULL)
41         {
42                 m_filename = new char[strlen(filename)+1]; AUD_NEW("string")
43                 strcpy(m_filename, filename);
44         }
45         else
46                 m_filename = NULL;
47 }
48
49 AUD_FileFactory::AUD_FileFactory(unsigned char* buffer, int size)
50 {
51         m_filename = NULL;
52         m_buffer = AUD_Reference<AUD_Buffer>(new AUD_Buffer(size));
53         memcpy(m_buffer.get()->getBuffer(), buffer, size);
54 }
55
56 AUD_FileFactory::~AUD_FileFactory()
57 {
58         if(m_filename)
59         {
60                 delete[] m_filename; AUD_DELETE("string")
61         }
62 }
63
64 AUD_IReader* AUD_FileFactory::createReader()
65 {
66         AUD_IReader* reader = 0;
67
68 #ifdef WITH_SNDFILE
69         try
70         {
71                 if(m_filename)
72                         reader = new AUD_SndFileReader(m_filename);
73                 else
74                         reader = new AUD_SndFileReader(m_buffer);
75                 AUD_NEW("reader")
76                 return reader;
77         }
78         catch(AUD_Exception e) {}
79 #endif
80
81 #ifdef WITH_FFMPEG
82         try
83         {
84                 if(m_filename)
85                         reader = new AUD_FFMPEGReader(m_filename);
86                 else
87                         reader = new AUD_FFMPEGReader(m_buffer);
88                 AUD_NEW("reader")
89                 return reader;
90         }
91         catch(AUD_Exception e) {}
92 #endif
93
94         return reader;
95 }