[WASAPI] set stream audio category
[xbmc.git] / xbmc / cores / AudioEngine / Sinks / pipewire / PipewireProxy.cpp
blob69a5397fea04bd74ff2c551d6603576aa600e462
1 /*
2 * Copyright (C) 2010-2021 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PipewireProxy.h"
11 #include "PipewireRegistry.h"
12 #include "ServiceBroker.h"
13 #include "cores/AudioEngine/Interfaces/AE.h"
14 #include "utils/log.h"
16 #include <stdexcept>
18 using namespace KODI;
19 using namespace PIPEWIRE;
21 CPipewireProxy::CPipewireProxy(CPipewireRegistry& registry,
22 uint32_t id,
23 const char* type,
24 uint32_t version)
25 : m_registry(registry), m_proxyEvents(CreateProxyEvents())
27 m_proxy.reset(
28 reinterpret_cast<pw_proxy*>(pw_registry_bind(registry.Get(), id, type, version, 0)));
29 if (!m_proxy)
31 CLog::Log(LOGERROR, "CPipewireProxy: failed to create proxy: {}", strerror(errno));
32 throw std::runtime_error("CPipewireProxy: failed to create proxy");
35 pw_proxy_add_listener(m_proxy.get(), &m_proxyListener, &m_proxyEvents, this);
38 CPipewireProxy::~CPipewireProxy()
40 spa_hook_remove(&m_proxyListener);
43 void CPipewireProxy::Bound(void* userdata, uint32_t id)
45 CLog::Log(LOGDEBUG, "CPipewireProxy::{} - id={}", __FUNCTION__, id);
47 auto AE = CServiceBroker::GetActiveAE();
48 if (AE)
49 AE->DeviceCountChange("PIPEWIRE");
52 void CPipewireProxy::Removed(void* userdata)
54 CLog::Log(LOGDEBUG, "CPipewireProxy::{}", __FUNCTION__);
56 auto AE = CServiceBroker::GetActiveAE();
57 if (AE)
58 AE->DeviceCountChange("PIPEWIRE");
61 pw_proxy_events CPipewireProxy::CreateProxyEvents()
63 pw_proxy_events proxyEvents = {};
64 proxyEvents.version = PW_VERSION_PROXY_EVENTS;
65 proxyEvents.bound = Bound;
66 proxyEvents.removed = Removed;
68 return proxyEvents;