2 * Copyright (C) 2010-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "AEFactory.h"
23 #include "Utils/AEUtil.h"
25 #include "Engines/ActiveAE/ActiveAE.h"
27 #include "guilib/LocalizeStrings.h"
28 #include "settings/lib/Setting.h"
29 #include "settings/Settings.h"
30 #include "utils/StringUtils.h"
32 IAE* CAEFactory::AE = NULL;
33 static float g_fVolume = 1.0f;
34 static bool g_bMute = false;
36 IAE *CAEFactory::GetEngine()
41 bool CAEFactory::LoadEngine()
43 return CAEFactory::LoadEngine(AE_ENGINE_ACTIVE);
46 bool CAEFactory::LoadEngine(enum AEEngine engine)
48 /* can only load the engine once, XBMC restart is required to change it */
55 case AE_ENGINE_ACTIVE : AE = new ActiveAE::CActiveAE(); break;
60 if (AE && !AE->CanInit())
69 void CAEFactory::UnLoadEngine()
79 bool CAEFactory::StartEngine()
92 bool CAEFactory::Suspend()
100 bool CAEFactory::Resume()
108 bool CAEFactory::IsSuspended()
111 return AE->IsSuspended();
113 /* No engine to process audio */
117 /* engine wrapping */
118 IAESound *CAEFactory::MakeSound(const std::string &file)
121 return AE->MakeSound(file);
126 void CAEFactory::FreeSound(IAESound *sound)
129 AE->FreeSound(sound);
132 void CAEFactory::SetSoundMode(const int mode)
135 AE->SetSoundMode(mode);
138 void CAEFactory::OnSettingsChange(std::string setting)
141 AE->OnSettingsChange(setting);
144 void CAEFactory::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough)
147 AE->EnumerateOutputDevices(devices, passthrough);
150 void CAEFactory::VerifyOutputDevice(std::string &device, bool passthrough)
152 AEDeviceList devices;
153 EnumerateOutputDevices(devices, passthrough);
154 std::string firstDevice;
156 for (AEDeviceList::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt)
158 /* remember the first device so we can default to it if required */
159 if (firstDevice.empty())
160 firstDevice = deviceIt->second;
162 if (deviceIt->second == device)
164 else if (deviceIt->first == device)
166 device = deviceIt->second;
171 /* if the device wasnt found, set it to the first viable output */
172 device = firstDevice;
175 std::string CAEFactory::GetDefaultDevice(bool passthrough)
178 return AE->GetDefaultDevice(passthrough);
183 bool CAEFactory::SupportsRaw(AEDataFormat format)
185 // check if passthrough is enabled
186 if (!CSettings::Get().GetBool("audiooutput.passthrough"))
189 // fixed config disabled passthrough
190 if (CSettings::Get().GetInt("audiooutput.config") == AE_CONFIG_FIXED)
193 // check if the format is enabled in settings
194 if (format == AE_FMT_AC3 && !CSettings::Get().GetBool("audiooutput.ac3passthrough"))
196 if (format == AE_FMT_DTS && !CSettings::Get().GetBool("audiooutput.dtspassthrough"))
198 if (format == AE_FMT_EAC3 && !CSettings::Get().GetBool("audiooutput.eac3passthrough"))
200 if (format == AE_FMT_TRUEHD && !CSettings::Get().GetBool("audiooutput.truehdpassthrough"))
202 if (format == AE_FMT_DTSHD && !CSettings::Get().GetBool("audiooutput.dtshdpassthrough"))
206 return AE->SupportsRaw(format);
211 bool CAEFactory::SupportsSilenceTimeout()
214 return AE->SupportsSilenceTimeout();
220 * Returns true if current AudioEngine supports at lest two basic quality levels
221 * @return true if quality setting is supported, otherwise false
223 bool CAEFactory::SupportsQualitySetting(void)
228 return ((AE->SupportsQualityLevel(AE_QUALITY_LOW)? 1 : 0) +
229 (AE->SupportsQualityLevel(AE_QUALITY_MID)? 1 : 0) +
230 (AE->SupportsQualityLevel(AE_QUALITY_HIGH)? 1 : 0)) >= 2;
233 void CAEFactory::SetMute(const bool enabled)
236 AE->SetMute(enabled);
241 bool CAEFactory::IsMuted()
244 return AE->IsMuted();
246 return g_bMute || (g_fVolume == 0.0f);
249 float CAEFactory::GetVolume()
252 return AE->GetVolume();
257 void CAEFactory::SetVolume(const float volume)
260 AE->SetVolume(volume);
265 void CAEFactory::Shutdown()
271 IAEStream *CAEFactory::MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate,
272 unsigned int encodedSampleRate, CAEChannelInfo channelLayout, unsigned int options)
275 return AE->MakeStream(dataFormat, sampleRate, encodedSampleRate, channelLayout, options);
280 IAEStream *CAEFactory::FreeStream(IAEStream *stream)
283 return AE->FreeStream(stream);
288 void CAEFactory::GarbageCollect()
291 AE->GarbageCollect();
294 void CAEFactory::SettingOptionsAudioDevicesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string ¤t)
296 SettingOptionsAudioDevicesFillerGeneral(setting, list, current, false);
299 void CAEFactory::SettingOptionsAudioDevicesPassthroughFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string ¤t)
301 SettingOptionsAudioDevicesFillerGeneral(setting, list, current, true);
304 void CAEFactory::SettingOptionsAudioQualityLevelsFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int ¤t)
309 if(AE->SupportsQualityLevel(AE_QUALITY_LOW))
310 list.push_back(std::make_pair(g_localizeStrings.Get(13506), AE_QUALITY_LOW));
311 if(AE->SupportsQualityLevel(AE_QUALITY_MID))
312 list.push_back(std::make_pair(g_localizeStrings.Get(13507), AE_QUALITY_MID));
313 if(AE->SupportsQualityLevel(AE_QUALITY_HIGH))
314 list.push_back(std::make_pair(g_localizeStrings.Get(13508), AE_QUALITY_HIGH));
315 if(AE->SupportsQualityLevel(AE_QUALITY_REALLYHIGH))
316 list.push_back(std::make_pair(g_localizeStrings.Get(13509), AE_QUALITY_REALLYHIGH));
319 void CAEFactory::SettingOptionsAudioStreamsilenceFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int ¤t)
324 list.push_back(std::make_pair(g_localizeStrings.Get(20422), XbmcThreads::EndTime::InfiniteValue));
325 list.push_back(std::make_pair(g_localizeStrings.Get(13551), 0));
327 if (AE->SupportsSilenceTimeout())
329 list.push_back(std::make_pair(StringUtils::Format(g_localizeStrings.Get(13554).c_str(), 1), 1));
330 for (int i = 2; i <= 10; i++)
332 list.push_back(std::make_pair(StringUtils::Format(g_localizeStrings.Get(13555).c_str(), i), i));
337 void CAEFactory::SettingOptionsAudioDevicesFillerGeneral(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string ¤t, bool passthrough)
339 current = ((const CSettingString*)setting)->GetValue();
340 std::string firstDevice;
342 bool foundValue = false;
343 AEDeviceList sinkList;
344 EnumerateOutputDevices(sinkList, passthrough);
345 if (sinkList.size() == 0)
346 list.push_back(std::make_pair("Error - no devices found", "error"));
349 for (AEDeviceList::const_iterator sink = sinkList.begin(); sink != sinkList.end(); ++sink)
351 if (sink == sinkList.begin())
352 firstDevice = sink->second;
354 list.push_back(std::make_pair(sink->first, sink->second));
356 if (StringUtils::EqualsNoCase(current, sink->second))
362 current = firstDevice;
365 void CAEFactory::RegisterAudioCallback(IAudioCallback* pCallback)
368 AE->RegisterAudioCallback(pCallback);
371 void CAEFactory::UnregisterAudioCallback()
374 AE->UnregisterAudioCallback();
377 bool CAEFactory::IsSettingVisible(const std::string &condition, const std::string &value, const std::string &settingId)
379 if (settingId.empty() || value.empty() || !AE)
382 return AE->IsSettingVisible(value);
385 void CAEFactory::KeepConfiguration(unsigned int millis)
388 AE->KeepConfiguration(millis);
391 void CAEFactory::DeviceChange()