Debian Codegraph @

modules/lsp-audio-pipewire-lib/include/lsp-plug.in/audio/pipewire/impl/cast.h

raw
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: 1 мая 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_IMPL_CAST_H_
23 #define LSP_PLUG_IN_AUDIO_PIPEWIRE_IMPL_CAST_H_
24
25 #include <lsp-plug.in/audio/pipewire/version.h>
26
27 #include <lsp-plug.in/audio/iface/types.h>
28 #include <lsp-plug.in/audio/pipewire/backend.h>
29 #include <pw-headers/pipewire/proxy.h>
30
31 namespace lsp
32 {
33 namespace audio
34 {
35 namespace pipewire
36 {
37 constexpr const char *prop_true = "true";
38 constexpr const char *prop_false = "false";
39
40 constexpr const char *BACKEND_MEDIA_TYPE = "Audio";
41 constexpr const char *BACKEND_MEDIA_CATEGORY = "Duplex";
42 constexpr const char *BACKEND_MEDIA_ROLE = "DSP";
43 constexpr const char *BACKEND_CLIENT_API = "native";
44
45 constexpr const char *BACKEND_CONFIG_FILE = "client.conf";
46
47 constexpr const char *PORT_FORMAT_DSP_AUDIO = "32 bit float mono audio";
48 constexpr const char *PORT_FORMAT_DSP_MIDI = "8 bit raw midi";
49 constexpr const char *PORT_FORMAT_DSP_MIDI2 = "32 bit raw UMP";
50 constexpr const char *PORT_FORMAT_DSP_OTHER = "other";
51
52 constexpr const char *DEFAULT_DEVICE_NAME = "system";
53 constexpr const char *DEFAULT_SERVER_NAME = "default";
54
55 constexpr const char *METADATA_DEFAULT_NAME = "default";
56
57 constexpr const char *ACTION_UPDATE_PROPERTIES = "update-props";
58
59 constexpr const char *BACKEN_DEFAULT_NODE_GROUP = "group.dsp.0";
60
61 constexpr const uint32_t RING_BUFFER_SIZE = 0x1000;
62
63 static inline pipewire::backend_t *cast(audio::backend_t *self)
64 {
65 return static_cast<pipewire::backend_t *>(self);
66 }
67
68 static inline pipewire::backend_t *cast(void *self)
69 {
70 return static_cast<pipewire::backend_t *>(self);
71 }
72
73 template <typename T>
74 static inline pw_proxy *to_pw_proxy(T *arg)
75 {
76 return reinterpret_cast<pw_proxy *>(arg);
77 }
78
79 static inline const char *port_format_dsp(size_t flags)
80 {
81 switch (flags & PORT_TYPE_MASK)
82 {
83 case PORT_TYPE_AUDIO:
84 return PORT_FORMAT_DSP_AUDIO;
85 case PORT_TYPE_MIDI:
86 return PORT_FORMAT_DSP_MIDI;
87 case PORT_TYPE_MIDI2:
88 return PORT_FORMAT_DSP_MIDI2;
89 default:
90 break;
91 }
92 return PORT_FORMAT_DSP_OTHER;
93 }
94
95 inline const char * decode_spa_command_type(uint32_t type)
96 {
97 switch (type)
98 {
99 case SPA_TYPE_COMMAND_Device:
100 return "SPA_TYPE_COMMAND_Device";
101 case SPA_TYPE_COMMAND_Node:
102 return "SPA_TYPE_COMMAND_Node";
103 default:
104 break;
105 }
106 return "unknown";
107 }
108
109 inline const char * decode_spa_node_command(uint32_t id)
110 {
111 #define V(key) \
112 case key: return # key;
113
114 switch (id)
115 {
116 V(SPA_NODE_COMMAND_Suspend)
117 V(SPA_NODE_COMMAND_Pause)
118 V(SPA_NODE_COMMAND_Start)
119 V(SPA_NODE_COMMAND_Enable)
120 V(SPA_NODE_COMMAND_Disable)
121 V(SPA_NODE_COMMAND_Flush)
122 V(SPA_NODE_COMMAND_Drain)
123 V(SPA_NODE_COMMAND_Marker)
124 V(SPA_NODE_COMMAND_ParamBegin)
125 V(SPA_NODE_COMMAND_ParamEnd)
126 V(SPA_NODE_COMMAND_RequestProcess)
127 default: break;
128 }
129 #undef V
130
131 return "unknown";
132 }
133
134 inline const char * decode_spa_param_id(uint32_t id)
135 {
136 #define V(key) \
137 case key: return # key;
138
139 switch (id)
140 {
141 V(SPA_PARAM_Invalid)
142 V(SPA_PARAM_PropInfo)
143 V(SPA_PARAM_Props)
144 V(SPA_PARAM_EnumFormat)
145 V(SPA_PARAM_Format)
146 V(SPA_PARAM_Buffers)
147 V(SPA_PARAM_Meta)
148 V(SPA_PARAM_IO)
149 V(SPA_PARAM_Profile)
150 V(SPA_PARAM_EnumPortConfig)
151 V(SPA_PARAM_PortConfig)
152 V(SPA_PARAM_EnumRoute)
153 V(SPA_PARAM_Route)
154 V(SPA_PARAM_Control)
155 V(SPA_PARAM_Latency)
156 V(SPA_PARAM_ProcessLatency)
157 V(SPA_PARAM_Tag)
158 default: break;
159 }
160 #undef V
161
162 return "unknown";
163 }
164
165 } /* namespace pipewire */
166 } /* namespace audio */
167 } /* namespace lsp */
168
169
170 #endif /* LSP_PLUG_IN_AUDIO_PIPEWIRE_IMPL_CAST_H_ */