OBSPropertiesView 简介:
obs 属性窗口是非常常用的窗口,像双击某个摄像头,麦克风,扬声器等设备资源时,就会弹出一个属性窗口。
属性窗口的处理封装在 OBSPropertiesView 类里面, 一个属性窗口往往包含了一个或多个下拉框的设置,这个设置信息是保存到配置文件的。
理解了里面的逻辑就可以很容易的使用该类来自定义自己的需要下拉属性框的 UI 界面。
OBSPropertiesView 使用:
创建一个 OBSPropertiesView 对象,需要一个设备源,简单示例如下
OBSPropertiesView *CreatePropertiesView(obs_source_t *pSource){
auto pSettings = obs_source_get_settings(pSource);
auto pView = new OBSPropertiesView(pSettings, pSource,
(PropertiesReloadCallback)obs_source_properties,
(PropertiesUpdateCallback)obs_source_update);
pView->setParent(DeviceTestWindow::getWidget());
pView->setGeometry(QRect(240, 53, 370, 28));
pView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
pView->setStyleSheet(testPageQss);
obs_data_release(pSettings);
return pView;
}
创建一个扬声器的属性窗口:
auto pSource = obs_get_source_by_name(Str("Basic.DesktopDevice1"));
view = CreatePropertiesView(pSource);
OBSPropertiesView 分析,以上面的扬声器为例:
创建属性列表调用关系(非堆栈反序,是正序)如下:
obs64.exe!OBSPropertiesView::OBSPropertiesView(...)
obs64.exe!OBSPropertiesView::ReloadProperties()
obs.dll!obs_source_properties(const obs_source * source)
win-wasapi.dll!GetWASAPIPropertiesOutput(void * __formal)
win-wasapi.dll!GetWASAPIProperties(bool input) //这里创建一个属性对象,并把获取到的扬声器设备名称和ID添加到属性列表中(会多添加一条默认数据)
把属性列表中的数据添加到属性下拉框的调用关系(非堆栈反序,是正序)如下:
obs64.exe!OBSPropertiesView::OBSPropertiesView(...)
obs64.exe!OBSPropertiesView::ReloadProperties()
obs64.exe!OBSPropertiesView::RefreshProperties()
obs64.exe!OBSPropertiesView::AddProperty(...)
obs64.exe!OBSPropertiesView::AddList(...) //添加所有项,设置当前项,并关联处理下拉菜单的变更信号
扬声器数据获取接口 GetWASAPIAudioDevices(std::vector<AudioDeviceInfo> &devices, bool input)
OBSPropertiesView 部分数据结构:
QWidget *widget //属性窗口
properties_t properties //所有属性(一个属性窗口往往包含了一个或多个属性)
OBSData settings //属性设置
获取属性窗口中第一个属性 obs_properties_first(properties.get());
获取属性窗口中最后一个下拉框(下拉框是存在 widget->layout->addRow(label, combox), 即在 label 后面)
auto pLayout = widget->layout();
auto nCount = pLayout->count();
auto pLayoutItem = pLayout->itemAt(nCount-1);
return pLayoutItem->widget();
获取属性下拉框当前设置的设备
auto nCurrentIndex = pComboBox->currentIndex();
auto pCurrentDeviceId = obs_property_list_item_string(pProperty, nCurrentIndex);
auto pCurrentDeviceName = obs_property_list_item_name(pProperty, nCurrentIndex);
auto qstrCurrentDeviceName = QString::fromUtf8(pCurrentDeviceName);
获取 obs 保存的当前设置的设备
auto pSource = obs_get_source_by_name(Str("Basic.DesktopDevice1"));
auto pSettings = obs_source_get_settings(pSource);
auto pSettingsDeviceId = obs_data_get_string(pSettings, "device_id");
QString qstrSettingsDeviceId = pSettingsDeviceId;
obs_data_release(pSettings);
QString qstrSettingsDeviceName;
typedef void (*TPFGetWASAPIAudioDevices)(std::vector<AudioDeviceInfo> &devices, bool input);
TPFGetWASAPIAudioDevices pfGetWASAPIAudioDevices = (TPFGetWASAPIAudioDevices)obs_get_module_func("win-wasapi.dll", "GetWASAPIAudioDevices");
if(pfGetWASAPIAudioDevices)
{
vector<AudioDeviceInfo> devices;
pfGetWASAPIAudioDevices(devices, false);
for (AudioDeviceInfo device : devices) {
QString qstrDeviceId = device.id.c_str();
if (qstrDeviceId == qstrSettingsDeviceId)
{
qstrSettingsDeviceName = QString::fromUtf8(device.name.c_str());
break;
}
}
}
OBSPropertiesView 分析
最新推荐文章于 2025-04-24 08:30:00 发布
本文详细探讨了OBSPropertiesView的功能与应用,揭示其在系统配置和信息展示中的重要作用。通过对各个属性的剖析,帮助读者理解如何有效地利用这一工具进行系统监控和管理。

2873

被折叠的 条评论
为什么被折叠?



