添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
风流倜傥的金针菇  ·  repair mkv after ...·  3 周前    · 
直爽的围巾  ·  結核病 - 防疫新知 | ...·  5 月前    · 
气宇轩昂的豆腐  ·  Apache ...·  6 月前    · 

上一节知道,在OBS中任右键,会弹出一菜单,可以添加通过插件模块注册的各种”输入源“
当在菜单中选中某种类型的”输入源“之后,就会调用函数AddSource。其中 id是各个模块注册输入源时提供的源id,该ID应全局惟一。

void OBSBasic::AddSource(const char *id)
    if (id && *id)
        //创建QT对话框对象。OBSBasicSourceSelect继承于QDialog
        OBSBasicSourceSelect sourceSelect(this, id, undo_s);
        //弹出并显示对话框,等待用户输入信息
        sourceSelect.exec();
        //参数校验
        if (should_show_properties(sourceSelect.newSource, id)) 
            //创建输入源实例
            CreatePropertiesWindow(sourceSelect.newSource);

AddSource函数分两步:

对话框OBSBasicSourceSelect

第一步是通过使用OBSBasicSourceSelect弹出结话框。OBSBasicSourceSelect继承于QDialog,故通过exec()函数显示对话框。
102550588878
用户配置弹出对话框做相应的配置选择后。点击确认后,执行的是函数OBSBasicSourceSelect的成员函数on_buttonBox_accepted。

该函数会根据是新建还是添加现在执行不同的流程:

void OBSBasicSourceSelect::on_buttonBox_accepted()
    bool useExisting = ui->selectExisting->isChecked();//新建按钮是否选中
    bool visible = ui->sourceVisible->isChecked();//便源可见选项
    if (useExisting){
    else //添加新源
        //名称是否为空,默认名为媒体源
        if (ui->sourceName->text().isEmpty()) {
            OBSMessageBox::warning(this,
                           QTStr("NoNameEntered.Title"),//请输入一个有效的名称
                           QTStr("NoNameEntered.Text"));//您不能使用空白名称。
            return;
        //添加新源
        if (!AddNew(this, id, QT_TO_UTF8(ui->sourceName->text()),  visible, newSource))
            return;
    done(DialogCode::Accepted);

AddNew函数的原理校验用户输入的名称重复性,如果不重复,就创建源实例,创建后的新源实例加入场景中。

bool AddNew(QWidget *parent, const char *id, const char *name,
        const bool visible, OBSSource &newSource)
    //获取主窗口
    OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
    //获取主窗口当前的场景
    OBSScene scene = main->GetCurrentScene();
    bool success = false;
    if (!scene)
        return false;
    //是否名字已经存在
    OBSSourceAutoRelease source = obs_get_source_by_name(name);
    if (source && parent) {
        OBSMessageBox::information(parent, QTStr("NameExists.Title"),
                       QTStr("NameExists.Text"));
        const char *v_id = obs_get_latest_input_type_id(id);
        source = obs_source_create(v_id, name, NULL, nullptr);
        if (source) 
            AddSourceData data;
            data.source = source;
            data.visible = visible;
            //添加到当彰场景中
            obs_enter_graphics();
            obs_scene_atomic_update(scene, AddSource, &data);
            obs_leave_graphics();
    return success;

创建源属性对话框

使用AddNew添加新源,而newSource以引用的方式返回,即sourceSelect.newSource

    if (should_show_properties(sourceSelect.newSource, id)) {
        CreatePropertiesWindow(sourceSelect.newSource);

新创建的源是struct obs_source_t类型,新创建的源需要进行配置。所以这里会通过CreatePropertiesWindow函数创建并显示属性对话框。

void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
    bool closed = true;
    if (properties)
        closed = properties->close();
    if (!closed)
        return;
    properties = new OBSBasicProperties(this, source);
    properties->Init();
    properties->setAttribute(Qt::WA_DeleteOnClose, true);

如对于视频媒体源加的属性对话框:
13211228098