Skip to content

Commit ead25e8

Browse files
iganakovkv2019i
authored andcommitted
kd: add ams support
Add support for AMS notifications Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
1 parent 5aae7e1 commit ead25e8

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

src/samples/audio/detect_test.c

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <rtos/alloc.h>
1818
#include <rtos/init.h>
1919
#include <sof/lib/memory.h>
20-
#include <sof/lib/notifier.h>
2120
#include <rtos/wait.h>
2221
#include <sof/lib/uuid.h>
2322
#include <sof/list.h>
@@ -41,6 +40,13 @@
4140
#include <stdint.h>
4241
#include <stdlib.h>
4342
#include <sof/samples/audio/kwd_nn_detect_test.h>
43+
#if CONFIG_AMS
44+
#include <sof/lib/ams.h>
45+
#include <sof/lib/ams_msg.h>
46+
#include <ipc4/ams_helpers.h>
47+
#else
48+
#include <sof/lib/notifier.h>
49+
#endif
4450

4551
#define ACTIVATION_DEFAULT_SHIFT 3
4652
#define ACTIVATION_DEFAULT_COEF 0.05
@@ -85,7 +91,6 @@ struct comp_data {
8591
uint32_t keyphrase_samples; /**< keyphrase length in samples */
8692
uint32_t drain_req; /** defines draining size in bytes. */
8793
uint16_t sample_valid_bytes;
88-
struct kpb_event_data event_data;
8994
struct kpb_client client_data;
9095

9196
#if CONFIG_KWD_NN_SAMPLE_KEYPHRASE
@@ -98,6 +103,12 @@ struct comp_data {
98103
void (*detect_func)(struct comp_dev *dev,
99104
const struct audio_stream __sparse_cache *source, uint32_t frames);
100105
struct sof_ipc_comp_event event;
106+
107+
#if CONFIG_AMS
108+
uint32_t kpd_uuid_id;
109+
#else
110+
struct kpb_event_data event_data;
111+
#endif /* CONFIG_AMS */
101112
};
102113

103114
static inline bool detector_is_sample_width_supported(enum sof_ipc_frame sf)
@@ -140,6 +151,31 @@ static void notify_host(const struct comp_dev *dev)
140151
#endif /* CONFIG_IPC_MAJOR_4 */
141152
}
142153

154+
#if CONFIG_AMS
155+
156+
/* Key-phrase detected message*/
157+
static const ams_uuid_t ams_kpd_msg_uuid = AMS_KPD_MSG_UUID;
158+
159+
static int ams_notify_kpb(const struct comp_dev *dev)
160+
{
161+
struct comp_data *cd = comp_get_drvdata(dev);
162+
struct ams_message_payload ams_payload;
163+
164+
cd->client_data.r_ptr = NULL;
165+
cd->client_data.sink = NULL;
166+
cd->client_data.id = 0; /**< TODO: acquire proper id from kpb */
167+
/* time in milliseconds */
168+
cd->client_data.drain_req = (cd->drain_req != 0) ?
169+
cd->drain_req :
170+
cd->config.drain_req;
171+
172+
ams_helper_prepare_payload(dev, &ams_payload, cd->kpd_uuid_id,
173+
(uint8_t *)&cd->client_data,
174+
sizeof(struct kpb_client));
175+
176+
return ams_send(&ams_payload);
177+
}
178+
#else
143179
static void notify_kpb(const struct comp_dev *dev)
144180
{
145181
struct comp_data *cd = comp_get_drvdata(dev);
@@ -160,11 +196,16 @@ static void notify_kpb(const struct comp_dev *dev)
160196
NOTIFIER_TARGET_CORE_ALL_MASK, &cd->event_data,
161197
sizeof(cd->event_data));
162198
}
199+
#endif /* CONFIG_AMS */
163200

164201
void detect_test_notify(const struct comp_dev *dev)
165202
{
166203
notify_host(dev);
204+
#if CONFIG_AMS
205+
ams_notify_kpb(dev);
206+
#else
167207
notify_kpb(dev);
208+
#endif
168209
}
169210

170211
static void default_detect_test(struct comp_dev *dev,
@@ -719,6 +760,15 @@ static void test_keyword_free(struct comp_dev *dev)
719760

720761
comp_info(dev, "test_keyword_free()");
721762

763+
#if CONFIG_AMS
764+
int ret;
765+
766+
/* Unregister KD as AMS producer */
767+
ret = ams_helper_unregister_producer(dev, cd->kpd_uuid_id);
768+
if (ret)
769+
comp_err(dev, "test_keyword_free(): unregister ams error %d", ret);
770+
#endif
771+
722772
ipc_msg_free(cd->msg);
723773
comp_data_blob_handler_free(cd->model_handler);
724774
rfree(cd);
@@ -796,6 +846,10 @@ static int test_keyword_params(struct comp_dev *dev,
796846
return err;
797847
}
798848

849+
#if CONFIG_AMS
850+
cd->kpd_uuid_id = AMS_INVALID_MSG_TYPE;
851+
#endif /* CONFIG_AMS */
852+
799853
cd->config.activation_threshold = err;
800854

801855
return 0;
@@ -874,6 +928,7 @@ static int test_keyword_prepare(struct comp_dev *dev)
874928
struct comp_data *cd = comp_get_drvdata(dev);
875929
uint16_t valid_bits = cd->sample_valid_bytes * 8;
876930
uint16_t sample_width;
931+
int ret;
877932

878933
#if CONFIG_IPC_MAJOR_4
879934
sample_width = cd->base_cfg.audio_fmt.depth;
@@ -887,7 +942,7 @@ static int test_keyword_prepare(struct comp_dev *dev)
887942
/* Default threshold value has to be changed
888943
* according to host new format.
889944
*/
890-
int ret = test_keyword_get_threshold(dev, valid_bits);
945+
ret = test_keyword_get_threshold(dev, valid_bits);
891946

892947
if (ret < 0) {
893948
comp_err(dev, "test_keyword_prepare(): unsupported sample width %u",
@@ -902,6 +957,14 @@ static int test_keyword_prepare(struct comp_dev *dev)
902957
&cd->data_blob_size,
903958
&cd->data_blob_crc);
904959

960+
#if CONFIG_AMS
961+
/* Register KD as AMS producer */
962+
ret = ams_helper_register_producer(dev, &cd->kpd_uuid_id,
963+
ams_kpd_msg_uuid);
964+
if (ret)
965+
return ret;
966+
#endif
967+
905968
return comp_set_state(dev, COMP_TRIGGER_PREPARE);
906969
}
907970

0 commit comments

Comments
 (0)