|
27 | 27 | #include <rtos/clk.h> |
28 | 28 | #include <rtos/init.h> |
29 | 29 | #include <sof/lib/memory.h> |
30 | | -#include <sof/lib/notifier.h> |
31 | 30 | #include <sof/lib/pm_runtime.h> |
32 | 31 | #include <sof/lib/uuid.h> |
33 | 32 | #include <sof/list.h> |
|
47 | 46 | #include <stdbool.h> |
48 | 47 | #include <stddef.h> |
49 | 48 | #include <stdint.h> |
| 49 | +#if CONFIG_AMS |
| 50 | +#include <sof/lib/ams.h> |
| 51 | +#include <sof/lib/ams_msg.h> |
| 52 | +#include <ipc4/ams_helpers.h> |
| 53 | +#else |
| 54 | +#include <sof/lib/notifier.h> |
| 55 | +#endif |
50 | 56 |
|
51 | 57 | static const struct comp_driver comp_kpb; |
52 | 58 |
|
@@ -100,11 +106,17 @@ struct comp_data { |
100 | 106 | uint32_t num_of_in_channels; |
101 | 107 | uint32_t offsets[KPB_MAX_MICSEL_CHANNELS]; |
102 | 108 | struct kpb_micselector_config mic_sel; |
| 109 | + |
| 110 | +#if CONFIG_AMS |
| 111 | + uint32_t kpd_uuid_id; |
| 112 | +#endif |
103 | 113 | }; |
104 | 114 |
|
105 | 115 | /*! KPB private functions */ |
| 116 | +#ifndef CONFIG_AMS |
106 | 117 | static void kpb_event_handler(void *arg, enum notify_id type, void *event_data); |
107 | 118 | static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli); |
| 119 | +#endif |
108 | 120 | static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli); |
109 | 121 | static enum task_state kpb_draining_task(void *arg); |
110 | 122 | static int kpb_buffer_data(struct comp_dev *dev, |
@@ -135,6 +147,25 @@ static uint64_t kpb_task_deadline(void *data) |
135 | 147 | return SOF_TASK_DEADLINE_ALMOST_IDLE; |
136 | 148 | } |
137 | 149 |
|
| 150 | +#if CONFIG_AMS |
| 151 | + |
| 152 | +/* Key-phrase detected message*/ |
| 153 | +static const ams_uuid_t ams_kpd_msg_uuid = AMS_KPD_MSG_UUID; |
| 154 | + |
| 155 | +/* Key-phrase detected notification handler*/ |
| 156 | +static void kpb_ams_kpd_notification(const struct ams_message_payload *const ams_message_payload, |
| 157 | + void *ctx) |
| 158 | +{ |
| 159 | + struct kpb_client *cli_data = (struct kpb_client *)ams_message_payload->message; |
| 160 | + struct comp_dev *dev = ctx; |
| 161 | + |
| 162 | + comp_dbg(dev, "kpb_ams_kpd_notification()"); |
| 163 | + |
| 164 | + kpb_init_draining(dev, cli_data); |
| 165 | +} |
| 166 | + |
| 167 | +#endif /* CONFIG_AMS */ |
| 168 | + |
138 | 169 | #ifdef __ZEPHYR__ |
139 | 170 |
|
140 | 171 | static void kpb_lock(struct comp_data *kpb) |
@@ -620,8 +651,18 @@ static void kpb_free(struct comp_dev *dev) |
620 | 651 |
|
621 | 652 | comp_info(dev, "kpb_free()"); |
622 | 653 |
|
| 654 | +#if CONFIG_AMS |
| 655 | + /* Unregister KPB as AMS consumer */ |
| 656 | + int ret; |
| 657 | + |
| 658 | + ret = ams_helper_unregister_consumer(dev, kpb->kpd_uuid_id, |
| 659 | + kpb_ams_kpd_notification); |
| 660 | + if (ret) |
| 661 | + comp_err(dev, "kpb_free(): AMS unregister error %d", ret); |
| 662 | +#else |
623 | 663 | /* Unregister KPB from notifications */ |
624 | 664 | notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); |
| 665 | +#endif/* CONFIG_AMS */ |
625 | 666 |
|
626 | 667 | /* Reclaim memory occupied by history buffer */ |
627 | 668 | kpb_free_history_buffer(kpb->hd.c_hb); |
@@ -697,6 +738,10 @@ static int kpb_params(struct comp_dev *dev, |
697 | 738 | kpb->host_period_size = params->host_period_bytes; |
698 | 739 | kpb->config.sampling_width = params->sample_container_bytes * 8; |
699 | 740 |
|
| 741 | +#if CONFIG_AMS |
| 742 | + kpb->kpd_uuid_id = AMS_INVALID_MSG_TYPE; |
| 743 | +#endif |
| 744 | + |
700 | 745 | return 0; |
701 | 746 | } |
702 | 747 |
|
@@ -772,9 +817,17 @@ static int kpb_prepare(struct comp_dev *dev) |
772 | 817 | kpb->clients[i].r_ptr = NULL; |
773 | 818 | } |
774 | 819 |
|
| 820 | +#if CONFIG_AMS |
| 821 | + /* AMS Register KPB for notification */ |
| 822 | + ret = ams_helper_register_consumer(dev, &kpb->kpd_uuid_id, |
| 823 | + ams_kpd_msg_uuid, |
| 824 | + kpb_ams_kpd_notification); |
| 825 | +#else |
775 | 826 | /* Register KPB for notification */ |
776 | 827 | ret = notifier_register(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT, |
777 | 828 | kpb_event_handler, 0); |
| 829 | +#endif /* CONFIG_AMS */ |
| 830 | + |
778 | 831 | if (ret < 0) { |
779 | 832 | kpb_free_history_buffer(kpb->hd.c_hb); |
780 | 833 | kpb->hd.c_hb = NULL; |
@@ -917,8 +970,10 @@ static int kpb_reset(struct comp_dev *dev) |
917 | 970 | kpb_reset_history_buffer(kpb->hd.c_hb); |
918 | 971 | } |
919 | 972 |
|
| 973 | +#ifndef CONFIG_AMS |
920 | 974 | /* Unregister KPB from notifications */ |
921 | 975 | notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); |
| 976 | +#endif |
922 | 977 | /* Finally KPB is ready after reset */ |
923 | 978 | kpb_change_state(kpb, KPB_STATE_PREPARING); |
924 | 979 |
|
@@ -1422,6 +1477,7 @@ static int kpb_buffer_data(struct comp_dev *dev, |
1422 | 1477 | return ret; |
1423 | 1478 | } |
1424 | 1479 |
|
| 1480 | +#ifndef CONFIG_AMS |
1425 | 1481 | /** |
1426 | 1482 | * \brief Main event dispatcher. |
1427 | 1483 | * \param[in] arg - KPB component internal data. |
@@ -1501,6 +1557,7 @@ static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli) |
1501 | 1557 |
|
1502 | 1558 | return ret; |
1503 | 1559 | } |
| 1560 | +#endif /* CONFIG_AMS */ |
1504 | 1561 |
|
1505 | 1562 | /** |
1506 | 1563 | * \brief Prepare history buffer for draining. |
|
0 commit comments