changed: Improve (fallback) logic for subtitle downloading
[vuplus_xbmc] / xbmc / cores / AudioEngine / Engines / CoreAudio / CoreAudioDevice.h
1 #pragma once
2 /*
3  *      Copyright (C) 2011-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "system.h"
23
24 #if defined(TARGET_DARWIN_OSX)
25
26 #include <string>
27
28 #include "ICoreAudioSource.h"
29 #include "CoreAudioStream.h"
30
31 #include <CoreAudio/CoreAudio.h>
32
33 typedef std::list<UInt32> CoreAudioDataSourceList;
34 typedef std::list<AudioDeviceID> CoreAudioDeviceList;
35
36 class CCoreAudioChannelLayout;
37
38 class CCoreAudioDevice
39 {
40 public:
41   CCoreAudioDevice();
42   CCoreAudioDevice(AudioDeviceID deviceId);
43   virtual ~CCoreAudioDevice();
44   
45   bool          Open(AudioDeviceID deviceId);
46   void          Close();
47   
48   void          Start();
49   void          Stop();
50   void          RemoveObjectListenerProc(AudioObjectPropertyListenerProc callback, void *pClientData);
51   bool          SetObjectListenerProc(AudioObjectPropertyListenerProc callback, void *pClientData);
52   
53   AudioDeviceID GetId() {return m_DeviceId;}
54   std::string   GetName();
55   UInt32        GetTotalOutputChannels();
56   bool          GetStreams(AudioStreamIdList *pList);
57   bool          IsRunning();
58   bool          SetHogStatus(bool hog);
59   pid_t         GetHogStatus();
60   bool          SetMixingSupport(UInt32 mix);
61   bool          GetMixingSupport();
62   bool          SetCurrentVolume(Float32 vol);
63   bool          GetPreferredChannelLayout(CCoreAudioChannelLayout &layout);
64   bool          GetDataSources(CoreAudioDataSourceList *pList);
65   Float64       GetNominalSampleRate();
66   bool          SetNominalSampleRate(Float64 sampleRate);
67   UInt32        GetNumLatencyFrames();
68   UInt32        GetBufferSize();
69   bool          SetBufferSize(UInt32 size);
70
71   virtual bool  SetInputSource(ICoreAudioSource *pSource, unsigned int frameSize, unsigned int outputBufferIndex);
72 protected:
73   bool          AddIOProc();
74   bool          RemoveIOProc();
75
76   static OSStatus DirectRenderCallback(AudioDeviceID inDevice, 
77     const AudioTimeStamp *inNow, const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime, 
78     AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *inClientData);
79
80   bool              m_Started;
81   ICoreAudioSource *m_pSource;
82   AudioDeviceID     m_DeviceId;
83   int               m_MixerRestore;
84   AudioDeviceIOProc m_IoProc;
85   AudioObjectPropertyListenerProc m_ObjectListenerProc;
86   
87   Float64           m_SampleRateRestore;
88   pid_t             m_HogPid;
89   unsigned int      m_frameSize;
90   unsigned int      m_OutputBufferIndex;
91   unsigned int      m_BufferSizeRestore;
92 };
93
94 #endif