| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-audio-pipewire-lib |
| 6 |
* Created on: 3 мая 2026 г. |
| 7 |
* |
| 8 |
* lsp-audio-pipewire-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-audio-pipewire-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-audio-pipewire-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_AUDIO_PIPEWIRE_REGISTRY_H_ |
| 23 |
#define LSP_PLUG_IN_AUDIO_PIPEWIRE_REGISTRY_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/audio/pipewire/version.h> |
| 26 |
|
| 27 |
#include <lsp-plug.in/audio/pipewire/registry_types.h> |
| 28 |
#include <lsp-plug.in/common/status.h> |
| 29 |
|
| 30 |
#include <pw-headers/pipewire/core.h> |
| 31 |
#include <pw-headers/spa/utils/dict.h> |
| 32 |
|
| 33 |
namespace lsp |
| 34 |
{ |
| 35 |
namespace audio |
| 36 |
{ |
| 37 |
namespace pipewire |
| 38 |
{ |
| 39 |
/** |
| 40 |
* The reigstry for pipewire objects |
| 41 |
*/ |
| 42 |
struct registry |
| 43 |
{ |
| 44 |
private: |
| 45 |
typedef struct storage_t |
| 46 |
{ |
| 47 |
object_t **vObjects; |
| 48 |
uint32_t nCount; |
| 49 |
uint32_t nCapacity; |
| 50 |
} storage_t; |
| 51 |
|
| 52 |
protected: |
| 53 |
char *sDefaultSource; |
| 54 |
char *sDefaultSink; |
| 55 |
storage_t vClients; |
| 56 |
storage_t vNodes; |
| 57 |
storage_t vPorts; |
| 58 |
storage_t vLinks; |
| 59 |
|
| 60 |
protected: |
| 61 |
static inline void init_storage(storage_t & storage) noexcept; |
| 62 |
template <typename T> |
| 63 |
static inline void destroy_storage(storage_t & storage) noexcept; |
| 64 |
template <typename T> |
| 65 |
static inline T *find_by_id(storage_t & storage, uint32_t id) noexcept; |
| 66 |
static object_t *find_object_by_id(storage_t & storage, uint32_t id) noexcept; |
| 67 |
static uint32_t storage_index_of(storage_t & storage, uint32_t id) noexcept; |
| 68 |
static bool store_object(storage_t & storage, object_t * & old, object_t *object) noexcept; |
| 69 |
template <typename T> |
| 70 |
static bool add_to_storage(storage_t & storage, T *object) noexcept; |
| 71 |
template <typename T> |
| 72 |
static inline T *remove_by_id(storage_t & storage, uint32_t id) noexcept; |
| 73 |
|
| 74 |
static inline void destroy(client_t *iteme) noexcept; |
| 75 |
static inline void destroy(node_t *item) noexcept; |
| 76 |
static inline void destroy(port_t *item) noexcept; |
| 77 |
static inline void destroy(link_t *item) noexcept; |
| 78 |
|
| 79 |
static inline client_t *alloc_client() noexcept; |
| 80 |
static inline node_t *alloc_node() noexcept; |
| 81 |
static inline port_t *alloc_port() noexcept; |
| 82 |
static inline link_t *alloc_link() noexcept; |
| 83 |
|
| 84 |
protected: |
| 85 |
char *make_unique_id(const char *prefix, uint32_t id) noexcept; |
| 86 |
|
| 87 |
public: |
| 88 |
registry() noexcept; |
| 89 |
registry(const registry &) = delete; |
| 90 |
registry(registry && src) = delete; |
| 91 |
~registry() noexcept; |
| 92 |
|
| 93 |
registry & operator = (const registry &) = delete; |
| 94 |
registry & operator = (registry && src) = delete; |
| 95 |
|
| 96 |
void construct() noexcept; |
| 97 |
void destroy() noexcept; |
| 98 |
|
| 99 |
public: // PipeWire management interface |
| 100 |
status_t process_add(uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props) noexcept; |
| 101 |
status_t process_metadata(uint32_t id, const char *key, const char *type, const char *value) noexcept; |
| 102 |
status_t process_remove(uint32_t id) noexcept; |
| 103 |
|
| 104 |
public: |
| 105 |
const node_t *find_node_by_id(uint32_t id) const noexcept; |
| 106 |
const node_t *find_node_by_name(const char *name) const noexcept; |
| 107 |
const node_t *find_node_by_nick(const char *name) const noexcept; |
| 108 |
const node_t *find_node_by_string(const char *name) const noexcept; |
| 109 |
const node_t *find_node_by_uid(const char *uid) const noexcept; |
| 110 |
const port_t *find_node_port(uint32_t node_id, const char *port_id, uint32_t direction) const noexcept; |
| 111 |
|
| 112 |
const port_t *find_port_by_id(uint32_t id) const noexcept; |
| 113 |
const port_t *find_port(const char *port_id, uint32_t direction) const noexcept; |
| 114 |
|
| 115 |
const link_t *find_link(const port_t *src, const port_t *dst) const noexcept; |
| 116 |
const link_t *find_link(uint32_t src_node_id, uint32_t src_port_id, uint32_t dst_node_id, uint32_t dst_port_id) const noexcept; |
| 117 |
}; |
| 118 |
} /* namespace pipewire */ |
| 119 |
} /* namespace audio */ |
| 120 |
} /* namespace lsp */ |
| 121 |
|
| 122 |
#endif /* LSP_PLUG_IN_AUDIO_PIPEWIRE_REGISTRY_H_ */ |