android video service wakelock

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-11-23 19:47:16 +08:00
parent c6ace470e3
commit bd81e4d0fb
7 changed files with 87 additions and 9 deletions

View File

@@ -80,6 +80,39 @@ pub fn get_active_username() -> String {
#[cfg(target_os = "android")]
pub const PA_SAMPLE_RATE: u32 = 48000;
#[cfg(target_os = "android")]
#[derive(Default)]
pub struct WakeLock {
lock: Option<android_wakelock::WakeLock>,
}
#[cfg(target_os = "android")]
impl WakeLock {
pub fn new(tag: &str) -> Self {
let tag = format!("{}:{tag}", crate::get_app_name());
match android_wakelock::partial(tag) {
Ok(lock) => Self { lock: Some(lock) },
Err(e) => {
hbb_common::log::error!("Failed to get wakelock: {e:?}");
Self::default()
}
}
}
pub fn acquire(&self) -> Option<android_wakelock::Guard> {
match self.lock.as_ref() {
Some(lock) => match lock.acquire() {
Ok(guard) => Some(guard),
Err(e) => {
hbb_common::log::error!("Failed to acquire wakelock guard: {e:?}");
None
}
},
None => None,
}
}
}
pub(crate) struct InstallingService; // please use new
impl InstallingService {

View File

@@ -363,8 +363,12 @@ fn get_capturer(current: usize, portable_service_running: bool) -> ResultType<Ca
}
fn run(vs: VideoService) -> ResultType<()> {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
#[cfg(not(target_os = "android"))]
let _wake_lock = get_wake_lock();
#[cfg(target_os = "android")]
let wake_lock = crate::platform::WakeLock::new("video service");
#[cfg(target_os = "android")]
let _lock_guard = wake_lock.acquire();
// Wayland only support one video capturer for now. It is ok to call ensure_inited() here.
//
@@ -619,7 +623,6 @@ fn get_recorder(
height: usize,
codec_name: &CodecName,
) -> Arc<Mutex<Option<Recorder>>> {
#[cfg(not(target_os = "ios"))]
let recorder = if !Config::get_option("allow-auto-record-incoming").is_empty() {
use crate::hbbs_http::record_upload;
@@ -644,8 +647,6 @@ fn get_recorder(
} else {
Default::default()
};
#[cfg(target_os = "ios")]
let recorder: Arc<Mutex<Option<Recorder>>> = Default::default();
recorder
}
@@ -690,7 +691,6 @@ fn handle_one_frame(
vf.display = display as _;
let mut msg = Message::new();
msg.set_video_frame(vf);
#[cfg(not(target_os = "ios"))]
recorder
.lock()
.unwrap()
@@ -735,7 +735,7 @@ fn start_uac_elevation_check() {
});
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
#[cfg(not(target_os = "android"))]
fn get_wake_lock() -> crate::platform::WakeLock {
let (display, idle, sleep) = if cfg!(windows) {
(true, false, false)
@@ -784,7 +784,7 @@ pub fn make_display_changed_msg(
width: display.width,
height: display.height,
cursor_embedded: display_service::capture_cursor_embedded(),
#[cfg(not(any(target_os = "android", target_os = "ios")))]
#[cfg(not(target_os = "android"))]
resolutions: Some(SupportedResolutions {
resolutions: if display.name.is_empty() {
vec![]