[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / cores / AudioEngine / Sinks / AESinkWASAPI.h
1 #pragma once
2 /*
3 *      Copyright (C) 2010-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 "../Interfaces/AESink.h"
23 #include <stdint.h>
24 #include <mmdeviceapi.h>
25 #include <Audioclient.h>
26 #include "../Utils/AEDeviceInfo.h"
27
28 #include "threads/CriticalSection.h"
29
30 class CAESinkWASAPI : public IAESink
31 {
32 public:
33     virtual const char *GetName() { return "WASAPI"; }
34
35     CAESinkWASAPI();
36     virtual ~CAESinkWASAPI();
37
38     virtual bool Initialize  (AEAudioFormat &format, std::string &device);
39     virtual void Deinitialize();
40
41     virtual double       GetDelay                    ();
42     virtual double       GetCacheTotal               ();
43     virtual unsigned int AddPackets                  (uint8_t *data, unsigned int frames, bool hasAudio, bool blocking = false);
44     virtual void         Drain                       ();
45     static  void         EnumerateDevicesEx          (AEDeviceInfoList &deviceInfoList, bool force = false);
46 private:
47     bool         InitializeExclusive(AEAudioFormat &format);
48     void         AEChannelsFromSpeakerMask(DWORD speakers);
49     static DWORD        SpeakerMaskFromAEChannels(const CAEChannelInfo &channels);
50     static void         BuildWaveFormatExtensible(AEAudioFormat &format, WAVEFORMATEXTENSIBLE &wfxex);
51     static void         BuildWaveFormatExtensibleIEC61397(AEAudioFormat &format, WAVEFORMATEXTENSIBLE_IEC61937 &wfxex);
52
53     static const char  *WASAPIErrToStr(HRESULT err);
54
55     HANDLE              m_needDataEvent;
56     IMMDevice          *m_pDevice;
57     IAudioClient       *m_pAudioClient;
58     IAudioRenderClient *m_pRenderClient;
59
60     AEAudioFormat       m_format;
61     enum AEDataFormat   m_encodedFormat;
62     unsigned int        m_encodedChannels;
63     unsigned int        m_encodedSampleRate;
64     CAEChannelInfo      m_channelLayout;
65     std::string         m_device;
66
67     enum AEDataFormat   sinkReqFormat;
68     enum AEDataFormat   sinkRetFormat;
69
70     bool                m_running;
71     bool                m_initialized;
72     bool                m_isSuspended;    /* sink is in a suspended state - release audio device */
73     bool                m_isDirty;        /* sink output failed - needs re-init or new device */
74
75     unsigned int        m_uiBufferLen;    /* wasapi endpoint buffer size, in frames */
76     double              m_avgTimeWaiting; /* time between next buffer of data from SoftAE and driver call for data */
77     double              m_sinkLatency;    /* time in seconds of total duration of the two WASAPI buffers */
78     unsigned int        m_lastWriteToBuffer;
79
80     uint8_t            *m_pBuffer;
81     int                 m_bufferPtr;
82 };