changed: Improve (fallback) logic for subtitle downloading
[vuplus_xbmc] / xbmc / cores / AudioEngine / Engines / CoreAudio / CoreAudioAEHAL.cpp
1 /*
2  *      Copyright (C) 2011-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 "CoreAudioAEHAL.h"
22 #include "CoreAudioAE.h"
23 #include "utils/log.h"
24
25 #include <sstream>
26
27 // Helper Functions
28 std::string GetError(OSStatus error)
29 {
30   char buffer[128];
31  
32   *(UInt32 *)(buffer + 1) = CFSwapInt32HostToBig(error);
33   if (isprint(buffer[1]) && isprint(buffer[2]) &&
34       isprint(buffer[3]) && isprint(buffer[4]))
35   {
36     buffer[0] = buffer[5] = '\'';
37     buffer[6] = '\0';
38   }
39   else
40   {
41     // no, format it as an integer
42     sprintf(buffer, "%d", (int)error);
43   }
44  
45   return std::string(buffer);
46 }
47
48 const char* StreamDescriptionToString(AudioStreamBasicDescription desc, std::string &str)
49 {
50   char fourCC[5] = {
51     (desc.mFormatID >> 24) & 0xFF,
52     (desc.mFormatID >> 16) & 0xFF,
53     (desc.mFormatID >>  8) & 0xFF,
54      desc.mFormatID        & 0xFF,
55     0
56   };
57
58   std::stringstream sstr; 
59   switch (desc.mFormatID)
60   {
61     case kAudioFormatLinearPCM:
62       sstr  << "["
63             << fourCC
64             << "] "
65             << ((desc.mFormatFlags & kAudioFormatFlagIsNonMixable) ? "" : "Mixable " )
66             << ((desc.mFormatFlags & kAudioFormatFlagIsNonInterleaved) ? "Non-" : "" )
67             << "Interleaved "
68             << desc.mChannelsPerFrame
69             << " Channel "
70             << desc.mBitsPerChannel
71             << "-bit "
72             << ((desc.mFormatFlags & kAudioFormatFlagIsFloat) ? "Floating Point " : "Signed Integer ")
73             << ((desc.mFormatFlags & kAudioFormatFlagIsBigEndian) ? "BE" : "LE")
74             << " ("
75             << (UInt32)desc.mSampleRate
76             << "Hz)";
77       str = sstr.str();
78       break;
79     case kAudioFormatAC3:
80       sstr  << "["
81             << fourCC
82             << "] "
83             << ((desc.mFormatFlags & kAudioFormatFlagIsBigEndian) ? "BE" : "LE")
84             << " AC-3/DTS ("
85             << (UInt32)desc.mSampleRate
86             << "Hz)";
87       str = sstr.str();                
88       break;
89     case kAudioFormat60958AC3:
90       sstr  << "["
91             << fourCC
92             << "] AC-3/DTS for S/PDIF "
93             << ((desc.mFormatFlags & kAudioFormatFlagIsBigEndian) ? "BE" : "LE")
94             << " ("
95             << (UInt32)desc.mSampleRate
96             << "Hz)";
97       str = sstr.str();
98       break;
99     default:
100       sstr  << "["
101             << fourCC
102             << "]";
103       break;
104   }
105   return str.c_str();
106 }