Skip to content

Commit

Permalink
Keep reference while resizing scene
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro committed Oct 30, 2023
1 parent ed9f9a4 commit a64eeed
Showing 1 changed file with 55 additions and 38 deletions.
93 changes: 55 additions & 38 deletions vertical-canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ void vendor_request_invoke(obs_data_t *request_data, obs_data_t *response_data,
obs_data_set_bool(response_data, "success", false);
}


void vendor_request_save_replay(obs_data_t *request_data,
obs_data_t *response_data, void *p)
{
Expand All @@ -395,37 +394,38 @@ void vendor_request_save_replay(obs_data_t *request_data,
}

void vendor_request_update_stream_key(obs_data_t *request_data,
obs_data_t *response_data, void *)
obs_data_t *response_data, void *)
{
// Parse request_data to get the new stream_key
const char *new_stream_key = obs_data_get_string(request_data, "stream_key");
const auto width = obs_data_get_int(request_data, "width");
const auto height = obs_data_get_int(request_data, "height");
// Parse request_data to get the new stream_key
const char *new_stream_key =
obs_data_get_string(request_data, "stream_key");
const auto width = obs_data_get_int(request_data, "width");
const auto height = obs_data_get_int(request_data, "height");

if (!new_stream_key || !strlen(new_stream_key)) {
obs_data_set_string(response_data, "error", "'stream_key' not set");
obs_data_set_bool(response_data, "success", false);
return;
}
if (!new_stream_key || !strlen(new_stream_key)) {
obs_data_set_string(response_data, "error",
"'stream_key' not set");
obs_data_set_bool(response_data, "success", false);
return;
}

// Loop through each CanvasDock to find the right one
for (const auto &it : canvas_docks) {
if ((width && it->GetCanvasWidth() != width) ||
(height && it->GetCanvasHeight() != height))
continue;
// Loop through each CanvasDock to find the right one
for (const auto &it : canvas_docks) {
if ((width && it->GetCanvasWidth() != width) ||
(height && it->GetCanvasHeight() != height))
continue;

// Update stream_key using the UpdateStreamKey method of CanvasDock
QMetaObject::invokeMethod(
it, "UpdateStreamKey",
Q_ARG(QString, QString::fromUtf8(new_stream_key)));

obs_data_set_bool(response_data, "success", true);
return;
}
// Update stream_key using the UpdateStreamKey method of CanvasDock
QMetaObject::invokeMethod(
it, "UpdateStreamKey",
Q_ARG(QString, QString::fromUtf8(new_stream_key)));

obs_data_set_bool(response_data, "success", false);
}
obs_data_set_bool(response_data, "success", true);
return;
}

obs_data_set_bool(response_data, "success", false);
}

update_info_t *verison_update_info = nullptr;

Expand Down Expand Up @@ -567,10 +567,8 @@ void obs_module_post_load(void)
vendor_request_invoke,
(void *)"StopVirtualCam");
obs_websocket_vendor_register_request(vendor, "update_stream_key",
vendor_request_update_stream_key,
(void *)"UpdateStreamKey");


vendor_request_update_stream_key,
(void *)"UpdateStreamKey");

verison_update_info = update_info_create_single(
"[vertical-canvas]", "OBS", "https://api.aitum.tv/vertical",
Expand Down Expand Up @@ -1690,7 +1688,8 @@ struct SceneFindData {
SceneFindData &operator=(SceneFindData &&) = delete;

inline SceneFindData(const vec2 &pos_, bool selectBelow_)
: pos(pos_), selectBelow(selectBelow_)
: pos(pos_),
selectBelow(selectBelow_)
{
}
};
Expand All @@ -1706,7 +1705,8 @@ struct SceneFindBoxData {
SceneFindBoxData &operator=(SceneFindData &&) = delete;

inline SceneFindBoxData(const vec2 &startPos_, const vec2 &pos_)
: startPos(startPos_), pos(pos_)
: startPos(startPos_),
pos(pos_)
{
}
};
Expand Down Expand Up @@ -4328,7 +4328,8 @@ struct HandleFindData {
HandleFindData &operator=(HandleFindData &&) = delete;

inline HandleFindData(const vec2 &pos_, float scale)
: pos(pos_), radius(HANDLE_SEL_RADIUS / scale)
: pos(pos_),
radius(HANDLE_SEL_RADIUS / scale)
{
matrix4_identity(&parent_xform);
}
Expand Down Expand Up @@ -7259,16 +7260,31 @@ void CanvasDock::ResizeScene(QString scene_name)
auto s = obs_get_source_by_name(scene_name.toUtf8().constData());
if (!s)
return;
if (!obs_source_is_scene(s)) {
auto scene = obs_scene_from_source(s);
if (!scene) {
obs_source_release(s);
return;
}
obs_scene_enum_items(
scene,
[](obs_scene_t *, obs_sceneitem_t *item, void *) {
obs_source_get_ref(obs_sceneitem_get_source(item));
return true;
},
nullptr);
obs_source_save(s);
auto data = obs_source_get_settings(s);
obs_data_set_int(data, "cx", canvas_width);
obs_data_set_int(data, "cy", canvas_height);
obs_source_load(s);
obs_data_release(data);
obs_scene_enum_items(
scene,
[](obs_scene_t *, obs_sceneitem_t *item, void *) {
obs_source_release(obs_sceneitem_get_source(item));
return true;
},
nullptr);
obs_source_release(s);
}

Expand Down Expand Up @@ -7470,10 +7486,11 @@ void CanvasDock::OpenSourceProjector()
obs_source_get_name(source));
}

void CanvasDock::updateStreamKey(const QString& newStreamKey) {
// Your code to update the stream_key, assuming stream_key is a member variable
this->stream_key = newStreamKey.toStdString();
// any additional actions needed to apply the new stream key
void CanvasDock::updateStreamKey(const QString &newStreamKey)
{
// Your code to update the stream_key, assuming stream_key is a member variable
this->stream_key = newStreamKey.toStdString();
// any additional actions needed to apply the new stream key
}

LockedCheckBox::LockedCheckBox() {}
Expand Down

0 comments on commit a64eeed

Please sign in to comment.