OBS
+ -

OSB-WASAPI插件obs_module_load函数

2024-03-21 12 0

obs_module_load是OBS插件模块必须实现的函数,其对应于结构体obs_module中load函数指针:

 bool (*load)(void);  //函数名必须为obs_module_load

WASAPI的插件函数代码如下:

bool obs_module_load(void)
{
    /* MS says 20348, but process filtering seems to work earlier */
    struct win_version_info ver;
    get_win_ver(&ver);
    struct win_version_info minimum;
    minimum.major = 10;
    minimum.minor = 0;
    minimum.build = 19041;
    minimum.revis = 0;
    const bool process_filter_supported = win_version_compare(&ver, &minimum) >= 0;

    RegisterWASAPIInput();
    RegisterWASAPIDeviceOutput();

    if (process_filter_supported)
        RegisterWASAPIProcessOutput();

    notify = new WASAPINotify();
    notify->AddDefaultDeviceChangedCallback(obs_current_module(), default_device_changed_callback);

    return true;
}

第一部分是获取系统的版本号,用于判断是否支持process_filter,关于这个特性,本人也暂未研究。反正就是WIN10新系统中的一个新特性。

第二部分是使用RegisterWASAPIInput函数注册OBS源,这是音频的CAPTURE类型,即麦克风。

void RegisterWASAPIInput()
{
    obs_source_info info = {};
    info.id = "wasapi_input_capture";
    info.type = OBS_SOURCE_TYPE_INPUT;
    info.output_flags = OBS_SOURCE_AUDIO | OBS_SOURCE_DO_NOT_DUPLICATE;
    info.get_name = GetWASAPIInputName;
    info.create = CreateWASAPIInput;
    info.destroy = DestroyWASAPISource;
    info.update = UpdateWASAPISource;
    info.activate = ActivateWASAPISource;
    info.deactivate = DeactivateWASAPISource;
    info.get_defaults = GetWASAPIDefaultsInput;
    info.get_properties = GetWASAPIPropertiesInput;
    info.icon_type = OBS_ICON_TYPE_AUDIO_INPUT;
    obs_register_source(&info);
}

OBS源其实是一个结构体,也可认为是一个对象,该对象有一些属性和相关的回调函数。
属性如id,类型之类,函数为OBS应用使用时,需要支持的一些回调函数。

第三部分是使用RegisterWASAPIDeviceOutput注册设备输出,即扬声器。

void RegisterWASAPIDeviceOutput()
{
    obs_source_info info = {};
    info.id = "wasapi_output_capture";
    info.type = OBS_SOURCE_TYPE_INPUT;
    info.output_flags = OBS_SOURCE_AUDIO | OBS_SOURCE_DO_NOT_DUPLICATE |
                OBS_SOURCE_DO_NOT_SELF_MONITOR;
    info.get_name = GetWASAPIDeviceOutputName;
    info.create = CreateWASAPIDeviceOutput;
    info.destroy = DestroyWASAPISource;
    info.update = UpdateWASAPISource;
    info.activate = ActivateWASAPISource;
    info.deactivate = DeactivateWASAPISource;
    info.get_defaults = GetWASAPIDefaultsDeviceOutput;
    info.get_properties = GetWASAPIPropertiesDeviceOutput;
    info.icon_type = OBS_ICON_TYPE_AUDIO_OUTPUT;
    obs_register_source(&info);
}

第四部分是如果支持process filtering,则注册相应的OBS源:


void RegisterWASAPIProcessOutput()
{
    obs_source_info info = {};
    info.id = "wasapi_process_output_capture";
    info.type = OBS_SOURCE_TYPE_INPUT;
    info.output_flags = OBS_SOURCE_AUDIO | OBS_SOURCE_DO_NOT_DUPLICATE |
                OBS_SOURCE_DO_NOT_SELF_MONITOR;
    info.get_name = GetWASAPIProcessOutputName;
    info.create = CreateWASAPIProcessOutput;
    info.destroy = DestroyWASAPISource;
    info.update = UpdateWASAPISource;
    info.activate = ActivateWASAPISource;
    info.deactivate = DeactivateWASAPISource;
    info.get_defaults = GetWASAPIDefaultsProcessOutput;
    info.get_properties = GetWASAPIPropertiesProcessOutput;
    info.icon_type = OBS_ICON_TYPE_PROCESS_AUDIO_OUTPUT;
    obs_register_source(&info);
}

最后是当音频设备发生变化时,注册回调通知设备发生变化。比如某个麦克风插入电脑了,从电脑中移除了之类。

    notify = new WASAPINotify();
    notify->AddDefaultDeviceChangedCallback(obs_current_module(), default_device_changed_callback);

0 篇笔记 写笔记

获取默认的音频设备属性getDefaultDevice
使用COREAPI获取默认音频属性wstring DeviceAPOInfo::getDefaultDevice(bool input, int role){ wstring result; IMMDeviceEnumerator* enumerator = NULL; ......
Windows音频音擎audiodg与APO关系
APO与其他音频过滤框架(如VST)的区别在于,APO是Windows音频引擎使用的过滤框架。VST:Virtual Studio TechnologyWindows音频引擎是Windows音频堆栈的核心组件。它的作用是在单个应用程序音频流和硬件音频设备之间架起桥梁。因此,它可以处理各种任务......
使用WASAPI随机打开默认麦克风并录音
// mictest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include #include #include #inc......
自动挂机麦克风录音测试
要则试麦克风重复打开关闭的功能,如果手动也太麻烦了。为了让打开关闭的时间更随机一点,使用WASAPI做了这么一个小功能。#include #include #include #inc......
OBS模块WASAPI的其中OBS_DECLARE_MODULE和OBS_MODULE_USE_DEFAULT_LOCALE
OBS插件模块WASAPI用于实现Windows音频的。其源文件目录位于:obs-studio-masterpluginswin-wasapi源文件有:CMakeLists.txtdata //资源文件目录enum-wasapi.cppenum-wasapi.hppplugin-m......
OSB-WASAPI插件obs_module_load函数
obs_module_load是OBS插件模块必须实现的函数,其对应于结构体obs_module中load函数指针: bool (*load)(void); //函数名必须为obs_module_loadWASAPI的插件函数代码如下:bool obs_module_load(void){......
Windows10应用层音频框架及模块关系图
在 Windows 操作系统中,处理音频缓冲的主要组件包括以下几个:其中各个模块的DLL依赖关系如下:音频各个模块之间的关系图如下: 核心音频 API 包括在 Audioses.dll 和 Mmdevapi.dll 用户模式系统模块中实现的 MMDevice API、WASAPI、DeviceTo......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

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

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