-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhost.h
107 lines (89 loc) · 2.1 KB
/
host.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef _HOST_H_
#define _HOST_H_
#include <dlfcn.h>
#include <pthread.h>
#include <stdexcept>
#include <vector>
#include "log.h"
#include "plugins/audio/audioPlugin.h"
#define USE_HOST_SO
#ifdef USE_HOST_SO
struct Host {
AudioPluginHandlerInterface* (*load)();
AudioPluginHandlerInterface* audioPluginHandler = NULL;
}* host = NULL;
AudioPlugin& getPlugin(std::string name, int16_t track = -1)
{
return host->audioPluginHandler->getPlugin(name, track);
}
void hostConfig(nlohmann::json& config)
{
if (host) {
host->audioPluginHandler->config(config);
}
}
void sendAudioEvent(AudioEventType event)
{
host->audioPluginHandler->sendEvent(event);
}
void* hostThread(void* = NULL)
{
if (host) {
host->audioPluginHandler->loop();
}
return NULL;
}
void loadHostPlugin()
{
if (host) {
logWarn("Host plugin already loaded");
return;
}
#ifdef IS_RPI
void* handle = dlopen("host/libzicHost.arm.so", RTLD_LAZY);
#else
void* handle = dlopen("host/libzicHost.x86.so", RTLD_LAZY);
#endif
if (!handle) {
logError("Cannot open host library libzicHost: %s", dlerror());
return;
}
dlerror();
host = new Host();
host->load = (AudioPluginHandlerInterface * (*)()) dlsym(handle, "load");
const char* dlsym_error = dlerror();
if (dlsym_error) {
logError("Host plugin, cannot load symbol: %s", dlsym_error);
dlclose(handle);
return;
}
host->audioPluginHandler = host->load();
}
#else
#include "host/AudioPluginHandler.h"
#include "plugins/audio/valueInterface.h"
void* hostThread(void* = NULL)
{
AudioPluginHandler::get().loop();
return NULL;
}
AudioPlugin& getPlugin(std::string name, int16_t track = -1)
{
return AudioPluginHandler::get().getPlugin(name, track);
}
void sendAudioEvent(AudioEventType event)
{
AudioPluginHandler::get().sendEvent(event);
}
void loadHostPlugin()
{
}
#endif
void startHostThread()
{
logDebug("Starting host in thread\n");
pthread_t ptid;
pthread_create(&ptid, NULL, &hostThread, NULL);
pthread_setname_np(ptid, "host");
}
#endif