Android Soundtrigger喚醒相關時序學習梳理

本文所寫內容是在高通芯片平臺相關代碼基礎上學習整理匯總,如有描述不當之處,歡迎指正!

1、SoundTrigger注冊喚醒監聽事件回調流程(SoundTrigger HAL層到ADSP層,不包括FWK層)

//(1)SoundTriggerSession 回調
vendor/qcom/opensource/audio-hal/st-hal/SoundTriggerSession.cpp
void SoundTriggerSession::GetRecognitionCallback(recognition_callback_t *callback)*callback = rec_callback_;//(2)StartRecognition()接口,關聯到 callback
int SoundTriggerSession::StartRecognition(const struct sound_trigger_recognition_config *config,recognition_callback_t callback,void *cookie,uint32_t version)rec_callback_ = callback;//(3)在pal_callback()中調用callback()將存放在sound_trigger_recognition_event 中的數據傳遞fwkint SoundTriggerSession::pal_callback(pal_stream_handle_t *stream_handle,uint32_t event_id,uint32_t *event_data,uint32_t event_size,uint64_t cookie)struct sound_trigger_recognition_event *st_event = nullptr;
recognition_callback_t callback;
session->GetRecognitionCallback(&callback);callback(st_event, session->GetCookie());//(4)在SoundTriggerDevice()中調用SoundTriggerSession::StartRecognition()
vendor/qcom/opensource/audio-hal/st-hal/SoundTriggerDevice.cpp
static int stdev_start_recognition(const struct sound_trigger_hw_device *dev,sound_model_handle_t sound_model_handle,const struct sound_trigger_recognition_config *config,recognition_callback_t callback,void *cookie)ATRACE_BEGIN("sthal: stdev_start_recognition");
status = st_session->StartRecognition(config, callback, cookie, hw_properties_extended.header.version);//(5)在SoundTriggerDevice::Init()中進行接口初始化
int SoundTriggerDevice::Init(hw_device_t **device, const hw_module_t *module)STHAL_DBG(LOG_TAG, "Register LSM HIDL service");device_->start_recognition = stdev_start_recognition;device_->stop_recognition = stdev_stop_recognition;//(6)SoundTriggerHw開啟監聽,調用SoundTriggerDevice::start_recognition()
hardware/interfaces/soundtrigger/2.3/default/SoundTriggerHw.cpp
Return<int32_t> SoundTriggerHw::startRecognition(int32_t modelHandle, const V2_0::ISoundTriggerHw::RecognitionConfig& config,const sp<V2_0::ISoundTriggerHwCallback>& /* callback */, int32_t /* cookie */)ret = mHwDevice->start_recognition(mHwDevice, client->getHalHandle(), halConfig,recognitionCallback_, client.get());//(7)SoundTriggerDetector 調用startRecognition()注冊回調給到HAL層
frameworks/base/media/java/android/media/soundtrigger/SoundTriggerDetector.java
public boolean startRecognition(@RecognitionFlags int recognitionFlags)
try {status = mSoundTriggerSession.startRecognition(mSoundModel,mRecognitionCallback, new RecognitionConfig(captureTriggerAudio,allowMultipleTriggers, null, null, audioCapabilities),runInBatterySaver);} catch (RemoteException e) {return false;}/*** This class should be constructed by the {@link SoundTriggerManager}.* @hide*/SoundTriggerDetector(ISoundTriggerSession soundTriggerSession,@NonNull GenericSoundModel soundModel,@NonNull Callback callback, @Nullable Handler handler) {mSoundTriggerSession = soundTriggerSession;mSoundModel = soundModel;mCallback = callback;if (handler == null) {mHandler = new MyHandler();} else {mHandler = new MyHandler(handler.getLooper());}mRecognitionCallback = new RecognitionCallback();}事件上報時有兩個結構體,一個是sound_trigger_recognition_config,這個是sound_trigger_recognition配置相關的;
還有一個sound_trigger_recognition_event,這個的英文注釋如下:Generic recognition event sent via recognition callback。
prebuilts/vndk/v32/arm/include/system/media/audio/include/system/sound_trigger.h
/** configuration for sound trigger capture session passed to start_recognition()*/struct sound_trigger_recognition_config {audio_io_handle_t    capture_handle;    /* IO handle that will be used for capture.N/A if capture_requested is false */audio_devices_t      capture_device;    /* input device requested for detection capture */bool                 capture_requested; /* capture and buffer audio for this recognitioninstance */unsigned int         num_phrases;   /* number of key phrases recognition extras */struct sound_trigger_phrase_recognition_extra phrases[SOUND_TRIGGER_MAX_PHRASES];/* configuration for each key phrase */unsigned int        data_size;         /* size of opaque capture configuration data */unsigned int        data_offset;       /* offset of opaque data start from start of this struct(e.g sizeof struct sound_trigger_recognition_config) */};Generic recognition event sent via recognition callbackstruct __attribute__((aligned(8))) sound_trigger_recognition_event {int                              status;            /* recognition status e.g.RECOGNITION_STATUS_SUCCESS */sound_trigger_sound_model_type_t type;              /* event type, same as sound model type.e.g. SOUND_MODEL_TYPE_KEYPHRASE */sound_model_handle_t             model;             /* loaded sound model that triggered theevent */bool                             capture_available; /* it is possible to capture audio from thisutterance buffered by theimplementation */int                              capture_session;   /* audio session ID. framework use */int                              capture_delay_ms;  /* delay in ms between end of modeldetection and start of audio availablefor capture. A negative value is possible(e.g. if key phrase is also available forcapture */int                              capture_preamble_ms; /* duration in ms of audio capturedbefore the start of the trigger.0 if none. */bool                             trigger_in_data; /* the opaque data is the capture ofthe trigger sound */audio_config_t                   audio_config;        /* audio format of either the trigger inevent data or to use for capture of therest of the utterance */unsigned int                     data_size;         /* size of opaque event data */unsigned int                     data_offset;       /* offset of opaque data start from start ofthis struct (e.g sizeof structsound_trigger_phrase_recognition_event) */};

SoundTriggerDetector調用startRecognition()時將事件監聽回調注冊到SoundTriggerHal層。

2、高通芯片AudioReach架構芯片平臺ADSP層喚醒事件上報流程

喚醒上報事件代碼時序(高通AudioReach架構芯片平臺)(1)喚醒模塊代碼上報喚醒事件
capi_wakeup_raise_event_to_dsp_client()me_ptr->cb_info.event_cb(me_ptr->cb_info.event_context,CAPI_EVENT_DATA_TO_DSP_CLIENT_V2, &event_info)CAPI_EVENT_DATA_TO_DSP_CLIENT_V2 = 15(2)capi的callback()回調接口處理此事件消息
gen_topo_capi_cb_handler.c
gen_topo_capi_callback_base(gen_topo_module_t *module_ptr,capi_event_id_t    id,capi_event_info_t *event_info_ptr)switch (id)case CAPI_EVENT_DATA_TO_DSP_CLIENT:case CAPI_EVENT_DATA_TO_DSP_CLIENT_V2:return ar_result_to_capi_err(topo_ptr->topo_to_cntr_vtable_ptr->handle_capi_event(module_ptr, id, event_info_ptr));ADSP.HT.5.8/adsp_proc/avs/fwk/spf/containers/spl_cntr/core/src/spl_cntr.c.handle_capi_event                           = spl_cntr_handle_capi_event,(3)調用spf框架的spl_cntr_handle_capi_event()
ADSP.HT.5.8/adsp_proc/avs/fwk/spf/containers/spl_cntr/core/src/spl_cntr_event_util.c
ar_result_t spl_cntr_handle_capi_event(gen_topo_module_t *module_ptr,capi_event_id_t    event_id,capi_event_info_t *event_info_ptr){spl_cntr_t *me_ptr = (spl_cntr_t *)GET_BASE_PTR(spl_cntr_t, topo, module_ptr->topo_ptr);ar_result_t result = AR_EOK;result = cu_handle_capi_event(&me_ptr->cu, &module_ptr->gu, event_id, event_info_ptr);return result;}cu_handle_capi_event()switch (event_id)case CAPI_EVENT_DATA_TO_DSP_CLIENT_V2:{result |= cu_handle_event_data_to_dsp_client_v2_topo_cb(cu_ptr, module_ptr, event_info_ptr);break;}(4)路由到spf框架的cu_handle_event_data_to_dsp_client_v2_topo_cb()接口
ADSP.HT.5.8/adsp_proc/avs/fwk/spf/containers/cmn/container_utils/core/src/cu_utils_island.c
/* Topo callback to handle module event to DSP client v2 */ar_result_t cu_handle_event_data_to_dsp_client_v2_topo_cb(cu_base_t *        cu_ptr,gu_module_t *      module_ptr,capi_event_info_t *event_info_ptr)capi_event_data_to_dsp_client_v2_t *payload_ptr =(capi_event_data_to_dsp_client_v2_t *)(event_info_ptr->payload.data_ptr);gpr_cmd_alloc_ext_v2_t args;args.heap_index    = dest_address.a.gpr_heap_index;args.src_domain_id = dest_address.a.dest_domain_id;args.dst_domain_id = dest_address.a.src_domain_id;args.src_port      = module_ptr->module_instance_id;args.dst_port      = dest_address.a.src_port;args.token         = payload_ptr->token;args.opcode        = APM_EVENT_MODULE_TO_CLIENT;args.payload_size  = sizeof(apm_module_event_t) + payload_ptr->payload.actual_data_len;args.client_data   = 0;args.ret_packet    = &event_packet_ptr;result             = __gpr_cmd_alloc_ext_v2(&args);//調用gpr接口發送gpr消息給到client端result = __gpr_cmd_async_send(event_packet_ptr);(5)調用gpr接口,為gpr消息申請分配對應的內存大小,
分配原則:先從靜態內存池分配,靜態分配失敗,再從動態內存分配,兩者都失敗,上報內存分配失敗。
ADSP.HT.5.8/adsp_proc/gpr/core/src/gpr_drv_island.c
uint32_t __gpr_cmd_alloc_ext_v2(gpr_cmd_alloc_ext_v2_t *args)rc = __gpr_cmd_alloc_v2(args->payload_size, args->heap_index, &new_packet);uint32_t __gpr_cmd_alloc_v2(uint32_t alloc_size, gpr_heap_index_t heap_index, gpr_packet_t **ret_packet)new_packet = (gpr_packet_t *)gpr_memq_alloc(block);// If packet couldnt not be allocated in static pool, check dynamic poolgpr_allocate_dynamic_packet(&new_packet, packet_size);

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/913914.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/913914.shtml
英文地址,請注明出處:http://en.pswp.cn/news/913914.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

OSPF實驗以及核心原理全解

OSPF&#xff08;Open Shortest Path First&#xff0c;開放式最短路徑優先&#xff09;是一種基于鏈路狀態的內部網關協議&#xff08;IGP&#xff09;&#xff0c;廣泛應用于中大型網絡中。它通過維護網絡拓撲信息&#xff0c;使用 SPF&#xff08;最短路徑優先&#xff09;算…

Using Spring for Apache Pulsar:Transactions

本節介紹Spring for Apache Pulsar如何支持事務。OverviewSpring for Apache Pulsar事務支持是基于Spring Framework提供的事務支持構建的。在高層&#xff0c;事務資源向事務管理器注冊&#xff0c;事務管理器反過來處理注冊資源的事務狀態&#xff08;提交、回滾等&#xff0…

在Ubuntu上從零開始編譯并運行Home Assistant源碼并集成HACS與小米開源的Ha Xiaomi Home

目錄1. 前言&&疊甲2. 使用的環境3. 相關鏈接4. 前期步驟4.1 安裝路徑提前說明4.2 Ubuntu 相關依賴安裝4.3 Python源碼編譯安裝4.3.1 編譯安裝4.3.2 換源4.3.3 環境變量5. 構建Home Assistant源碼5.1 clone源碼5.2 創建虛擬Python環境5.3 安裝項目依賴5.4 安裝項目5.5 運…

【實習篇】之Http頭部字段之Disposition介紹

Http頭部字段之DispositionDisposition頭部字段介紹RFC規范介紹RFC 6266與RFC 2047實習的時候公司將一個某個關于下載的Bug交給了我來修&#xff0c;看了代碼和日志后發現是Disposition字段的規范兼容性惹的鍋&#xff0c;因為有些協議使用的是老協議&#xff0c;我們的項目沒有…

VM文件管理與Vi/vim操作

[rootlocalhost /]# sudo mkdir /opt [rootlocalhost /]# sudo mkdir /opt/tmp [rootlocalhost /]# sudo touch /opt/tmp/a.txt [rootlocalhost /]# ls /opt/tmp/ a.txt [rootlocalhost /]# 3.步驟1&#xff1a;創建文件并插入日期時間vi /tmp/newfile在vi編輯器中輸入以下命令…

【Android】安卓四大組件之內容提供者(ContentProvider):從基礎到進階

你手機里的通訊錄&#xff0c;存儲了所有聯系人的信息。如果你想把這些聯系人信息分享給其他App&#xff0c;就可以通過ContentProvider來實現。。 一、什么是 ContentProvider ?ContentProvider? 是 Android 四大組件之一&#xff0c;負責實現?跨應用程序的數據共享與訪問…

Vue-19-前端框架Vue之應用基礎組件通信(二)

文章目錄 1 v-model(父子相傳)1.1 App.vue1.2 Father.vue1.2.1 v-model用在html標簽上1.2.2 v-model用在html標簽上(本質寫法)1.2.3 v-model用在組件標簽上1.2.4 v-model用在組件標簽上(本質寫法)1.3 MyInput(自定義的組件)1.4 修改modelValue1.4.1 Father.vue1.4.2 MyInput.vu…

寶塔下載pgsql適配spring ai

1.寶塔安裝pgvector 1.先去github下載pgvectorpgvector/pgvector: Open-source vector similarity search for Postgres 2.把壓縮包上傳到系統文件的/temp下解壓&#xff0c;重命名文件名為pgvector&#xff0c;之后命令操作 cd /tmp cd pgvector export PG_CONFIG/www/serv…

RK3568項目(八)--linux驅動開發之基礎外設(上)

目錄 一、引言 二、準備工作 ------>2.1、驅動加載/卸載命令 三、字符設備驅動開發 ------>3.1、驅動模塊的加載和卸載 ------>3.2、外部模塊編譯模板 Makefile ------>3.3、cdev 四、LED驅動 ------>4.1、原理圖 ------>4.2、驅動 五、設備樹 -…

BUUCTF在線評測-練習場-WebCTF習題[GXYCTF2019]BabySQli1-flag獲取、解析

解題思路打開靶場&#xff0c;題目提示是sql注入輸入數據&#xff0c;判斷下閉合11123報錯&#xff1a;Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 1 at line 1報錯提示…

“AI 曼哈頓計劃”:科技競賽還是人類挑戰?

美國國會下屬的經濟與安全審查委員會已將“推動建立并資助一項堪比曼哈頓計劃的通用人工智能研發項目”列為其對國會的核心建議之一&#xff0c;明確顯示出對AI競賽戰略意義的高度重視。與此同時&#xff0c;美國能源部在近幾個月中多次公開將人工智能的突破比作“下一場曼哈頓…

音頻信號的預加重:提升語音清晰度

一、預加重介紹預加重是一種信號處理技術&#xff0c;主要用于增強音頻信號中的高頻成分。由于人類語音的頻譜特性&#xff0c;尤其是在輔音和音調的表達上&#xff0c;高頻成分對于語音的清晰度至關重要。然而&#xff0c;在錄音和傳輸過程中&#xff0c;這些高頻成分往往會受…

WebSocket實戰:實現實時聊天應用 - 雙向通信技術詳解

目錄一、WebSocket&#xff1a;實時通信的"高速公路"1.1 HTTP的短板&#xff1a;永遠的"單相思"1.2 WebSocket的優勢&#xff1a;真正的"雙向對話"二、30分鐘搭建聊天服務器2.1 環境準備2.2 WebSocket配置類2.3 核心消息處理器三、前端實現&…

宏集案例 | 基于CODESYS的自動化控制系統,開放架構 × 高度集成 × 遠程運維

??案例概況客戶&#xff1a;MACS Sterilisationsanlagen GmbH&#xff08;Ermafa Environmental Technologies GmbH 旗下&#xff09; 應用場景&#xff1a;醫療與感染性廢棄物的無害化處理控制系統應用產品&#xff1a;宏集Berghof高性能控制器設備&#xff08;一&#xff0…

學習JNI 二

創建一個名為Learn1項目&#xff08;Android Studio&#xff09;。一、項目結構二、配置 build.gradlebuild.gradle.kts(:app)plugins {alias(libs.plugins.android.application)alias(libs.plugins.jetbrains.kotlin.android) }android {namespace "com.demo.learn1&quo…

基于Spring Boot+Vue的DIY手工社預約管理系統(Echarts圖形化、騰訊地圖API)

2.10 視頻課程管理功能實現2.11手工互動&#xff08;視頻彈幕&#xff09;2.8預約設置管理功能實現&#x1f388;系統亮點&#xff1a;Echarts圖形化、騰訊地圖API&#xff1b;文檔包含功能結構圖、系統架構圖、用例圖、實體屬性圖、E-R圖。一.系統開發工具與環境搭建1.系統設計…

leetcode 每日一題 1353. 最多可以參加的會議數目

更多技術訪問 我的個人網站 &#xff08;免費服務器&#xff0c;沒有80/443端口&#xff09; 1353. 最多可以參加的會議數目 給你一個數組 events&#xff0c;其中 events[i] [startDayi, endDayi] &#xff0c;表示會議 i 開始于 startDayi &#xff0c;結束于 endDayi 。 …

AI+智慧園區 | 事件處置自動化——大模型重構園區治理邏輯

在智慧園區的建設浪潮中&#xff0c;事件管理一直是園區高效運營的關鍵環節。考拉悠然所推出的大模型 智慧園區解決方案&#xff0c;在事件智能閉環管理方面獨樹一幟&#xff0c;為園區的日常運營編織了一張嚴密、高效、智能的管理網絡&#xff0c;實現了從事件感知到處置的全…

FFmpeg Windows安裝

FFmpeg 用于音頻文件轉換 Builds - CODEX FFMPEG gyan.dev ffmpeg-release-full.7z 下載完成之后 zip解壓 大概就是 ffmpeg/ └── bin/ └── ffmpeg.exe 配置環境變量 ffmpeg -version 有可能idea還是找不到命令 就把命令路徑寫在程序里 例如

【2025/07/10】GitHub 今日熱門項目

GitHub 今日熱門項目 &#x1f680; 每日精選優質開源項目 | 發現優質開源項目&#xff0c;跟上技術發展趨勢 &#x1f4cb; 報告概覽 &#x1f4ca; 統計項&#x1f4c8; 數值&#x1f4dd; 說明&#x1f4c5; 報告日期2025-07-10 (周四)GitHub Trending 每日快照&#x1f55…