Skip to content

Commit

Permalink
Merge pull request #12 from iamscottxu/optimization
Browse files Browse the repository at this point in the history
Code  optimization
  • Loading branch information
iamscottxu authored Jan 16, 2021
2 parents 53c04e3 + 7218150 commit 8a6822e
Show file tree
Hide file tree
Showing 14 changed files with 397 additions and 303 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ set(obs-rtspserver_SOURCES
rtspoutput.rc
rtsp_output.cpp
rtsp_properties.cpp
my_rtsp_output.cpp
rtsp_output_helper.cpp
)

set(obs-rtspserver_HEADERS
rtsp_output.h
rtsp_properties.h
my_rtsp_output.h
rtsp_output_helper.h
)

if(WIN32)
Expand Down Expand Up @@ -69,7 +69,7 @@ target_link_libraries(obs-rtspserver
set_target_properties(obs-rtspserver
PROPERTIES
FOLDER "plugins"
VERSION "1.1.4"
VERSION "1.2.0"
PRODUCTNAME "OBS RTSP Server Plugin")

install_obs_plugin_with_data(obs-rtspserver data)
6 changes: 5 additions & 1 deletion data/locale/de-DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Option="Optionen"
Target="Ziel"
Address="URL: "
AddressCopy="Kopieren"
StartFailed="Ausgabe konnte nicht gestartet werden"
OutputOptions="Ausgabe-Optionen: "
OutputOptionsTip="Hinweis: Wenn Sie die Ausgabe-Optionen ändern wollen öffnen Sie: Datei->Einstellungen->Ausgabe->Streaming."
ErrorBeginDataCapture="can't begin data capture"
ErrorInitEncoders="initialize encoders error"
ErrorStartRtspServer="starting RTSP server failed on port '%d'"
ErrorEncode="encode error"
ErrorUnknown="unknown error"
6 changes: 5 additions & 1 deletion data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ Option="Options"
Target="Target"
Address="URL: "
AddressCopy="Copy"
StartFailed="Failed to start output"
OutputOptions="Output Options: "
OutputOptionsTip="Tip: Open File->Settings->Output->Streaming to change output options."
ErrorBeginDataCapture="can't begin data capture"
ErrorInitEncoders="initialize encoders error"
ErrorStartRtspServer="starting RTSP server failed on port '%d'"
ErrorEncode="encode error"
ErrorUnknown="unknown error"

6 changes: 5 additions & 1 deletion data/locale/zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Option="选项"
Target="目标"
Address="URL:"
AddressCopy="复制"
StartFailed="无法启动输出"
OutputOptions="输出选项:"
OutputOptionsTip="提示:打开 文件->设置->输出->串流 以更改输出选项。"
ErrorBeginDataCapture="无法开始数据捕获"
ErrorInitEncoders="初始化编码器时发生错误"
ErrorStartRtspServer="在端口“%d”上启动RTSP服务器失败"
ErrorEncode="编码错误"
ErrorUnknown="未知错误"
6 changes: 5 additions & 1 deletion data/locale/zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Reset="重置"
Target="目標"
Address="URL:"
AddressCopy="拷貝"
StartFailed="啟動輸出失敗"
OutputOptions="輸出選項:"
OutputOptionsTip="提示:打開 檔案->設定->輸出->串流 以更改輸出選項。"
ErrorBeginDataCapture="無法開始數據捕獲"
ErrorInitEncoders="初始化編碼器錯誤"
ErrorStartRtspServer="端口 %d 上啟動RTSP伺服器失敗"
ErrorEncode="編碼錯誤"
ErrorUnknown="未知錯誤"
149 changes: 0 additions & 149 deletions my_rtsp_output.cpp

This file was deleted.

52 changes: 29 additions & 23 deletions rtsp_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#include <util/config-file.h>
#include <QMainWindow>
#include <QAction>
#include <mutex>
#include <net/Logger.h>
#include "helper.h"
#include "my_rtsp_output.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")

RtspProperties *rtspProperties;

void obs_frontend_event(enum obs_frontend_event event, void *ptr);
void rtsp_output_auto_start();
void rtsp_output_stop();
void rtsp_output_auto_start(RtspOutputHelper *rtspOutputHelper);
void rtsp_output_stop(RtspOutputHelper *rtspOutputHelper);
void server_log_write_callback(xop::Priority priority, std::string info);

const char *obs_module_name(void)
Expand All @@ -31,22 +31,26 @@ const char *obs_module_description(void)
bool obs_module_load(void)
{
xop::Logger::instance().setWriteCallback(server_log_write_callback);
rtsp_output_register();

RtspOutputHelper *rtspOutputHelper;
{
auto *data = rtsp_output_read_data();
rtspOutputHelper = RtspOutputHelper::CreateRtspOutput(data);
obs_data_release(data);
}

QMainWindow *mainWindow = (QMainWindow *)obs_frontend_get_main_window();
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
auto mainWindow = (QMainWindow *)obs_frontend_get_main_window();
auto action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("RtspServer"));

obs_frontend_push_ui_translation(obs_module_get_string);
rtspProperties = new RtspProperties(mainWindow);
auto rtspProperties = new RtspProperties(rtspOutputHelper->GetOutputName(), mainWindow);
obs_frontend_pop_ui_translation();

auto menu_cb = [] {
rtspProperties->exec();
};

action->connect(action, &QAction::triggered, menu_cb);
action->connect(action, &QAction::triggered, rtspProperties, &QDialog::exec);

obs_frontend_add_event_callback(obs_frontend_event, nullptr);
obs_frontend_add_event_callback(obs_frontend_event, rtspOutputHelper);

return true;
}
Expand All @@ -58,19 +62,21 @@ void obs_module_unload(void)

void obs_frontend_event(enum obs_frontend_event event, void *ptr)
{
switch ((int)event) {
auto rtspOutputHelper = (RtspOutputHelper *)ptr;
switch (event) {
case OBS_FRONTEND_EVENT_FINISHED_LOADING:
rtsp_output_auto_start();
rtsp_output_auto_start(rtspOutputHelper);
break;
case OBS_FRONTEND_EVENT_EXIT:
rtsp_output_stop();
rtsp_output_stop(rtspOutputHelper);
delete rtspOutputHelper;
break;
}
}

void rtsp_output_auto_start()
void rtsp_output_auto_start(RtspOutputHelper *rtspOutputHelper)
{
config_t *config = rtsp_properties_open_config();
auto *config = rtsp_properties_open_config();
auto autoStart = false;
if (config) {
autoStart =
Expand All @@ -79,13 +85,13 @@ void rtsp_output_auto_start()
}
if (!autoStart)
return;
rtspProperties->GetMyRtspOutput()->UpdateEncoder();
rtspProperties->GetMyRtspOutput()->Start();
rtspOutputHelper->UpdateEncoder();
rtspOutputHelper->Start();
}

void rtsp_output_stop()
void rtsp_output_stop(RtspOutputHelper *rtspOutputHelper)
{
rtspProperties->GetMyRtspOutput()->Stop();
rtspOutputHelper->Stop();
}

void server_log_write_callback(xop::Priority priority, std::string info)
Expand Down
Loading

0 comments on commit 8a6822e

Please sign in to comment.