diff --git a/src/ctrlm_utils.cpp b/src/ctrlm_utils.cpp index eb8c7b7e..77e4167c 100644 --- a/src/ctrlm_utils.cpp +++ b/src/ctrlm_utils.cpp @@ -29,23 +29,18 @@ #include "ctrlm_utils.h" #include #include +#include +#include #include #include -// dsMgr includes -#include "host.hpp" -#include "exception.hpp" -#include "videoOutputPort.hpp" -#include "videoOutputPortType.hpp" -#include "videoOutputPortConfig.hpp" -#include "audioOutputPort.hpp" -#include "frontPanelIndicator.hpp" -#include "manager.hpp" -#include "dsMgr.h" -#include "dsRpc.h" -#include "dsDisplay.h" +#include "thunder/plugins/ctrlm_thunder_plugin_display_settings.h" #include -// end dsMgr includes + +using std::map; +using std::tuple; +using std::get; +using std::string; #define BLOCK_SIZE (1024 * 4 * 10) /* bytes */ #define MAX_RECURSE_DEPTH 20 @@ -1574,89 +1569,68 @@ char *ctrlm_do_regex(char *re, char *str) { } bool ctrlm_dsmgr_init() { - if(device::Manager::IsInitialized) { - XLOGD_INFO("DSMgr already initialized"); - return true; - } - try { - device::Manager::Initialize(); - XLOGD_INFO("DSMgr is initialized"); - } - catch (...) { - XLOGD_WARN("Failed to initialize DSMgr"); - return false; - } return true; } bool ctrlm_dsmgr_deinit() { - try { - if(device::Manager::IsInitialized) { - device::Manager::DeInitialize(); - } - } - catch(...) { - XLOGD_WARN("Failed to deinitialize DSMgr"); - return false; - } return true; } bool ctrlm_dsmgr_mute_audio(bool mute) { - try { - dsAudioDuckingAction_t action = mute ? dsAUDIO_DUCKINGACTION_START : dsAUDIO_DUCKINGACTION_STOP; - device::Host::getInstance().getAudioOutputPort("SPEAKER0").setAudioDucking(action, dsAUDIO_DUCKINGTYPE_ABSOLUTE, mute ? 0 : 100); - XLOGD_INFO("Audio is %smuted", mute?"":"un-"); - } - catch(std::exception& error) { - XLOGD_WARN("Muting sound error : %s", error.what()); - return false; - } - return true; + auto *ds = Thunder::DisplaySettings::ctrlm_thunder_plugin_display_settings_t::getInstance(); + if(!ds) { + XLOGD_ERROR("DisplaySettings plugin not available"); + return false; + } + bool action = mute; // true = start ducking (mute), false = stop ducking (unmute) + bool type = false; // false = absolute ducking + bool ret = ds->set_audio_ducking(action, type, mute ? 0 : 100); + if(ret) { + XLOGD_INFO("Audio is %smuted", mute?"":"un-"); + } else { + XLOGD_WARN("Muting sound error"); + } + return ret; } bool ctrlm_dsmgr_duck_audio(bool enable, bool relative, double vol) { - if(vol < 0 || vol > 1) { + XLOGD_INFO("[CTRLM_DUCK_AUDIO] Function called: enable=%d, relative=%d, vol=%f", enable, relative, vol); + if(vol < 0 || vol > 1) { + XLOGD_ERROR("[CTRLM_DUCK_AUDIO] Invalid volume %f (must be 0.0-1.0)", vol); XLOGD_ERROR("Invalid volume"); return false; - } - try { - unsigned char level = (unsigned char)((vol * 100) + 0.5); - - dsAudioDuckingAction_t action = enable ? dsAUDIO_DUCKINGACTION_START : dsAUDIO_DUCKINGACTION_STOP; - dsAudioDuckingType_t type = relative ? dsAUDIO_DUCKINGTYPE_RELATIVE : dsAUDIO_DUCKINGTYPE_ABSOLUTE; + } - device::Host::getInstance().getAudioOutputPort("SPEAKER0").setAudioDucking(action, type, level); + XLOGD_INFO("[CTRLM_DUCK_AUDIO] Using thunder displaysetting path"); + unsigned char level = (unsigned char)((vol * 100) + 0.5); + bool action = enable; // true = start ducking, false = stop ducking + bool type = relative; // true = relative, false = absolute + XLOGD_INFO("[CTRLM_DUCK_AUDIO] Calculated: action=%d, type=%d, level=%u", action, type, level); - if(enable) { - XLOGD_INFO("Audio ducking enabled - type <%s> level <%u%%>", relative ? "RELATIVE" : "ABSOLUTE", level); - } else { - XLOGD_INFO("Audio ducking disabled"); - } - } - catch(std::exception& error) { - XLOGD_WARN("Ducking sound error : %s", error.what()); - return false; - } - return true; -} - -bool ctrlm_dsmgr_LED(bool on) { - try { - device::FrontPanelIndicator &led = device::FrontPanelIndicator::getInstance("Power"); - if (on) { - led.setColor(0xFFFFFF); - led.setBrightness(100); - } - led.setState(on); - } - catch(std::exception& error) { - XLOGD_WARN("LED error : %s", error.what()); - return false; - } - return true; + XLOGD_INFO("[CTRLM_DUCK_AUDIO] Getting DisplaySettings instance..."); + auto *ds = Thunder::DisplaySettings::ctrlm_thunder_plugin_display_settings_t::getInstance(); + if(!ds) { + XLOGD_ERROR("[CTRLM_DUCK_AUDIO] DisplaySettings plugin not available"); + XLOGD_ERROR("DisplaySettings plugin not available"); + return false; + } + XLOGD_INFO("[CTRLM_DUCK_AUDIO] DisplaySettings instance obtained successfully"); + XLOGD_INFO("[CTRLM_DUCK_AUDIO] Calling set_audio_ducking..."); + bool ret = ds->set_audio_ducking(action, type, level); + XLOGD_INFO("[CTRLM_DUCK_AUDIO] set_audio_ducking returned: %d", ret); + if(ret) { + if(enable) { + XLOGD_INFO("Audio ducking enabled - type <%s> level <%u%%>", relative ? "RELATIVE" : "ABSOLUTE", level); + } else { + XLOGD_INFO("Audio ducking disabled"); + } + } else { + XLOGD_WARN("Muting sound error"); + } + XLOGD_INFO("[CTRLM_DUCK_AUDIO] Returning: %d", ret); + return ret; } - + bool ctrlm_is_voice_assistant(ctrlm_rcu_controller_type_t controller_type) { switch(controller_type) { case CTRLM_RCU_CONTROLLER_TYPE_XR19: diff --git a/src/ctrlm_utils.h b/src/ctrlm_utils.h index baed40e7..23f97184 100644 --- a/src/ctrlm_utils.h +++ b/src/ctrlm_utils.h @@ -231,7 +231,6 @@ char *ctrlm_do_regex(char *re, char *str); bool ctrlm_dsmgr_init(); bool ctrlm_dsmgr_mute_audio(bool mute); bool ctrlm_dsmgr_duck_audio(bool enable, bool relative, double vol); -bool ctrlm_dsmgr_LED(bool on); bool ctrlm_dsmgr_deinit(); bool ctrlm_is_voice_assistant(ctrlm_rcu_controller_type_t controller_type); diff --git a/src/factory/CMakeLists.txt b/src/factory/CMakeLists.txt index 530cbf5b..535481f3 100644 --- a/src/factory/CMakeLists.txt +++ b/src/factory/CMakeLists.txt @@ -47,7 +47,7 @@ target_sources(ctrlm-fta PRIVATE iarm/ctrlmf_iarm_control_manager.cpp ) -target_link_libraries(ctrlm-fta c rdkversion dbus-1 glib-2.0 IARMBus xr-voice-sdk pthread nopoll secure_wrapper ds) +target_link_libraries(ctrlm-fta c rdkversion dbus-1 glib-2.0 IARMBus xr-voice-sdk pthread nopoll secure_wrapper) target_link_libraries(controlFactory c ctrlm-fta secure_wrapper) if(AUTH_ENABLED) @@ -61,19 +61,20 @@ if(THUNDER) thunder/ctrlmf_thunder_controller.cpp thunder/ctrlmf_thunder_plugin.cpp thunder/ctrlmf_thunder_plugin_system_audio_player.cpp + thunder/ctrlmf_thunder_plugin_display_settings.cpp ) - target_link_libraries(controlFactory WPEFrameworkCore WPEFrameworkPlugins) + target_link_libraries(ctrlm-fta WPEFrameworkCore WPEFrameworkPlugins) if(WPE_FRAMEWORK_COM_SOCKET) - target_link_libraries(controlFactory WPEFrameworkCOM WPEFrameworkWebSocket) + target_link_libraries(ctrlm-fta WPEFrameworkCOM WPEFrameworkWebSocket) endif() if(WPE_FRAMEWORK_PROTO_TRACING) - target_link_libraries(controlFactory WPEFrameworkProtocols WPEFrameworkTracing) + target_link_libraries(ctrlm-fta WPEFrameworkProtocols WPEFrameworkTracing) endif() if(THUNDER_SECURITY) add_compile_definitions(PRIVATE THUNDER_SECURITY) - target_link_libraries(controlFactory WPEFrameworkSecurityUtil secure_wrapper) + target_link_libraries(ctrlm-fta WPEFrameworkSecurityUtil secure_wrapper) endif() endif() diff --git a/src/factory/ctrlmf_audio_control.cpp b/src/factory/ctrlmf_audio_control.cpp index f8f4d7e2..0a450d3a 100644 --- a/src/factory/ctrlmf_audio_control.cpp +++ b/src/factory/ctrlmf_audio_control.cpp @@ -5,94 +5,86 @@ #include #include #include -// dsMgr includes -#include "host.hpp" -#include "exception.hpp" -#include "videoOutputPort.hpp" -#include "videoOutputPortType.hpp" -#include "videoOutputPortConfig.hpp" -#include "audioOutputPort.hpp" -#include "frontPanelIndicator.hpp" -#include "manager.hpp" -#include "dsMgr.h" -#include "dsRpc.h" -#include "dsDisplay.h" -// end dsMgr includes + +#include "thunder/ctrlmf_thunder_plugin_display_settings.h" bool ctrlmf_audio_control_init(void) { - if(device::Manager::IsInitialized) { - XLOGD_INFO("DSMgr already initialized"); - return(true); - } - try { - device::Manager::Initialize(); - XLOGD_INFO("DSMgr is initialized"); - } - catch (...) { - XLOGD_WARN("Failed to initialize DSMgr"); - return(false); - } + // DSMgr initialization is no longer needed; Thunder plugins self-initialise. return(true); } bool ctrlmf_audio_control_term(void) { - try { - if(device::Manager::IsInitialized) { - device::Manager::DeInitialize(); - } - } - catch(...) { - XLOGD_WARN("Failed to deinitialize DSMgr"); - return(false); - } + // DSMgr deinitialization is no longer needed; Thunder plugins self-manage. return(true); } bool ctrlmf_audio_control_mute(bool mute) { + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] Function called: mute=%d", mute); if(!ctrlmf_is_initialized()) { XLOGD_ERROR("not initialized"); return(false); } + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] Using Displaysettings path"); + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] Getting DisplaySettings instance..."); - try { - dsAudioDuckingAction_t action = mute ? dsAUDIO_DUCKINGACTION_START : dsAUDIO_DUCKINGACTION_STOP; - device::Host::getInstance().getAudioOutputPort("SPEAKER0").setAudioDucking(action, dsAUDIO_DUCKINGTYPE_ABSOLUTE, mute ? 0 : 100); - XLOGD_INFO("Audio is %smuted", mute?"":"un-"); + auto *ds = Thunder::DisplaySettings::ctrlmf_thunder_plugin_display_settings_t::getInstance(); + if(!ds) { + XLOGD_ERROR("DisplaySettings plugin not available"); + return(false); } - catch(std::exception& error) { - XLOGD_WARN("Muting sound error : %s", error.what()); - return(false); + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] DisplaySettings instance obtained"); + bool action = mute; // true = start ducking (mute), false = stop ducking (unmute) + bool type = false; // false = absolute ducking + unsigned char level = mute ? 0 : 100; + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] Calculated: action=%d, type=%d, level=%u", action, type, level); + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] Calling set_audio_ducking..."); + bool ret = ds->set_audio_ducking(action, type, level); + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] set_audio_ducking returned: %d", ret); + + if(ret) { + XLOGD_INFO("Audio is %smuted", mute ? "" : "un-"); + } else { + XLOGD_WARN("Muting sound error"); } - return(true); + XLOGD_INFO("[CTRLMF_AUDIO_MUTE] Returning: %d", ret); + return(ret); } bool ctrlmf_audio_control_attenuate(bool enable, bool relative, double vol) { + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] Function called: enable=%d, relative=%d, vol=%f", enable, relative, vol); if(!ctrlmf_is_initialized()) { XLOGD_ERROR("not initialized"); return(false); } - if(vol < 0 || vol > 1) { - XLOGD_ERROR("Invalid volume"); - return(false); + XLOGD_ERROR("Invalid volume"); + return(false); } - try { - unsigned char level = (unsigned char)((vol * 100) + 0.5); - - dsAudioDuckingAction_t action = enable ? dsAUDIO_DUCKINGACTION_START : dsAUDIO_DUCKINGACTION_STOP; - dsAudioDuckingType_t type = relative ? dsAUDIO_DUCKINGTYPE_RELATIVE : dsAUDIO_DUCKINGTYPE_ABSOLUTE; - - device::Host::getInstance().getAudioOutputPort("SPEAKER0").setAudioDucking(action, type, level); + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] Using Displaysettings path"); + unsigned char level = (unsigned char)((vol * 100) + 0.5); + bool action = enable; // true = start ducking, false = stop ducking + bool type = relative; // true = relative, false = absolute + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] Calculated: action=%d, type=%d, level=%u", action, type, level); + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] Getting DisplaySettings instance..."); + auto *ds = Thunder::DisplaySettings::ctrlmf_thunder_plugin_display_settings_t::getInstance(); + if(!ds) { + XLOGD_ERROR("DisplaySettings plugin not available"); + return(false); + } + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] DisplaySettings instance obtained successfully"); + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] Calling set_audio_ducking..."); + bool ret = ds->set_audio_ducking(action, type, level); + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] set_audio_ducking returned: %d", ret); + if(ret) { if(enable) { XLOGD_INFO("Audio ducking enabled - type <%s> level <%u%%>", relative ? "RELATIVE" : "ABSOLUTE", level); } else { XLOGD_INFO("Audio ducking disabled"); } + } else { + XLOGD_WARN("Ducking sound error"); } - catch(std::exception& error) { - XLOGD_WARN("Ducking sound error : %s", error.what()); - return(false); - } - return(true); + XLOGD_INFO("[CTRLMF_AUDIO_ATTENUATE] Returning: %d", ret); + return(ret); } diff --git a/src/factory/thunder/ctrlmf_thunder_plugin.cpp b/src/factory/thunder/ctrlmf_thunder_plugin.cpp index 4f95cb07..756a3cf5 100644 --- a/src/factory/thunder/ctrlmf_thunder_plugin.cpp +++ b/src/factory/thunder/ctrlmf_thunder_plugin.cpp @@ -186,18 +186,23 @@ void ctrlm_thunder_plugin_t::on_thunder_ready(bool boot) { } } -bool ctrlm_thunder_plugin_t::call_plugin(std::string method, void *params, void *response) { +bool ctrlm_thunder_plugin_t::call_plugin(std::string method, void *params, void *response, unsigned int retries) { bool ret = false; + unsigned int attempts = 0; auto clientObject = (JSONRPC::LinkType*)this->plugin_client; JsonObject *jsonParams = (JsonObject *)params; JsonObject *jsonResponse = (JsonObject *)response; if(clientObject) { if(!method.empty() && jsonParams && jsonResponse) { - uint32_t thunderRet = clientObject->Invoke(CALL_TIMEOUT, _T(method), *jsonParams, *jsonResponse); - if(thunderRet == Core::ERROR_NONE) { - ret = true; - } else { - XLOGD_ERROR("%s: Thunder call failed <%s> <%u>\n", __FUNCTION__, method.c_str(), thunderRet); + uint32_t thunderRet = Core::ERROR_TIMEDOUT; + while(thunderRet == Core::ERROR_TIMEDOUT && attempts <= retries) { + thunderRet = clientObject->Invoke(CALL_TIMEOUT, _T(method), *jsonParams, *jsonResponse); + if(thunderRet == Core::ERROR_NONE) { + ret = true; + } else { + XLOGD_ERROR("%s: Thunder call failed <%s> <%u>\n", __FUNCTION__, method.c_str(), thunderRet); + attempts++; + } } } else { XLOGD_ERROR("%s: Invalid parameters\n", __FUNCTION__); diff --git a/src/factory/thunder/ctrlmf_thunder_plugin.h b/src/factory/thunder/ctrlmf_thunder_plugin.h index 4c5ea2e5..6403236e 100644 --- a/src/factory/thunder/ctrlmf_thunder_plugin.h +++ b/src/factory/thunder/ctrlmf_thunder_plugin.h @@ -101,10 +101,11 @@ class ctrlm_thunder_plugin_t { * This functions is used to call a Thunder Plugin method. * @param method The method in which the user wants to call. * @param params The WPEFramework JsonObject containing the parameters for the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash) - * @param params The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash) + * @param response The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash) + * @param retries The number of retries if the call times out (defaults to 0). * @return True if the call succeeded, otherwise False. */ - bool call_plugin(std::string method, void *params, void *response); + bool call_plugin(std::string method, void *params, void *response, unsigned int retries = 0); /** * This functions is used to call a Thunder Controller method. @@ -146,4 +147,4 @@ class ctrlm_thunder_plugin_t { }; }; -#endif \ No newline at end of file +#endif diff --git a/src/factory/thunder/ctrlmf_thunder_plugin_display_settings.cpp b/src/factory/thunder/ctrlmf_thunder_plugin_display_settings.cpp new file mode 100644 index 00000000..3635bf05 --- /dev/null +++ b/src/factory/thunder/ctrlmf_thunder_plugin_display_settings.cpp @@ -0,0 +1,72 @@ +/* + * If not stated otherwise in this file or this component's license file the + * following copyright and licenses apply: + * + * Copyright 2015 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +#include "ctrlmf_thunder_plugin_display_settings.h" +#include +#include +#include +#include +#include + +using namespace Thunder; +using namespace DisplaySettings; +using namespace WPEFramework; + +ctrlmf_thunder_plugin_display_settings_t::ctrlmf_thunder_plugin_display_settings_t() : ctrlm_thunder_plugin_t("DisplaySettings", "org.rdk.DisplaySettings", 1) { +} + +ctrlmf_thunder_plugin_display_settings_t::~ctrlmf_thunder_plugin_display_settings_t() { +} + +ctrlmf_thunder_plugin_display_settings_t *ctrlmf_thunder_plugin_display_settings_t::getInstance() { + static ctrlmf_thunder_plugin_display_settings_t instance; + return &instance; +} + +bool ctrlmf_thunder_plugin_display_settings_t::set_audio_ducking( + bool action, bool type, unsigned char level) { + XLOGD_INFO("[CTRLMF_THUNDER_DS_DUCKING] Function called: action=%d (%s), type=%d (%s), level=%u", action, action ? "start" : "stop", type, type ? "relative" : "absolute", level); + JsonObject params, response; + params["audioPort"] = "SPEAKER0"; + params["mode"] = "raw"; + params["action"] = action ? "start" : "stop"; + params["duckingType"] = type ? "relative" : "absolute"; + params["level"] = (int)level; + + std::string params_str; + params.ToString(params_str); + XLOGD_INFO("[CTRLMF_THUNDER_DS_DUCKING] JSON params: %s", params_str.c_str()); + + XLOGD_INFO("[CTRLMF_THUNDER_DS_DUCKING] Calling DisplaySettings plugin 'setAudioDucking'..."); + if(!this->call_plugin("setAudioDucking", (void *)¶ms, (void *)&response)) { + XLOGD_ERROR("DisplaySettings setAudioDucking call failed"); + return false; + } + XLOGD_INFO("[CTRLMF_THUNDER_DS_DUCKING] call_plugin returned true, checking response..."); + + std::string response_str; + response.ToString(response_str); + XLOGD_INFO("[CTRLMF_THUNDER_DS_DUCKING] Response JSON: %s", response_str.c_str()); + + if(!response["success"].Boolean()) { + XLOGD_ERROR("DisplaySettings setAudioDucking returned failure: %s", response_str.c_str()); + return false; + } + XLOGD_INFO("[CTRLMF_THUNDER_DS_DUCKING] SUCCESS: Returning true"); + return true; +} diff --git a/src/factory/thunder/ctrlmf_thunder_plugin_display_settings.h b/src/factory/thunder/ctrlmf_thunder_plugin_display_settings.h new file mode 100644 index 00000000..c0cb4ee4 --- /dev/null +++ b/src/factory/thunder/ctrlmf_thunder_plugin_display_settings.h @@ -0,0 +1,59 @@ +/* + * If not stated otherwise in this file or this component's license file the + * following copyright and licenses apply: + * + * Copyright 2014 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +#ifndef __CTRLMF_THUNDER_PLUGIN_DISPLAY_SETTINGS_H__ +#define __CTRLMF_THUNDER_PLUGIN_DISPLAY_SETTINGS_H__ +#include "ctrlmf_thunder_plugin.h" + +namespace Thunder { +namespace DisplaySettings { + +/** + * This class is used within Control Factory to interact with the DisplaySettings Thunder Plugin. + */ +class ctrlmf_thunder_plugin_display_settings_t : public Thunder::Plugin::ctrlm_thunder_plugin_t { +public: + /** + * This function is used to get the Thunder Display Settings instance, as it is a Singleton. + * @return The instance of the Thunder Display Settings, or NULL on error. + */ + static ctrlmf_thunder_plugin_display_settings_t *getInstance(); + + /** + * Display Settings Thunder Plugin Destructor + */ + virtual ~ctrlmf_thunder_plugin_display_settings_t(); + + /** + * Calls DisplaySettings.setAudioDucking on the SPEAKER0 audio port. + * @param action true to start ducking, false to stop + * @param type true for relative ducking, false for absolute + * @param level Volume level 0-100 + * @return true on success + */ + bool set_audio_ducking(bool action, bool type, unsigned char level); + +protected: + /** + * DisplaySettings Thunder Plugin Default Constructor + */ + ctrlmf_thunder_plugin_display_settings_t(); +}; +}; +}; +#endif diff --git a/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.cpp b/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.cpp index b11001e6..80551a46 100644 --- a/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.cpp +++ b/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.cpp @@ -186,3 +186,37 @@ void ctrlm_thunder_plugin_display_settings_t::on_initial_activation() { Thunder::Plugin::ctrlm_thunder_plugin_t::on_initial_activation(); } + +bool ctrlm_thunder_plugin_display_settings_t::set_audio_ducking( + bool action, bool type, unsigned char level) { + XLOGD_INFO("[THUNDER_DS_DUCKING] Function called: action=%d (%s), type=%d (%s), level=%u", action, action ? "start" : "stop", type, type ? "relative" : "absolute", level); + JsonObject params, response; + params["audioPort"] = "SPEAKER0"; + params["mode"] = "raw"; + params["action"] = action ? "start" : "stop"; + params["duckingType"] = type ? "relative" : "absolute"; + params["level"] = (int)level; + + std::string params_str; + params.ToString(params_str); + XLOGD_INFO("[THUNDER_DS_DUCKING] JSON params: %s", params_str.c_str()); + + XLOGD_INFO("[THUNDER_DS_DUCKING] Calling DisplaySettings plugin 'setAudioDucking'..."); + if(!this->call_plugin("setAudioDucking", (void *)¶ms, (void *)&response)) { + XLOGD_ERROR("DisplaySettings setAudioDucking call failed"); + return false; + } + XLOGD_INFO("[THUNDER_DS_DUCKING] call_plugin returned true, checking response..."); + + std::string response_str; + response.ToString(response_str); + XLOGD_INFO("[THUNDER_DS_DUCKING] Response JSON: %s", response_str.c_str()); + + if(!response["success"].Boolean()) { + XLOGD_ERROR("[THUNDER_DS_DUCKING] success=false in response"); + XLOGD_ERROR("DisplaySettings setAudioDucking returned failure: %s", response_str.c_str()); + return false; + } + XLOGD_INFO("[THUNDER_DS_DUCKING] SUCCESS: Returning true"); + return true; +} diff --git a/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.h b/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.h index b7f068fc..86f0bfb7 100644 --- a/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.h +++ b/src/thunder/plugins/ctrlm_thunder_plugin_display_settings.h @@ -46,6 +46,15 @@ class ctrlm_thunder_plugin_display_settings_t : public Thunder::Plugin::ctrlm_th */ void get_edid(std::vector &edid); + /** + * Calls DisplaySettings.setAudioDucking on the SPEAKER0 audio port. + * @param action true to start ducking, false to stop + * @param type true for relative ducking, false for absolute + * @param level Volume level 0-100 + * @return true on success + */ + bool set_audio_ducking(bool action, bool type, unsigned char level); + public: /** * This function is technically used internally but from static function. This is used to handle hotplug events. @@ -89,4 +98,4 @@ class ctrlm_thunder_plugin_display_settings_t : public Thunder::Plugin::ctrlm_th }; }; }; -#endif \ No newline at end of file +#endif