Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github_28344065
scrcpy
提交
aa97eed2
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,发现更多精彩内容 >>
提交
aa97eed2
编写于
8月 12, 2018
作者:
N
npes87184
提交者:
Romain Vimont
8月 15, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
installer -> file_handler
Signed-off-by:
N
npes87184
<
npes87184@gmail.com
>
上级
2daeb1fd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
230 addition
and
10 deletion
+230
-10
app/meson.build
app/meson.build
+1
-1
app/src/file_handler.c
app/src/file_handler.c
+181
-0
app/src/file_handler.h
app/src/file_handler.h
+39
-0
app/src/scrcpy.c
app/src/scrcpy.c
+9
-9
未找到文件。
app/meson.build
浏览文件 @
aa97eed2
...
...
@@ -6,10 +6,10 @@ src = [
'src/convert.c',
'src/decoder.c',
'src/device.c',
'src/file_handler.c',
'src/fpscounter.c',
'src/frames.c',
'src/inputmanager.c',
'src/installer.c',
'src/lockutil.c',
'src/net.c',
'src/scrcpy.c',
...
...
app/src/
instal
ler.c
→
app/src/
file_hand
ler.c
浏览文件 @
aa97eed2
#include "
instal
ler.h"
#include "
file_hand
ler.h"
#include <string.h>
#include "command.h"
...
...
@@ -9,137 +9,136 @@
// it could be used with a command queue instead of a filename queue
// then we would have a generic invoker (useful if we want to handle more async commands)
SDL_bool
apk_queue_is_empty
(
const
struct
apk
_queue
*
queue
)
{
SDL_bool
file_queue_is_empty
(
const
struct
file
_queue
*
queue
)
{
return
queue
->
head
==
queue
->
tail
;
}
SDL_bool
apk_queue_is_full
(
const
struct
apk
_queue
*
queue
)
{
return
(
queue
->
head
+
1
)
%
APK
_QUEUE_SIZE
==
queue
->
tail
;
SDL_bool
file_queue_is_full
(
const
struct
file
_queue
*
queue
)
{
return
(
queue
->
head
+
1
)
%
FILE
_QUEUE_SIZE
==
queue
->
tail
;
}
SDL_bool
apk_queue_init
(
struct
apk
_queue
*
queue
)
{
SDL_bool
file_queue_init
(
struct
file
_queue
*
queue
)
{
queue
->
head
=
0
;
queue
->
tail
=
0
;
return
SDL_TRUE
;
}
void
apk_queue_destroy
(
struct
apk
_queue
*
queue
)
{
void
file_queue_destroy
(
struct
file
_queue
*
queue
)
{
int
i
=
queue
->
tail
;
while
(
i
!=
queue
->
head
)
{
SDL_free
(
queue
->
data
[
i
]);
i
=
(
i
+
1
)
%
APK
_QUEUE_SIZE
;
i
=
(
i
+
1
)
%
FILE
_QUEUE_SIZE
;
}
}
SDL_bool
apk_queue_push
(
struct
apk_queue
*
queue
,
const
char
*
apk
)
{
if
(
apk
_queue_is_full
(
queue
))
{
SDL_bool
file_queue_push
(
struct
file_queue
*
queue
,
const
char
*
file
)
{
if
(
file
_queue_is_full
(
queue
))
{
return
SDL_FALSE
;
}
queue
->
data
[
queue
->
head
]
=
SDL_strdup
(
apk
);
queue
->
head
=
(
queue
->
head
+
1
)
%
APK
_QUEUE_SIZE
;
queue
->
data
[
queue
->
head
]
=
SDL_strdup
(
file
);
queue
->
head
=
(
queue
->
head
+
1
)
%
FILE
_QUEUE_SIZE
;
return
SDL_TRUE
;
}
SDL_bool
apk_queue_take
(
struct
apk_queue
*
queue
,
char
**
apk
)
{
if
(
apk
_queue_is_empty
(
queue
))
{
SDL_bool
file_queue_take
(
struct
file_queue
*
queue
,
char
**
file
)
{
if
(
file
_queue_is_empty
(
queue
))
{
return
SDL_FALSE
;
}
// transfer ownership
*
apk
=
queue
->
data
[
queue
->
tail
];
queue
->
tail
=
(
queue
->
tail
+
1
)
%
APK
_QUEUE_SIZE
;
*
file
=
queue
->
data
[
queue
->
tail
];
queue
->
tail
=
(
queue
->
tail
+
1
)
%
FILE
_QUEUE_SIZE
;
return
SDL_TRUE
;
}
SDL_bool
installer_init
(
struct
installer
*
instal
ler
,
const
char
*
serial
)
{
SDL_bool
file_handler_init
(
struct
file_handler
*
file_hand
ler
,
const
char
*
serial
)
{
if
(
!
apk_queue_init
(
&
instal
ler
->
queue
))
{
if
(
!
file_queue_init
(
&
file_hand
ler
->
queue
))
{
return
SDL_FALSE
;
}
if
(
!
(
instal
ler
->
mutex
=
SDL_CreateMutex
()))
{
if
(
!
(
file_hand
ler
->
mutex
=
SDL_CreateMutex
()))
{
return
SDL_FALSE
;
}
if
(
!
(
instal
ler
->
event_cond
=
SDL_CreateCond
()))
{
SDL_DestroyMutex
(
instal
ler
->
mutex
);
if
(
!
(
file_hand
ler
->
event_cond
=
SDL_CreateCond
()))
{
SDL_DestroyMutex
(
file_hand
ler
->
mutex
);
return
SDL_FALSE
;
}
if
(
serial
)
{
instal
ler
->
serial
=
SDL_strdup
(
serial
);
if
(
!
instal
ler
->
serial
)
{
file_hand
ler
->
serial
=
SDL_strdup
(
serial
);
if
(
!
file_hand
ler
->
serial
)
{
LOGW
(
"Cannot strdup serial"
);
SDL_DestroyMutex
(
instal
ler
->
mutex
);
SDL_DestroyMutex
(
file_hand
ler
->
mutex
);
return
SDL_FALSE
;
}
}
else
{
instal
ler
->
serial
=
NULL
;
file_hand
ler
->
serial
=
NULL
;
}
// lazy initialization
instal
ler
->
initialized
=
SDL_FALSE
;
file_hand
ler
->
initialized
=
SDL_FALSE
;
instal
ler
->
stopped
=
SDL_FALSE
;
instal
ler
->
current_process
=
PROCESS_NONE
;
file_hand
ler
->
stopped
=
SDL_FALSE
;
file_hand
ler
->
current_process
=
PROCESS_NONE
;
return
SDL_TRUE
;
}
void
installer_destroy
(
struct
installer
*
instal
ler
)
{
SDL_DestroyCond
(
instal
ler
->
event_cond
);
SDL_DestroyMutex
(
instal
ler
->
mutex
);
apk_queue_destroy
(
&
instal
ler
->
queue
);
SDL_free
((
void
*
)
instal
ler
->
serial
);
void
file_handler_destroy
(
struct
file_handler
*
file_hand
ler
)
{
SDL_DestroyCond
(
file_hand
ler
->
event_cond
);
SDL_DestroyMutex
(
file_hand
ler
->
mutex
);
file_queue_destroy
(
&
file_hand
ler
->
queue
);
SDL_free
((
void
*
)
file_hand
ler
->
serial
);
}
SDL_bool
installer_install_apk
(
struct
installer
*
installer
,
const
char
*
apk
)
{
SDL_bool
file_handler_do
(
struct
file_handler
*
file_handler
,
const
char
*
file
)
{
SDL_bool
res
;
// start
instal
ler if it's used for the first time
if
(
!
instal
ler
->
initialized
)
{
if
(
!
installer_start
(
instal
ler
))
{
// start
file_hand
ler if it's used for the first time
if
(
!
file_hand
ler
->
initialized
)
{
if
(
!
file_handler_start
(
file_hand
ler
))
{
return
SDL_FALSE
;
}
instal
ler
->
initialized
=
SDL_TRUE
;
file_hand
ler
->
initialized
=
SDL_TRUE
;
}
mutex_lock
(
instal
ler
->
mutex
);
SDL_bool
was_empty
=
apk_queue_is_empty
(
&
instal
ler
->
queue
);
res
=
apk_queue_push
(
&
installer
->
queue
,
apk
);
mutex_lock
(
file_hand
ler
->
mutex
);
SDL_bool
was_empty
=
file_queue_is_empty
(
&
file_hand
ler
->
queue
);
res
=
file_queue_push
(
&
file_handler
->
queue
,
file
);
if
(
was_empty
)
{
cond_signal
(
instal
ler
->
event_cond
);
cond_signal
(
file_hand
ler
->
event_cond
);
}
mutex_unlock
(
instal
ler
->
mutex
);
mutex_unlock
(
file_hand
ler
->
mutex
);
return
res
;
}
static
int
run_
instal
ler
(
void
*
data
)
{
struct
installer
*
instal
ler
=
data
;
static
int
run_
file_hand
ler
(
void
*
data
)
{
struct
file_handler
*
file_hand
ler
=
data
;
for
(;;)
{
mutex_lock
(
instal
ler
->
mutex
);
instal
ler
->
current_process
=
PROCESS_NONE
;
while
(
!
installer
->
stopped
&&
apk_queue_is_empty
(
&
instal
ler
->
queue
))
{
cond_wait
(
installer
->
event_cond
,
instal
ler
->
mutex
);
mutex_lock
(
file_hand
ler
->
mutex
);
file_hand
ler
->
current_process
=
PROCESS_NONE
;
while
(
!
file_handler
->
stopped
&&
file_queue_is_empty
(
&
file_hand
ler
->
queue
))
{
cond_wait
(
file_handler
->
event_cond
,
file_hand
ler
->
mutex
);
}
if
(
instal
ler
->
stopped
)
{
if
(
file_hand
ler
->
stopped
)
{
// stop immediately, do not process further events
mutex_unlock
(
instal
ler
->
mutex
);
mutex_unlock
(
file_hand
ler
->
mutex
);
break
;
}
char
*
current_apk
;
#ifdef BUILD_DEBUG
bool
non_empty
=
apk_queue_take
(
&
instal
ler
->
queue
,
&
current_apk
);
bool
non_empty
=
file_queue_take
(
&
file_hand
ler
->
queue
,
&
current_apk
);
SDL_assert
(
non_empty
);
#else
apk_queue_take
(
&
instal
ler
->
queue
,
&
current_apk
);
file_queue_take
(
&
file_hand
ler
->
queue
,
&
current_apk
);
#endif
LOGI
(
"Installing %s..."
,
current_apk
);
process_t
process
=
adb_install
(
instal
ler
->
serial
,
current_apk
);
instal
ler
->
current_process
=
process
;
process_t
process
=
adb_install
(
file_hand
ler
->
serial
,
current_apk
);
file_hand
ler
->
current_process
=
process
;
mutex_unlock
(
instal
ler
->
mutex
);
mutex_unlock
(
file_hand
ler
->
mutex
);
if
(
process_check_success
(
process
,
"adb install"
))
{
LOGI
(
"%s installed successfully"
,
current_apk
);
...
...
@@ -151,32 +150,32 @@ static int run_installer(void *data) {
return
0
;
}
SDL_bool
installer_start
(
struct
installer
*
instal
ler
)
{
LOGD
(
"Starting
instal
ler thread"
);
SDL_bool
file_handler_start
(
struct
file_handler
*
file_hand
ler
)
{
LOGD
(
"Starting
file_hand
ler thread"
);
installer
->
thread
=
SDL_CreateThread
(
run_installer
,
"installer"
,
instal
ler
);
if
(
!
instal
ler
->
thread
)
{
LOGC
(
"Could not start
instal
ler thread"
);
file_handler
->
thread
=
SDL_CreateThread
(
run_file_handler
,
"file_handler"
,
file_hand
ler
);
if
(
!
file_hand
ler
->
thread
)
{
LOGC
(
"Could not start
file_hand
ler thread"
);
return
SDL_FALSE
;
}
return
SDL_TRUE
;
}
void
installer_stop
(
struct
installer
*
instal
ler
)
{
mutex_lock
(
instal
ler
->
mutex
);
instal
ler
->
stopped
=
SDL_TRUE
;
cond_signal
(
instal
ler
->
event_cond
);
if
(
instal
ler
->
current_process
!=
PROCESS_NONE
)
{
if
(
!
cmd_terminate
(
instal
ler
->
current_process
))
{
void
file_handler_stop
(
struct
file_handler
*
file_hand
ler
)
{
mutex_lock
(
file_hand
ler
->
mutex
);
file_hand
ler
->
stopped
=
SDL_TRUE
;
cond_signal
(
file_hand
ler
->
event_cond
);
if
(
file_hand
ler
->
current_process
!=
PROCESS_NONE
)
{
if
(
!
cmd_terminate
(
file_hand
ler
->
current_process
))
{
LOGW
(
"Cannot terminate install process"
);
}
cmd_simple_wait
(
instal
ler
->
current_process
,
NULL
);
instal
ler
->
current_process
=
PROCESS_NONE
;
cmd_simple_wait
(
file_hand
ler
->
current_process
,
NULL
);
file_hand
ler
->
current_process
=
PROCESS_NONE
;
}
mutex_unlock
(
instal
ler
->
mutex
);
mutex_unlock
(
file_hand
ler
->
mutex
);
}
void
installer_join
(
struct
installer
*
instal
ler
)
{
SDL_WaitThread
(
instal
ler
->
thread
,
NULL
);
void
file_handler_join
(
struct
file_handler
*
file_hand
ler
)
{
SDL_WaitThread
(
file_hand
ler
->
thread
,
NULL
);
}
app/src/
instal
ler.h
→
app/src/
file_hand
ler.h
浏览文件 @
aa97eed2
#ifndef
APK_INSTAL
LER_H
#define
APK_INSTALLE
R_H
#ifndef
FILE_HAND
LER_H
#define
FILE_HADNEL
R_H
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_stdinc.h>
#include <SDL2/SDL_thread.h>
#include "command.h"
#define
APK
_QUEUE_SIZE 16
#define
FILE
_QUEUE_SIZE 16
// NOTE(AdoPi)
apk
_queue and control_event can use a generic queue
// NOTE(AdoPi)
file
_queue and control_event can use a generic queue
struct
apk
_queue
{
char
*
data
[
APK
_QUEUE_SIZE
];
struct
file
_queue
{
char
*
data
[
FILE
_QUEUE_SIZE
];
int
tail
;
int
head
;
};
struct
instal
ler
{
struct
file_hand
ler
{
const
char
*
serial
;
SDL_Thread
*
thread
;
SDL_mutex
*
mutex
;
...
...
@@ -24,17 +24,16 @@ struct installer {
SDL_bool
stopped
;
SDL_bool
initialized
;
process_t
current_process
;
struct
apk
_queue
queue
;
struct
file
_queue
queue
;
};
SDL_bool
installer_init
(
struct
installer
*
instal
ler
,
const
char
*
serial
);
void
installer_destroy
(
struct
installer
*
instal
ler
);
SDL_bool
file_handler_init
(
struct
file_handler
*
file_hand
ler
,
const
char
*
serial
);
void
file_handler_destroy
(
struct
file_handler
*
file_hand
ler
);
SDL_bool
installer_start
(
struct
installer
*
instal
ler
);
void
installer_stop
(
struct
installer
*
instal
ler
);
void
installer_join
(
struct
installer
*
instal
ler
);
SDL_bool
file_handler_start
(
struct
file_handler
*
file_hand
ler
);
void
file_handler_stop
(
struct
file_handler
*
file_hand
ler
);
void
file_handler_join
(
struct
file_handler
*
file_hand
ler
);
// install an apk
SDL_bool
installer_install_apk
(
struct
installer
*
installer
,
const
char
*
filename
);
SDL_bool
file_handler_do
(
struct
file_handler
*
file_handler
,
const
char
*
filename
);
#endif
app/src/scrcpy.c
浏览文件 @
aa97eed2
...
...
@@ -13,6 +13,7 @@
#include "decoder.h"
#include "device.h"
#include "events.h"
#include "file_handler.h"
#include "frames.h"
#include "fpscounter.h"
#include "inputmanager.h"
...
...
@@ -22,14 +23,13 @@
#include "screen.h"
#include "server.h"
#include "tinyxpm.h"
#include "installer.h"
static
struct
server
server
=
SERVER_INITIALIZER
;
static
struct
screen
screen
=
SCREEN_INITIALIZER
;
static
struct
frames
frames
;
static
struct
decoder
decoder
;
static
struct
controller
controller
;
static
struct
installer
instal
ler
;
static
struct
file_handler
file_hand
ler
;
static
struct
input_manager
input_manager
=
{
.
controller
=
&
controller
,
...
...
@@ -105,7 +105,7 @@ static SDL_bool event_loop(void) {
input_manager_process_mouse_button
(
&
input_manager
,
&
event
.
button
);
break
;
case
SDL_DROPFILE
:
installer_install_apk
(
&
instal
ler
,
event
.
drop
.
file
);
file_handler_do
(
&
file_hand
ler
,
event
.
drop
.
file
);
break
;
}
}
...
...
@@ -175,7 +175,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
goto
finally_destroy_server
;
}
if
(
!
installer_init
(
&
instal
ler
,
server
.
serial
))
{
if
(
!
file_handler_init
(
&
file_hand
ler
,
server
.
serial
))
{
ret
=
SDL_FALSE
;
server_stop
(
&
server
);
goto
finally_destroy_frames
;
...
...
@@ -188,7 +188,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
if
(
!
decoder_start
(
&
decoder
))
{
ret
=
SDL_FALSE
;
server_stop
(
&
server
);
goto
finally_destroy_
instal
ler
;
goto
finally_destroy_
file_hand
ler
;
}
if
(
!
controller_init
(
&
controller
,
device_socket
))
{
...
...
@@ -226,10 +226,10 @@ finally_stop_decoder:
// stop the server before decoder_join() to wake up the decoder
server_stop
(
&
server
);
decoder_join
(
&
decoder
);
finally_destroy_
instal
ler:
installer_stop
(
&
instal
ler
);
installer_join
(
&
instal
ler
);
installer_destroy
(
&
instal
ler
);
finally_destroy_
file_hand
ler:
file_handler_stop
(
&
file_hand
ler
);
file_handler_join
(
&
file_hand
ler
);
file_handler_destroy
(
&
file_hand
ler
);
finally_destroy_frames:
frames_destroy
(
&
frames
);
finally_destroy_server:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录