加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rtsp_main.cpp 3.99 KB
一键复制 编辑 原始数据 按行查看 历史
scottxu 提交于 2021-06-06 16:57 . Save settings when program closes.
#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: ;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化