Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
尘离序散
obs-studio
提交
99deb082
O
obs-studio
项目概览
尘离序散
/
obs-studio
与 Fork 源项目一致
从无法访问的项目Fork
通知
30
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
obs-studio
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
99deb082
编写于
5月 04, 2015
作者:
P
Palana
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libobs: Add refcounting helpers
上级
a907d749
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
5 deletion
+54
-5
libobs/obs-internal.h
libobs/obs-internal.h
+42
-0
libobs/obs.c
libobs/obs.c
+12
-5
未找到文件。
libobs/obs-internal.h
浏览文件 @
99deb082
...
...
@@ -275,6 +275,48 @@ extern void obs_context_data_setname(struct obs_context_data *context,
const
char
*
name
);
/* ------------------------------------------------------------------------- */
/* ref-counting */
struct
obs_weak_ref
{
volatile
long
refs
;
volatile
long
weak_refs
;
};
static
inline
void
obs_ref_addref
(
struct
obs_weak_ref
*
ref
)
{
os_atomic_inc_long
(
&
ref
->
refs
);
}
static
inline
bool
obs_ref_release
(
struct
obs_weak_ref
*
ref
)
{
return
os_atomic_dec_long
(
&
ref
->
refs
)
==
-
1
;
}
static
inline
void
obs_weak_ref_addref
(
struct
obs_weak_ref
*
ref
)
{
os_atomic_inc_long
(
&
ref
->
weak_refs
);
}
static
inline
bool
obs_weak_ref_release
(
struct
obs_weak_ref
*
ref
)
{
return
os_atomic_dec_long
(
&
ref
->
weak_refs
)
==
-
1
;
}
static
inline
bool
obs_weak_ref_get_ref
(
struct
obs_weak_ref
*
ref
)
{
long
owners
=
ref
->
refs
;
while
(
owners
>
-
1
)
{
if
(
os_atomic_compare_swap_long
(
&
ref
->
refs
,
owners
,
owners
+
1
))
return
true
;
owners
=
ref
->
refs
;
}
return
false
;
}
/* ------------------------------------------------------------------------- */
/* sources */
...
...
libobs/obs.c
浏览文件 @
99deb082
...
...
@@ -1164,7 +1164,7 @@ obs_source_t *obs_get_source_by_name(const char *name)
}
static
inline
void
*
get_context_by_name
(
void
*
vfirst
,
const
char
*
name
,
pthread_mutex_t
*
mutex
)
pthread_mutex_t
*
mutex
,
void
*
(
*
addref
)(
void
*
)
)
{
struct
obs_context_data
**
first
=
vfirst
;
struct
obs_context_data
*
context
;
...
...
@@ -1173,8 +1173,10 @@ static inline void *get_context_by_name(void *vfirst, const char *name,
context
=
*
first
;
while
(
context
)
{
if
(
strcmp
(
context
->
name
,
name
)
==
0
)
if
(
strcmp
(
context
->
name
,
name
)
==
0
)
{
context
=
addref
(
context
);
break
;
}
context
=
context
->
next
;
}
...
...
@@ -1182,25 +1184,30 @@ static inline void *get_context_by_name(void *vfirst, const char *name,
return
context
;
}
static
inline
void
*
obs_id_
(
void
*
data
)
{
return
data
;
}
obs_output_t
*
obs_get_output_by_name
(
const
char
*
name
)
{
if
(
!
obs
)
return
NULL
;
return
get_context_by_name
(
&
obs
->
data
.
first_output
,
name
,
&
obs
->
data
.
outputs_mutex
);
&
obs
->
data
.
outputs_mutex
,
obs_id_
);
}
obs_encoder_t
*
obs_get_encoder_by_name
(
const
char
*
name
)
{
if
(
!
obs
)
return
NULL
;
return
get_context_by_name
(
&
obs
->
data
.
first_encoder
,
name
,
&
obs
->
data
.
encoders_mutex
);
&
obs
->
data
.
encoders_mutex
,
obs_id_
);
}
obs_service_t
*
obs_get_service_by_name
(
const
char
*
name
)
{
if
(
!
obs
)
return
NULL
;
return
get_context_by_name
(
&
obs
->
data
.
first_service
,
name
,
&
obs
->
data
.
services_mutex
);
&
obs
->
data
.
services_mutex
,
obs_id_
);
}
gs_effect_t
*
obs_get_default_effect
(
void
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录