[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / cores / AudioEngine / Engines / ActiveAE / ActiveAESink.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 "threads/Event.h"
23 #include "threads/Thread.h"
24 #include "utils/ActorProtocol.h"
25 #include "Interfaces/AE.h"
26 #include "Interfaces/AESink.h"
27 #include "AESinkFactory.h"
28 #include "ActiveAEResample.h"
29 #include "Utils/AEConvert.h"
30
31 namespace ActiveAE
32 {
33 using namespace Actor;
34
35 class CEngineStats;
36
37 struct SinkConfig
38 {
39   AEAudioFormat format;
40   CEngineStats *stats;
41   const std::string *device;
42 };
43
44 class CSinkControlProtocol : public Protocol
45 {
46 public:
47   CSinkControlProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
48   enum OutSignal
49   {
50     CONFIGURE,
51     UNCONFIGURE,
52     SILENCEMODE,
53     VOLUME,
54     FLUSH,
55     TIMEOUT,
56   };
57   enum InSignal
58   {
59     ACC,
60     ERR,
61     STATS,
62   };
63 };
64
65 class CSinkDataProtocol : public Protocol
66 {
67 public:
68   CSinkDataProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
69   enum OutSignal
70   {
71     SAMPLE = 0,
72     DRAIN,
73   };
74   enum InSignal
75   {
76     RETURNSAMPLE,
77     ACC,
78   };
79 };
80
81 class CActiveAESink : private CThread
82 {
83 public:
84   CActiveAESink(CEvent *inMsgEvent);
85   void EnumerateSinkList(bool force);
86   void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
87   std::string GetDefaultDevice(bool passthrough);
88   void Start();
89   void Dispose();
90   bool HasVolume();
91   AEDeviceType GetDeviceType(const std::string &device);
92   bool HasPassthroughDevice();
93   CSinkControlProtocol m_controlPort;
94   CSinkDataProtocol m_dataPort;
95
96 protected:
97   void Process();
98   void StateMachine(int signal, Protocol *port, Message *msg);
99   void PrintSinks();
100   void GetDeviceFriendlyName(std::string &device);
101   void OpenSink();
102   void ReturnBuffers();
103
104   unsigned int OutputSamples(CSampleBuffer* samples);
105   void ConvertInit(CSampleBuffer* samples);
106   inline void EnsureConvertBuffer(CSampleBuffer* samples);
107   inline uint8_t* Convert(CSampleBuffer* samples);
108
109   void GenerateNoise();
110
111   CEvent m_outMsgEvent;
112   CEvent *m_inMsgEvent;
113   int m_state;
114   bool m_bStateMachineSelfTrigger;
115   int m_extTimeout;
116   bool m_extError;
117   unsigned int m_extSilenceTimeout;
118   XbmcThreads::EndTime m_extSilenceTimer;
119
120   CSampleBuffer m_sampleOfSilence;
121   uint8_t *m_convertBuffer;
122   int m_convertBufferSampleSize;
123   CAEConvert::AEConvertFrFn m_convertFn;
124   enum
125   {
126     CHECK_CONVERT,
127     NEED_CONVERT,
128     NEED_BYTESWAP,
129     SKIP_CONVERT,
130   } m_convertState;
131
132   std::string m_deviceFriendlyName;
133   std::string m_device;
134   AESinkInfoList m_sinkInfoList;
135   IAESink *m_sink;
136   AEAudioFormat m_sinkFormat, m_requestedFormat;
137   CEngineStats *m_stats;
138   float m_volume;
139 };
140
141 }