3 * Copyright (C) 2010-2013 Team XBMC
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)
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.
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/>.
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"
33 using namespace Actor;
41 const std::string *device;
44 class CSinkControlProtocol : public Protocol
47 CSinkControlProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
66 class CSinkDataProtocol : public Protocol
69 CSinkDataProtocol(std::string name, CEvent* inEvent, CEvent *outEvent) : Protocol(name, inEvent, outEvent) {};
82 class CActiveAESink : private CThread
85 CActiveAESink(CEvent *inMsgEvent);
86 void EnumerateSinkList(bool force);
87 void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
88 std::string GetDefaultDevice(bool passthrough);
92 AEDeviceType GetDeviceType(const std::string &device);
93 bool HasPassthroughDevice();
94 CSinkControlProtocol m_controlPort;
95 CSinkDataProtocol m_dataPort;
99 void StateMachine(int signal, Protocol *port, Message *msg);
101 void GetDeviceFriendlyName(std::string &device);
103 void ReturnBuffers();
104 bool IsCompatible(const AEAudioFormat format, const std::string &device);
106 unsigned int OutputSamples(CSampleBuffer* samples);
107 void ConvertInit(CSampleBuffer* samples);
108 inline void EnsureConvertBuffer(CSampleBuffer* samples);
109 inline uint8_t* Convert(CSampleBuffer* samples);
111 void GenerateNoise();
113 CEvent m_outMsgEvent;
114 CEvent *m_inMsgEvent;
116 bool m_bStateMachineSelfTrigger;
119 int m_extSilenceTimeout;
120 XbmcThreads::EndTime m_extSilenceTimer;
122 CSampleBuffer m_sampleOfSilence;
123 uint8_t *m_convertBuffer;
124 int m_convertBufferSampleSize;
125 CAEConvert::AEConvertFrFn m_convertFn;
134 std::string m_deviceFriendlyName;
135 std::string m_device;
136 AESinkInfoList m_sinkInfoList;
138 AEAudioFormat m_sinkFormat, m_requestedFormat;
139 CEngineStats *m_stats;