Decklink: inital preview out work
This commit is contained in:
parent
75d62a8d86
commit
6d07885b08
@ -10,17 +10,24 @@ DecklinkOutputUI::DecklinkOutputUI(QWidget *parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setSizeGripEnabled(true);
|
||||
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
propertiesView = nullptr;
|
||||
previewPropertiesView = nullptr;
|
||||
|
||||
connect(ui->startOutput, SIGNAL(released()), this, SLOT(StartOutput()));
|
||||
connect(ui->stopOutput, SIGNAL(released()), this, SLOT(StopOutput()));
|
||||
|
||||
connect(ui->startPreviewOutput, SIGNAL(released()), this, SLOT(StartPreviewOutput()));
|
||||
connect(ui->stopPreviewOutput, SIGNAL(released()), this, SLOT(StopPreviewOutput()));
|
||||
}
|
||||
|
||||
void DecklinkOutputUI::ShowHideDialog()
|
||||
{
|
||||
SetupPropertiesView();
|
||||
SetupPreviewPropertiesView();
|
||||
|
||||
setVisible(!isVisible());
|
||||
}
|
||||
@ -61,6 +68,43 @@ void DecklinkOutputUI::SaveSettings()
|
||||
obs_data_save_json_safe(settings, path, "tmp", "bak");
|
||||
}
|
||||
|
||||
void DecklinkOutputUI::SetupPreviewPropertiesView()
|
||||
{
|
||||
if (previewPropertiesView)
|
||||
delete previewPropertiesView;
|
||||
|
||||
obs_data_t *settings = obs_data_create();
|
||||
|
||||
OBSData data = load_preview_settings();
|
||||
if (data)
|
||||
obs_data_apply(settings, data);
|
||||
|
||||
previewPropertiesView = new OBSPropertiesView(settings,
|
||||
"decklink_output",
|
||||
(PropertiesReloadCallback) obs_get_output_properties,
|
||||
170);
|
||||
|
||||
ui->previewPropertiesLayout->addWidget(previewPropertiesView);
|
||||
obs_data_release(settings);
|
||||
|
||||
connect(previewPropertiesView, SIGNAL(Changed()), this, SLOT(PreviewPropertiesChanged()));
|
||||
}
|
||||
|
||||
void DecklinkOutputUI::SavePreviewSettings()
|
||||
{
|
||||
char *modulePath = obs_module_get_config_path(obs_current_module(), "");
|
||||
|
||||
os_mkdirs(modulePath);
|
||||
|
||||
char *path = obs_module_get_config_path(obs_current_module(),
|
||||
"decklinkPreviewOutputProps.json");
|
||||
|
||||
obs_data_t *settings = previewPropertiesView->GetSettings();
|
||||
if (settings)
|
||||
obs_data_save_json_safe(settings, path, "tmp", "bak");
|
||||
}
|
||||
|
||||
|
||||
void DecklinkOutputUI::StartOutput()
|
||||
{
|
||||
SaveSettings();
|
||||
@ -76,3 +120,20 @@ void DecklinkOutputUI::PropertiesChanged()
|
||||
{
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
|
||||
void DecklinkOutputUI::StartPreviewOutput()
|
||||
{
|
||||
SavePreviewSettings();
|
||||
preview_output_start();
|
||||
}
|
||||
|
||||
void DecklinkOutputUI::StopPreviewOutput()
|
||||
{
|
||||
preview_output_stop();
|
||||
}
|
||||
|
||||
void DecklinkOutputUI::PreviewPropertiesChanged()
|
||||
{
|
||||
SavePreviewSettings();
|
||||
}
|
@ -9,17 +9,26 @@ class DecklinkOutputUI : public QDialog {
|
||||
Q_OBJECT
|
||||
private:
|
||||
OBSPropertiesView *propertiesView;
|
||||
OBSPropertiesView *previewPropertiesView;
|
||||
|
||||
public slots:
|
||||
void StartOutput();
|
||||
void StopOutput();
|
||||
void PropertiesChanged();
|
||||
|
||||
void StartPreviewOutput();
|
||||
void StopPreviewOutput();
|
||||
void PreviewPropertiesChanged();
|
||||
|
||||
public:
|
||||
std::unique_ptr<Ui_Output> ui;
|
||||
DecklinkOutputUI(QWidget *parent);
|
||||
|
||||
void ShowHideDialog();
|
||||
|
||||
void SetupPropertiesView();
|
||||
void SaveSettings();
|
||||
|
||||
void SetupPreviewPropertiesView();
|
||||
void SavePreviewSettings();
|
||||
};
|
||||
|
@ -4,7 +4,10 @@
|
||||
#include <QAction>
|
||||
#include <util/util.hpp>
|
||||
#include <util/platform.h>
|
||||
#include <media-io/video-io.h>
|
||||
#include <media-io/video-frame.h>
|
||||
#include "DecklinkOutputUI.h"
|
||||
#include "../../../plugins/decklink/const.h"
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
OBS_MODULE_USE_DEFAULT_LOCALE("decklink-output-ui", "en-US")
|
||||
@ -12,9 +15,26 @@ OBS_MODULE_USE_DEFAULT_LOCALE("decklink-output-ui", "en-US")
|
||||
DecklinkOutputUI *doUI;
|
||||
|
||||
bool main_output_running = false;
|
||||
bool preview_output_running = false;
|
||||
|
||||
obs_output_t *output;
|
||||
|
||||
struct preview_output {
|
||||
bool enabled;
|
||||
obs_source_t *current_source;
|
||||
obs_output_t *output;
|
||||
|
||||
video_t *video_queue;
|
||||
gs_texrender_t *texrender;
|
||||
gs_stagesurf_t *stagesurface;
|
||||
uint8_t *video_data;
|
||||
uint32_t video_linesize;
|
||||
|
||||
obs_video_info ovi;
|
||||
};
|
||||
|
||||
static struct preview_output context = {0};
|
||||
|
||||
OBSData load_settings()
|
||||
{
|
||||
BPtr<char> path = obs_module_get_config_path(obs_current_module(),
|
||||
@ -57,6 +77,172 @@ void output_stop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OBSData load_preview_settings()
|
||||
{
|
||||
char *path = obs_module_get_config_path(obs_current_module(),
|
||||
"decklinkPreviewOutputProps.json");
|
||||
BPtr<char> jsonData = os_quick_read_utf8_file(path);
|
||||
if (!!jsonData) {
|
||||
obs_data_t *data = obs_data_create_from_json(jsonData);
|
||||
OBSData dataRet(data);
|
||||
obs_data_release(data);
|
||||
|
||||
return dataRet;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void on_preview_scene_changed(enum obs_frontend_event event, void *param);
|
||||
void render_preview_source(void *param, uint32_t cx, uint32_t cy);
|
||||
|
||||
void preview_output_start()
|
||||
{
|
||||
if (!preview_output_running) {
|
||||
OBSData settings = load_preview_settings();
|
||||
|
||||
if (settings != nullptr) {
|
||||
context.output = obs_output_create("decklink_output",
|
||||
"decklink_preview_output", settings, NULL);
|
||||
|
||||
obs_get_video_info(&context.ovi);
|
||||
|
||||
uint32_t width = context.ovi.base_width;
|
||||
uint32_t height = context.ovi.base_height;
|
||||
|
||||
obs_enter_graphics();
|
||||
context.texrender = gs_texrender_create(GS_BGRA, GS_ZS_NONE);
|
||||
context.stagesurface = gs_stagesurface_create(width, height, GS_BGRA);
|
||||
obs_leave_graphics();
|
||||
|
||||
const video_output_info *mainVOI = video_output_get_info(obs_get_video());
|
||||
|
||||
video_output_info vi = {0};
|
||||
vi.format = VIDEO_FORMAT_BGRA;
|
||||
vi.width = width;
|
||||
vi.height = height;
|
||||
vi.fps_den = context.ovi.fps_den;
|
||||
vi.fps_num = context.ovi.fps_num;
|
||||
vi.cache_size = 16;
|
||||
vi.colorspace = mainVOI->colorspace;
|
||||
vi.range = mainVOI->range;
|
||||
vi.name = "decklink_preview_output";
|
||||
|
||||
video_output_open(&context.video_queue, &vi);
|
||||
|
||||
obs_frontend_add_event_callback(on_preview_scene_changed, &context);
|
||||
if (obs_frontend_preview_program_mode_active()) {
|
||||
context.current_source = obs_frontend_get_current_preview_scene();
|
||||
} else {
|
||||
context.current_source = obs_frontend_get_current_scene();
|
||||
}
|
||||
obs_add_main_render_callback(render_preview_source, &context);
|
||||
|
||||
obs_output_set_media(context.output, context.video_queue, obs_get_audio());
|
||||
obs_output_start(context.output);
|
||||
|
||||
preview_output_running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void preview_output_stop()
|
||||
{
|
||||
if (preview_output_running) {
|
||||
obs_output_stop(context.output);
|
||||
video_output_stop(context.video_queue);
|
||||
|
||||
obs_remove_main_render_callback(render_preview_source, &context);
|
||||
obs_frontend_remove_event_callback(on_preview_scene_changed, &context);
|
||||
|
||||
obs_source_release(context.current_source);
|
||||
|
||||
obs_enter_graphics();
|
||||
gs_stagesurface_destroy(context.stagesurface);
|
||||
gs_texrender_destroy(context.texrender);
|
||||
obs_leave_graphics();
|
||||
|
||||
video_output_close(context.video_queue);
|
||||
|
||||
preview_output_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void on_preview_scene_changed(enum obs_frontend_event event, void *param)
|
||||
{
|
||||
auto ctx = (struct preview_output*)param;
|
||||
switch (event) {
|
||||
case OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED:
|
||||
case OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED:
|
||||
obs_source_release(ctx->current_source);
|
||||
ctx->current_source = obs_frontend_get_current_preview_scene();
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED:
|
||||
obs_source_release(ctx->current_source);
|
||||
ctx->current_source = obs_frontend_get_current_scene();
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_SCENE_CHANGED:
|
||||
if (!obs_frontend_preview_program_mode_active()) {
|
||||
obs_source_release(ctx->current_source);
|
||||
ctx->current_source = obs_frontend_get_current_scene();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void render_preview_source(void *param, uint32_t cx, uint32_t cy)
|
||||
{
|
||||
auto ctx = (struct preview_output*)param;
|
||||
|
||||
if (!ctx->current_source) return;
|
||||
|
||||
uint32_t width = obs_source_get_base_width(ctx->current_source);
|
||||
uint32_t height = obs_source_get_base_height(ctx->current_source);
|
||||
|
||||
gs_texrender_reset(ctx->texrender);
|
||||
|
||||
if (gs_texrender_begin(ctx->texrender, width, height)) {
|
||||
struct vec4 background;
|
||||
vec4_zero(&background);
|
||||
|
||||
gs_clear(GS_CLEAR_COLOR, &background, 0.0f, 0);
|
||||
gs_ortho(0.0f, (float)width, 0.0f, (float)height, -100.0f, 100.0f);
|
||||
|
||||
gs_blend_state_push();
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
|
||||
|
||||
obs_source_video_render(ctx->current_source);
|
||||
|
||||
gs_blend_state_pop();
|
||||
gs_texrender_end(ctx->texrender);
|
||||
|
||||
struct video_frame output_frame;
|
||||
if (video_output_lock_frame(ctx->video_queue, &output_frame, 1, os_gettime_ns()))
|
||||
{
|
||||
gs_stage_texture(ctx->stagesurface, gs_texrender_get_texture(ctx->texrender));
|
||||
|
||||
if (gs_stagesurface_map(ctx->stagesurface, &ctx->video_data, &ctx->video_linesize)) {
|
||||
uint32_t linesize = output_frame.linesize[0];
|
||||
for (uint32_t i = 0; i < ctx->ovi.base_height; i++) {
|
||||
uint32_t dst_offset = linesize * i;
|
||||
uint32_t src_offset = ctx->video_linesize * i;
|
||||
memcpy(output_frame.data[0] + dst_offset,
|
||||
ctx->video_data + src_offset,
|
||||
linesize);
|
||||
}
|
||||
|
||||
gs_stagesurface_unmap(ctx->stagesurface);
|
||||
ctx->video_data = nullptr;
|
||||
}
|
||||
|
||||
video_output_unlock_frame(ctx->video_queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addOutputUI(void)
|
||||
{
|
||||
QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction(
|
||||
@ -64,7 +250,9 @@ void addOutputUI(void)
|
||||
|
||||
QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window();
|
||||
|
||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||
doUI = new DecklinkOutputUI(window);
|
||||
obs_frontend_pop_ui_translation();
|
||||
|
||||
auto cb = []() {
|
||||
doUI->ShowHideDialog();
|
||||
@ -80,6 +268,11 @@ static void OBSEvent(enum obs_frontend_event event, void *)
|
||||
|
||||
if (settings && obs_data_get_bool(settings, "auto_start"))
|
||||
output_start();
|
||||
|
||||
OBSData previewSettings = load_preview_settings();
|
||||
|
||||
if (previewSettings && obs_data_get_bool(previewSettings, "auto_start"))
|
||||
preview_output_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,3 +3,6 @@
|
||||
void output_start();
|
||||
void output_stop();
|
||||
OBSData load_settings();
|
||||
void preview_output_start();
|
||||
void preview_output_stop();
|
||||
OBSData load_preview_settings();
|
@ -6,63 +6,122 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>793</width>
|
||||
<height>328</height>
|
||||
<width>785</width>
|
||||
<height>497</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Decklink Output</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>10</y>
|
||||
<width>751</width>
|
||||
<height>221</height>
|
||||
</rect>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="propertiesLayout"/>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="startOutput">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>520</x>
|
||||
<y>250</y>
|
||||
<width>113</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="stopOutput">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>650</x>
|
||||
<y>250</y>
|
||||
<width>113</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>420</x>
|
||||
<y>290</y>
|
||||
<width>351</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Keyer output requires RGB mode in advanced settings.</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Output</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="propertiesLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="startOutput">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopOutput">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Preview Output</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="previewPropertiesLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="startPreviewOutput">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopPreviewOutput">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Keyer output requires RGB mode in advanced settings.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user