Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ static int kpb_prepare(struct comp_dev *dev)
/* Init private data */
cd->kpb_no_of_clients = 0;
cd->buffered_data = 0;
cd->state = KPB_STATE_BUFFERING;

/* Init history buffer */
kpb_clear_history_buffer(cd->history_buffer);
Expand Down Expand Up @@ -437,16 +436,12 @@ static int kpb_reset(struct comp_dev *dev)
/* Reset history buffer */
kpb->is_internal_buffer_full = false;
kpb_clear_history_buffer(kpb->history_buffer);

/* Reset amount of buffered data */
kpb->buffered_data = 0;

/* Unregister KPB for async notification */
notifier_unregister(&kpb->kpb_events);

/* Reset KPB state to initial buffering state */
kpb->state = KPB_STATE_BUFFERING;

return comp_set_state(dev, COMP_TRIGGER_RESET);
}

Expand Down Expand Up @@ -474,17 +469,15 @@ static int kpb_copy(struct comp_dev *dev)
/* Get source and sink buffers */
source = list_first_item(&dev->bsource_list, struct comp_buffer,
sink_list);
sink = (kpb->state == KPB_STATE_BUFFERING) ? kpb->rt_sink
: kpb->cli_sink;

/* Pause selector copy during draining and/or draining on demand.
* We keep selector in this "paused" state as long as draining
* is going and later during direct copy to client's/host sink,
* in so called "draining on demand" state. In order to rearm
* detection algorithm kpb_reset is needed.
*/
if (kpb->state != KPB_STATE_BUFFERING)
/* Stop copying downstream if in draining */
if (kpb->state == KPB_STATE_DRAINING_ON_DEMAND) {
comp_update_buffer_consume(source, source->avail);
return PPL_STATUS_PATH_STOP;
}

sink = (kpb->state == KPB_STATE_BUFFERING) ? kpb->rt_sink
: kpb->cli_sink;

/* Process source data */
/* Check if there are valid pointers */
Expand Down Expand Up @@ -795,6 +788,7 @@ static void kpb_init_draining(struct comp_data *kpb, struct kpb_client *cli)
comp_set_attribute(kpb->cli_sink->sink,
COMP_ATTR_COPY_BLOCKING, 1);

kpb->state = KPB_STATE_DRAINING_ON_DEMAND;
/* Schedule draining task */
schedule_task(&kpb->draining_task, 0, 0,
SOF_SCHEDULE_FLAG_IDLE);
Expand Down Expand Up @@ -855,7 +849,7 @@ static uint64_t kpb_draining_task(void *arg)
/* Draining is done. Now switch KPB to copy real time stream
* to client's sink
*/
*draining_data->state = KPB_STATE_DRAINING_ON_DEMAND;
*draining_data->state = KPB_STATE_REALTIME;

/* Reset host-sink copy mode back to unblocking */
comp_set_attribute(sink->sink, COMP_ATTR_COPY_BLOCKING, 0);
Expand Down
1 change: 1 addition & 0 deletions src/include/sof/audio/kpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
enum kpb_state {
KPB_STATE_BUFFERING = 0,
KPB_STATE_DRAINING_ON_DEMAND,
KPB_STATE_REALTIME,
};

enum kpb_event {
Expand Down