mirror of
https://gitee.com/openharmony/ai_intelligent_voice_framework
synced 2024-10-06 22:13:34 +00:00
low power bugfix
Signed-off-by: lvqiang214 <lvqiang1@huawei.com>
This commit is contained in:
parent
4fd864d849
commit
8cf6872741
@ -8,10 +8,14 @@
|
||||
"auto-restart": true,
|
||||
"distributed": false,
|
||||
"dump_level": 1,
|
||||
"start-on-demand":{
|
||||
"commonevent":[
|
||||
"start-on-demand": {
|
||||
"commonevent": [
|
||||
{
|
||||
"name":"usual.event.BOOT_COMPLETED"
|
||||
"name": "usual.event.BOOT_COMPLETED"
|
||||
},
|
||||
{
|
||||
"name": "usual.event.POWER_SAVE_MODE_CHANGED",
|
||||
"value": "600"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -120,8 +120,11 @@ int32_t IntellVoiceService::ReleaseIntellVoiceEngine(IntellVoiceEngineType type)
|
||||
|
||||
void IntellVoiceService::OnStart(const SystemAbilityOnDemandReason &startReason)
|
||||
{
|
||||
INTELL_VOICE_LOG_INFO("enter, reason id:%{public}d", startReason.GetId());
|
||||
reasonId_ = static_cast<int32_t>(startReason.GetId());
|
||||
reasonName_ = startReason.GetName();
|
||||
reasonValue_ = startReason.GetValue();
|
||||
INTELL_VOICE_LOG_INFO("enter, reason id:%{public}d, reasonName:%{public}s, reasonValue:%{public}s",
|
||||
reasonId_, reasonName_.c_str(), reasonValue_.c_str());
|
||||
LoadIntellVoiceHost();
|
||||
|
||||
bool ret = Publish(this);
|
||||
@ -148,7 +151,6 @@ void IntellVoiceService::OnStop(void)
|
||||
const auto &manager = IntellVoiceServiceManager::GetInstance();
|
||||
if (manager != nullptr) {
|
||||
manager->HandleServiceStop();
|
||||
manager->StopThread();
|
||||
manager->ReleaseSwitchProvider();
|
||||
}
|
||||
|
||||
@ -315,10 +317,16 @@ void IntellVoiceService::OnDistributedKvDataServiceChange(bool isAdded)
|
||||
manager->HandleSilenceUpdate();
|
||||
|
||||
if (reasonId_ == static_cast<int32_t>(OHOS::OnDemandReasonId::COMMON_EVENT)) {
|
||||
INTELL_VOICE_LOG_INFO("power on start");
|
||||
INTELL_VOICE_LOG_INFO("common event start");
|
||||
manager->HandleSwitchOn(true, VOICE_WAKEUP_MODEL_UUID, false);
|
||||
manager->HandleSwitchOn(true, PROXIMAL_WAKEUP_MODEL_UUID, false);
|
||||
manager->HandleUnloadIntellVoiceService(true);
|
||||
if (reasonName_ == std::string("usual.event.POWER_SAVE_MODE_CHANGED")) {
|
||||
INTELL_VOICE_LOG_INFO("power save mode change");
|
||||
manager->HandlePowerSaveModeChange();
|
||||
} else {
|
||||
INTELL_VOICE_LOG_INFO("power on");
|
||||
manager->HandleUnloadIntellVoiceService(true);
|
||||
}
|
||||
} else if (reasonId_ == static_cast<int32_t>(OHOS::OnDemandReasonId::INTERFACE_CALL)) {
|
||||
INTELL_VOICE_LOG_INFO("interface call start");
|
||||
manager->HandleSwitchOn(true, VOICE_WAKEUP_MODEL_UUID, false);
|
||||
|
@ -81,6 +81,8 @@ private:
|
||||
|
||||
private:
|
||||
int32_t reasonId_ = -1;
|
||||
std::string reasonName_;
|
||||
std::string reasonValue_;
|
||||
std::shared_ptr<SystemEventObserver> systemEventObserver_ = nullptr;
|
||||
std::map<int32_t, std::function<void(bool)>> systemAbilityChangeMap_;
|
||||
};
|
||||
|
@ -48,6 +48,7 @@ namespace OHOS {
|
||||
namespace IntellVoiceEngine {
|
||||
static constexpr int32_t MAX_ATTEMPT_CNT = 10;
|
||||
static constexpr uint32_t MAX_TASK_NUM = 200;
|
||||
static constexpr uint32_t WAIT_SWICTH_ON_TIME = 2000; // 2000ms
|
||||
static const std::string SERVICE_MANAGER_THREAD_NAME = "ServMgrThread";
|
||||
static const std::string WHISPER_MODEL_PATH =
|
||||
"/sys_prod/variant/region_comm/china/etc/intellvoice/wakeup/dsp/whisper_wakeup_dsp_config";
|
||||
@ -436,6 +437,7 @@ void IntellVoiceServiceManager::OnSwitchChange(const std::string &switchKey)
|
||||
{
|
||||
if (switchKey == WAKEUP_KEY) {
|
||||
if (QuerySwitchStatus(switchKey)) {
|
||||
NoiftySwitchOnToPowerChange();
|
||||
HandleSwitchOn(false, VOICE_WAKEUP_MODEL_UUID, false);
|
||||
} else {
|
||||
HandleSwitchOff(false, VOICE_WAKEUP_MODEL_UUID);
|
||||
@ -444,6 +446,7 @@ void IntellVoiceServiceManager::OnSwitchChange(const std::string &switchKey)
|
||||
}
|
||||
} else if (switchKey == WHISPER_KEY) {
|
||||
if (QuerySwitchStatus(switchKey)) {
|
||||
NoiftySwitchOnToPowerChange();
|
||||
HandleSwitchOn(false, PROXIMAL_WAKEUP_MODEL_UUID, false);
|
||||
} else {
|
||||
HandleSwitchOff(false, PROXIMAL_WAKEUP_MODEL_UUID);
|
||||
@ -949,6 +952,45 @@ void IntellVoiceServiceManager::HandleHeadsetHostDie()
|
||||
HeadsetWakeupWrapper::GetInstance().NotifyHeadsetHdfDeath();
|
||||
}
|
||||
|
||||
void IntellVoiceServiceManager::NoiftySwitchOnToPowerChange()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(powerModeChangeMutex_);
|
||||
if (!notifyPowerModeChange_) {
|
||||
INTELL_VOICE_LOG_INFO("no need to notify");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
powerModeChangeCv_.notify_all();
|
||||
}
|
||||
|
||||
void IntellVoiceServiceManager::HandlePowerSaveModeChange()
|
||||
{
|
||||
if ((QuerySwitchStatus(WAKEUP_KEY)) || (QuerySwitchStatus(WHISPER_KEY))) {
|
||||
INTELL_VOICE_LOG_INFO("switch is on, no need to process");
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread([&]() {
|
||||
std::unique_lock<std::mutex> lock(powerModeChangeMutex_);
|
||||
if ((QuerySwitchStatus(WAKEUP_KEY)) || (QuerySwitchStatus(WHISPER_KEY))) {
|
||||
INTELL_VOICE_LOG_INFO("switch is on, no need to process");
|
||||
return;
|
||||
}
|
||||
notifyPowerModeChange_ = true;
|
||||
if (powerModeChangeCv_.wait_for(lock, std::chrono::milliseconds(WAIT_SWICTH_ON_TIME),
|
||||
[this] { return ((this->QuerySwitchStatus(WAKEUP_KEY)) || (this->QuerySwitchStatus(WHISPER_KEY))); })) {
|
||||
INTELL_VOICE_LOG_INFO("switch is on, do nothing");
|
||||
notifyPowerModeChange_ = false;
|
||||
return;
|
||||
}
|
||||
INTELL_VOICE_LOG_WARN("wait time out, switch is off, need to unload service");
|
||||
notifyPowerModeChange_ = false;
|
||||
HandleUnloadIntellVoiceService(true);
|
||||
}).detach();
|
||||
}
|
||||
|
||||
void IntellVoiceServiceManager::OnTriggerConnectServiceStart()
|
||||
{
|
||||
HandleSwitchOn(true, VOICE_WAKEUP_MODEL_UUID, false);
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
bool HandleOnIdle();
|
||||
void HandleServiceStop();
|
||||
void HandleHeadsetHostDie();
|
||||
void HandlePowerSaveModeChange();
|
||||
|
||||
void ProcBreathModel();
|
||||
void CreateSwitchProvider();
|
||||
@ -149,10 +150,14 @@ private:
|
||||
int32_t SwitchOffProc(int32_t uuid);
|
||||
bool IsNeedToUnloadService();
|
||||
int32_t UnloadIntellVoiceService();
|
||||
void NoiftySwitchOnToPowerChange();
|
||||
|
||||
private:
|
||||
static std::unique_ptr<IntellVoiceServiceManager> g_intellVoiceServiceMgr;
|
||||
static std::atomic<bool> g_enrollResult[ENGINE_TYPE_BUT];
|
||||
bool notifyPowerModeChange_ = false;
|
||||
std::mutex powerModeChangeMutex_;
|
||||
std::condition_variable powerModeChangeCv_;
|
||||
std::mutex deathMutex_;
|
||||
std::mutex detectorMutex_;
|
||||
std::mutex switchMutex_;
|
||||
|
Loading…
Reference in New Issue
Block a user