forked from iamscottxu/obs-rtspserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtsp_main.cpp
145 lines (127 loc) · 4 KB
/
rtsp_main.cpp
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
#include <obs-module.h>
#include <obs-frontend-api.h>
#include <util/config-file.h>
#include <QMainWindow>
#include <QAction>
#include <mutex>
#include <net/Logger.h>
#include "helper.h"
#include "rtsp_output_helper.h"
#include "rtsp_output.h"
#include "ui/rtsp_properties.hpp"
OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-rtspserver", "en-US")
void obs_frontend_event(enum obs_frontend_event event, void *ptr);
void rtsp_output_auto_start(RtspOutputHelper *rtspOutputHelper);
void rtsp_output_stop(RtspOutputHelper *rtspOutputHelper);
void rtsp_output_save_settings(RtspOutputHelper *rtspOutputHelper);
void rtsp_output_save_hotkey_settings(RtspOutputHelper *rtspOutputHelper);
void server_log_write_callback(xop::Priority priority, std::string info);
const char *obs_module_name(void)
{
return obs_module_text("RtspServer");
}
const char *obs_module_description(void)
{
return obs_module_text("RstpServer.Description");
}
bool obs_module_load(void)
{
xop::Logger::Instance().SetWriteCallback(server_log_write_callback);
rtsp_output_register();
RtspOutputHelper *rtspOutputHelper;
{
auto *settings = rtsp_output_read_data();
auto *config = rtsp_properties_open_config();
const char *str = nullptr;
str = config_get_string(config, HOTKEY_CONFIG_SECTIION,
"RtspOutput");
obs_data_t *hotkey = nullptr;
if (str) hotkey = obs_data_create_from_json(str);
rtspOutputHelper =
RtspOutputHelper::CreateRtspOutput(settings, hotkey);
obs_data_release(hotkey);
config_close(config);
obs_data_release(settings);
}
const auto mainWindow = static_cast<QMainWindow *>(obs_frontend_get_main_window());
const auto action = static_cast<QAction *>(obs_frontend_add_tools_menu_qaction(
obs_module_text("RtspServer")));
obs_frontend_push_ui_translation(obs_module_get_string);
const auto rtspProperties = new RtspProperties(rtspOutputHelper->GetOutputName(), mainWindow);
obs_frontend_pop_ui_translation();
QAction::connect(action, &QAction::triggered, rtspProperties, &QDialog::exec);
obs_frontend_add_event_callback(obs_frontend_event, rtspOutputHelper);
return true;
}
void obs_module_unload(void)
{
obs_frontend_remove_event_callback(obs_frontend_event, nullptr);
}
void obs_frontend_event(enum obs_frontend_event event, void *ptr)
{
const auto rtspOutputHelper = static_cast<RtspOutputHelper *>(ptr);
switch (event) {
case OBS_FRONTEND_EVENT_FINISHED_LOADING:
rtsp_output_auto_start(rtspOutputHelper);
break;
case OBS_FRONTEND_EVENT_EXIT:
rtsp_output_stop(rtspOutputHelper);
rtsp_output_save_settings(rtspOutputHelper);
rtsp_output_save_hotkey_settings(rtspOutputHelper);
delete rtspOutputHelper;
break;
default: ;
}
}
void rtsp_output_auto_start(RtspOutputHelper *rtspOutputHelper)
{
auto *config = rtsp_properties_open_config();
auto autoStart = false;
if (config) {
autoStart =
config_get_bool(config, CONFIG_SECTIION, "AutoStart");
config_close(config);
}
if (autoStart)
rtspOutputHelper->Start();
}
void rtsp_output_stop(RtspOutputHelper *rtspOutputHelper)
{
rtspOutputHelper->Stop();
}
void rtsp_output_save_hotkey_settings(RtspOutputHelper *rtspOutputHelper)
{
auto *data = rtspOutputHelper->HotkeysSave();
auto *str = obs_data_get_json(data);
auto *config = rtsp_properties_open_config();
config_set_string(config, HOTKEY_CONFIG_SECTIION, "RtspOutput", str);
config_save(config);
config_close(config);
}
void rtsp_output_save_settings(RtspOutputHelper *rtspOutputHelper)
{
auto *data = rtspOutputHelper->GetSettings();
rtsp_output_save_data(data);
}
void server_log_write_callback(xop::Priority priority, std::string info)
{
switch (priority) {
case xop::LOG_DEBUG:
blog(LOG_DEBUG, "[rtsp-server] %s", info.c_str());
break;
case xop::LOG_STATE:
blog(LOG_INFO, "[rtsp-server] %s", info.c_str());
break;
case xop::LOG_INFO:
blog(LOG_INFO, "[rtsp-server] %s", info.c_str());
break;
case xop::LOG_WARNING:
blog(LOG_WARNING, "[rtsp-server] %s", info.c_str());
break;
case xop::LOG_ERROR:
blog(LOG_ERROR, "[rtsp-server] %s", info.c_str());
break;
default: ;
}
}