代码拉取完成,页面将自动刷新
同步操作将从 scottxu/obs-rtspserver 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#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 "rtsp_properties.h"
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: ;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。