obs-scene添加场景
2024-06-24
12
0
void OBSBasic::SourceCreated(void *data, calldata_t *params)
{
obs_source_t *source = (obs_source_t *)calldata_ptr(params, "source");
if (obs_scene_from_source(source) != NULL)
QMetaObject::invokeMethod(static_cast<OBSBasic *>(data),
"AddScene", WaitConnection(),
Q_ARG(OBSSource, OBSSource(source)));
}
添加场景使用函数AddScene
/* Qt callbacks for invokeMethod */
void OBSBasic::AddScene(OBSSource source)
{
const char *name = obs_source_get_name(source);
obs_scene_t *scene = obs_scene_from_source(source);
QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
SetOBSRef(item, OBSScene(scene));
//添加到场景数组中
ui->scenes->insertItem(ui->scenes->currentRow() + 1, item);
...
}
场景也是一种obs_souce_t类型,故在枚举场景中,会使用如下方法枚举并显示:
struct OBSStudioAPI : obs_frontend_callbacks {
OBSBasic *main;
void obs_frontend_get_scenes(struct obs_frontend_source_list *sources) override
{
for (int i = 0; i < main->ui->scenes->count(); i++)
{
QListWidgetItem *item = main->ui->scenes->item(i);
OBSScene scene = GetOBSRef<OBSScene>(item);
obs_source_t *source = obs_scene_get_source(scene);
if (obs_source_get_ref(source) != nullptr)
da_push_back(sources->sources, &source);
}
}
};
OBSBasic类如下:
class OBSBasic : public OBSMainWindow
{
private:
std::unique_ptr<Ui::OBSBasic> ui;
}
当前scene
当前scene由ui回调:
void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
QListWidgetItem *)
{
OBSSource source;
if (current) {
OBSScene scene = GetOBSRef<OBSScene>(current);
source = obs_scene_get_source(scene);
currentScene = scene;
} else {
currentScene = NULL;
}
SetCurrentScene(source);
if (vcamEnabled && vcamConfig.type == VCamOutputType::PreviewOutput)
outputHandler->UpdateVirtualCamOutputSource();
if (api)
api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
UpdateContextBar();
}