PageRenderTime 33ms CodeModel.GetById 15ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/cores/paplayer/VGMCodec.cpp

http://github.com/xbmc/xbmc
C++ | 262 lines | 221 code | 20 blank | 21 comment | 156 complexity | aef0716a97863eb304fe4d9df2862176 MD5 | raw file
  1/*
  2 *      Copyright (C) 2005-2013 Team XBMC
  3 *      http://xbmc.org
  4 *
  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)
  8 *  any later version.
  9 *
 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.
 14 *
 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/>.
 18 *
 19 */
 20
 21#include "VGMCodec.h"
 22#include "utils/log.h"
 23#include "utils/URIUtils.h"
 24
 25VGMCodec::VGMCodec()
 26{
 27  m_CodecName = "vgm";
 28  m_vgm = 0;
 29  m_iDataPos = -1;
 30  m_DataFormat = AE_FMT_INVALID;
 31}
 32
 33VGMCodec::~VGMCodec()
 34{
 35  DeInit();
 36}
 37
 38bool VGMCodec::Init(const CStdString &strFile, unsigned int filecache)
 39{
 40  if (!m_dll.Load())
 41    return false; // error logged previously
 42
 43  m_dll.Init();
 44
 45  //CStdString strFileToLoad = "filereader://"+strFile;
 46  XFILE::CFile::Cache(strFile,"special://temp/"+URIUtils::GetFileName(strFile));
 47
 48  //m_vgm = m_dll.LoadVGM(strFileToLoad.c_str(),&m_SampleRate,&m_BitsPerSample,&m_Channels);
 49  m_vgm = m_dll.LoadVGM("special://temp/"+URIUtils::GetFileName(strFile),&m_SampleRate,&m_BitsPerSample,&m_Channels);
 50  if (!m_vgm)
 51  {
 52    CLog::Log(LOGERROR,"%s: error opening file %s!",__FUNCTION__,strFile.c_str());
 53    return false;
 54  }
 55
 56  switch (m_BitsPerSample)
 57  {
 58    case  8: m_DataFormat = AE_FMT_U8   ; break;
 59    case 16: m_DataFormat = AE_FMT_S16NE; break;
 60    case 32: m_DataFormat = AE_FMT_FLOAT; break;
 61  }
 62
 63  m_TotalTime = (int64_t)m_dll.GetLength(m_vgm);
 64
 65  return true;
 66}
 67
 68void VGMCodec::DeInit()
 69{
 70  if (m_vgm)
 71    m_dll.FreeVGM(m_vgm);
 72  m_vgm = 0;
 73}
 74
 75int64_t VGMCodec::Seek(int64_t iSeekTime)
 76{
 77  int64_t result = (int64_t)m_dll.Seek(m_vgm,(unsigned long)iSeekTime);
 78  m_iDataPos = result/1000*m_SampleRate*m_BitsPerSample*m_Channels/8;
 79
 80  return result;
 81}
 82
 83int VGMCodec::ReadPCM(BYTE *pBuffer, int size, int *actualsize)
 84{
 85  if (m_iDataPos == -1)
 86  {
 87    m_iDataPos = 0;
 88  }
 89
 90  if (m_iDataPos >= m_TotalTime/1000*m_SampleRate*m_BitsPerSample*m_Channels/8)
 91  {
 92    return READ_EOF;
 93  }
 94
 95  if ((*actualsize=m_dll.FillBuffer(m_vgm,(char*)pBuffer,size))> 0)
 96  {
 97    m_iDataPos += *actualsize;
 98    return READ_SUCCESS;
 99  }
100
101  return READ_ERROR;
102}
103
104bool VGMCodec::CanInit()
105{
106  return m_dll.CanLoad();
107}
108
109bool VGMCodec::IsSupportedFormat(const CStdString& strExt)
110{
111  if (strExt == "aax" ||
112      strExt == "acm" ||
113      strExt == "adp" ||
114      strExt == "ads" ||
115      strExt == "adx" ||
116      strExt == "afc" ||
117      strExt == "agsc" ||
118      strExt == "ahx" ||
119      strExt == "aifc" ||
120      strExt == "aix" ||
121      strExt == "amts" ||
122      strExt == "as4" ||
123      strExt == "asd" ||
124      strExt == "asf" ||
125      strExt == "asr" ||
126      strExt == "ass" ||
127      strExt == "ast" ||
128      strExt == "aud" ||
129      strExt == "aus" ||
130      strExt == "bg00" ||
131      strExt == "bgw" ||
132      strExt == "bh2pcm" ||
133      strExt == "bmdx" ||
134      strExt == "brstm" ||
135      strExt == "capdsp" ||
136      strExt == "ccc" ||
137      strExt == "cfn" ||
138      strExt == "cnk" ||
139      strExt == "dcs" ||
140      strExt == "de2" ||
141      strExt == "dsp" ||
142      strExt == "dvi" ||
143      strExt == "dxh" ||
144      strExt == "eam" ||
145      strExt == "emff" ||
146      strExt == "enth" ||
147      strExt == "fag" ||
148      strExt == "filp" ||
149      strExt == "fsb" ||
150      strExt == "gbts" ||
151      strExt == "gca" ||
152      strExt == "gcm" ||
153      strExt == "gcw" ||
154      strExt == "genh" ||
155      strExt == "gms" ||
156      strExt == "gsb" ||
157      strExt == "hgc1" ||
158      strExt == "hps" ||
159      strExt == "idsp" ||
160      strExt == "idvi" ||
161      strExt == "ikm" ||
162      strExt == "ild" ||
163      strExt == "int" ||
164      strExt == "isd" ||
165      strExt == "ivb" ||
166      strExt == "joe" ||
167      strExt == "kces" ||
168      strExt == "kcey" ||
169      strExt == "kraw" ||
170      strExt == "leg" ||
171      strExt == "logg" ||
172      strExt == "lwav" ||
173      strExt == "matx" ||
174      strExt == "mi4" ||
175      strExt == "mib" ||
176      strExt == "mic" ||
177      strExt == "mihb" ||
178      strExt == "mpdsp" ||
179      strExt == "mss" ||
180      strExt == "msvp" ||
181      strExt == "mus" ||
182      strExt == "musc" ||
183      strExt == "musx" ||
184      strExt == "mwv" ||
185      strExt == "npsf" ||
186      strExt == "nwa" ||
187      strExt == "omu" ||
188      strExt == "p2bt" ||
189      strExt == "pcm" ||
190      strExt == "pdt" ||
191      strExt == "pnb" ||
192      strExt == "pos" ||
193      strExt == "psh" ||
194      strExt == "psw" ||
195      strExt == "raw" ||
196      strExt == "rkv" ||
197      strExt == "rnd" ||
198      strExt == "rsd" ||
199      strExt == "rsf" ||
200      strExt == "rstm" ||
201      strExt == "rwsd" ||
202      strExt == "rwav" ||
203      strExt == "rws" ||
204      strExt == "rwx" ||
205      strExt == "rxw" ||
206      strExt == "sad" ||
207      strExt == "sdt" ||
208      strExt == "seg" ||
209      strExt == "sfl" ||
210      strExt == "sfs" ||
211      strExt == "sl3" ||
212      strExt == "sli" ||
213      strExt == "smp" ||
214      strExt == "sng" ||
215      strExt == "spd" ||
216      strExt == "spsd" ||
217      strExt == "spw" ||
218      strExt == "ss2" ||
219      strExt == "ss7" ||
220      strExt == "ssm" ||
221      strExt == "stma" ||
222      strExt == "str" ||
223      strExt == "strm" ||
224      strExt == "sts" ||
225      strExt == "svag" ||
226      strExt == "svs" ||
227      strExt == "swd" ||
228      strExt == "tec" ||
229      strExt == "thp" ||
230      strExt == "tydsp" ||
231      strExt == "um3" ||
232      strExt == "vag" ||
233      strExt == "vas" ||
234      strExt == "vgs" ||
235      strExt == "vig" ||
236      strExt == "vpk" ||
237      strExt == "vs" ||
238      strExt == "waa" ||
239      strExt == "wac" ||
240      strExt == "wad" ||
241      strExt == "wam" ||
242      strExt == "wavm" ||
243      strExt == "wp2" ||
244      strExt == "wsi" ||
245      strExt == "wvs" ||
246      strExt == "xa" ||
247      strExt == "xa2" ||
248      strExt == "xa30" ||
249      strExt == "xmu" ||
250      strExt == "xsf" ||
251      strExt == "xss" ||
252      strExt == "xvas" ||
253      strExt == "xwav" ||
254      strExt == "xwb" ||
255      strExt == "ydsp" ||
256      strExt == "ymf" ||
257      strExt == "zwdsp"
258)
259    return true;
260
261  return false;
262}