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"
25 #include "FLACcodec.h"
27 #include "ModplugCodec.h"
35 #include "ADPCMCodec.h"
36 #include "TimidityCodec.h"
38 #include "ASAPCodec.h"
41 #include "DVDPlayerCodec.h"
43 #include "utils/StringUtils.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 DVDPlayerCodec();
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();
112 else if (strFileType.Equals("tak"))
113 return new DVDPlayerCodec();
118 ICodec* CodecFactory::CreateCodecDemux(const CStdString& strFile, const CStdString& strContent, unsigned int filecache)
120 CURL urlFile(strFile);
121 if( strContent.Equals("audio/mpeg")
122 || strContent.Equals("audio/mpeg3")
123 || strContent.Equals("audio/mp3") )
124 return new MP3Codec();
125 else if (StringUtils::StartsWithNoCase(strContent, "audio/l16"))
127 PCMCodec * pcm_codec = new PCMCodec();
128 pcm_codec->SetMimeParams(strContent);
131 else if( strContent.Equals("audio/aac") || strContent.Equals("audio/aacp") ||
132 strContent.Equals("audio/x-ms-wma") ||
133 strContent.Equals("audio/x-ape") || strContent.Equals("audio/ape"))
135 DVDPlayerCodec *pCodec = new DVDPlayerCodec;
136 pCodec->SetContentType(strContent);
139 else if( strContent.Equals("application/ogg") || strContent.Equals("audio/ogg"))
140 return CreateOGGCodec(strFile,filecache);
141 else if (strContent.Equals("audio/x-xbmc-pcm"))
143 // audio/x-xbmc-pcm this is the used codec for AirTunes
144 // (apples audio only streaming)
145 DVDPlayerCodec *dvdcodec = new DVDPlayerCodec();
146 dvdcodec->SetContentType(strContent);
149 else if (strContent.Equals("audio/flac") || strContent.Equals("audio/x-flac") || strContent.Equals("application/x-flac"))
150 return new FLACCodec();
152 if (urlFile.GetProtocol() == "shout")
154 return new MP3Codec(); // if we got this far with internet radio - content-type was wrong. gamble on mp3.
157 if (urlFile.GetFileType().Equals("wav") || strContent.Equals("audio/wav") || strContent.Equals("audio/x-wav"))
160 //lets see what it contains...
161 //this kinda sucks 'cause if it's a plain wav file the file
162 //will be opened, sniffed and closed 2 times before it is opened *again* for wav
163 //would be better if the papcodecs could work with bitstreams instead of filenames.
164 DVDPlayerCodec *dvdcodec = new DVDPlayerCodec();
165 dvdcodec->SetContentType("audio/x-spdif-compressed");
166 if (dvdcodec->Init(strFile, filecache))
171 codec = new ADPCMCodec();
172 if (codec->Init(strFile, filecache))
178 codec = new WAVCodec();
179 if (codec->Init(strFile, filecache))
185 else if (urlFile.GetFileType().Equals("ogg") || urlFile.GetFileType().Equals("oggstream") || urlFile.GetFileType().Equals("oga"))
186 return CreateOGGCodec(strFile,filecache);
189 return CreateCodec(urlFile.GetFileType());
192 ICodec* CodecFactory::CreateOGGCodec(const CStdString& strFile,
193 unsigned int filecache)
195 // oldnemesis: we want to use OGGCodec() for OGG music since unlike DVDCodec
196 // it provides better timings for Karaoke. However OGGCodec() cannot handle
197 // ogg-flac and ogg videos, that's why this block.
198 ICodec* codec = new OGGCodec();
201 if (codec->Init(strFile, filecache))
208 return new DVDPlayerCodec();