blob: d86a83eb84c691e4f8d2740eb97403ea3fb5765b (
plain)
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
|
/*
* Copyright (C) 2010-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "AESinkFactory.h"
#include "Interfaces/AESink.h"
#include "ServiceBroker.h"
#include "utils/StringUtils.h"
#include "utils/log.h"
#include <algorithm>
using namespace AE;
std::map<std::string, AESinkRegEntry> CAESinkFactory::m_AESinkRegEntry;
void CAESinkFactory::RegisterSink(const AESinkRegEntry& regEntry)
{
m_AESinkRegEntry[regEntry.sinkName] = regEntry;
IAE *ae = CServiceBroker::GetActiveAE();
if (ae)
ae->DeviceChange();
}
void CAESinkFactory::ClearSinks()
{
m_AESinkRegEntry.clear();
}
bool CAESinkFactory::HasSinks()
{
return !m_AESinkRegEntry.empty();
}
void CAESinkFactory::ParseDevice(std::string &device, std::string &driver)
{
int pos = device.find_first_of(':');
bool found = false;
if (pos > 0)
{
driver = device.substr(0, pos);
for (const auto& reg : m_AESinkRegEntry)
{
if (!StringUtils::EqualsNoCase(driver, reg.second.sinkName))
continue;
device = device.substr(pos + 1, device.length() - pos - 1);
found = true;
}
}
if (!found)
driver.clear();
}
IAESink *CAESinkFactory::Create(std::string &device, AEAudioFormat &desiredFormat)
{
// extract the driver from the device string if it exists
std::string driver;
ParseDevice(device, driver);
AEAudioFormat tmpFormat = desiredFormat;
IAESink *sink;
std::string tmpDevice = device;
for (const auto& reg : m_AESinkRegEntry)
{
if (driver != reg.second.sinkName)
continue;
sink = reg.second.createFunc(tmpDevice, tmpFormat);
if (sink)
{
desiredFormat = tmpFormat;
return sink;
}
}
return nullptr;
}
void CAESinkFactory::EnumerateEx(std::vector<AESinkInfo>& list,
bool force,
const std::string& driver)
{
AESinkInfo info;
for (const auto& reg : m_AESinkRegEntry)
{
if (!driver.empty() && driver != reg.second.sinkName)
continue;
info.m_deviceInfoList.clear();
info.m_sinkName = reg.second.sinkName;
reg.second.enumerateFunc(info.m_deviceInfoList, force);
if (!info.m_deviceInfoList.empty())
list.push_back(info);
}
}
void CAESinkFactory::Cleanup()
{
for (const auto& reg : m_AESinkRegEntry)
{
if (reg.second.cleanupFunc)
reg.second.cleanupFunc();
}
}
|