-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioRouter.h
More file actions
62 lines (47 loc) · 2.25 KB
/
AudioRouter.h
File metadata and controls
62 lines (47 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This file is part of the Open Audio Live System project, a live audio environment
// Copyright (c) 2026 - Mathis DELGADO
//
// This project is distributed under the Creative Commons CC-BY-NC-SA licence. https://creativecommons.org/licenses/by-nc-sa/4.0
#ifndef AUDIOROUTER_H
#define AUDIOROUTER_H
#include "netutils/LowLatSocket.h"
#include "packet_structs.h"
#include <functional>
#include <queue>
#include <mutex>
#include <shared_mutex>
class AudioRouter {
public:
AudioRouter(uint16_t self_uid);
virtual ~AudioRouter() = default;
bool init_router(const std::string& eth_interface, const std::shared_ptr<NetworkMapper>& nmapper);
void poll_audio_data(bool async);
void poll_local_audio_buffer();
void poll_control_packets(bool async = true);
void send_audio_packet(const AudioPacket &packet, uint16_t dest_uid);
template<class T>
void send_control_packet(const T& pck, uint16_t dest_uid) {
m_control_iface->send_data(pck, dest_uid);
}
void set_routing_callback(const std::function<void(AudioPacket&, LowLatHeader&)> &callback);
void set_control_callback(const std::function<void(ControlPacket&, LowLatHeader&)>& callback);
void set_control_response_callback(const std::function<void(ControlResponsePacket&, LowLatHeader&)>& callback);
void set_pipe_create_callback(const std::function<void(ControlPipeCreatePacket&, LowLatHeader&)>& callback);
void set_control_query_callback(const std::function<void(ControlQueryPacket&, LowLatHeader&)>& callback);
private:
std::unique_ptr<LowLatSocket> m_audio_iface;
std::unique_ptr<LowLatSocket> m_control_iface;
uint16_t m_self_uid;
std::queue<AudioPacket> m_local_audio_fifo;
std::shared_ptr<NetworkMapper> m_nmapper;
#ifndef NO_THREADS
std::shared_mutex m_local_fifo_mutex;
#endif // NO_THREADS
protected:
std::function<void(AudioPacket&, LowLatHeader&)> m_routing_callback;
std::function<void(ControlPacket&, LowLatHeader&)> m_channel_control_callback;
std::function<void(ControlPipeCreatePacket&, LowLatHeader&)> m_pipe_create_callback;
std::function<void(ControlResponsePacket&, LowLatHeader&)> m_control_response_callback;
std::function<void(ControlQueryPacket&, LowLatHeader&)> m_control_query_callback;
};
#endif //AUDIOROUTER_H