mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
android video service wakelock
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -36,6 +36,7 @@ lazy_static = "1.4"
|
||||
log = "0.4"
|
||||
serde_json = "1.0"
|
||||
ndk = { version = "0.7", features = ["media"], optional = true}
|
||||
ndk-context = "0.1"
|
||||
|
||||
[target.'cfg(not(target_os = "android"))'.dev-dependencies]
|
||||
repng = "0.2"
|
||||
|
||||
@@ -19,6 +19,7 @@ lazy_static! {
|
||||
static ref MAIN_SERVICE_CTX: RwLock<Option<GlobalRef>> = RwLock::new(None); // MainService -> video service / audio service / info
|
||||
static ref VIDEO_RAW: Mutex<FrameRaw> = Mutex::new(FrameRaw::new("video", MAX_VIDEO_FRAME_TIMEOUT));
|
||||
static ref AUDIO_RAW: Mutex<FrameRaw> = Mutex::new(FrameRaw::new("audio", MAX_AUDIO_FRAME_TIMEOUT));
|
||||
static ref NDK_CONTEXT_INITED: Mutex<bool> = Default::default();
|
||||
}
|
||||
|
||||
const MAX_VIDEO_FRAME_TIMEOUT: Duration = Duration::from_millis(100);
|
||||
@@ -150,6 +151,7 @@ pub extern "system" fn Java_com_carriez_flutter_1hbb_MainService_init(
|
||||
*JVM.write().unwrap() = Some(jvm);
|
||||
if let Ok(context) = env.new_global_ref(ctx) {
|
||||
*MAIN_SERVICE_CTX.write().unwrap() = Some(context);
|
||||
init_ndk_context().ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +167,12 @@ pub fn call_main_service_pointer_input(kind: &str, mask: i32, x: i32, y: i32) ->
|
||||
ctx,
|
||||
"rustPointerInput",
|
||||
"(Ljava/lang/String;III)V",
|
||||
&[JValue::Object(&JObject::from(kind)), JValue::Int(mask), JValue::Int(x), JValue::Int(y)],
|
||||
&[
|
||||
JValue::Object(&JObject::from(kind)),
|
||||
JValue::Int(mask),
|
||||
JValue::Int(x),
|
||||
JValue::Int(y),
|
||||
],
|
||||
)?;
|
||||
return Ok(());
|
||||
} else {
|
||||
@@ -246,3 +253,26 @@ pub fn call_main_service_set_by_name(
|
||||
return Err(JniError::ThrowFailed(-1));
|
||||
}
|
||||
}
|
||||
|
||||
fn init_ndk_context() -> JniResult<()> {
|
||||
let mut lock = NDK_CONTEXT_INITED.lock().unwrap();
|
||||
if *lock {
|
||||
unsafe {
|
||||
ndk_context::release_android_context();
|
||||
}
|
||||
}
|
||||
if let (Some(jvm), Some(ctx)) = (
|
||||
JVM.read().unwrap().as_ref(),
|
||||
MAIN_SERVICE_CTX.read().unwrap().as_ref(),
|
||||
) {
|
||||
unsafe {
|
||||
ndk_context::initialize_android_context(
|
||||
jvm.get_java_vm_pointer() as _,
|
||||
ctx.as_obj().as_raw() as _,
|
||||
);
|
||||
}
|
||||
*lock = true;
|
||||
return Ok(());
|
||||
}
|
||||
Err(JniError::ThrowFailed(-1))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user