title
soaringsoul
2019-04-21 21:26:13
https://github.com/Genymobile/scrcpy https://www.jianshu.com/p/06f4b8919991
client(电脑端)
scrcpy bin文件 libav (FFmpeg): 视频流解码decode SDL: cross-platform UI api, 源码: scrcpy/app
main thread - 事件循环, 处理SDL_Event stream thread - 解码视频, 自定义EVENT_NEW_FRAME事件,push SDL_Event通知主线程更新 controller thread - 发送控制信息到手机端, control_event
鼠标移动事件 SDL_MOUSEMOTION, input_manager_process_mouse_motion
server(手机端)
源码scrcpy/server DesktopConnection - 负责和PC端建立网络连接 ScreenEncoder - 负责编码视频流 EventController - 线程负责传递控制信息
main thread - encoding and streaming the video to the client; controller thread - 接受控制事件
ScreenEncoder MediaFormat 设置格式 MediaCodec
DesktopConnection tunnelForward = true, 手机端作为网络服务端,电脑端作为网络客户端
tunnelForward = false, 手机端作为网络客户端,电脑端作为网络服务端
优先使用adb reverse(对应tunnelForward = false), 如果失败则使用adb forward(对应tunnel_forward=true)
手机端开发
手动安装和启动
进入server目录, 编译生成apk文件
adb push build/outputs/apk/debug/server-debug.apk /data/local/tmp/
adb shell "CLASSPATH=/data/local/tmp/server-debug.apk app_process / com.genymobile.scrcpy.Server 0 8000000 false - false"
build
prebuilt-deps: ffmpeg sdl adb
app: scrcpy bin文件源码 server: scrcpy-server.jar
scrcpy 手机端
使用android app方式开发: 生成IBinder时返回为null, 错误原因: E/SurfaceFlinger: Permission Denial: can't access SurfaceFlinger pid=4202, uid=10095
private static IBinder createDisplay() {
return SurfaceControl.createDisplay("scrcpy", true);
}
使用android java方法开发: 无权限问题, 但是无法获得Context,无法建立Activity和Service