Merge pull request #473 from Montellese/onplaybackspeedchanged
[vuplus_xbmc] / xbmc / cores / AudioRenderers / IOSAudioRenderer.h
1 /*
2  *      Copyright (C) 2010 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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #ifndef __IOSAUDIO_RENDERER_H__
23 #define __IOSAUDIO_RENDERER_H__
24
25 #include "IOSCoreAudio.h"
26 #include "PlatformDefs.h"
27 #include "IAudioRenderer.h"
28 #include "threads/Event.h"
29
30 class IOSAudioRingBuffer;
31 class CIOSAudioRenderer : public IAudioRenderer
32   {
33   public:
34     CIOSAudioRenderer();
35     virtual ~CIOSAudioRenderer();
36     virtual unsigned int GetChunkLen();
37     virtual float GetDelay();
38     virtual bool Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic=false, bool bPassthrough = false);
39     virtual bool Deinitialize();
40     virtual void Flush();
41     virtual unsigned int AddPackets(const void* data, unsigned int len);
42     virtual unsigned int GetSpace();
43     virtual float GetCacheTime();
44     virtual float GetCacheTotal();
45     virtual bool Pause();
46     virtual bool Stop();
47     virtual bool Resume();
48
49     virtual long GetCurrentVolume() const;
50     virtual void Mute(bool bMute);
51     virtual bool SetCurrentVolume(long nVolume);
52     virtual void SetDynamicRangeCompression(long drc) { m_drc = drc; }
53     virtual void WaitCompletion();
54
55     // Unimplemented IAudioRenderer methods
56     virtual int SetPlaySpeed(int iSpeed) {return 0;};
57     virtual void SwitchChannels(int iAudioStream, bool bAudioOnAllSpeakers) {};
58     virtual void UnRegisterAudioCallback() {};
59     virtual void RegisterAudioCallback(IAudioCallback* pCallback) {};
60
61     static void EnumerateAudioSinks(AudioSinkList& vAudioSinks, bool passthrough) {};
62   private:
63     OSStatus OnRender(AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData);
64     static OSStatus RenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData);
65     static void PropertyChanged(AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue);
66     static void PropertyChangeCallback(void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue);
67     bool InitializePCM(UInt32 channels, UInt32 samplesPerSecond, UInt32 bitsPerSample, enum PCMChannels *channelMap);
68
69     bool m_Pause;
70     bool m_Initialized; // Prevent multiple init/deinit
71
72     long m_CurrentVolume; // Courtesy of the jerk that made GetCurrentVolume a const...
73     bool m_EnableVolumeControl;
74
75     CIOSCoreAudioDevice m_AudioDevice;
76     UInt32 m_OutputBufferIndex;
77
78     // Stream format
79     int m_BitsPerChannel;
80     int m_ChannelsPerFrame;
81
82     IOSAudioRingBuffer *m_Buffer;
83     unsigned int m_BytesPerSec;
84     unsigned int m_BufferLen; ///< must always be num_chunks * chunk_size
85     unsigned int m_NumChunks;
86     unsigned int m_PacketSize;
87     unsigned int m_BytesPerFrame;
88     unsigned int m_BufferFrames;
89     unsigned int m_SamplesPerSec;
90
91     CEvent m_RunoutEvent;
92     long m_DoRunout;
93     unsigned int m_DataChannels;
94     unsigned int m_Channels;
95     bool m_Passthrough;
96
97     long m_drc;
98
99   };
100
101 #endif