Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github_28344065
scrcpy
提交
f13febe8
S
scrcpy
项目概览
github_28344065
/
scrcpy
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scrcpy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f13febe8
编写于
2月 23, 2021
作者:
R
Romain Vimont
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resizer_callbacks
上级
86d152ea
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
25 deletion
+71
-25
app/src/resizer.c
app/src/resizer.c
+33
-7
app/src/resizer.h
app/src/resizer.h
+9
-3
app/src/screen.c
app/src/screen.c
+29
-15
未找到文件。
app/src/resizer.c
浏览文件 @
f13febe8
...
...
@@ -7,8 +7,7 @@
bool
sc_resizer_init
(
struct
sc_resizer
*
resizer
,
struct
video_buffer
*
vb_in
,
struct
video_buffer
*
vb_out
,
enum
sc_scale_filter
scale_filter
,
struct
size
size
)
{
enum
sc_scale_filter
scale_filter
,
struct
size
size
)
{
bool
ok
=
sc_mutex_init
(
&
resizer
->
mutex
);
if
(
!
ok
)
{
return
false
;
...
...
@@ -20,15 +19,22 @@ sc_resizer_init(struct sc_resizer *resizer, struct video_buffer *vb_in,
return
false
;
}
ok
=
video_buffer_init
(
&
resizer
->
vb_out
,
false
);
// FIXME wait_consumer
if
(
!
ok
)
{
sc_cond_destroy
(
&
resizer
->
req_cond
);
sc_mutex_destroy
(
&
resizer
->
mutex
);
return
false
;
}
resizer
->
resized_frame
=
av_frame_alloc
();
if
(
!
resizer
->
resized_frame
)
{
video_buffer_destroy
(
&
resizer
->
vb_out
);
sc_cond_destroy
(
&
resizer
->
req_cond
);
sc_mutex_destroy
(
&
resizer
->
mutex
);
return
false
;
}
resizer
->
vb_in
=
vb_in
;
resizer
->
vb_out
=
vb_out
;
resizer
->
scale_filter
=
scale_filter
;
resizer
->
size
=
size
;
...
...
@@ -123,10 +129,16 @@ run_resizer(void *data) {
// Do the actual work without mutex
sc_resizer_swscale
(
resizer
);
video_buffer_producer_offer_frame
(
resizer
->
vb_out
,
&
resizer
->
resized_frame
);
sc_mutex_lock
(
&
resizer
->
mutex
);
// Update the original size of the resized frame
resizer
->
original_size
.
width
=
resizer
->
input_frame
->
width
;
resizer
->
original_size
.
height
=
resizer
->
input_frame
->
height
;
assert
(
resizer
->
original_size
.
width
);
assert
(
resizer
->
original_size
.
height
);
video_buffer_producer_offer_frame
(
&
resizer
->
vb_out
,
&
resizer
->
resized_frame
);
}
sc_mutex_unlock
(
&
resizer
->
mutex
);
...
...
@@ -154,7 +166,7 @@ sc_resizer_stop(struct sc_resizer *resizer) {
sc_cond_signal
(
&
resizer
->
req_cond
);
sc_mutex_unlock
(
&
resizer
->
mutex
);
video_buffer_interrupt
(
resizer
->
vb_out
);
video_buffer_interrupt
(
&
resizer
->
vb_out
);
}
void
...
...
@@ -162,6 +174,20 @@ sc_resizer_join(struct sc_resizer *resizer) {
sc_thread_join
(
&
resizer
->
thread
,
NULL
);
}
const
AVFrame
*
sc_resizer_consumer_take_frame
(
struct
sc_resizer
*
resizer
,
struct
size
*
out_original_size
)
{
// Locking the mutex is necessary to ensure that the size corresponds to the correct frame
sc_mutex_lock
(
&
resizer
->
mutex
);
const
AVFrame
*
frame
=
video_buffer_consumer_take_frame
(
&
resizer
->
vb_out
);
*
out_original_size
=
resizer
->
original_size
;
sc_mutex_unlock
(
&
resizer
->
mutex
);
return
frame
;
}
void
sc_resizer_process_new_frame
(
struct
sc_resizer
*
resizer
)
{
sc_mutex_lock
(
&
resizer
->
mutex
);
...
...
app/src/resizer.h
浏览文件 @
f13febe8
...
...
@@ -13,7 +13,7 @@
struct
sc_resizer
{
struct
video_buffer
*
vb_in
;
struct
video_buffer
*
vb_out
;
struct
video_buffer
vb_out
;
enum
sc_scale_filter
scale_filter
;
struct
size
size
;
...
...
@@ -21,6 +21,9 @@ struct sc_resizer {
const
AVFrame
*
input_frame
;
AVFrame
*
resized_frame
;
// original size of the available (resized) frame in vb_out
struct
size
original_size
;
sc_thread
thread
;
sc_mutex
mutex
;
sc_cond
req_cond
;
...
...
@@ -32,8 +35,7 @@ struct sc_resizer {
bool
sc_resizer_init
(
struct
sc_resizer
*
resizer
,
struct
video_buffer
*
vb_in
,
struct
video_buffer
*
vb_out
,
enum
sc_scale_filter
scale_filter
,
struct
size
size
);
enum
sc_scale_filter
scale_filter
,
struct
size
size
);
void
sc_resizer_destroy
(
struct
sc_resizer
*
resizer
);
...
...
@@ -47,6 +49,10 @@ sc_resizer_stop(struct sc_resizer *resizer);
void
sc_resizer_join
(
struct
sc_resizer
*
resizer
);
const
AVFrame
*
sc_resizer_consumer_take_frame
(
struct
sc_resizer
*
resizer
,
struct
size
*
out_original_size
);
void
sc_resizer_process_new_frame
(
struct
sc_resizer
*
resizer
);
...
...
app/src/screen.c
浏览文件 @
f13febe8
...
...
@@ -216,6 +216,25 @@ on_frame_skipped(struct video_buffer *vb, void *userdata) {
fps_counter_add_skipped_frame
(
screen
->
fps_counter
);
}
static
void
resizer_on_frame_available
(
struct
video_buffer
*
vb
,
void
*
userdata
)
{
(
void
)
vb
;
(
void
)
userdata
;
static
SDL_Event
new_frame_event
=
{
.
type
=
EVENT_NEW_FRAME
,
};
// Post the event on the UI thread
SDL_PushEvent
(
&
new_frame_event
);
}
static
void
resizer_on_frame_skipped
(
struct
video_buffer
*
vb
,
void
*
userdata
)
{
// Count skipped frames from decoder or resizer the same way
on_frame_skipped
(
vb
,
userdata
);
}
void
screen_init
(
struct
screen
*
screen
,
struct
video_buffer
*
vb
,
struct
fps_counter
*
fps_counter
)
{
...
...
@@ -271,19 +290,6 @@ is_swscale(enum sc_scale_filter scale_filter) {
&&
scale_filter
!=
SC_SCALE_FILTER_TRILINEAR
;
}
static
void
on_resizer_frame_available
(
struct
video_buffer
*
vb
,
void
*
userdata
)
{
(
void
)
vb
;
(
void
)
userdata
;
static
SDL_Event
new_frame_event
=
{
.
type
=
EVENT_NEW_FRAME
,
};
// Post the event on the UI thread
SDL_PushEvent
(
&
new_frame_event
);
}
bool
screen_init_rendering
(
struct
screen
*
screen
,
const
char
*
window_title
,
struct
size
frame_size
,
bool
always_on_top
,
...
...
@@ -378,8 +384,8 @@ screen_init_rendering(struct screen *screen, const char *window_title,
return
false
;
}
ok
=
sc_resizer_init
(
&
screen
->
resizer
,
screen
->
vb
,
&
screen
->
resizer_vb
,
scale_filter
,
window_size
);
ok
=
sc_resizer_init
(
&
screen
->
resizer
,
screen
->
vb
,
scale_filter
,
window_size
);
if
(
!
ok
)
{
LOGE
(
"Could not create resizer"
);
video_buffer_destroy
(
&
screen
->
resizer_vb
);
...
...
@@ -388,6 +394,14 @@ screen_init_rendering(struct screen *screen, const char *window_title,
return
false
;
}
static
const
struct
video_buffer_callbacks
cbs
=
{
.
on_frame_available
=
resizer_on_frame_available
,
.
on_frame_skipped
=
resizer_on_frame_skipped
,
};
video_buffer_set_consumer_callbacks
(
&
screen
->
resizer
.
vb_out
,
&
cbs
,
screen
);
ok
=
sc_resizer_start
(
&
screen
->
resizer
);
if
(
!
ok
)
{
LOGE
(
"Could not start resizer"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录