OBS-scene
+ -

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();
}

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!