-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2f1b28
commit 6b1272c
Showing
5 changed files
with
150 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#include "EventManager.hpp" | ||
|
||
#include "Library.hpp" | ||
|
||
#include <pipewire/core.h> | ||
#include <pipewire/node.h> | ||
|
||
using namespace pipewire; | ||
|
||
static constexpr auto NODE_TYPE_ID = "PipeWire:Interface:Node"; | ||
|
||
static constexpr pw_registry_events eventsRegistry = { PW_VERSION_REGISTRY_EVENTS, | ||
[](void *userData, const uint32_t id, | ||
const uint32_t /*permissions*/, const char *type, | ||
const uint32_t /*version*/, const spa_dict * /*props*/) { | ||
if (spa_streq(type, NODE_TYPE_ID)) { | ||
auto &manager = *static_cast< EventManager * >(userData); | ||
|
||
new NodeInfoData(manager, id); | ||
} | ||
}, | ||
[](void *userData, const uint32_t id) { | ||
auto &manager = *static_cast< EventManager* >(userData); | ||
|
||
manager.feedback().nodeRemoved(id); | ||
} }; | ||
|
||
static constexpr pw_node_events eventsNode = { PW_VERSION_NODE_EVENTS, | ||
[](void *userData, const pw_node_info *info) { | ||
auto data = static_cast< NodeInfoData* >(userData); | ||
|
||
data->manager().feedback().nodeAdded(info); | ||
|
||
delete data; | ||
}, | ||
nullptr }; | ||
|
||
EventManager::EventManager(pw_core *core, const Feedback &feedback) | ||
: m_feedback(feedback), m_registry(pw_core_get_registry(core, PW_VERSION_REGISTRY, 0)) { | ||
if (m_registry) { | ||
pw_registry_add_listener(m_registry, &m_registryListener, &eventsRegistry, this); | ||
} | ||
} | ||
|
||
EventManager::~EventManager() { | ||
if (m_registry) { | ||
spa_hook_remove(&m_registryListener); | ||
lib().proxy_destroy(reinterpret_cast< pw_proxy * >(m_registry)); | ||
} | ||
} | ||
|
||
NodeInfoData::NodeInfoData(EventManager &manager, const uint32_t id) | ||
: m_manager(manager), | ||
m_proxy(static_cast< pw_proxy * >(pw_registry_bind(manager.registry(), id, NODE_TYPE_ID, PW_VERSION_NODE, 0))), | ||
m_listener() { | ||
if (m_proxy) { | ||
lib().proxy_add_object_listener(m_proxy, &m_listener, &eventsNode, this); | ||
} | ||
} | ||
|
||
NodeInfoData::~NodeInfoData() { | ||
spa_hook_remove(&m_listener); | ||
|
||
if (m_proxy) { | ||
lib().proxy_destroy(m_proxy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#ifndef CROSSAUDIO_SRC_BACKENDS_PIPEWIRE_EVENTMANAGER_HPP | ||
#define CROSSAUDIO_SRC_BACKENDS_PIPEWIRE_EVENTMANAGER_HPP | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
|
||
#include <spa/utils/hook.h> | ||
|
||
struct pw_core; | ||
struct pw_node_info; | ||
struct pw_proxy; | ||
struct pw_registry; | ||
|
||
namespace pipewire { | ||
class EventManager { | ||
public: | ||
struct Feedback { | ||
std::function< void(const pw_node_info *info) > nodeAdded; | ||
std::function< void(uint32_t id) > nodeRemoved; | ||
}; | ||
|
||
EventManager(pw_core *core, const Feedback &feedback); | ||
~EventManager(); | ||
|
||
constexpr auto &feedback() { return m_feedback; } | ||
constexpr auto registry() { return m_registry; } | ||
|
||
private: | ||
EventManager(const EventManager &) = delete; | ||
EventManager &operator=(const EventManager &) = delete; | ||
|
||
Feedback m_feedback; | ||
pw_registry *m_registry; | ||
spa_hook m_registryListener; | ||
}; | ||
|
||
class NodeInfoData { | ||
public: | ||
NodeInfoData(EventManager &manager, const uint32_t id); | ||
~NodeInfoData(); | ||
|
||
constexpr auto &manager() { return m_manager; } | ||
|
||
private: | ||
EventManager &m_manager; | ||
pw_proxy *m_proxy; | ||
spa_hook m_listener; | ||
}; | ||
} // namespace pipewire | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters