2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "CodecFactory.h"
24 #include "CDDAcodec.h"
26 #include "FLACcodec.h"
28 #include "ModplugCodec.h"
36 #include "ADPCMCodec.h"
37 #include "TimidityCodec.h"
39 #include "ASAPCodec.h"
42 #include "DVDPlayerCodec.h"
45 ICodec* CodecFactory::CreateCodec(const CStdString& strFileType)
47 if (strFileType.Equals("mp3") || strFileType.Equals("mp2"))
48 return new MP3Codec();
49 else if (strFileType.Equals("pcm") || strFileType.Equals("l16"))
50 return new PCMCodec();
51 else if (strFileType.Equals("ape") || strFileType.Equals("mac"))
52 return new DVDPlayerCodec();
53 else if (strFileType.Equals("cdda"))
54 return new CDDACodec();
55 else if (strFileType.Equals("mpc") || strFileType.Equals("mp+") || strFileType.Equals("mpp"))
56 return new DVDPlayerCodec();
57 else if (strFileType.Equals("shn"))
58 return new DVDPlayerCodec();
59 else if (strFileType.Equals("mka"))
60 return new DVDPlayerCodec();
61 else if (strFileType.Equals("flac"))
62 return new FLACCodec();
63 else if (strFileType.Equals("wav"))
64 return new DVDPlayerCodec();
65 else if (strFileType.Equals("dts") || strFileType.Equals("ac3") ||
66 strFileType.Equals("m4a") || strFileType.Equals("aac") ||
67 strFileType.Equals("pvr"))
68 return new DVDPlayerCodec();
69 else if (strFileType.Equals("wv"))
70 return new DVDPlayerCodec();
71 else if (strFileType.Equals("669") || strFileType.Equals("abc") ||
72 strFileType.Equals("amf") || strFileType.Equals("ams") ||
73 strFileType.Equals("dbm") || strFileType.Equals("dmf") ||
74 strFileType.Equals("dsm") || strFileType.Equals("far") ||
75 strFileType.Equals("it") || strFileType.Equals("j2b") ||
76 strFileType.Equals("mdl") || strFileType.Equals("med") ||
77 strFileType.Equals("mod") || strFileType.Equals("itgz")||
78 strFileType.Equals("mt2") || strFileType.Equals("mtm") ||
79 strFileType.Equals("okt") || strFileType.Equals("pat") ||
80 strFileType.Equals("psm") || strFileType.Equals("ptm") ||
81 strFileType.Equals("s3m") || strFileType.Equals("stm") ||
82 strFileType.Equals("ult") || strFileType.Equals("umx") ||
83 strFileType.Equals("xm") || strFileType.Equals("mdgz") ||
84 strFileType.Equals("s3gz") || strFileType.Equals("xmgz"))
85 return new ModplugCodec();
86 else if (strFileType.Equals("nsf") || strFileType.Equals("nsfstream"))
87 return new NSFCodec();
89 else if (strFileType.Equals("spc"))
90 return new SPCCodec();
92 else if (strFileType.Equals("sid") || strFileType.Equals("sidstream"))
93 return new SIDCodec();
94 else if (VGMCodec::IsSupportedFormat(strFileType))
95 return new VGMCodec();
96 else if (strFileType.Equals("ym"))
98 else if (strFileType.Equals("wma"))
99 return new DVDPlayerCodec();
100 else if (strFileType.Equals("aiff") || strFileType.Equals("aif"))
101 return new DVDPlayerCodec();
102 else if (strFileType.Equals("xwav"))
103 return new ADPCMCodec();
104 else if (TimidityCodec::IsSupportedFormat(strFileType))
105 return new TimidityCodec();
106 #ifdef HAS_ASAP_CODEC
107 else if (ASAPCodec::IsSupportedFormat(strFileType) || strFileType.Equals("asapstream"))
108 return new ASAPCodec();
110 else if (strFileType.Equals("tta"))
111 return new DVDPlayerCodec();
116 ICodec* CodecFactory::CreateCodecDemux(const CStdString& strFile, const CStdString& strContent, unsigned int filecache)
118 CURL urlFile(strFile);
119 if( strContent.Equals("audio/mpeg")
120 || strContent.Equals("audio/mp3") )
121 return new MP3Codec();
122 else if (strContent.Left(9).Equals("audio/l16"))
124 PCMCodec * pcm_codec = new PCMCodec();
125 pcm_codec->SetMimeParams(strContent);
128 else if( strContent.Equals("audio/aac")
129 || strContent.Equals("audio/aacp") )
131 DVDPlayerCodec *pCodec = new DVDPlayerCodec;
132 if (urlFile.GetProtocol() == "shout" )
133 pCodec->SetContentType(strContent);
136 else if( strContent.Equals("audio/x-ms-wma") )
137 return new DVDPlayerCodec();
138 else if( strContent.Equals("audio/x-ape") || strContent.Equals("audio/ape") )
139 return new DVDPlayerCodec();
140 else if( strContent.Equals("application/ogg") || strContent.Equals("audio/ogg"))
141 return CreateOGGCodec(strFile,filecache);
142 else if (strContent.Equals("audio/x-xbmc-pcm"))
144 // audio/x-xbmc-pcm this is the used codec for AirTunes
145 // (apples audio only streaming)
146 DVDPlayerCodec *dvdcodec = new DVDPlayerCodec();
147 dvdcodec->SetContentType(strContent);
150 else if (strContent.Equals("audio/flac") || strContent.Equals("audio/x-flac") || strContent.Equals("application/x-flac"))
151 return new FLACCodec();
153 if (urlFile.GetProtocol() == "lastfm" || urlFile.GetProtocol() == "shout")
155 return new MP3Codec(); // if we got this far with internet radio - content-type was wrong. gamble on mp3.
158 if (urlFile.GetFileType().Equals("wav") || strContent.Equals("audio/wav") || strContent.Equals("audio/x-wav"))
161 //lets see what it contains...
162 //this kinda sucks 'cause if it's a plain wav file the file
163 //will be opened, sniffed and closed 2 times before it is opened *again* for wav
164 //would be better if the papcodecs could work with bitstreams instead of filenames.
165 DVDPlayerCodec *dvdcodec = new DVDPlayerCodec();
166 dvdcodec->SetContentType("audio/x-spdif-compressed");
167 if (dvdcodec->Init(strFile, filecache))
172 codec = new ADPCMCodec();
173 if (codec->Init(strFile, filecache))
179 codec = new WAVCodec();
180 if (codec->Init(strFile, filecache))
186 if (urlFile.GetFileType().Equals("cdda"))
188 //lets see what it contains...
189 //this kinda sucks 'cause if it's plain cdda the file
190 //will be opened, sniffed and closed before it is opened *again* for cdda
191 //would be better if the papcodecs could work with bitstreams instead of filenames.
192 DVDPlayerCodec *dvdcodec = new DVDPlayerCodec();
193 dvdcodec->SetContentType("audio/x-spdif-compressed");
194 if (dvdcodec->Init(strFile, filecache))
200 else if (urlFile.GetFileType().Equals("ogg") || urlFile.GetFileType().Equals("oggstream") || urlFile.GetFileType().Equals("oga"))
201 return CreateOGGCodec(strFile,filecache);
204 return CreateCodec(urlFile.GetFileType());
207 ICodec* CodecFactory::CreateOGGCodec(const CStdString& strFile,
208 unsigned int filecache)
210 // oldnemesis: we want to use OGGCodec() for OGG music since unlike DVDCodec
211 // it provides better timings for Karaoke. However OGGCodec() cannot handle
212 // ogg-flac and ogg videos, that's why this block.
213 ICodec* codec = new OGGCodec();
216 if (codec->Init(strFile, filecache))
223 return new DVDPlayerCodec();