ActiveAE: flush engine on flush stream if only one stream is active
[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 };
42
43 class CSinkControlProtocol : public Protocol
44 {
45 public:
46   CSinkControlProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
47   enum OutSignal
48   {
49     CONFIGURE,
50     UNCONFIGURE,
51     SILENCEMODE,
52     VOLUME,
53     FLUSH,
54     TIMEOUT,
55   };
56   enum InSignal
57   {
58     ACC,
59     ERR,
60     STATS,
61   };
62 };
63
64 class CSinkDataProtocol : public Protocol
65 {
66 public:
67   CSinkDataProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
68   enum OutSignal
69   {
70     SAMPLE = 0,
71     DRAIN,
72   };
73   enum InSignal
74   {
75     RETURNSAMPLE,
76     ACC,
77   };
78 };
79
80 class CActiveAESink : private CThread
81 {
82 public:
83   CActiveAESink(CEvent *inMsgEvent);
84   void EnumerateSinkList();
85   void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
86   std::string GetDefaultDevice(bool passthrough);
87   void Start();
88   void Dispose();
89   bool IsCompatible(const AEAudioFormat format, const std::string &device);
90   bool HasVolume();
91   CSinkControlProtocol m_controlPort;
92   CSinkDataProtocol m_dataPort;
93
94 protected:
95   void Process();
96   void StateMachine(int signal, Protocol *port, Message *msg);
97   void PrintSinks();
98   void GetDeviceFriendlyName(std::string &device);
99   void OpenSink();
100   void ReturnBuffers();
101
102   unsigned int OutputSamples(CSampleBuffer* samples);
103   void ConvertInit(CSampleBuffer* samples);
104   inline void EnsureConvertBuffer(CSampleBuffer* samples);
105   inline uint8_t* Convert(CSampleBuffer* samples);
106
107   void GenerateNoise();
108
109   CEvent m_outMsgEvent;
110   CEvent *m_inMsgEvent;
111   int m_state;
112   bool m_bStateMachineSelfTrigger;
113   int m_extTimeout;
114   bool m_extError;
115   bool m_extSilence;
116   int m_extCycleCounter;
117
118   CSampleBuffer m_sampleOfSilence;
119   CSampleBuffer m_sampleOfNoise;
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   AESinkInfoList m_sinkInfoList;
133   IAESink *m_sink;
134   AEAudioFormat m_sinkFormat, m_requestedFormat;
135   CEngineStats *m_stats;
136   float m_volume;
137 };
138
139 }