Debian Codegraph @

modules/lsp-audio-pipewire-lib/include/lsp-plug.in/audio/pipewire/messages.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: 7 мая 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_MESSAGES_H_
23 #define LSP_PLUG_IN_AUDIO_PIPEWIRE_MESSAGES_H_
24
25 #include <lsp-plug.in/audio/pipewire/version.h>
26
27 #include <lsp-plug.in/audio/pipewire/ringbuffer.h>
28 #include <lsp-plug.in/common/types.h>
29
30 namespace lsp
31 {
32 namespace audio
33 {
34 namespace pipewire
35 {
36 constexpr uint16_t MESSAGE_MAGIC = 0x5254;
37
38 enum message_type_t
39 {
40 MSG_UNKNOWN, // Unknown message
41 MSG_LATENCY, // Latency message
42 };
43
44 /**
45 * Common mesage header
46 */
47 typedef struct header_t
48 {
49 uint16_t magic; // Magic header
50 uint16_t type; // type of the message
51 uint16_t length; // Length of the whole message
52 uint16_t cksum; // Checksum of the message
53 } header_t;
54
55 /**
56 * Latency change message
57 */
58 typedef struct latency_t
59 {
60 uint32_t latency; // Message latency
61 } latency_t;
62
63 /**
64 * Common message which can be fetched from ring buffer
65 */
66 typedef struct message_t
67 {
68 header_t header;
69 union
70 {
71 uint8_t data[4];
72 latency_t latency;
73 };
74 } message_t;
75
76 /**
77 * Initialize message header
78 * @param header message header
79 * @param type message type
80 * @param length the payload length
81 */
82 void init_header(header_t *header, uint16_t type, uint16_t length) noexcept;
83
84 /**
85 * Validate message header
86 * @param header message header to validate
87 * @return zero value on valid checksum
88 */
89 uint16_t header_checksum(const header_t *header) noexcept;
90
91 /**
92 * Read the whole message from ring buffer
93 * @param message message to read
94 * @param buffer buffer to read data
95 * @return status of operation
96 */
97 status_t read_message(message_t *message, ringbuffer *buffer) noexcept;
98
99 /**
100 * Write the whole message to the ring buffer
101 * @param buffer buffer to read data
102 * @param message message to read
103 * @return status of operation
104 */
105 status_t write_message(ringbuffer *bufer, const message_t *message) noexcept;
106
107 } /* namespace pipewire */
108 } /* namespace audio */
109 } /* namespace lsp */
110
111
112 #endif /* LSP_PLUG_IN_AUDIO_PIPEWIRE_MESSAGES_H_ */