-
Notifications
You must be signed in to change notification settings - Fork 349
ams: add support for ams to kd and kpb modules #7158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |
| #include <rtos/clk.h> | ||
| #include <rtos/init.h> | ||
| #include <sof/lib/memory.h> | ||
| #include <sof/lib/notifier.h> | ||
| #include <sof/lib/pm_runtime.h> | ||
| #include <sof/lib/uuid.h> | ||
| #include <sof/list.h> | ||
|
|
@@ -47,6 +46,13 @@ | |
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
| #if CONFIG_AMS | ||
| #include <sof/lib/ams.h> | ||
| #include <sof/lib/ams_msg.h> | ||
| #include <ipc4/ams_helpers.h> | ||
| #else | ||
| #include <sof/lib/notifier.h> | ||
| #endif | ||
|
|
||
| static const struct comp_driver comp_kpb; | ||
|
|
||
|
|
@@ -100,11 +106,17 @@ struct comp_data { | |
| uint32_t num_of_in_channels; | ||
| uint32_t offsets[KPB_MAX_MICSEL_CHANNELS]; | ||
| struct kpb_micselector_config mic_sel; | ||
|
|
||
| #if CONFIG_AMS | ||
| uint32_t kpd_uuid_id; | ||
| #endif | ||
| }; | ||
|
|
||
| /*! KPB private functions */ | ||
| #ifndef CONFIG_AMS | ||
| static void kpb_event_handler(void *arg, enum notify_id type, void *event_data); | ||
| static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli); | ||
| #endif | ||
| static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli); | ||
| static enum task_state kpb_draining_task(void *arg); | ||
| static int kpb_buffer_data(struct comp_dev *dev, | ||
|
|
@@ -135,6 +147,25 @@ static uint64_t kpb_task_deadline(void *data) | |
| return SOF_TASK_DEADLINE_ALMOST_IDLE; | ||
| } | ||
|
|
||
| #if CONFIG_AMS | ||
|
|
||
| /* Key-phrase detected message*/ | ||
| static const ams_uuid_t ams_kpd_msg_uuid = AMS_KPD_MSG_UUID; | ||
|
|
||
| /* Key-phrase detected notification handler*/ | ||
| static void kpb_ams_kpd_notification(const struct ams_message_payload *const ams_message_payload, | ||
| void *ctx) | ||
| { | ||
| struct kpb_client *cli_data = (struct kpb_client *)ams_message_payload->message; | ||
| struct comp_dev *dev = ctx; | ||
|
|
||
| comp_dbg(dev, "kpb_ams_kpd_notification()"); | ||
|
|
||
| kpb_init_draining(dev, cli_data); | ||
| } | ||
|
|
||
| #endif /* CONFIG_AMS */ | ||
plbossart marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #ifdef __ZEPHYR__ | ||
|
|
||
| static void kpb_lock(struct comp_data *kpb) | ||
|
|
@@ -620,8 +651,18 @@ static void kpb_free(struct comp_dev *dev) | |
|
|
||
| comp_info(dev, "kpb_free()"); | ||
|
|
||
| #if CONFIG_AMS | ||
| /* Unregister KPB as AMS consumer */ | ||
| int ret; | ||
|
|
||
| ret = ams_helper_unregister_consumer(dev, kpb->kpd_uuid_id, | ||
| kpb_ams_kpd_notification); | ||
| if (ret) | ||
| comp_err(dev, "kpb_free(): AMS unregister error %d", ret); | ||
| #else | ||
| /* Unregister KPB from notifications */ | ||
| notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); | ||
| #endif/* CONFIG_AMS */ | ||
|
|
||
| /* Reclaim memory occupied by history buffer */ | ||
| kpb_free_history_buffer(kpb->hd.c_hb); | ||
|
|
@@ -697,6 +738,10 @@ static int kpb_params(struct comp_dev *dev, | |
| kpb->host_period_size = params->host_period_bytes; | ||
| kpb->config.sampling_width = params->sample_container_bytes * 8; | ||
|
|
||
| #if CONFIG_AMS | ||
| kpb->kpd_uuid_id = AMS_INVALID_MSG_TYPE; | ||
| #endif | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -772,9 +817,17 @@ static int kpb_prepare(struct comp_dev *dev) | |
| kpb->clients[i].r_ptr = NULL; | ||
| } | ||
|
|
||
| #if CONFIG_AMS | ||
| /* AMS Register KPB for notification */ | ||
| ret = ams_helper_register_consumer(dev, &kpb->kpd_uuid_id, | ||
| ams_kpd_msg_uuid, | ||
| kpb_ams_kpd_notification); | ||
| #else | ||
| /* Register KPB for notification */ | ||
| ret = notifier_register(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT, | ||
| kpb_event_handler, 0); | ||
| #endif /* CONFIG_AMS */ | ||
iganakov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (ret < 0) { | ||
| kpb_free_history_buffer(kpb->hd.c_hb); | ||
| kpb->hd.c_hb = NULL; | ||
|
|
@@ -917,8 +970,10 @@ static int kpb_reset(struct comp_dev *dev) | |
| kpb_reset_history_buffer(kpb->hd.c_hb); | ||
| } | ||
|
|
||
| #ifndef CONFIG_AMS | ||
| /* Unregister KPB from notifications */ | ||
| notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); | ||
| #endif | ||
|
||
| /* Finally KPB is ready after reset */ | ||
| kpb_change_state(kpb, KPB_STATE_PREPARING); | ||
|
|
||
|
|
@@ -1422,6 +1477,7 @@ static int kpb_buffer_data(struct comp_dev *dev, | |
| return ret; | ||
| } | ||
|
|
||
| #ifndef CONFIG_AMS | ||
| /** | ||
| * \brief Main event dispatcher. | ||
| * \param[in] arg - KPB component internal data. | ||
|
|
@@ -1501,6 +1557,7 @@ static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli) | |
|
|
||
| return ret; | ||
| } | ||
| #endif /* CONFIG_AMS */ | ||
|
|
||
| /** | ||
| * \brief Prepare history buffer for draining. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright (c) 2023 Intel Corporation | ||
| * | ||
| * Author: Ievgen Ganakov <ievgen.ganakov@intel.com> | ||
| */ | ||
|
|
||
| #ifndef __SOF_LIB_AMS_HELPERS_H__ | ||
| #define __SOF_LIB_AMS_HELPERS_H__ | ||
|
|
||
| #include <sof/lib/ams.h> | ||
| #include <sof/lib/ams_msg.h> | ||
| #include <stdint.h> | ||
|
|
||
| #if CONFIG_AMS | ||
|
|
||
| int ams_helper_register_producer(const struct comp_dev *dev, | ||
| uint32_t *ams_uuid_id, | ||
| const uint8_t *msg_uuid); | ||
|
|
||
| int ams_helper_unregister_producer(const struct comp_dev *dev, | ||
| uint32_t ams_uuid_id); | ||
|
|
||
| int ams_helper_register_consumer(struct comp_dev *dev, | ||
| uint32_t *ams_uuid_id, | ||
| const uint8_t *msg_uuid, | ||
| ams_msg_callback_fn callback); | ||
|
|
||
| int ams_helper_unregister_consumer(struct comp_dev *dev, | ||
| uint32_t ams_uuid_id, | ||
| ams_msg_callback_fn callback); | ||
|
|
||
| void ams_helper_prepare_payload(const struct comp_dev *dev, | ||
| struct ams_message_payload *payload, | ||
| uint32_t ams_uuid_id, | ||
| uint8_t *message, | ||
| size_t message_size); | ||
|
|
||
| #endif /* CONFIG_AMS */ | ||
|
|
||
| #endif /* __SOF_LIB_AMS_HELPERS_H__ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright (c) 2023 Intel Corporation | ||
| * | ||
| * Author: Ievgen Ganakov <ievgen.ganakov@intel.com> | ||
| */ | ||
|
|
||
| #ifndef __SOF_LIB_AMS_MSG_H__ | ||
| #define __SOF_LIB_AMS_MSG_H__ | ||
|
|
||
| /* AMS messages */ | ||
| typedef uint8_t ams_uuid_t[16]; | ||
|
|
||
| /* Key-phrase detected AMS message uuid: 80a11122-b36c-11ed-afa1-0242ac120002*/ | ||
| #define AMS_KPD_MSG_UUID { 0x80, 0xa1, 0x11, 0x22, 0xb3, 0x6c, 0x11, 0xed, \ | ||
| 0xaf, 0xa1, 0x02, 0x42, 0xac, 0x12, 0x00, 0x02 } | ||
|
|
||
| #endif /* __SOF_LIB_AMS_MSG_H__ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| /* | ||
| * Copyright(c) 2023 Intel Corporation. All rights reserved. | ||
| * | ||
| * Author: Ievgen Ganakov <ievgen.ganakov@intel.com> | ||
| */ | ||
|
|
||
| #include <ipc4/ams_helpers.h> | ||
| #include <sof/audio/component.h> | ||
|
|
||
| #if CONFIG_AMS | ||
|
|
||
| int ams_helper_register_producer(const struct comp_dev *dev, | ||
| uint32_t *ams_uuid_id, | ||
| const uint8_t *msg_uuid) | ||
| { | ||
| uint16_t mod_id = IPC4_MOD_ID(dev_comp_id(dev)); | ||
| uint16_t inst_id = IPC4_INST_ID(dev_comp_id(dev)); | ||
| int ret; | ||
|
|
||
| ret = ams_get_message_type_id(msg_uuid, ams_uuid_id); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| return ams_register_producer(*ams_uuid_id, mod_id, inst_id); | ||
| } | ||
|
|
||
| int ams_helper_unregister_producer(const struct comp_dev *dev, | ||
| uint32_t ams_uuid_id) | ||
| { | ||
| uint16_t mod_id = IPC4_MOD_ID(dev_comp_id(dev)); | ||
| uint16_t inst_id = IPC4_INST_ID(dev_comp_id(dev)); | ||
|
|
||
| return ams_unregister_producer(ams_uuid_id, mod_id, inst_id); | ||
| } | ||
|
|
||
| int ams_helper_register_consumer(struct comp_dev *dev, | ||
| uint32_t *ams_uuid_id, | ||
| const uint8_t *msg_uuid, | ||
| ams_msg_callback_fn callback) | ||
| { | ||
| uint16_t mod_id = IPC4_MOD_ID(dev_comp_id(dev)); | ||
| uint16_t inst_id = IPC4_INST_ID(dev_comp_id(dev)); | ||
| int ret; | ||
|
|
||
| ret = ams_get_message_type_id(msg_uuid, ams_uuid_id); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| return ams_register_consumer(*ams_uuid_id, mod_id, inst_id, callback, dev); | ||
| } | ||
|
|
||
| int ams_helper_unregister_consumer(struct comp_dev *dev, | ||
| uint32_t ams_uuid_id, | ||
| ams_msg_callback_fn callback) | ||
| { | ||
| uint16_t mod_id = IPC4_MOD_ID(dev_comp_id(dev)); | ||
| uint16_t inst_id = IPC4_INST_ID(dev_comp_id(dev)); | ||
|
|
||
| return ams_unregister_consumer(ams_uuid_id, mod_id, inst_id, callback); | ||
| } | ||
|
|
||
| void ams_helper_prepare_payload(const struct comp_dev *dev, | ||
| struct ams_message_payload *payload, | ||
| uint32_t ams_uuid_id, | ||
| uint8_t *message, | ||
| size_t message_size) | ||
| { | ||
| uint16_t mod_id = IPC4_MOD_ID(dev_comp_id(dev)); | ||
| uint16_t inst_id = IPC4_INST_ID(dev_comp_id(dev)); | ||
|
|
||
| payload->message_type_id = ams_uuid_id; | ||
| payload->producer_module_id = mod_id; | ||
| payload->producer_instance_id = inst_id; | ||
| payload->message_length = message_size; | ||
| payload->message = message; | ||
| } | ||
|
|
||
| #endif /* CONFIG_AMS */ |
Uh oh!
There was an error while loading. Please reload this page.