/
AEFactory.cpp
399 lines (326 loc) · 9.7 KB
/
AEFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
* Copyright (C) 2010-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "system.h"
#include "AEFactory.h"
#include "Engines/ActiveAE/ActiveAE.h"
#include "guilib/LocalizeStrings.h"
#include "settings/lib/Setting.h"
#include "settings/Settings.h"
#include "utils/StringUtils.h"
IAE* CAEFactory::AE = NULL;
static float g_fVolume = 1.0f;
static bool g_bMute = false;
IAE *CAEFactory::GetEngine()
{
return AE;
}
bool CAEFactory::LoadEngine()
{
/* can only load the engine once, XBMC restart is required to change it */
if (AE)
return false;
AE = new ActiveAE::CActiveAE();
if (AE && !AE->CanInit())
{
delete AE;
AE = NULL;
}
return AE != NULL;
}
void CAEFactory::UnLoadEngine()
{
if(AE)
{
AE->Shutdown();
delete AE;
AE = NULL;
}
}
bool CAEFactory::StartEngine()
{
if (!AE)
return false;
if (AE->Initialize())
return true;
delete AE;
AE = NULL;
return false;
}
bool CAEFactory::Suspend()
{
if(AE)
return AE->Suspend();
return false;
}
bool CAEFactory::Resume()
{
if(AE)
return AE->Resume();
return false;
}
bool CAEFactory::IsSuspended()
{
if(AE)
return AE->IsSuspended();
/* No engine to process audio */
return true;
}
/* engine wrapping */
IAESound *CAEFactory::MakeSound(const std::string &file)
{
if(AE)
return AE->MakeSound(file);
return NULL;
}
void CAEFactory::FreeSound(IAESound *sound)
{
if(AE)
AE->FreeSound(sound);
}
void CAEFactory::SetSoundMode(const int mode)
{
if(AE)
AE->SetSoundMode(mode);
}
void CAEFactory::OnSettingsChange(std::string setting)
{
if(AE)
AE->OnSettingsChange(setting);
}
void CAEFactory::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough)
{
if(AE)
AE->EnumerateOutputDevices(devices, passthrough);
}
void CAEFactory::VerifyOutputDevice(std::string &device, bool passthrough)
{
AEDeviceList devices;
EnumerateOutputDevices(devices, passthrough);
std::string firstDevice;
for (AEDeviceList::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt)
{
/* remember the first device so we can default to it if required */
if (firstDevice.empty())
firstDevice = deviceIt->second;
if (deviceIt->second == device)
return;
else if (deviceIt->first == device)
{
device = deviceIt->second;
return;
}
}
/* if the device wasnt found, set it to the first viable output */
device = firstDevice;
}
std::string CAEFactory::GetDefaultDevice(bool passthrough)
{
if(AE)
return AE->GetDefaultDevice(passthrough);
return "default";
}
bool CAEFactory::SupportsRaw(AEDataFormat format, int samplerate)
{
// check if passthrough is enabled
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_AUDIOOUTPUT_PASSTHROUGH))
return false;
// fixed config disabled passthrough
if (CSettings::GetInstance().GetInt(CSettings::SETTING_AUDIOOUTPUT_CONFIG) == AE_CONFIG_FIXED)
return false;
// check if the format is enabled in settings
if ((((AEDataFormat)((int)format & ~PT_FORMAT_RAW_CLASS)) == AE_FMT_AC3) && !CSettings::GetInstance().GetBool(CSettings::SETTING_AUDIOOUTPUT_AC3PASSTHROUGH))
return false;
if ((((AEDataFormat)((int)format & ~PT_FORMAT_RAW_CLASS)) == AE_FMT_DTS) && !CSettings::GetInstance().GetBool(CSettings::SETTING_AUDIOOUTPUT_DTSPASSTHROUGH))
return false;
if ((((AEDataFormat)((int)format & ~PT_FORMAT_RAW_CLASS)) == AE_FMT_EAC3) && !CSettings::GetInstance().GetBool(CSettings::SETTING_AUDIOOUTPUT_EAC3PASSTHROUGH))
return false;
if ((((AEDataFormat)((int)format & ~PT_FORMAT_RAW_CLASS)) == AE_FMT_TRUEHD) && !CSettings::GetInstance().GetBool(CSettings::SETTING_AUDIOOUTPUT_TRUEHDPASSTHROUGH))
return false;
if ((((AEDataFormat)((int)format & ~PT_FORMAT_RAW_CLASS)) == AE_FMT_DTSHD) && !CSettings::GetInstance().GetBool(CSettings::SETTING_AUDIOOUTPUT_DTSHDPASSTHROUGH))
return false;
if(AE)
return AE->SupportsRaw(format, samplerate);
return false;
}
bool CAEFactory::SupportsSilenceTimeout()
{
if(AE)
return AE->SupportsSilenceTimeout();
return false;
}
bool CAEFactory::HasStereoAudioChannelCount()
{
if(AE)
return AE->HasStereoAudioChannelCount();
return false;
}
bool CAEFactory::HasHDAudioChannelCount()
{
if(AE)
return AE->HasHDAudioChannelCount();
return false;
}
/**
* Returns true if current AudioEngine supports at lest two basic quality levels
* @return true if quality setting is supported, otherwise false
*/
bool CAEFactory::SupportsQualitySetting(void)
{
if (!AE)
return false;
return ((AE->SupportsQualityLevel(AE_QUALITY_LOW)? 1 : 0) +
(AE->SupportsQualityLevel(AE_QUALITY_MID)? 1 : 0) +
(AE->SupportsQualityLevel(AE_QUALITY_HIGH)? 1 : 0)) >= 2;
}
void CAEFactory::SetMute(const bool enabled)
{
if(AE)
AE->SetMute(enabled);
g_bMute = enabled;
}
bool CAEFactory::IsMuted()
{
if(AE)
return AE->IsMuted();
return g_bMute || (g_fVolume == 0.0f);
}
float CAEFactory::GetVolume()
{
if(AE)
return AE->GetVolume();
return g_fVolume;
}
void CAEFactory::SetVolume(const float volume)
{
if(AE)
AE->SetVolume(volume);
else
g_fVolume = volume;
}
void CAEFactory::Shutdown()
{
if(AE)
AE->Shutdown();
}
IAEStream *CAEFactory::MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate,
unsigned int encodedSampleRate, CAEChannelInfo channelLayout, unsigned int options)
{
if(AE)
return AE->MakeStream(dataFormat, sampleRate, encodedSampleRate, channelLayout, options);
return NULL;
}
IAEStream *CAEFactory::FreeStream(IAEStream *stream)
{
if(AE)
return AE->FreeStream(stream);
return NULL;
}
void CAEFactory::GarbageCollect()
{
if(AE)
AE->GarbageCollect();
}
void CAEFactory::SettingOptionsAudioDevicesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string ¤t, void *data)
{
SettingOptionsAudioDevicesFillerGeneral(setting, list, current, false);
}
void CAEFactory::SettingOptionsAudioDevicesPassthroughFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string ¤t, void *data)
{
SettingOptionsAudioDevicesFillerGeneral(setting, list, current, true);
}
void CAEFactory::SettingOptionsAudioQualityLevelsFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
if (!AE)
return;
if(AE->SupportsQualityLevel(AE_QUALITY_LOW))
list.push_back(std::make_pair(g_localizeStrings.Get(13506), AE_QUALITY_LOW));
if(AE->SupportsQualityLevel(AE_QUALITY_MID))
list.push_back(std::make_pair(g_localizeStrings.Get(13507), AE_QUALITY_MID));
if(AE->SupportsQualityLevel(AE_QUALITY_HIGH))
list.push_back(std::make_pair(g_localizeStrings.Get(13508), AE_QUALITY_HIGH));
if(AE->SupportsQualityLevel(AE_QUALITY_REALLYHIGH))
list.push_back(std::make_pair(g_localizeStrings.Get(13509), AE_QUALITY_REALLYHIGH));
if(AE->SupportsQualityLevel(AE_QUALITY_GPU))
list.push_back(std::make_pair(g_localizeStrings.Get(38010), AE_QUALITY_GPU));
}
void CAEFactory::SettingOptionsAudioStreamsilenceFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
if (!AE)
return;
list.push_back(std::make_pair(g_localizeStrings.Get(20422), XbmcThreads::EndTime::InfiniteValue));
list.push_back(std::make_pair(g_localizeStrings.Get(13551), 0));
if (AE->SupportsSilenceTimeout())
{
list.push_back(std::make_pair(StringUtils::Format(g_localizeStrings.Get(13554).c_str(), 1), 1));
for (int i = 2; i <= 10; i++)
{
list.push_back(std::make_pair(StringUtils::Format(g_localizeStrings.Get(13555).c_str(), i), i));
}
}
}
void CAEFactory::SettingOptionsAudioDevicesFillerGeneral(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string ¤t, bool passthrough)
{
current = ((const CSettingString*)setting)->GetValue();
std::string firstDevice;
bool foundValue = false;
AEDeviceList sinkList;
EnumerateOutputDevices(sinkList, passthrough);
if (sinkList.size() == 0)
list.push_back(std::make_pair("Error - no devices found", "error"));
else
{
for (AEDeviceList::const_iterator sink = sinkList.begin(); sink != sinkList.end(); ++sink)
{
if (sink == sinkList.begin())
firstDevice = sink->second;
list.push_back(std::make_pair(sink->first, sink->second));
if (StringUtils::EqualsNoCase(current, sink->second))
foundValue = true;
}
}
if (!foundValue)
current = firstDevice;
}
void CAEFactory::RegisterAudioCallback(IAudioCallback* pCallback)
{
if (AE)
AE->RegisterAudioCallback(pCallback);
}
void CAEFactory::UnregisterAudioCallback()
{
if (AE)
AE->UnregisterAudioCallback();
}
bool CAEFactory::IsSettingVisible(const std::string &condition, const std::string &value, const CSetting *setting, void *data)
{
if (setting == NULL || value.empty() || !AE)
return false;
return AE->IsSettingVisible(value);
}
void CAEFactory::KeepConfiguration(unsigned int millis)
{
if (AE)
AE->KeepConfiguration(millis);
}
void CAEFactory::DeviceChange()
{
if (AE)
AE->DeviceChange();
}