Merge pull request #3165 from taxigps/3d_ass_size
[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     ISCOMPATIBLE,
54     VOLUME,
55     FLUSH,
56     TIMEOUT,
57   };
58   enum InSignal
59   {
60     ACC,
61     ERR,
62     STATS,
63   };
64 };
65
66 class CSinkDataProtocol : public Protocol
67 {
68 public:
69   CSinkDataProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
70   enum OutSignal
71   {
72     SAMPLE = 0,
73     DRAIN,
74   };
75   enum InSignal
76   {
77     RETURNSAMPLE,
78     ACC,
79   };
80 };
81
82 class CActiveAESink : private CThread
83 {
84 public:
85   CActiveAESink(CEvent *inMsgEvent);
86   void EnumerateSinkList();
87   void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
88   std::string GetDefaultDevice(bool passthrough);
89   void Start();
90   void Dispose();
91   bool HasVolume();
92   CSinkControlProtocol m_controlPort;
93   CSinkDataProtocol m_dataPort;
94
95 protected:
96   void Process();
97   void StateMachine(int signal, Protocol *port, Message *msg);
98   void PrintSinks();
99   void GetDeviceFriendlyName(std::string &device);
100   void OpenSink();
101   void ReturnBuffers();
102   bool IsCompatible(const AEAudioFormat format, const std::string &device);
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   bool m_extSilence;
118
119   CSampleBuffer m_sampleOfSilence;
120   uint8_t *m_convertBuffer;
121   int m_convertBufferSampleSize;
122   CAEConvert::AEConvertFrFn m_convertFn;
123   enum
124   {
125     CHECK_CONVERT,
126     NEED_CONVERT,
127     NEED_BYTESWAP,
128     SKIP_CONVERT,
129   } m_convertState;
130
131   std::string m_deviceFriendlyName;
132   std::string m_device;
133   AESinkInfoList m_sinkInfoList;
134   IAESink *m_sink;
135   AEAudioFormat m_sinkFormat, m_requestedFormat;
136   CEngineStats *m_stats;
137   float m_volume;
138 };
139
140 }