Skip to content

Commit

Permalink
Merge pull request #20 from rustdesk/master
Browse files Browse the repository at this point in the history
try sync
  • Loading branch information
eltorio authored Apr 19, 2024
2 parents 5b89f2e + c757789 commit b34ae8c
Show file tree
Hide file tree
Showing 102 changed files with 1,603 additions and 615 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
env:
FLUTTER_VERSION: "3.16.9"
FLUTTER_RUST_BRIDGE_VERSION: "1.80.1"
RUST_VERSION: "1.75" # https://github.com/rustdesk/rustdesk/discussions/7503

jobs:
generate_bridge:
Expand Down Expand Up @@ -49,9 +50,9 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
toolchain: ${{ env.RUST_VERSION }}
targets: ${{ matrix.job.target }}
components: ''
components: "rustfmt"

- uses: Swatinem/rust-cache@v2
with:
Expand Down
27 changes: 18 additions & 9 deletions .github/workflows/flutter-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
RUST_VERSION: "1.75" # https://github.com/rustdesk/rustdesk/discussions/7503
CARGO_NDK_VERSION: "3.1.2"
LLVM_VERSION: "15.0.6"
FLUTTER_VERSION: "3.19.5"
FLUTTER_VERSION: "3.19.6"
FLUTTER_RUST_BRIDGE_VERSION: "1.80.1"
# for arm64 linux because official Dart SDK does not work
FLUTTER_ELINUX_VERSION: "3.16.9"
Expand Down Expand Up @@ -113,7 +113,18 @@ jobs:
shell: bash

- name: Build rustdesk
run: python3 .\build.py --portable --hwcodec --flutter --vram --skip-portable-pack
run: |
Invoke-WebRequest -Uri https://github.com/rustdesk-org/rdev/releases/download/usbmmidd_v2/usbmmidd_v2.zip -OutFile usbmmidd_v2.zip
$SHA256_SUM = '629b51e9944762bae73948171c65d09a79595cf4c771a82ebc003fbba5b24f51'
if ((Get-FileHash -Path .\usbmmidd_v2.zip -Algorithm SHA256).Hash -ne $SHA256_SUM) {
Write-Error "SHA256 sum mismatch, falling back to the non-virtual-display version"
python3 .\build.py --portable --hwcodec --flutter --vram --skip-portable-pack
} else {
Write-Host "SHA256 sum matched, using the virtual-display version"
Expand-Archive usbmmidd_v2.zip -DestinationPath .
python3 .\build.py --portable --hwcodec --flutter --vram --skip-portable-pack --virtual-display
mv -Force .\usbmmidd_v2 ./flutter/build/windows/x64/runner/Release/
}
- name: find Runner.res
# Windows: find Runner.res (compiled from ./flutter/windows/runner/Runner.rc), copy to ./Runner.res
Expand Down Expand Up @@ -169,7 +180,7 @@ jobs:
if: env.UPLOAD_ARTIFACT == 'true'
run: |
pushd ./res/msi
python preprocess.py -arp -d ../../rustdesk
python preprocess.py --arp -d ../../rustdesk
nuget restore msi.sln
msbuild msi.sln -p:Configuration=Release -p:Platform=x64 /p:TargetVersion=Windows10
mv ./Package/bin/x64/Release/en-us/Package.msi ../../SignOutput/rustdesk-${{ env.VERSION }}-${{ matrix.job.arch }}-beta.msi
Expand Down Expand Up @@ -331,8 +342,7 @@ jobs:
- name: Build rustdesk
run: |
# --hwcodec not supported on macos yet
./build.py --flutter
./build.py --flutter --hwcodec
- name: create unsigned dmg
if: env.UPLOAD_ARTIFACT == 'true'
Expand Down Expand Up @@ -486,8 +496,7 @@ jobs:
- name: Build rustdesk
run: |
# --hwcodec not supported on macos yet
./build.py --flutter ${{ matrix.job.extra-build-args }}
./build.py --flutter --hwcodec ${{ matrix.job.extra-build-args }}
- name: create unsigned dmg
if: env.UPLOAD_ARTIFACT == 'true'
Expand Down Expand Up @@ -636,7 +645,7 @@ jobs:
- name: Build rustdesk lib
run: |
rustup target add ${{ matrix.job.target }}
cargo build --features flutter --release --target aarch64-apple-ios --lib
cargo build --features flutter,hwcodec --release --target aarch64-apple-ios --lib
- name: Build rustdesk
shell: bash
Expand Down Expand Up @@ -1257,7 +1266,7 @@ jobs:
export DEFAULT_FEAT=linux_headless
fi
export CARGO_INCREMENTAL=0
cargo build --lib --features flutter,flutter_texture_render,${{ matrix.job.extra-build-features }},$DEFAULT_FEAT --release
cargo build --lib --features flutter,flutter_texture_render,hwcodec,${{ matrix.job.extra-build-features }},$DEFAULT_FEAT --release
- name: Upload Artifacts
uses: actions/upload-artifact@master
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ system_shutdown = "4.0"
qrcode-generator = "4.1"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winuser", "wincrypt", "shellscalingapi", "pdh", "synchapi", "memoryapi", "shellapi"] }
winapi = { version = "0.3", features = ["winuser", "wincrypt", "shellscalingapi", "pdh", "synchapi", "memoryapi", "shellapi", "devguid", "setupapi", "cguid", "cfgmgr32"] }
winreg = "0.11"
windows-service = "0.6"
virtual_display = { path = "libs/virtual_display", optional = true }
Expand Down
15 changes: 12 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def get_arch() -> str:


def system2(cmd):
err = os.system(cmd)
if err != 0:
print(f"Error occurred when executing: {cmd}. Exiting.")
exit_code = os.system(cmd)
if exit_code != 0:
sys.stderr.write(f"Error occurred when executing: `{cmd}`. Exiting.\n")
sys.exit(-1)


Expand Down Expand Up @@ -153,6 +153,12 @@ def make_parser():
action='store_true',
help='Skip packing, only flutter version + Windows supported'
)
parser.add_argument(
'--virtual-display',
action='store_true',
default=False,
help='Build rustdesk libs with the virtual display feature enabled'
)
parser.add_argument(
"--package",
type=str
Expand Down Expand Up @@ -293,6 +299,9 @@ def get_features(args):
features.append('appimage')
if args.unix_file_copy_paste:
features.append('unix-file-copy-paste')
if windows:
if args.virtual_display:
features.append('virtual_display_driver')
print("features:", features)
return features

Expand Down
1 change: 0 additions & 1 deletion flutter/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,3 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib") { version { strictly("$kotlin_version") } }
}

apply plugin: 'com.google.gms.google-services'
40 changes: 0 additions & 40 deletions flutter/android/app/google-services.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.carriez.flutter_hbb

import ffi.FFI

/**
* Capture screen,get video and audio,send to rust.
* Dispatch notifications
Expand Down Expand Up @@ -64,10 +66,6 @@ const val AUDIO_CHANNEL_MASK = AudioFormat.CHANNEL_IN_STEREO

class MainService : Service() {

init {
System.loadLibrary("rustdesk")
}

@Keep
@RequiresApi(Build.VERSION_CODES.N)
fun rustPointerInput(kind: String, mask: Int, x: Int, y: Int) {
Expand Down Expand Up @@ -156,23 +154,9 @@ class MainService : Service() {
private val powerManager: PowerManager by lazy { applicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager }
private val wakeLock: PowerManager.WakeLock by lazy { powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "rustdesk:wakelock")}

// jvm call rust
private external fun init(ctx: Context)

/// When app start on boot, app_dir will not be passed from flutter
/// so pass a app_dir here to rust server
private external fun startServer(app_dir: String)
private external fun startService()
private external fun onVideoFrameUpdate(buf: ByteBuffer)
private external fun onAudioFrameUpdate(buf: ByteBuffer)
private external fun translateLocale(localeName: String, input: String): String
private external fun refreshScreen()
private external fun setFrameRawEnable(name: String, value: Boolean)
// private external fun sendVp9(data: ByteArray)

private fun translate(input: String): String {
Log.d(logTag, "translate:$LOCAL_NAME")
return translateLocale(LOCAL_NAME, input)
return FFI.translateLocale(LOCAL_NAME, input)
}

companion object {
Expand Down Expand Up @@ -211,7 +195,7 @@ class MainService : Service() {
override fun onCreate() {
super.onCreate()
Log.d(logTag,"MainService onCreate")
init(this)
FFI.init(this)
HandlerThread("Service", Process.THREAD_PRIORITY_BACKGROUND).apply {
start()
serviceLooper = looper
Expand All @@ -223,7 +207,7 @@ class MainService : Service() {
// keep the config dir same with flutter
val prefs = applicationContext.getSharedPreferences(KEY_SHARED_PREFERENCES, FlutterActivity.MODE_PRIVATE)
val configPath = prefs.getString(KEY_APP_DIR_CONFIG_PATH, "") ?: ""
startServer(configPath)
FFI.startServer(configPath, "")

createForegroundNotification()
}
Expand Down Expand Up @@ -278,7 +262,7 @@ class MainService : Service() {
SCREEN_INFO.dpi = dpi
if (isStart) {
stopCapture()
refreshScreen()
FFI.refreshScreen()
startCapture()
}
}
Expand Down Expand Up @@ -306,7 +290,7 @@ class MainService : Service() {
createForegroundNotification()

if (intent.getBooleanExtra(EXT_INIT_FROM_BOOT, false)) {
startService()
FFI.startService()
}
Log.d(logTag, "service starting: ${startId}:${Thread.currentThread()}")
val mediaProjectionManager =
Expand Down Expand Up @@ -354,12 +338,15 @@ class MainService : Service() {
).apply {
setOnImageAvailableListener({ imageReader: ImageReader ->
try {
if (!isStart) {
return@setOnImageAvailableListener
}
imageReader.acquireLatestImage().use { image ->
if (image == null) return@setOnImageAvailableListener
if (image == null || !isStart) return@setOnImageAvailableListener
val planes = image.planes
val buffer = planes[0].buffer
buffer.rewind()
onVideoFrameUpdate(buffer)
FFI.onVideoFrameUpdate(buffer)
}
} catch (ignored: java.lang.Exception) {
}
Expand Down Expand Up @@ -393,21 +380,24 @@ class MainService : Service() {
}
checkMediaPermission()
_isStart = true
setFrameRawEnable("video",true)
setFrameRawEnable("audio",true)
FFI.setFrameRawEnable("video",true)
FFI.setFrameRawEnable("audio",true)
return true
}

@Synchronized
fun stopCapture() {
Log.d(logTag, "Stop Capture")
setFrameRawEnable("video",false)
setFrameRawEnable("audio",false)
FFI.setFrameRawEnable("video",false)
FFI.setFrameRawEnable("audio",false)
_isStart = false
// release video
virtualDisplay?.release()
surface?.release()
imageReader?.close()
imageReader = null
// suface needs to be release after imageReader.close to imageReader access released surface
// https://github.com/rustdesk/rustdesk/issues/4118#issuecomment-1515666629
surface?.release()
videoEncoder?.let {
it.signalEndOfInputStream()
it.stop()
Expand All @@ -418,18 +408,13 @@ class MainService : Service() {

// release audio
audioRecordStat = false
audioRecorder?.release()
audioRecorder = null
minBufferSize = 0
}

fun destroy() {
Log.d(logTag, "destroy service")
_isReady = false

stopCapture()
imageReader?.close()
imageReader = null

mediaProjection = null
checkMediaPermission()
Expand Down Expand Up @@ -537,9 +522,13 @@ class MainService : Service() {
thread {
while (audioRecordStat) {
audioReader!!.readSync(audioRecorder!!)?.let {
onAudioFrameUpdate(it)
FFI.onAudioFrameUpdate(it)
}
}
// let's release here rather than onDestroy to avoid threading issue
audioRecorder?.release()
audioRecorder = null
minBufferSize = 0
Log.d(logTag, "Exit audio thread")
}
} catch (e: Exception) {
Expand Down
21 changes: 21 additions & 0 deletions flutter/android/app/src/main/kotlin/ffi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ffi.kt

package ffi

import android.content.Context
import java.nio.ByteBuffer

object FFI {
init {
System.loadLibrary("rustdesk")
}

external fun init(ctx: Context)
external fun startServer(app_dir: String, custom_client_config: String)
external fun startService()
external fun onVideoFrameUpdate(buf: ByteBuffer)
external fun onAudioFrameUpdate(buf: ByteBuffer)
external fun translateLocale(localeName: String, input: String): String
external fun refreshScreen()
external fun setFrameRawEnable(name: String, value: Boolean)
}
Binary file not shown.
Loading

0 comments on commit b34ae8c

Please sign in to comment.