1.流程图示
2.代码分析
void base_set_log_handler(log_handler_t *handler, void param)
函数说明:设置log的回调函数,obs提供默认函数def_log_handler,def_log_handler内部实现将log重新定向到stdout或者stderr。
参数:log_handler_t 定义typedef void (log_handler_t)(int lvl, const char *msg, va_list args, void *) 详见base.h 70
参数:param 回调函数的输入参数,一般设为null;
bool obs_startup(const char*locale, const char *module_config_path, profiler_name_store_t *store)
函数说明:初始化obs的相关资源,如:各类互斥量、句柄、热键等
参数:locale 国际化,切换各种语言。例如:“en-US”、“zh-CN”等。
参数:module_config_path 模块配置文件目录。
参数:store 未关注,待定
返回值: bool
int obs_reset_video(struct obs_video_info *ovi)
函数说明:初始化video参数
参数: ovi video参数
struct obs_video_info {
#ifndef SWIG
/**
* Graphics module to use (usually "libobs-opengl" or "libobs-d3d11")
*/
const char *graphics_module;
#endif
uint32_t fps_num; /**< Output FPS numerator */
uint32_t fps_den; /**< Output FPS denominator */
uint32_t base_width; /**< Base compositing width */
uint32_t base_height; /**< Base compositing height */
uint32_t output_width; /**< Output width */
uint32_t output_height; /**< Output height */
enum video_format output_format; /**< Output format */
/** Video adapter index to use (NOTE: avoid for optimus laptops) */
uint32_t adapter;
/** Use shaders to convert to different color formats */
bool gpu_conversion;
enum video_colorspace colorspace; /**< YUV type (if YUV) */
enum video_range_type range; /**< YUV range (if YUV) */
enum obs_scale_type scale_type; /**< How to scale if scaling */
};
返回值:0(OBS_VIDEO_SUCCESS)表示成功,非0表示失败,具体参见宏定义obs-defs.h(45-50行)
void obs_load_all_modules()
函数说明:自动加载指定目录的所有模块,若不通过obs_add_module_path增加新目录,默认加载目录是../../obs-plugins/32bit(64bit)和../../data/obs-plugins/%module%。
obs_source_t *obs_source_create(const char *id, const char *name, obs_data_t *settings, obs_data_t *hotkey_data)
函数说明:创建source
参数:id source标识符
name source的名称。若给定的name不唯一,则自动修改唯一
settings source配置,可以设置null
hotkey_data source hotkey , 可以设置null
返回值:source数据指针,null表示失败
void obs_source_filter_add(obs_source_t *source, obs_source_t *filter)
函数说明: 给source增加filter
obs_scene_t *obs_scene_create(const char *name)
函数说明:创建scene
参数:name scene source的名称,若名称不唯一,则自动修改唯一
返回值:scene指针
obs_sceneitem_t *obs_scene_add(obs_scene_t *scene, obs_source_t *source)
函数说明:给scene增加source
返回值:scene的一个新的item指针
void obs_set_output_source(uint32_t channel, obs_source_t *source)
函数说明:为channel设置输出source
obs_display_t *obs_display_create(const struct gs_init_data *graphics_data, uint32_t background_color)
函数说明:增加新窗体连接渲染管线。这个过程会创建一个新的swap chain,每一帧都会更新。
参数:graphics_data
struct gs_init_data {
struct gs_window window;
uint32_t cx, cy;
uint32_t num_backbuffers;
enum gs_color_format format;
enum gs_zstencil_format zsformat;
uint32_t adapter;
};
参数:background_color 背景色
返回值:obs_display_t 显示上下文,失败返回null
struct obs_display {
bool update_color_space;
bool enabled;
uint32_t cx, cy;
uint32_t next_cx, next_cy;
uint32_t background_color;
gs_swapchain_t *swap;
pthread_mutex_t draw_callbacks_mutex;
pthread_mutex_t draw_info_mutex;
DARRAY(struct draw_callback) draw_callbacks;
struct obs_display *next;
struct obs_display **prev_next;
};
void obs_display_add_draw_callback(obs_display_t display, void (draw)(void *param, uint32_t cx, uint32_t cy), void *param)
函数说明:为显示上下文增加渲染回调,窗体渲染后调用回调。
参数:display 显示上下文
参数:draw 每帧更新回调
参数:param 关联回调函数参数
void obs_display_destroy(obs_display_t *display)
函数说明:释放显示上下文
void obs_shutdown()
函数说明:释放obs相关资源