Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
尘离序散
obs-studio
提交
beba96b2
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,发现更多精彩内容 >>
未验证
提交
beba96b2
编写于
6月 21, 2020
作者:
J
Jim
提交者:
GitHub
6月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3051 from jpark37/mac-threads
libobs: Use autoreleasepool for graphics thread
上级
434d08c1
6aa50b3e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
138 addition
and
88 deletion
+138
-88
libobs/obs-cocoa.m
libobs/obs-cocoa.m
+14
-0
libobs/obs-internal.h
libobs/obs-internal.h
+20
-0
libobs/obs-video.c
libobs/obs-video.c
+99
-88
libobs/obs.c
libobs/obs.c
+5
-0
未找到文件。
libobs/obs-cocoa.m
浏览文件 @
beba96b2
...
@@ -1804,3 +1804,17 @@ bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *plat,
...
@@ -1804,3 +1804,17 @@ bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *plat,
return
false
;
return
false
;
}
}
void
*
obs_graphics_thread_autorelease
(
void
*
param
)
{
@autoreleasepool
{
return
obs_graphics_thread
(
param
);
}
}
bool
obs_graphics_thread_loop_autorelease
(
struct
obs_graphics_context
*
context
)
{
@autoreleasepool
{
return
obs_graphics_thread_loop
(
context
);
}
}
libobs/obs-internal.h
浏览文件 @
beba96b2
...
@@ -434,7 +434,27 @@ struct obs_core {
...
@@ -434,7 +434,27 @@ struct obs_core {
extern
struct
obs_core
*
obs
;
extern
struct
obs_core
*
obs
;
struct
obs_graphics_context
{
uint64_t
last_time
;
uint64_t
interval
;
uint64_t
frame_time_total_ns
;
uint64_t
fps_total_ns
;
uint32_t
fps_total_frames
;
#ifdef _WIN32
bool
gpu_was_active
;
#endif
bool
raw_was_active
;
bool
was_active
;
const
char
*
video_thread_name
;
};
extern
void
*
obs_graphics_thread
(
void
*
param
);
extern
void
*
obs_graphics_thread
(
void
*
param
);
extern
bool
obs_graphics_thread_loop
(
struct
obs_graphics_context
*
context
);
#ifdef __APPLE__
extern
void
*
obs_graphics_thread_autorelease
(
void
*
param
);
extern
bool
obs_graphics_thread_loop_autorelease
(
struct
obs_graphics_context
*
context
);
#endif
extern
gs_effect_t
*
obs_load_effect
(
gs_effect_t
**
effect
,
const
char
*
file
);
extern
gs_effect_t
*
obs_load_effect
(
gs_effect_t
**
effect
,
const
char
*
file
);
...
...
libobs/obs-video.c
浏览文件 @
beba96b2
...
@@ -921,124 +921,135 @@ static void uninit_winrt_state(struct winrt_state *winrt)
...
@@ -921,124 +921,135 @@ static void uninit_winrt_state(struct winrt_state *winrt)
static
const
char
*
tick_sources_name
=
"tick_sources"
;
static
const
char
*
tick_sources_name
=
"tick_sources"
;
static
const
char
*
render_displays_name
=
"render_displays"
;
static
const
char
*
render_displays_name
=
"render_displays"
;
static
const
char
*
output_frame_name
=
"output_frame"
;
static
const
char
*
output_frame_name
=
"output_frame"
;
void
*
obs_graphics_thread
(
void
*
param
)
bool
obs_graphics_thread_loop
(
struct
obs_graphics_context
*
context
)
{
{
#ifdef _WIN32
/* defer loop break to clean up sources */
struct
winrt_state
winrt
;
const
bool
stop_requested
=
video_output_stopped
(
obs
->
video
.
video
);
init_winrt_state
(
&
winrt
);
#endif // #ifdef _WIN32
uint64_t
last_time
=
0
;
uint64_t
frame_start
=
os_gettime_ns
();
uint64_t
interval
=
video_output_get_frame_time
(
obs
->
video
.
video
);
uint64_t
frame_time_ns
;
uint64_t
frame_time_total_ns
=
0
;
bool
raw_active
=
obs
->
video
.
raw_active
>
0
;
uint64_t
fps_total_ns
=
0
;
uint32_t
fps_total_frames
=
0
;
#ifdef _WIN32
#ifdef _WIN32
bool
gpu_was_active
=
false
;
const
bool
gpu_active
=
obs
->
video
.
gpu_encoder_active
>
0
;
const
bool
active
=
raw_active
||
gpu_active
;
#else
const
bool
gpu_active
=
0
;
const
bool
active
=
raw_active
;
#endif
#endif
bool
raw_was_active
=
false
;
bool
was_active
=
false
;
is_graphics_thread
=
true
;
if
(
!
context
->
was_active
&&
active
)
clear_base_frame_data
();
if
(
!
context
->
raw_was_active
&&
raw_active
)
clear_raw_frame_data
();
#ifdef _WIN32
if
(
!
context
->
gpu_was_active
&&
gpu_active
)
clear_gpu_frame_data
();
obs
->
video
.
video_time
=
os_gettime_ns
();
context
->
gpu_was_active
=
gpu_active
;
obs
->
video
.
video_frame_interval_ns
=
interval
;
#endif
context
->
raw_was_active
=
raw_active
;
context
->
was_active
=
active
;
os_set_thread_name
(
"libobs: graphics thread"
);
profile_start
(
context
->
video_thread_name
);
const
char
*
video_thread_name
=
profile_store_name
(
gs_enter_context
(
obs
->
video
.
graphics
);
obs_get_profiler_name_store
(),
gs_begin_frame
();
"obs_graphics_thread(%g"
NBSP
"ms)"
,
interval
/
1000000
.);
gs_leave_context
();
profile_register_root
(
video_thread_name
,
interval
);
srand
((
unsigned
int
)
time
(
NULL
));
profile_start
(
tick_sources_name
);
context
->
last_time
=
tick_sources
(
obs
->
video
.
video_time
,
context
->
last_time
);
profile_end
(
tick_sources_name
);
for
(;;)
{
execute_graphics_tasks
();
/* defer loop break to clean up sources */
const
bool
stop_requested
=
video_output_stopped
(
obs
->
video
.
video
);
uint64_t
frame_start
=
os_gettime_ns
();
uint64_t
frame_time_ns
;
bool
raw_active
=
obs
->
video
.
raw_active
>
0
;
#ifdef _WIN32
#ifdef _WIN32
const
bool
gpu_active
=
obs
->
video
.
gpu_encoder_active
>
0
;
MSG
msg
;
const
bool
active
=
raw_active
||
gpu_active
;
while
(
PeekMessage
(
&
msg
,
NULL
,
0
,
0
,
PM_REMOVE
))
{
#else
TranslateMessage
(
&
msg
);
const
bool
gpu_active
=
0
;
DispatchMessage
(
&
msg
)
;
const
bool
active
=
raw_active
;
}
#endif
#endif
if
(
!
was_active
&&
active
)
profile_start
(
output_frame_name
);
clear_base_frame_data
();
output_frame
(
raw_active
,
gpu_active
);
if
(
!
raw_was_active
&&
raw_active
)
profile_end
(
output_frame_name
);
clear_raw_frame_data
();
#ifdef _WIN32
if
(
!
gpu_was_active
&&
gpu_active
)
clear_gpu_frame_data
();
gpu_was_active
=
gpu_active
;
profile_start
(
render_displays_name
);
#endif
render_displays
();
raw_was_active
=
raw_active
;
profile_end
(
render_displays_name
);
was_active
=
active
;
profile_start
(
video_thread_name
)
;
frame_time_ns
=
os_gettime_ns
()
-
frame_start
;
gs_enter_context
(
obs
->
video
.
graphics
);
profile_end
(
context
->
video_thread_name
);
gs_begin_frame
();
gs_leave_context
();
profile_start
(
tick_sources_name
);
profile_reenable_thread
();
last_time
=
tick_sources
(
obs
->
video
.
video_time
,
last_time
);
profile_end
(
tick_sources_name
);
execute_graphics_tasks
();
video_sleep
(
&
obs
->
video
,
raw_active
,
gpu_active
,
&
obs
->
video
.
video_time
,
context
->
interval
);
#ifdef _WIN32
context
->
frame_time_total_ns
+=
frame_time_ns
;
MSG
msg
;
context
->
fps_total_ns
+=
(
obs
->
video
.
video_time
-
context
->
last_time
);
while
(
PeekMessage
(
&
msg
,
NULL
,
0
,
0
,
PM_REMOVE
))
{
context
->
fps_total_frames
++
;
TranslateMessage
(
&
msg
);
DispatchMessage
(
&
msg
);
}
#endif
profile_start
(
output_frame_name
);
if
(
context
->
fps_total_ns
>=
1000000000ULL
)
{
output_frame
(
raw_active
,
gpu_active
);
obs
->
video
.
video_fps
=
profile_end
(
output_frame_name
);
(
double
)
context
->
fps_total_frames
/
((
double
)
context
->
fps_total_ns
/
1000000000
.
0
);
obs
->
video
.
video_avg_frame_time_ns
=
context
->
frame_time_total_ns
/
(
uint64_t
)
context
->
fps_total_frames
;
profile_start
(
render_displays_name
);
context
->
frame_time_total_ns
=
0
;
render_displays
();
context
->
fps_total_ns
=
0
;
profile_end
(
render_displays_name
);
context
->
fps_total_frames
=
0
;
}
frame_time_ns
=
os_gettime_ns
()
-
frame_start
;
return
!
stop_requested
;
}
profile_end
(
video_thread_name
);
void
*
obs_graphics_thread
(
void
*
param
)
{
#ifdef _WIN32
struct
winrt_state
winrt
;
init_winrt_state
(
&
winrt
);
#endif // #ifdef _WIN32
profile_reenable_thread
()
;
is_graphics_thread
=
true
;
video_sleep
(
&
obs
->
video
,
raw_active
,
gpu_active
,
const
uint64_t
interval
=
video_output_get_frame_time
(
obs
->
video
.
video
);
&
obs
->
video
.
video_time
,
interval
);
frame_time_total_ns
+=
frame_time_ns
;
obs
->
video
.
video_time
=
os_gettime_ns
();
fps_total_ns
+=
(
obs
->
video
.
video_time
-
last_time
);
obs
->
video
.
video_frame_interval_ns
=
interval
;
fps_total_frames
++
;
if
(
fps_total_ns
>=
1000000000ULL
)
{
os_set_thread_name
(
"libobs: graphics thread"
);
obs
->
video
.
video_fps
=
(
double
)
fps_total_frames
/
((
double
)
fps_total_ns
/
1000000000
.
0
);
obs
->
video
.
video_avg_frame_time_ns
=
frame_time_total_ns
/
(
uint64_t
)
fps_total_frames
;
frame_time_total_ns
=
0
;
const
char
*
video_thread_name
=
profile_store_name
(
fps_total_ns
=
0
;
obs_get_profiler_name_store
(),
fps_total_frames
=
0
;
"obs_graphics_thread(%g"
NBSP
"ms)"
,
interval
/
1000000
.)
;
}
profile_register_root
(
video_thread_name
,
interval
);
if
(
stop_requested
)
srand
((
unsigned
int
)
time
(
NULL
));
break
;
}
struct
obs_graphics_context
context
;
context
.
interval
=
video_output_get_frame_time
(
obs
->
video
.
video
);
context
.
frame_time_total_ns
=
0
;
context
.
fps_total_ns
=
0
;
context
.
fps_total_frames
=
0
;
context
.
last_time
=
0
;
#ifdef _WIN32
context
.
gpu_was_active
=
false
;
#endif
context
.
raw_was_active
=
false
;
context
.
was_active
=
false
;
context
.
video_thread_name
=
video_thread_name
;
#ifdef __APPLE__
while
(
obs_graphics_thread_loop_autorelease
(
&
context
))
#else
while
(
obs_graphics_thread_loop
(
&
context
))
#endif
;
#ifdef _WIN32
#ifdef _WIN32
uninit_winrt_state
(
&
winrt
);
uninit_winrt_state
(
&
winrt
);
...
...
libobs/obs.c
浏览文件 @
beba96b2
...
@@ -429,8 +429,13 @@ static int obs_init_video(struct obs_video_info *ovi)
...
@@ -429,8 +429,13 @@ static int obs_init_video(struct obs_video_info *ovi)
if
(
pthread_mutex_init
(
&
video
->
task_mutex
,
NULL
)
<
0
)
if
(
pthread_mutex_init
(
&
video
->
task_mutex
,
NULL
)
<
0
)
return
OBS_VIDEO_FAIL
;
return
OBS_VIDEO_FAIL
;
#ifdef __APPLE__
errorcode
=
pthread_create
(
&
video
->
video_thread
,
NULL
,
obs_graphics_thread_autorelease
,
obs
);
#else
errorcode
=
pthread_create
(
&
video
->
video_thread
,
NULL
,
errorcode
=
pthread_create
(
&
video
->
video_thread
,
NULL
,
obs_graphics_thread
,
obs
);
obs_graphics_thread
,
obs
);
#endif
if
(
errorcode
!=
0
)
if
(
errorcode
!=
0
)
return
OBS_VIDEO_FAIL
;
return
OBS_VIDEO_FAIL
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录