-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathobs-streamelements-core-plugin.cpp
More file actions
193 lines (150 loc) · 4.66 KB
/
obs-streamelements-core-plugin.cpp
File metadata and controls
193 lines (150 loc) · 4.66 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <obs-frontend-api.h>
#include <util/threading.h>
#include <util/platform.h>
#include <util/util.hpp>
#include <util/dstr.hpp>
#include <obs-module.h>
#include <obs-frontend-api.h>
#include <obs.hpp>
#include <obs-config.h>
#include <functional>
#include <sstream>
#include <thread>
#include <mutex>
#include "json11/json11.hpp"
#include "obs-websocket-api/obs-websocket-api.h"
#include "cef-headers.hpp"
#include "streamelements/audio-wrapper-source.h"
#include "streamelements/Version.generated.hpp"
#define ENABLE_PLUGIN 1
OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-streamelements-core", "en-US")
MODULE_EXPORT const char *obs_module_description(void)
{
return "SE.Live";
}
using namespace std;
using namespace json11;
/* ========================================================================= */
#include <obs-frontend-api.h>
#include "streamelements/StreamElementsGlobalStateManager.hpp"
#include "streamelements/StreamElementsUtils.hpp"
/* ========================================================================= */
static void log_remaining_objects()
{
StreamElementsVideoCompositionBase::CompositionInfo::
LogRemainingCompositionInfos();
obs_enum_sources(
[](void *, obs_source_t *source) -> bool {
auto id = obs_source_get_id(source);
auto name = obs_source_get_name(source);
blog(LOG_WARNING,
"[obs-streamelements-core]: remaining source id '%s', name '%s'",
id, name);
return true;
},
nullptr);
obs_enum_outputs(
[](void *, obs_output_t *output) -> bool {
auto id = obs_output_get_id(output);
auto name = obs_output_get_name(output);
blog(LOG_WARNING,
"[obs-streamelements-core]: remaining output id '%s', name '%s'",
id, name);
return true;
},
nullptr);
obs_enum_encoders(
[](void *, obs_encoder_t *encoder) -> bool {
auto id = obs_encoder_get_id(encoder);
auto name = obs_encoder_get_name(encoder);
blog(LOG_WARNING,
"[obs-streamelements-core]: remaining encoder id '%s', name '%s'",
id, name);
return true;
},
nullptr);
obs_enum_services([](void *, obs_service_t *service) -> bool {
auto id = obs_service_get_id(service);
auto name = obs_service_get_name(service);
blog(LOG_WARNING,
"[obs-streamelements-core]: remaining service id '%s', name '%s'",
id, name);
return true;
}, nullptr);
}
/* ========================================================================= */
MODULE_EXPORT bool obs_module_load(void)
{
#if ENABLE_PLUGIN
std::string version = GetStreamElementsPluginVersionString();
blog(LOG_INFO, "[obs-streamelements-core]: Version %s",
version.c_str());
obs_register_source(&audio_wrapper_source);
#endif
return true;
}
void handle_obs_frontend_event(enum obs_frontend_event event, void *data)
{
SEAsyncCallContextMarker asyncMarker(__FILE__, __LINE__);
static bool isRunning = true;
switch (event) {
case OBS_FRONTEND_EVENT_FINISHED_LOADING:
isRunning = true;
blog(LOG_INFO, "[obs-streamelements-core]: initializing");
// Initialize StreamElements plug-in
StreamElementsGlobalStateManager::GetInstance()->Initialize(
static_cast<QMainWindow *>(obs_frontend_get_main_window()));
blog(LOG_INFO, "[obs-streamelements-core]: init done");
break;
case OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN:
case OBS_FRONTEND_EVENT_EXIT:
if (!isRunning)
return;
isRunning = false;
obs_frontend_remove_event_callback(handle_obs_frontend_event,
nullptr);
// Shutdown StreamElements plug-in
blog(LOG_INFO, "[obs-streamelements-core]: shutting down");
//StreamElementsGlobalStateManager::GetInstance()
// ->Shutdown();
StreamElementsGlobalStateManager::Destroy();
break;
default:
break;
}
}
MODULE_EXPORT void obs_module_post_load(void)
{
#if ENABLE_PLUGIN
obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);
/*
auto vendor = obs_websocket_register_vendor("obs-streamelements-core");
if (!vendor)
return;
auto emit_event_request_cb = [](obs_data_t *request_data, obs_data_t *,
void *) {
const char *event_name =
obs_data_get_string(request_data, "event_name");
if (!event_name)
return;
OBSDataAutoRelease event_data =
obs_data_get_obj(request_data, "event_data");
const char *event_data_string =
event_data ? obs_data_get_json(event_data) : "{}";
};
if (!obs_websocket_vendor_register_request(
vendor, "emit_event", emit_event_request_cb, nullptr))
blog(LOG_WARNING,
"[obs-streamelements-core]: Failed to register obs-websocket request emit_event");
*/
#endif
}
MODULE_EXPORT void obs_module_unload(void)
{
#if ENABLE_PLUGIN
log_remaining_objects();
blog(LOG_INFO, "[obs-streamelements-core]: shutdown complete");
SETRACE_DUMP();
#endif
}