Skip to content

Commit 5aae7e1

Browse files
iganakovkv2019i
authored andcommitted
kpb: add ams support
Add AMS notifications support to KPB module Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
1 parent 7ae382d commit 5aae7e1

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

src/audio/kpb.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <rtos/clk.h>
2828
#include <rtos/init.h>
2929
#include <sof/lib/memory.h>
30-
#include <sof/lib/notifier.h>
3130
#include <sof/lib/pm_runtime.h>
3231
#include <sof/lib/uuid.h>
3332
#include <sof/list.h>
@@ -47,6 +46,13 @@
4746
#include <stdbool.h>
4847
#include <stddef.h>
4948
#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
5056

5157
static const struct comp_driver comp_kpb;
5258

@@ -100,11 +106,17 @@ struct comp_data {
100106
uint32_t num_of_in_channels;
101107
uint32_t offsets[KPB_MAX_MICSEL_CHANNELS];
102108
struct kpb_micselector_config mic_sel;
109+
110+
#if CONFIG_AMS
111+
uint32_t kpd_uuid_id;
112+
#endif
103113
};
104114

105115
/*! KPB private functions */
116+
#ifndef CONFIG_AMS
106117
static void kpb_event_handler(void *arg, enum notify_id type, void *event_data);
107118
static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli);
119+
#endif
108120
static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli);
109121
static enum task_state kpb_draining_task(void *arg);
110122
static int kpb_buffer_data(struct comp_dev *dev,
@@ -135,6 +147,25 @@ static uint64_t kpb_task_deadline(void *data)
135147
return SOF_TASK_DEADLINE_ALMOST_IDLE;
136148
}
137149

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+
138169
#ifdef __ZEPHYR__
139170

140171
static void kpb_lock(struct comp_data *kpb)
@@ -620,8 +651,18 @@ static void kpb_free(struct comp_dev *dev)
620651

621652
comp_info(dev, "kpb_free()");
622653

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
623663
/* Unregister KPB from notifications */
624664
notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT);
665+
#endif/* CONFIG_AMS */
625666

626667
/* Reclaim memory occupied by history buffer */
627668
kpb_free_history_buffer(kpb->hd.c_hb);
@@ -697,6 +738,10 @@ static int kpb_params(struct comp_dev *dev,
697738
kpb->host_period_size = params->host_period_bytes;
698739
kpb->config.sampling_width = params->sample_container_bytes * 8;
699740

741+
#if CONFIG_AMS
742+
kpb->kpd_uuid_id = AMS_INVALID_MSG_TYPE;
743+
#endif
744+
700745
return 0;
701746
}
702747

@@ -772,9 +817,17 @@ static int kpb_prepare(struct comp_dev *dev)
772817
kpb->clients[i].r_ptr = NULL;
773818
}
774819

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
775826
/* Register KPB for notification */
776827
ret = notifier_register(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT,
777828
kpb_event_handler, 0);
829+
#endif /* CONFIG_AMS */
830+
778831
if (ret < 0) {
779832
kpb_free_history_buffer(kpb->hd.c_hb);
780833
kpb->hd.c_hb = NULL;
@@ -917,8 +970,10 @@ static int kpb_reset(struct comp_dev *dev)
917970
kpb_reset_history_buffer(kpb->hd.c_hb);
918971
}
919972

973+
#ifndef CONFIG_AMS
920974
/* Unregister KPB from notifications */
921975
notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT);
976+
#endif
922977
/* Finally KPB is ready after reset */
923978
kpb_change_state(kpb, KPB_STATE_PREPARING);
924979

@@ -1422,6 +1477,7 @@ static int kpb_buffer_data(struct comp_dev *dev,
14221477
return ret;
14231478
}
14241479

1480+
#ifndef CONFIG_AMS
14251481
/**
14261482
* \brief Main event dispatcher.
14271483
* \param[in] arg - KPB component internal data.
@@ -1501,6 +1557,7 @@ static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli)
15011557

15021558
return ret;
15031559
}
1560+
#endif /* CONFIG_AMS */
15041561

15051562
/**
15061563
* \brief Prepare history buffer for draining.

0 commit comments

Comments
 (0)