[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / cores / paplayer / ASAPCodec.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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 "ASAPCodec.h"
22 #include "utils/URIUtils.h"
23 #include "filesystem/File.h"
24
25 ASAPCodec::ASAPCodec()
26 {
27   m_CodecName = "asap";
28 }
29
30 ASAPCodec::~ASAPCodec()
31 {
32 }
33
34 bool ASAPCodec::Init(const CStdString &strFile, unsigned int filecache)
35 {
36   if (!m_dll.Load())
37     return false;
38
39   CStdString strFileToLoad = strFile;
40   int song = -1;
41   CStdString strExtension;
42   URIUtils::GetExtension(strFile, strExtension);
43   strExtension.MakeLower();
44   if (strExtension == ".asapstream")
45   {
46     CStdString strFileName = URIUtils::GetFileName(strFile);
47     int iStart = strFileName.ReverseFind('-') + 1;
48     song = atoi(strFileName.substr(iStart, strFileName.size() - iStart - 11).c_str()) - 1;
49     CStdString strPath = strFile;
50     URIUtils::GetDirectory(strPath, strFileToLoad);
51     URIUtils::RemoveSlashAtEnd(strFileToLoad);
52   }
53
54   int duration;
55   if (!m_dll.asapLoad(strFileToLoad.c_str(), song, &m_Channels, &duration))
56     return false;
57   m_TotalTime = duration;
58   m_SampleRate = 44100;
59   m_BitsPerSample = 16;
60   m_DataFormat = AE_FMT_S16NE;
61   return true;
62 }
63
64 void ASAPCodec::DeInit()
65 {
66 }
67
68 int64_t ASAPCodec::Seek(int64_t iSeekTime)
69 {
70   m_dll.asapSeek((int) iSeekTime);
71   return iSeekTime;
72 }
73
74 int ASAPCodec::ReadPCM(BYTE *pBuffer, int size, int *actualsize)
75 {
76   *actualsize = m_dll.asapGenerate(pBuffer, size);
77   if (*actualsize < size)
78     return READ_EOF;
79   return READ_SUCCESS;
80 }
81
82 bool ASAPCodec::CanInit()
83 {
84   return m_dll.CanLoad();
85 }
86
87 bool ASAPCodec::IsSupportedFormat(const CStdString &strExt)
88 {
89   if(strExt.empty())
90     return false;
91   CStdString ext = strExt;
92   if (ext[0] == '.')
93     ext.erase(0, 1);
94   return ext == "sap"
95     || ext == "cmc" || ext == "cmr" || ext == "dmc"
96     || ext == "mpt" || ext == "mpd" || ext == "rmt"
97     || ext == "tmc" || ext == "tm8" || ext == "tm2"
98     || ext == "cms" || ext == "cm3" || ext == "dlt";
99 }