From 09937049a6edb10d6a54ac10de998712cfa9a693 Mon Sep 17 00:00:00 2001 From: csf Date: Thu, 30 Jun 2022 16:19:36 +0800 Subject: [PATCH] enable hwcodec --- libs/scrap/src/common/codec.rs | 25 +++++++++++++++++++--- src/ui.rs | 10 ++++++++- src/ui/index.tis | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/libs/scrap/src/common/codec.rs b/libs/scrap/src/common/codec.rs index 6e9d1a8b9..bfcae031e 100644 --- a/libs/scrap/src/common/codec.rs +++ b/libs/scrap/src/common/codec.rs @@ -11,8 +11,9 @@ use crate::vpxcodec::*; use hbb_common::{ anyhow::anyhow, + config::Config2, log, - message_proto::{video_frame, Message, VP9s, VideoCodecState, test_delay}, + message_proto::{test_delay, video_frame, Message, VP9s, VideoCodecState}, ResultType, }; #[cfg(feature = "hwcodec")] @@ -187,7 +188,11 @@ impl Encoder { #[inline] pub fn current_hw_encoder_name() -> Option { #[cfg(feature = "hwcodec")] - return HwEncoder::current_name().lock().unwrap().clone(); + if check_hwcodec_config() { + return HwEncoder::current_name().lock().unwrap().clone(); + } else { + return None; + } #[cfg(not(feature = "hwcodec"))] return None; } @@ -208,7 +213,14 @@ impl Decoder { // video_codec_state is mainted by creation and destruction of Decoder. // It has been ensured to use after Decoder's creation. #[cfg(feature = "hwcodec")] - return MY_DECODER_STATE.lock().unwrap().clone(); + if check_hwcodec_config() { + return MY_DECODER_STATE.lock().unwrap().clone(); + } else { + return VideoCodecState { + ScoreVpx: SCORE_VPX, + ..Default::default() + }; + } #[cfg(not(feature = "hwcodec"))] VideoCodecState { ScoreVpx: SCORE_VPX, @@ -330,3 +342,10 @@ impl Decoder { return Ok(ret); } } + +fn check_hwcodec_config() -> bool { + if let Some(v) = Config2::get().options.get("enable-hwcodec") { + return v != "N"; + } + return true; // default is true +} diff --git a/src/ui.rs b/src/ui.rs index b93c11d44..4671ff19b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -702,7 +702,7 @@ impl UI { let p = "explorer"; #[cfg(target_os = "macos")] let p = "open"; - #[cfg(target_os = "linux")] + #[cfg(target_os = "linux")] let p = if std::path::Path::new("/usr/bin/firefox").exists() { "firefox" } else { @@ -753,6 +753,13 @@ impl UI { self.get_option_("custom-rendezvous-server"), ) } + + fn has_hwcodec(&self) -> bool { + #[cfg(not(feature = "hwcodec"))] + return false; + #[cfg(feature = "hwcodec")] + return true; + } } impl sciter::EventHandler for UI { @@ -829,6 +836,7 @@ impl sciter::EventHandler for UI { fn discover(); fn get_lan_peers(); fn get_uuid(); + fn has_hwcodec(); } } diff --git a/src/ui/index.tis b/src/ui/index.tis index 70cc8f870..4a998220d 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -165,6 +165,44 @@ class AudioInputs: Reactor.Component { } } +var enhancementsMenu; +class Enhancements: Reactor.Component { + function this() { + enhancementsMenu = this; + } + + function render() { + var has_hwcodec = handler.has_hwcodec(); + var me = this; + self.timer(1ms, function() { me.toggleMenuState() }); + return
  • {translate('Enhancements')} + + {has_hwcodec ?
  • {svg_checkmark}{translate("Hardware Codec")}
  • : ""} +
  • {svg_checkmark}{translate("ABR")}
  • +
    +
  • ; + } + + function toggleMenuState() { + for (var el in $$(menu#enhancements-menu>li)) { + if (el.id && el.id.indexOf("enable-") == 0) { + var enabled = handler.get_option(el.id) != "N"; + el.attributes.toggleClass("selected", enabled); + } + } + + } + + event click $(menu#enhancements-menu>li) (_, me) { + var v = me.id; + if (v.indexOf("enable-") == 0) { + handler.set_option(v, handler.get_option(v) != 'N' ? 'N' : ''); + } + this.toggleMenuState(); + } +} + + function getUserName() { try { return JSON.parse(handler.get_local_option("user_info")).name; @@ -204,6 +242,7 @@ class MyIdMenu: Reactor.Component {
  • {svg_checkmark}{translate('Enable File Transfer')}
  • {svg_checkmark}{translate('Enable TCP Tunneling')}
  • +
  • {svg_checkmark}{translate('Enable remote configuration modification')}
  • {translate('ID/Relay Server')}